27 #include "tdehtmlview.moc"
29 #include "tdehtmlview.h"
31 #include "tdehtml_part.h"
32 #include "tdehtml_events.h"
34 #include "html/html_documentimpl.h"
35 #include "html/html_inlineimpl.h"
36 #include "html/html_formimpl.h"
37 #include "rendering/render_arena.h"
38 #include "rendering/render_canvas.h"
39 #include "rendering/render_frames.h"
40 #include "rendering/render_replaced.h"
41 #include "rendering/render_layer.h"
42 #include "rendering/render_line.h"
43 #include "rendering/render_table.h"
45 #define protected public
46 #include "rendering/render_text.h"
48 #include "xml/dom2_eventsimpl.h"
49 #include "css/cssstyleselector.h"
50 #include "css/csshelper.h"
51 #include "misc/htmlhashes.h"
52 #include "misc/helper.h"
53 #include "misc/loader.h"
54 #include "tdehtml_settings.h"
55 #include "tdehtml_printsettings.h"
57 #include "tdehtmlpart_p.h"
59 #ifndef TDEHTML_NO_CARET
60 #include "tdehtml_caret_p.h"
61 #include "xml/dom2_rangeimpl.h"
64 #include <tdeapplication.h>
67 #include <kdialogbase.h>
68 #include <kiconloader.h>
71 #include <knotifyclient.h>
73 #include <ksimpleconfig.h>
74 #include <kstandarddirs.h>
75 #include <tdestdaccel.h>
76 #include <kstringhandler.h>
81 #include <tqobjectlist.h>
82 #include <tqpaintdevicemetrics.h>
83 #include <tqpainter.h>
84 #include <tqptrdict.h>
85 #include <tqtooltip.h>
87 #include <tqstylesheet.h>
89 #include <tqvaluevector.h>
102 #define PAINT_BUFFER_HEIGHT 128
106 void dumpLineBoxes(RenderFlow *flow);
111 using namespace tdehtml;
112 class TDEHTMLToolTip;
115 #ifndef TQT_NO_TOOLTIP
117 class TDEHTMLToolTip :
public TQToolTip
120 TDEHTMLToolTip(
TDEHTMLView *view, TDEHTMLViewPrivate* vp) : TQToolTip(view->viewport())
127 virtual void maybeTip(
const TQPoint &);
131 TDEHTMLViewPrivate* m_viewprivate;
136 class TDEHTMLViewPrivate {
137 friend class TDEHTMLToolTip;
140 enum PseudoFocusNodes {
146 enum CompletedState {
153 : underMouse( 0 ), underMouseNonShared( 0 ), visibleWidgets( 107 )
154 #ifndef NO_SMOOTH_SCROLL_HACK
155 , dx(0), dy(0), ddx(0), ddy(0), rdx(0), rdy(0), scrolling(false)
158 #ifndef TDEHTML_NO_CARET
159 m_caretViewContext = 0;
162 postponed_autorepeat = NULL;
164 vmode = TQScrollView::Auto;
165 hmode = TQScrollView::Auto;
170 prevScrollbarVisible =
true;
172 possibleTripleClick =
false;
173 emitCompletedAfterRepaint = CSNone;
174 cursor_icon_widget = NULL;
175 m_mouseScrollTimer = 0;
176 m_mouseScrollIndicator = 0;
178 ~TDEHTMLViewPrivate()
180 delete formCompletions;
182 delete paintBuffer; paintBuffer =0;
183 delete vertPaintBuffer;
184 delete postponed_autorepeat;
187 if (underMouseNonShared)
188 underMouseNonShared->deref();
190 #ifndef TDEHTML_NO_CARET
191 delete m_caretViewContext;
192 delete m_editorContext;
194 delete cursor_icon_widget;
195 delete m_mouseScrollTimer;
196 delete m_mouseScrollIndicator;
203 if (underMouseNonShared)
204 underMouseNonShared->deref();
205 underMouseNonShared = 0;
207 useSlowRepaints =
false;
208 tabMovePending =
false;
209 lastTabbingDirection =
true;
210 pseudoFocusNode = PFNone;
211 #ifndef TDEHTML_NO_SCROLLBARS
217 vmode = TQScrollView::AlwaysOff;
218 hmode = TQScrollView::AlwaysOff;
225 scrollBarMoved =
false;
226 contentsMoving =
false;
227 ignoreWheelEvents =
false;
236 isDoubleClick =
false;
237 scrollingSelf =
false;
238 delete postponed_autorepeat;
239 postponed_autorepeat = NULL;
243 scrollSuspended =
false;
244 scrollSuspendPreActivate =
false;
246 firstRelayout =
true;
247 needsFullRepaint =
true;
249 layoutSchedulingEnabled =
true;
251 updateRegion = TQRegion();
252 m_dialogsAllowed =
true;
253 #ifndef TDEHTML_NO_CARET
254 if (m_caretViewContext) {
255 m_caretViewContext->caretMoved =
false;
256 m_caretViewContext->keyReleasePending =
false;
259 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
260 typeAheadActivated =
false;
262 accessKeysActivated =
false;
263 accessKeysPreActivate =
false;
266 TDEHTMLFactory::ref();
267 accessKeysEnabled = TDEHTMLFactory::defaultHTMLSettings()->accessKeysEnabled();
268 TDEHTMLFactory::deref();
270 emitCompletedAfterRepaint = CSNone;
272 void newScrollTimer(TQWidget *view,
int tid)
275 view->killTimer(scrollTimerId);
277 scrollSuspended =
false;
279 enum ScrollDirection { ScrollLeft, ScrollRight, ScrollUp, ScrollDown };
281 void adjustScroller(TQWidget *view, ScrollDirection direction, ScrollDirection oppositedir)
283 static const struct {
int msec, pixels; } timings [] = {
284 {320,1}, {224,1}, {160,1}, {112,1}, {80,1}, {56,1}, {40,1},
285 {28,1}, {20,1}, {20,2}, {20,3}, {20,4}, {20,6}, {20,8}, {0,0}
287 if (!scrollTimerId ||
288 (
static_cast<int>(scrollDirection) != direction &&
289 (
static_cast<int>(scrollDirection) != oppositedir || scrollSuspended))) {
291 scrollBy = timings[scrollTiming].pixels;
292 scrollDirection = direction;
293 newScrollTimer(view, view->startTimer(timings[scrollTiming].msec));
294 }
else if (scrollDirection == direction &&
295 timings[scrollTiming+1].msec && !scrollSuspended) {
296 scrollBy = timings[++scrollTiming].pixels;
297 newScrollTimer(view, view->startTimer(timings[scrollTiming].msec));
298 }
else if (scrollDirection == oppositedir) {
300 scrollBy = timings[--scrollTiming].pixels;
301 newScrollTimer(view, view->startTimer(timings[scrollTiming].msec));
304 scrollSuspended =
false;
307 #ifndef TDEHTML_NO_CARET
311 CaretViewContext *caretViewContext() {
312 if (!m_caretViewContext) m_caretViewContext =
new CaretViewContext();
313 return m_caretViewContext;
318 EditorContext *editorContext() {
319 if (!m_editorContext) m_editorContext =
new EditorContext();
320 return m_editorContext;
326 unsigned int pixelbooth;
327 unsigned int repaintbooth;
331 TQPixmap *paintBuffer;
332 TQPixmap *vertPaintBuffer;
333 NodeImpl *underMouse;
334 NodeImpl *underMouseNonShared;
336 bool tabMovePending:1;
337 bool lastTabbingDirection:1;
338 PseudoFocusNodes pseudoFocusNode:2;
339 bool scrollBarMoved:1;
340 bool contentsMoving:1;
342 TQScrollView::ScrollBarMode vmode;
343 TQScrollView::ScrollBarMode hmode;
344 bool prevScrollbarVisible:1;
346 bool useSlowRepaints:1;
347 bool ignoreWheelEvents:1;
349 int borderX, borderY;
354 int clickX, clickY, clickCount;
357 int prevMouseX, prevMouseY;
360 TQKeyEvent* postponed_autorepeat;
366 ScrollDirection scrollDirection :2;
367 bool scrollSuspended :1;
368 bool scrollSuspendPreActivate :1;
370 bool firstRelayout :1;
371 bool layoutSchedulingEnabled :1;
372 bool needsFullRepaint :1;
374 bool possibleTripleClick :1;
376 bool m_dialogsAllowed :1;
377 TQRegion updateRegion;
378 TDEHTMLToolTip *tooltip;
379 TQPtrDict<TQWidget> visibleWidgets;
380 #ifndef TDEHTML_NO_CARET
381 CaretViewContext *m_caretViewContext;
382 EditorContext *m_editorContext;
384 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
388 bool typeAheadActivated;
390 bool accessKeysEnabled;
391 bool accessKeysActivated;
392 bool accessKeysPreActivate;
393 CompletedState emitCompletedAfterRepaint;
395 TQWidget* cursor_icon_widget;
398 short m_mouseScroll_byX;
399 short m_mouseScroll_byY;
400 TQTimer *m_mouseScrollTimer;
401 TQWidget *m_mouseScrollIndicator;
402 #ifndef NO_SMOOTH_SCROLL_HACK
415 #ifndef TQT_NO_TOOLTIP
426 static bool findImageMapRect(HTMLImageElementImpl *img,
const TQPoint &scrollOfs,
427 const TQPoint &p, TQRect &r, TQString &s)
429 HTMLMapElementImpl* map;
430 if (img && img->getDocument()->isHTMLDocument() &&
431 (map =
static_cast<HTMLDocumentImpl*
>(img->getDocument())->getMap(img->imageMap()))) {
432 RenderObject::NodeInfo info(
true,
false);
433 RenderObject *rend = img->renderer();
435 if (!rend || !rend->absolutePosition(ax, ay))
438 bool inside = map->mapMouseEvent(p.x() - ax + scrollOfs.x(),
439 p.y() - ay + scrollOfs.y(), rend->contentWidth(),
440 rend->contentHeight(), info);
441 if (inside && info.URLElement()) {
442 HTMLAreaElementImpl *area =
static_cast<HTMLAreaElementImpl *
>(info.URLElement());
443 Q_ASSERT(area->id() == ID_AREA);
444 s = area->getAttribute(ATTR_TITLE).string();
445 TQRegion reg = area->cachedRegion();
446 if (!s.isEmpty() && !reg.isEmpty()) {
447 r = reg.boundingRect();
456 void TDEHTMLToolTip::maybeTip(
const TQPoint& p)
458 DOM::NodeImpl *node = m_viewprivate->underMouseNonShared;
461 if ( node->isElementNode() ) {
462 DOM::ElementImpl *e =
static_cast<DOM::ElementImpl*
>( node );
468 if (e->id() == ID_IMG && !e->getAttribute( ATTR_USEMAP ).isEmpty()) {
469 found = findImageMapRect(
static_cast<HTMLImageElementImpl *
>(e),
470 m_view->viewportToContents(TQPoint(0, 0)), p, r, s);
473 s = e->getAttribute( ATTR_TITLE ).string();
476 region |= TQRect( m_view->contentsToViewport( r.topLeft() ), r.size() );
477 if ( !s.isEmpty() ) {
478 tip( region, TQStyleSheet::convertFromPlainText( s, TQStyleSheetItem::WhiteSpaceNormal ) );
482 node = node->parentNode();
488 : TQScrollView( parent, name, (WFlags)(WResizeNoErase | WRepaintNoErase) )
493 d =
new TDEHTMLViewPrivate;
494 TQScrollView::setVScrollBarMode(d->vmode);
495 TQScrollView::setHScrollBarMode(d->hmode);
496 connect(kapp, TQ_SIGNAL(tdedisplayPaletteChanged()),
this, TQ_SLOT(slotPaletteChanged()));
497 connect(
this, TQ_SIGNAL(contentsMoving(
int,
int)),
this, TQ_SLOT(slotScrollBarMoved()));
502 static_cast<TDEHTMLView *
>(viewport())->setWFlags(WPaintUnclipped);
504 setResizePolicy(Manual);
505 viewport()->setMouseTracking(
true);
506 viewport()->setBackgroundMode(NoBackground);
508 KImageIO::registerFormats();
510 #ifndef TQT_NO_TOOLTIP
511 d->tooltip =
new TDEHTMLToolTip(
this, d );
514 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
515 connect(&d->timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(findTimeout()));
521 #ifndef NO_SMOOTH_SCROLL_HACK
523 connect(&d->timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(scrollTick()));
528 TDEHTMLView::~TDEHTMLView()
535 DOM::DocumentImpl *doc = m_part->xmlDocImpl();
542 void TDEHTMLView::init()
544 if(!d->paintBuffer) d->paintBuffer =
new TQPixmap(PAINT_BUFFER_HEIGHT, PAINT_BUFFER_HEIGHT);
545 if(!d->vertPaintBuffer)
546 d->vertPaintBuffer =
new TQPixmap(10, PAINT_BUFFER_HEIGHT);
547 if(!d->tp) d->tp =
new TQPainter();
549 setFocusPolicy(TQWidget::StrongFocus);
550 viewport()->setFocusProxy(
this);
557 installEventFilter(
this);
559 setAcceptDrops(
true);
560 TQSize s = viewportSize(4095, 4095);
561 resizeContents(s.width(), s.height());
564 void TDEHTMLView::clear()
567 setStaticBackground(
true);
568 #ifndef TDEHTML_NO_CARET
572 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
573 if( d->typeAheadActivated )
576 if (d->accessKeysEnabled && d->accessKeysActivated)
578 viewport()->unsetCursor();
579 if ( d->cursor_icon_widget )
580 d->cursor_icon_widget->hide();
585 TQScrollView::setHScrollBarMode(d->hmode);
586 TQScrollView::setVScrollBarMode(d->vmode);
587 verticalScrollBar()->setEnabled(
false );
588 horizontalScrollBar()->setEnabled(
false );
591 void TDEHTMLView::hideEvent(TQHideEvent* e)
593 TQScrollView::hideEvent(e);
594 if ( m_part && m_part->xmlDocImpl() )
595 m_part->xmlDocImpl()->docLoader()->pauseAnimations();
598 void TDEHTMLView::showEvent(TQShowEvent* e)
600 TQScrollView::showEvent(e);
601 if ( m_part && m_part->xmlDocImpl() )
602 m_part->xmlDocImpl()->docLoader()->resumeAnimations();
605 void TDEHTMLView::resizeEvent (TQResizeEvent* e)
607 int dw = e->oldSize().width() - e->size().width();
608 int dh = e->oldSize().height() - e->size().height();
612 dw = dw>0 ? kMax(0, contentsWidth()-dw) : contentsWidth();
613 dh = dh>0 ? kMax(0, contentsHeight()-dh) : contentsHeight();
615 resizeContents(dw, dh);
617 TQScrollView::resizeEvent(e);
619 if ( m_part && m_part->xmlDocImpl() )
620 m_part->xmlDocImpl()->dispatchWindowEvent( EventImpl::RESIZE_EVENT,
false,
false );
623 void TDEHTMLView::viewportResizeEvent (TQResizeEvent* e)
625 TQScrollView::viewportResizeEvent(e);
630 if (d->layoutSchedulingEnabled)
632 #ifndef TDEHTML_NO_CARET
635 recalcAndStoreCaretPos();
640 TDEApplication::sendPostedEvents(viewport(), TQEvent::Paint);
644 void TDEHTMLView::drawContents( TQPainter*)
648 void TDEHTMLView::drawContents( TQPainter *p,
int ex,
int ey,
int ew,
int eh )
652 if ( d->timer.elapsed() > 5000 ) {
653 tqDebug(
"drawed %d pixels in %d repaints the last %d milliseconds",
654 d->pixelbooth, d->repaintbooth, d->timer.elapsed() );
659 d->pixelbooth += ew*eh;
664 if(!m_part || !m_part->xmlDocImpl() || !m_part->xmlDocImpl()->renderer()) {
665 p->fillRect(ex, ey, ew, eh, palette().active().brush(TQColorGroup::Base));
667 }
else if ( d->complete &&
static_cast<RenderCanvas*
>(m_part->xmlDocImpl()->renderer())->needsLayout() ) {
669 unscheduleRelayout();
674 kdDebug( 6000 ) <<
"WARNING: drawContents reentered! " <<
endl;
679 TQPoint pt = contentsToViewport(TQPoint(ex, ey));
680 TQRegion cr = TQRect(pt.x(), pt.y(), ew, eh);
683 for (TQPtrDictIterator<TQWidget> it(d->visibleWidgets); it.current(); ++it) {
684 TQWidget *w = it.current();
685 RenderWidget* rw =
static_cast<RenderWidget*
>( it.currentKey() );
686 if (w && rw && !rw->isTDEHTMLWidget()) {
688 rw->absolutePosition(x, y);
689 contentsToViewport(x, y, x, y);
690 int pbx = rw->borderLeft()+rw->paddingLeft();
691 int pby = rw->borderTop()+rw->paddingTop();
692 TQRect g = TQRect(x+pbx, y+pby,
693 rw->width()-pbx-rw->borderRight()-rw->paddingRight(),
694 rw->height()-pby-rw->borderBottom()-rw->paddingBottom());
695 if ( !rw->isFrame() && ((g.top() > pt.y()+eh) || (g.bottom() <= pt.y()) ||
696 (g.right() <= pt.x()) || (g.left() > pt.x()+ew) ))
698 RenderLayer* rl = rw->needsMask() ? rw->enclosingStackingContext() : 0;
699 TQRegion mask = rl ? rl->getMask() : TQRegion();
700 if (!mask.isNull()) {
702 o = contentsToViewport(o);
703 mask.translate(o.x(),o.y());
704 mask = mask.intersect( TQRect(g.x(),g.y(),g.width(),g.height()) );
721 #ifndef DEBUG_NO_PAINT_BUFFER
722 p->setClipRegion(cr);
724 if (eh > PAINT_BUFFER_HEIGHT && ew <= 10) {
725 if ( d->vertPaintBuffer->height() < visibleHeight() )
726 d->vertPaintBuffer->resize(10, visibleHeight());
727 d->tp->begin(d->vertPaintBuffer);
728 d->tp->translate(-ex, -ey);
729 d->tp->fillRect(ex, ey, ew, eh, palette().active().brush(TQColorGroup::Base));
730 m_part->xmlDocImpl()->renderer()->layer()->paint(d->tp, TQRect(ex, ey, ew, eh));
732 p->drawPixmap(ex, ey, *d->vertPaintBuffer, 0, 0, ew, eh);
735 if ( d->paintBuffer->width() < visibleWidth() )
736 d->paintBuffer->resize(visibleWidth(),PAINT_BUFFER_HEIGHT);
740 int ph = eh-py < PAINT_BUFFER_HEIGHT ? eh-py : PAINT_BUFFER_HEIGHT;
741 d->tp->begin(d->paintBuffer);
742 d->tp->translate(-ex, -ey-py);
743 d->tp->fillRect(ex, ey+py, ew, ph, palette().active().brush(TQColorGroup::Base));
744 m_part->xmlDocImpl()->renderer()->layer()->paint(d->tp, TQRect(ex, ey+py, ew, ph));
747 p->drawPixmap(ex, ey+py, *d->paintBuffer, 0, 0, ew, ph);
748 py += PAINT_BUFFER_HEIGHT;
753 ex = contentsX(); ey = contentsY();
754 ew = visibleWidth(); eh = visibleHeight();
755 TQRect pr(ex,ey,ew,eh);
756 kdDebug() <<
"[" << ++cnt <<
"]" <<
" clip region: " << pr <<
endl;
759 p->fillRect(ex, ey, ew, eh, palette().active().brush(TQColorGroup::Base));
760 m_part->xmlDocImpl()->renderer()->layer()->paint(p, pr);
763 #ifndef TDEHTML_NO_CARET
764 if (d->m_caretViewContext && d->m_caretViewContext->visible) {
765 TQRect pos(d->m_caretViewContext->x, d->m_caretViewContext->y,
766 d->m_caretViewContext->width, d->m_caretViewContext->height);
767 if (pos.intersects(TQRect(ex, ey, ew, eh))) {
768 p->setRasterOp(XorROP);
770 if (pos.width() == 1)
771 p->drawLine(pos.topLeft(), pos.bottomRight());
773 p->fillRect(pos, white);
782 tdehtml::DrawContentsEvent
event( p, ex, ey, ew, eh );
783 TQApplication::sendEvent( m_part, &event );
794 void TDEHTMLView::setMarginHeight(
int h)
802 if( m_part && m_part->xmlDocImpl() ) {
803 DOM::DocumentImpl *document = m_part->xmlDocImpl();
805 tdehtml::RenderCanvas* canvas =
static_cast<tdehtml::RenderCanvas *
>(document->renderer());
806 if ( !canvas )
return;
808 d->layoutSchedulingEnabled=
false;
811 RenderObject * ref = 0;
812 RenderObject* root = document->documentElement() ? document->documentElement()->renderer() : 0;
814 if (document->isHTMLDocument()) {
815 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(document)->body();
816 if(body && body->renderer() && body->id() == ID_FRAMESET) {
817 TQScrollView::setVScrollBarMode(AlwaysOff);
818 TQScrollView::setHScrollBarMode(AlwaysOff);
819 body->renderer()->setNeedsLayout(
true);
827 d->tooltip =
new TDEHTMLToolTip(
this, d );
830 ref = (!body || root->style()->hidesOverflow()) ? root : body->renderer();
836 if( ref->style()->overflowX() == OHIDDEN ) {
837 if (d->hmode == Auto) TQScrollView::setHScrollBarMode(AlwaysOff);
838 }
else if (ref->style()->overflowX() == OSCROLL ) {
839 if (d->hmode == Auto) TQScrollView::setHScrollBarMode(AlwaysOn);
841 if (TQScrollView::hScrollBarMode() == AlwaysOff) TQScrollView::setHScrollBarMode(d->hmode);
842 }
if ( ref->style()->overflowY() == OHIDDEN ) {
843 if (d->vmode == Auto) TQScrollView::setVScrollBarMode(AlwaysOff);
844 }
else if (ref->style()->overflowY() == OSCROLL ) {
845 if (d->vmode == Auto) TQScrollView::setVScrollBarMode(AlwaysOn);
847 if (TQScrollView::vScrollBarMode() == AlwaysOff) TQScrollView::setVScrollBarMode(d->vmode);
850 d->needsFullRepaint = d->firstRelayout;
851 if (_height != visibleHeight() || _width != visibleWidth()) {;
852 d->needsFullRepaint =
true;
853 _height = visibleHeight();
854 _width = visibleWidth();
861 if (d->firstRelayout) {
864 d->firstRelayout =
false;
865 verticalScrollBar()->setEnabled(
true );
866 horizontalScrollBar()->setEnabled(
true );
869 ElementImpl *listitem = m_part->xmlDocImpl()->getElementById(
"__test_element__");
870 if (listitem)
kdDebug(6000) <<
"after layout, before repaint" <<
endl;
871 if (listitem) dumpLineBoxes(
static_cast<RenderFlow *
>(listitem->renderer()));
873 #ifndef TDEHTML_NO_CARET
876 && !d->complete && d->m_caretViewContext
877 && !d->m_caretViewContext->caretMoved) {
880 recalcAndStoreCaretPos();
884 if (d->accessKeysEnabled && d->accessKeysActivated) {
885 emit hideAccessKeys();
891 _width = visibleWidth();
893 killTimer(d->layoutTimerId);
894 d->layoutTimerId = 0;
895 d->layoutSchedulingEnabled=
true;
898 void TDEHTMLView::closeChildDialogs()
900 TQObjectList *dlgs = queryList(
"TQDialog");
901 for (TQObject *dlg = dlgs->first(); dlg; dlg = dlgs->next())
905 if ( dlgbase->testWFlags( WShowModal ) ) {
906 kdDebug(6000) <<
"closeChildDialogs: closing dialog " << dlgbase <<
endl;
914 kdWarning() <<
"closeChildDialogs: not a KDialogBase! Don't use QDialogs in KDE! " <<
static_cast<TQWidget*
>(dlg) <<
endl;
915 static_cast<TQWidget*
>(dlg)->hide();
919 d->m_dialogsAllowed =
false;
922 bool TDEHTMLView::dialogsAllowed() {
923 bool allowed = d->m_dialogsAllowed;
926 allowed &= p->
view()->dialogsAllowed();
930 void TDEHTMLView::closeEvent( TQCloseEvent* ev )
933 TQScrollView::closeEvent( ev );
941 void TDEHTMLView::viewportMousePressEvent( TQMouseEvent *_mouse )
943 if (!m_part->xmlDocImpl())
return;
944 if (d->possibleTripleClick && ( _mouse->button() & TQt::MouseButtonMask ) == TQt::LeftButton)
946 viewportMouseDoubleClickEvent( _mouse );
951 viewportToContents(_mouse->x(), _mouse->y(), xm, ym);
954 d->isDoubleClick =
false;
956 DOM::NodeImpl::MouseEvent mev( _mouse->stateAfter(), DOM::NodeImpl::MousePress );
957 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
961 if ( (_mouse->button() == TQt::MidButton) &&
962 !m_part->d->m_bOpenMiddleClick && !d->m_mouseScrollTimer &&
963 mev.url.isNull() && (mev.innerNode.elementId() != ID_INPUT) ) {
964 TQPoint point = mapFromGlobal( _mouse->globalPos() );
966 d->m_mouseScroll_byX = 0;
967 d->m_mouseScroll_byY = 0;
969 d->m_mouseScrollTimer =
new TQTimer(
this );
970 connect( d->m_mouseScrollTimer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(slotMouseScrollTimer()) );
972 if ( !d->m_mouseScrollIndicator ) {
973 TQPixmap pixmap, icon;
974 pixmap.resize( 48, 48 );
975 pixmap.fill( TQColor( tqRgba( 127, 127, 127, 127 ) ) );
977 TQPainter p( &pixmap );
979 p.drawPixmap( 16, 0, icon );
981 p.drawPixmap( 0, 16, icon );
983 p.drawPixmap( 16, 32,icon );
985 p.drawPixmap( 32, 16, icon );
986 p.drawEllipse( 23, 23, 2, 2 );
988 d->m_mouseScrollIndicator =
new TQWidget(
this, 0 );
989 d->m_mouseScrollIndicator->setFixedSize( 48, 48 );
990 d->m_mouseScrollIndicator->setPaletteBackgroundPixmap( pixmap );
992 d->m_mouseScrollIndicator->move( point.x()-24, point.y()-24 );
994 bool hasHorBar = visibleWidth() < contentsWidth();
995 bool hasVerBar = visibleHeight() < contentsHeight();
999 if ( config->
readBoolEntry(
"ShowMouseScrollIndicator",
true ) ) {
1000 d->m_mouseScrollIndicator->show();
1001 d->m_mouseScrollIndicator->unsetCursor();
1003 TQBitmap mask = d->m_mouseScrollIndicator->paletteBackgroundPixmap()->createHeuristicMask(
true );
1005 if ( hasHorBar && !hasVerBar ) {
1006 TQBitmap bm( 16, 16,
true );
1007 bitBlt( &mask, 16, 0, &bm, 0, 0, -1, -1 );
1008 bitBlt( &mask, 16, 32, &bm, 0, 0, -1, -1 );
1009 d->m_mouseScrollIndicator->setCursor( KCursor::SizeHorCursor );
1011 else if ( !hasHorBar && hasVerBar ) {
1012 TQBitmap bm( 16, 16,
true );
1013 bitBlt( &mask, 0, 16, &bm, 0, 0, -1, -1 );
1014 bitBlt( &mask, 32, 16, &bm, 0, 0, -1, -1 );
1015 d->m_mouseScrollIndicator->setCursor( KCursor::SizeVerCursor );
1018 d->m_mouseScrollIndicator->setCursor( KCursor::SizeAllCursor );
1020 d->m_mouseScrollIndicator->setMask( mask );
1023 if ( hasHorBar && !hasVerBar )
1024 viewport()->setCursor( KCursor::SizeHorCursor );
1025 else if ( !hasHorBar && hasVerBar )
1026 viewport()->setCursor( KCursor::SizeVerCursor );
1028 viewport()->setCursor( KCursor::SizeAllCursor );
1033 else if ( d->m_mouseScrollTimer ) {
1034 delete d->m_mouseScrollTimer;
1035 d->m_mouseScrollTimer = 0;
1037 if ( d->m_mouseScrollIndicator )
1038 d->m_mouseScrollIndicator->hide();
1045 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1046 d->clickCount,_mouse,
true,DOM::NodeImpl::MousePress);
1048 tdehtml::RenderObject* r = mev.innerNode.handle() ? mev.innerNode.handle()->renderer() : 0;
1049 if (r && r->isWidget())
1052 if (!swallowEvent) {
1055 tdehtml::MousePressEvent
event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
1056 TQApplication::sendEvent( m_part, &event );
1061 void TDEHTMLView::viewportMouseDoubleClickEvent( TQMouseEvent *_mouse )
1063 if(!m_part->xmlDocImpl())
return;
1066 viewportToContents(_mouse->x(), _mouse->y(), xm, ym);
1068 kdDebug( 6000 ) <<
"mouseDblClickEvent: x=" << xm <<
", y=" << ym <<
endl;
1070 d->isDoubleClick =
true;
1072 DOM::NodeImpl::MouseEvent mev( _mouse->stateAfter(), DOM::NodeImpl::MouseDblClick );
1073 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1077 if (d->clickCount > 0 &&
1078 TQPoint(d->clickX-xm,d->clickY-ym).manhattanLength() <= TQApplication::startDragDistance())
1085 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1086 d->clickCount,_mouse,
true,DOM::NodeImpl::MouseDblClick);
1088 tdehtml::RenderObject* r = mev.innerNode.handle() ? mev.innerNode.handle()->renderer() : 0;
1089 if (r && r->isWidget())
1092 if (!swallowEvent) {
1093 tdehtml::MouseDoubleClickEvent
event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode, d->clickCount );
1094 TQApplication::sendEvent( m_part, &event );
1097 d->possibleTripleClick=
true;
1098 TQTimer::singleShot(TQApplication::doubleClickInterval(),
this,TQ_SLOT(tripleClickTimeout()));
1101 void TDEHTMLView::tripleClickTimeout()
1103 d->possibleTripleClick =
false;
1107 static inline void forwardPeripheralEvent(tdehtml::RenderWidget* r, TQMouseEvent* me,
int x,
int y)
1111 r->absolutePosition(absx, absy);
1112 TQPoint p(x-absx, y-absy);
1113 TQMouseEvent fw(me->type(), p, me->button(), me->state());
1114 TQWidget* w = r->widget();
1115 TQScrollView* sc = ::tqt_cast<TQScrollView*>(w);
1116 if (sc && !::tqt_cast<TQListBox*>(w))
1117 static_cast<tdehtml::RenderWidget::ScrollViewEventPropagator*
>(sc)->sendEvent(
static_cast<TQEvent*
>(&fw));
1119 static_cast<tdehtml::RenderWidget::EventPropagator*
>(w)->sendEvent(
static_cast<TQEvent*
>(&fw));
1123 static bool targetOpensNewWindow(
TDEHTMLPart *part, TQString target)
1125 if (!target.isEmpty() && (target.lower() !=
"_top") &&
1126 (target.lower() !=
"_self") && (target.lower() !=
"_parent")) {
1127 if (target.lower() ==
"_blank")
1139 void TDEHTMLView::viewportMouseMoveEvent( TQMouseEvent * _mouse )
1141 if ( d->m_mouseScrollTimer ) {
1142 TQPoint point = mapFromGlobal( _mouse->globalPos() );
1144 int deltaX = point.x() - d->m_mouseScrollIndicator->x() - 24;
1145 int deltaY = point.y() - d->m_mouseScrollIndicator->y() - 24;
1147 (deltaX > 0) ? d->m_mouseScroll_byX = 1 : d->m_mouseScroll_byX = -1;
1148 (deltaY > 0) ? d->m_mouseScroll_byY = 1 : d->m_mouseScroll_byY = -1;
1150 double adX = TQABS(deltaX)/30.0;
1151 double adY = TQABS(deltaY)/30.0;
1153 d->m_mouseScroll_byX = kMax(kMin(d->m_mouseScroll_byX *
int(adX*adX), SHRT_MAX), SHRT_MIN);
1154 d->m_mouseScroll_byY = kMax(kMin(d->m_mouseScroll_byY *
int(adY*adY), SHRT_MAX), SHRT_MIN);
1156 if (d->m_mouseScroll_byX == 0 && d->m_mouseScroll_byY == 0) {
1157 d->m_mouseScrollTimer->stop();
1159 else if (!d->m_mouseScrollTimer->isActive()) {
1160 d->m_mouseScrollTimer->changeInterval( 20 );
1164 if(!m_part->xmlDocImpl())
return;
1167 viewportToContents(_mouse->x(), _mouse->y(), xm, ym);
1169 DOM::NodeImpl::MouseEvent mev( _mouse->stateAfter(), DOM::NodeImpl::MouseMove );
1171 m_part->xmlDocImpl()->prepareMouseEvent( _mouse->state() & TQt::MouseButtonMask , xm, ym, &mev );
1177 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEMOVE_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
false,
1178 0,_mouse,
true,DOM::NodeImpl::MouseMove);
1180 if (d->clickCount > 0 &&
1181 TQPoint(d->clickX-xm,d->clickY-ym).manhattanLength() > TQApplication::startDragDistance()) {
1186 m_part->executeScheduledScript();
1188 DOM::NodeImpl* fn = m_part->xmlDocImpl()->focusNode();
1189 if (fn && fn != mev.innerNode.handle() &&
1190 fn->renderer() && fn->renderer()->isWidget()) {
1191 forwardPeripheralEvent(
static_cast<tdehtml::RenderWidget*
>(fn->renderer()), _mouse, xm, ym);
1194 tdehtml::RenderObject* r = mev.innerNode.handle() ? mev.innerNode.handle()->renderer() : 0;
1195 tdehtml::RenderStyle* style = (r && r->style()) ? r->style() : 0;
1197 bool mailtoCursor =
false;
1198 bool newWindowCursor =
false;
1199 switch ( style ? style->cursor() : CURSOR_AUTO) {
1201 if ( r && r->isText() )
1203 if ( mev.url.length() && m_part->settings()->changeCursor() ) {
1205 if (mev.url.string().startsWith(
"mailto:") && mev.url.string().find(
'@')>0)
1206 mailtoCursor =
true;
1208 newWindowCursor = targetOpensNewWindow( m_part, mev.target.string() );
1211 if (r && r->isFrameSet() && !
static_cast<RenderFrameSet*
>(r)->noResize())
1212 c = TQCursor(
static_cast<RenderFrameSet*
>(r)->cursorShape());
1218 case CURSOR_POINTER:
1220 if (mev.url.string().startsWith(
"mailto:") && mev.url.string().find(
'@')>0)
1221 mailtoCursor =
true;
1223 newWindowCursor = targetOpensNewWindow( m_part, mev.target.string() );
1225 case CURSOR_PROGRESS:
1231 case CURSOR_E_RESIZE:
1232 case CURSOR_W_RESIZE:
1235 case CURSOR_N_RESIZE:
1236 case CURSOR_S_RESIZE:
1239 case CURSOR_NE_RESIZE:
1240 case CURSOR_SW_RESIZE:
1243 case CURSOR_NW_RESIZE:
1244 case CURSOR_SE_RESIZE:
1256 case CURSOR_DEFAULT:
1260 if ( viewport()->cursor().handle() != c.handle() ) {
1263 p->
view()->viewport()->unsetCursor();
1266 viewport()->setCursor( c );
1270 if ( ( mailtoCursor || newWindowCursor ) && isVisible() && hasFocus() ) {
1274 if (d->cursor_icon_widget) {
1275 const TQPixmap *pm = d->cursor_icon_widget->backgroundPixmap();
1276 if (!pm || pm->serialNumber()!=icon_pixmap.serialNumber()) {
1277 delete d->cursor_icon_widget;
1278 d->cursor_icon_widget = 0;
1282 if( !d->cursor_icon_widget ) {
1283 d->cursor_icon_widget =
new TQWidget( NULL, NULL, WX11BypassWM );
1284 XSetWindowAttributes attr;
1285 attr.save_under = True;
1286 XChangeWindowAttributes( tqt_xdisplay(), d->cursor_icon_widget->winId(), CWSaveUnder, &attr );
1287 d->cursor_icon_widget->resize( icon_pixmap.width(), icon_pixmap.height());
1288 if( icon_pixmap.mask() )
1289 d->cursor_icon_widget->setMask( *icon_pixmap.mask());
1291 d->cursor_icon_widget->clearMask();
1292 d->cursor_icon_widget->setBackgroundPixmap( icon_pixmap );
1293 d->cursor_icon_widget->erase();
1295 TQPoint c_pos = TQCursor::pos();
1296 d->cursor_icon_widget->move( c_pos.x() + 15, c_pos.y() + 15 );
1297 XRaiseWindow( tqt_xdisplay(), d->cursor_icon_widget->winId());
1298 TQApplication::flushX();
1299 d->cursor_icon_widget->show();
1302 else if ( d->cursor_icon_widget )
1303 d->cursor_icon_widget->hide();
1305 if (r && r->isWidget()) {
1313 if (!swallowEvent) {
1314 tdehtml::MouseMoveEvent
event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
1315 TQApplication::sendEvent( m_part, &event );
1319 void TDEHTMLView::viewportMouseReleaseEvent( TQMouseEvent * _mouse )
1321 bool swallowEvent =
false;
1323 viewportToContents(_mouse->x(), _mouse->y(), xm, ym);
1324 DOM::NodeImpl::MouseEvent mev( _mouse->stateAfter(), DOM::NodeImpl::MouseRelease );
1326 if ( m_part->xmlDocImpl() )
1328 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1330 swallowEvent = dispatchMouseEvent(EventImpl::MOUSEUP_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1331 d->clickCount,_mouse,
false,DOM::NodeImpl::MouseRelease);
1333 if (d->clickCount > 0 &&
1334 TQPoint(d->clickX-xm,d->clickY-ym).manhattanLength() <= TQApplication::startDragDistance()) {
1335 TQMouseEvent me(d->isDoubleClick ? TQEvent::MouseButtonDblClick : TQEvent::MouseButtonRelease,
1336 _mouse->pos(), _mouse->button(), _mouse->state());
1337 dispatchMouseEvent(EventImpl::CLICK_EVENT, mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1338 d->clickCount, &me,
true, DOM::NodeImpl::MouseRelease);
1341 DOM::NodeImpl* fn = m_part->xmlDocImpl()->focusNode();
1342 if (fn && fn != mev.innerNode.handle() &&
1343 fn->renderer() && fn->renderer()->isWidget() &&
1344 _mouse->button() != TQt::MidButton) {
1345 forwardPeripheralEvent(
static_cast<tdehtml::RenderWidget*
>(fn->renderer()), _mouse, xm, ym);
1348 tdehtml::RenderObject* r = mev.innerNode.handle() ? mev.innerNode.handle()->renderer() : 0;
1349 if (r && r->isWidget())
1353 if (!swallowEvent) {
1354 tdehtml::MouseReleaseEvent
event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
1355 TQApplication::sendEvent( m_part, &event );
1360 bool TDEHTMLView::dispatchKeyEvent( TQKeyEvent *_ke )
1362 if (!m_part->xmlDocImpl())
1384 if( _ke == d->postponed_autorepeat )
1389 if( _ke->type() == TQEvent::KeyPress )
1391 if( !_ke->isAutoRepeat())
1393 bool ret = dispatchKeyEventHelper( _ke,
false );
1395 if( !ret && dispatchKeyEventHelper( _ke,
true ))
1401 bool ret = dispatchKeyEventHelper( _ke,
true );
1402 if( !ret && d->postponed_autorepeat )
1403 keyPressEvent( d->postponed_autorepeat );
1404 delete d->postponed_autorepeat;
1405 d->postponed_autorepeat = NULL;
1413 if ( d->postponed_autorepeat ) {
1414 delete d->postponed_autorepeat;
1415 d->postponed_autorepeat = 0;
1418 if( !_ke->isAutoRepeat()) {
1419 return dispatchKeyEventHelper( _ke,
false );
1423 d->postponed_autorepeat =
new TQKeyEvent( _ke->type(), _ke->key(), _ke->ascii(), _ke->state(),
1424 _ke->text(), _ke->isAutoRepeat(), _ke->count());
1425 if( _ke->isAccepted())
1426 d->postponed_autorepeat->accept();
1428 d->postponed_autorepeat->ignore();
1435 bool TDEHTMLView::dispatchKeyEventHelper( TQKeyEvent *_ke,
bool keypress )
1437 DOM::NodeImpl* keyNode = m_part->xmlDocImpl()->focusNode();
1439 return keyNode->dispatchKeyEvent(_ke, keypress);
1441 return m_part->xmlDocImpl()->dispatchKeyEvent(_ke, keypress);
1445 void TDEHTMLView::keyPressEvent( TQKeyEvent *_ke )
1447 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
1448 if(d->typeAheadActivated)
1451 if(_ke->key() == Key_BackSpace)
1453 d->findString = d->findString.left(d->findString.length() - 1);
1455 if(!d->findString.isEmpty())
1464 d->timer.start(3000,
true);
1468 else if(_ke->key() == Key_Escape)
1475 else if(_ke->key() == Key_Space || !TQString(_ke->text()).stripWhiteSpace().isEmpty())
1477 d->findString += _ke->text();
1481 d->timer.start(3000,
true);
1488 #ifndef TDEHTML_NO_CARET
1490 || (m_part->xmlDocImpl() && m_part->xmlDocImpl()->focusNode()
1491 && m_part->xmlDocImpl()->focusNode()->contentEditable())) {
1492 d->caretViewContext()->keyReleasePending =
true;
1493 caretKeyPressEvent(_ke);
1499 if (d->accessKeysEnabled && _ke->key() == Key_Control && _ke->state()==0 && !d->accessKeysActivated)
1501 d->accessKeysPreActivate=
true;
1506 if (_ke->key() == Key_Shift && _ke->state()==0)
1507 d->scrollSuspendPreActivate=
true;
1512 if (d->accessKeysEnabled && d->accessKeysActivated)
1514 int state = ( _ke->state() & ( ShiftButton | ControlButton | AltButton | MetaButton ));
1515 if ( state==0 || state==ShiftButton) {
1516 if (_ke->key() != Key_Shift) accessKeysTimeout();
1517 handleAccessKey( _ke );
1521 accessKeysTimeout();
1524 if ( dispatchKeyEvent( _ke )) {
1530 int offs = (clipper()->height() < 30) ? clipper()->height() : 30;
1531 if (_ke->state() & TQt::ShiftButton)
1535 scrollBy( 0, -clipper()->height() + offs );
1536 if(d->scrollSuspended)
1537 d->newScrollTimer(
this, 0);
1542 d->adjustScroller(
this, TDEHTMLViewPrivate::ScrollDown, TDEHTMLViewPrivate::ScrollUp);
1547 d->adjustScroller(
this, TDEHTMLViewPrivate::ScrollUp, TDEHTMLViewPrivate::ScrollDown);
1552 d->adjustScroller(
this, TDEHTMLViewPrivate::ScrollLeft, TDEHTMLViewPrivate::ScrollRight);
1557 d->adjustScroller(
this, TDEHTMLViewPrivate::ScrollRight, TDEHTMLViewPrivate::ScrollLeft);
1561 switch ( _ke->key() )
1565 if (!d->scrollTimerId || d->scrollSuspended)
1566 scrollBy( 0, 10 * _ke->count() );
1567 if (d->scrollTimerId)
1568 d->newScrollTimer(
this, 0);
1573 scrollBy( 0, clipper()->height() - offs );
1574 if(d->scrollSuspended)
1575 d->newScrollTimer(
this, 0);
1580 if (!d->scrollTimerId || d->scrollSuspended)
1581 scrollBy( 0, -10 * _ke->count());
1582 if (d->scrollTimerId)
1583 d->newScrollTimer(
this, 0);
1587 scrollBy( 0, -clipper()->height() + offs );
1588 if(d->scrollSuspended)
1589 d->newScrollTimer(
this, 0);
1593 if (!d->scrollTimerId || d->scrollSuspended)
1594 scrollBy( 10 * _ke->count(), 0 );
1595 if (d->scrollTimerId)
1596 d->newScrollTimer(
this, 0);
1600 if (!d->scrollTimerId || d->scrollSuspended)
1601 scrollBy( -10 * _ke->count(), 0 );
1602 if (d->scrollTimerId)
1603 d->newScrollTimer(
this, 0);
1609 if (m_part->xmlDocImpl()) {
1610 NodeImpl *n = m_part->xmlDocImpl()->focusNode();
1616 setContentsPos( 0, 0 );
1617 if(d->scrollSuspended)
1618 d->newScrollTimer(
this, 0);
1621 setContentsPos( 0, contentsHeight() - visibleHeight() );
1622 if(d->scrollSuspended)
1623 d->newScrollTimer(
this, 0);
1630 if (d->scrollTimerId)
1631 d->newScrollTimer(
this, 0);
1639 void TDEHTMLView::findTimeout()
1641 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
1642 d->typeAheadActivated =
false;
1644 m_part->setStatusBarText(i18n(
"Find stopped."), TDEHTMLPart::BarDefaultText);
1645 m_part->enableFindAheadActions(
true );
1649 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
1650 void TDEHTMLView::startFindAhead(
bool linksOnly )
1654 d->findLinksOnly =
true;
1655 m_part->setStatusBarText(i18n(
"Starting -- find links as you type"),
1656 TDEHTMLPart::BarDefaultText);
1660 d->findLinksOnly =
false;
1661 m_part->setStatusBarText(i18n(
"Starting -- find text as you type"),
1662 TDEHTMLPart::BarDefaultText);
1666 d->typeAheadActivated =
true;
1668 m_part->enableFindAheadActions(
false );
1669 d->timer.start(3000,
true);
1672 void TDEHTMLView::findAhead(
bool increase)
1676 if(d->findLinksOnly)
1678 m_part->
findText(d->findString, TDEHTMLPart::FindNoPopups |
1679 TDEHTMLPart::FindLinksOnly,
this);
1682 status = i18n(
"Link found: \"%1\".");
1687 status = i18n(
"Link not found: \"%1\".");
1692 m_part->
findText(d->findString, TDEHTMLPart::FindNoPopups,
this);
1695 status = i18n(
"Text found: \"%1\".");
1700 status = i18n(
"Text not found: \"%1\".");
1704 m_part->setStatusBarText(status.arg(d->findString.lower()),
1705 TDEHTMLPart::BarDefaultText);
1708 void TDEHTMLView::updateFindAheadTimeout()
1710 if( d->typeAheadActivated )
1711 d->timer.start( 3000,
true );
1716 void TDEHTMLView::keyReleaseEvent(TQKeyEvent *_ke)
1718 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
1719 if(d->typeAheadActivated) {
1724 if (d->m_caretViewContext && d->m_caretViewContext->keyReleasePending) {
1726 d->m_caretViewContext->keyReleasePending =
false;
1730 if( d->scrollSuspendPreActivate && _ke->key() != Key_Shift )
1731 d->scrollSuspendPreActivate =
false;
1732 if( _ke->key() == Key_Shift && d->scrollSuspendPreActivate && _ke->state() == TQt::ShiftButton
1735 if (d->scrollTimerId)
1737 d->scrollSuspended = !d->scrollSuspended;
1738 #ifndef NO_SMOOTH_SCROLL_HACK
1739 if( d->scrollSuspended )
1745 if (d->accessKeysEnabled)
1747 if (d->accessKeysPreActivate && _ke->key() != Key_Control)
1748 d->accessKeysPreActivate=
false;
1752 m_part->setStatusBarText(i18n(
"Access Keys activated"),TDEHTMLPart::BarOverrideText);
1753 d->accessKeysActivated =
true;
1754 d->accessKeysPreActivate =
false;
1758 else if (d->accessKeysActivated)
1760 accessKeysTimeout();
1767 if ( dispatchKeyEvent( _ke ) )
1773 TQScrollView::keyReleaseEvent(_ke);
1776 void TDEHTMLView::contentsContextMenuEvent ( TQContextMenuEvent * )
1780 if (!m_part->xmlDocImpl())
return;
1784 DOM::NodeImpl::MouseEvent mev( _ce->state(), DOM::NodeImpl::MouseMove );
1785 m_part->xmlDocImpl()->prepareMouseEvent( xm, ym, &mev );
1787 NodeImpl *targetNode = mev.innerNode.handle();
1788 if (targetNode && targetNode->renderer() && targetNode->renderer()->isWidget()) {
1791 targetNode->renderer()->absolutePosition(absx,absy);
1792 TQPoint pos(xm-absx,ym-absy);
1794 TQWidget *w =
static_cast<RenderWidget*
>(targetNode->renderer())->widget();
1795 TQContextMenuEvent cme(_ce->reason(),pos,_ce->globalPos(),_ce->state());
1796 setIgnoreEvents(
true);
1797 TQApplication::sendEvent(w,&cme);
1798 setIgnoreEvents(
false);
1803 bool TDEHTMLView::focusNextPrevChild(
bool next )
1806 if (m_part->xmlDocImpl() && focusNextPrevNode(next))
1808 if (m_part->xmlDocImpl()->focusNode())
1809 kdDebug() <<
"focusNode.name: "
1810 << m_part->xmlDocImpl()->focusNode()->nodeName().string() <<
endl;
1815 d->pseudoFocusNode = TDEHTMLViewPrivate::PFNone;
1819 return TQWidget::focusNextPrevChild(next);
1822 void TDEHTMLView::doAutoScroll()
1824 TQPoint pos = TQCursor::pos();
1825 pos = viewport()->mapFromGlobal( pos );
1828 viewportToContents(pos.x(), pos.y(), xm, ym);
1830 pos = TQPoint(pos.x() - viewport()->x(), pos.y() - viewport()->y());
1831 if ( (pos.y() < 0) || (pos.y() > visibleHeight()) ||
1832 (pos.x() < 0) || (pos.x() > visibleWidth()) )
1834 ensureVisible( xm, ym, 0, 5 );
1836 #ifndef TDEHTML_NO_SELECTION
1839 if (m_part->isExtendingSelection()) {
1840 RenderObject::NodeInfo renderInfo(
true,
false);
1841 m_part->xmlDocImpl()->renderer()->layer()
1842 ->nodeAtPoint(renderInfo, xm, ym);
1843 innerNode = renderInfo.innerNode();
1846 if (innerNode.handle() && innerNode.handle()->renderer()) {
1848 innerNode.handle()->renderer()->absolutePosition(absX, absY);
1850 m_part->extendSelectionTo(xm, ym, absX, absY, innerNode);
1857 class HackWidget :
public TQWidget
1860 inline void setNoErase() { setWFlags(getWFlags()|WRepaintNoErase); }
1863 bool TDEHTMLView::eventFilter(TQObject *o, TQEvent *e)
1865 if ( e->type() == TQEvent::AccelOverride ) {
1866 TQKeyEvent* ke = (TQKeyEvent*) e;
1869 || (m_part->xmlDocImpl() && m_part->xmlDocImpl()->focusNode()
1870 && m_part->xmlDocImpl()->focusNode()->contentEditable())) {
1872 if ( (ke->state() & ControlButton) || (ke->state() & ShiftButton) ) {
1873 switch ( ke->key() ) {
1890 if ( e->type() == TQEvent::Leave ) {
1891 if ( d->cursor_icon_widget )
1892 d->cursor_icon_widget->hide();
1893 m_part->resetHoverText();
1896 TQWidget *view = viewport();
1901 if(e->type() == TQEvent::ChildInserted) {
1902 TQObject *c =
static_cast<TQChildEvent*
>(e)->child();
1903 if (c->isWidgetType()) {
1904 TQWidget *w =
static_cast<TQWidget*
>(c);
1906 if (w->parentWidget(
true) == view) {
1907 if (!strcmp(w->name(),
"__tdehtml")) {
1908 w->installEventFilter(
this);
1910 if (!::tqt_cast<TQFrame*>(w))
1911 w->setBackgroundMode( TQWidget::NoBackground );
1912 static_cast<HackWidget *
>(w)->setNoErase();
1913 if (!w->childrenListObject().isEmpty()) {
1914 TQObjectListIterator it(w->childrenListObject());
1915 for (; it.current(); ++it) {
1916 TQWidget *widget = ::tqt_cast<TQWidget *>(it.current());
1917 if (widget && !widget->isTopLevel()) {
1918 if (!::tqt_cast<TQFrame*>(w))
1919 widget->setBackgroundMode( TQWidget::NoBackground );
1920 static_cast<HackWidget *
>(widget)->setNoErase();
1921 widget->installEventFilter(
this);
1929 }
else if (o->isWidgetType()) {
1930 TQWidget *v =
static_cast<TQWidget*
>(o);
1932 while (v && v != view) {
1934 v = v->parentWidget(
true);
1937 if (v && !strcmp(c->name(),
"__tdehtml")) {
1939 TQWidget *w =
static_cast<TQWidget*
>(o);
1941 case TQEvent::Paint:
1942 if (!allowWidgetPaintEvents) {
1948 while (v && v != view) {
1951 v = v->parentWidget();
1953 viewportToContents( x, y, x, y );
1954 TQPaintEvent *pe =
static_cast<TQPaintEvent*
>(e);
1955 bool asap = !d->contentsMoving && ::tqt_cast<TQScrollView *>(c);
1958 if ( asap && !d->painting && m_part->xmlDocImpl() && m_part->xmlDocImpl()->renderer() &&
1959 !
static_cast<tdehtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer())->needsLayout() ) {
1960 repaintContents(x + pe->rect().x(), y + pe->rect().y(),
1961 pe->rect().width(), pe->rect().height(),
true);
1963 scheduleRepaint(x + pe->rect().x(), y + pe->rect().y(),
1964 pe->rect().width(), pe->rect().height(), asap);
1968 case TQEvent::MouseMove:
1969 case TQEvent::MouseButtonPress:
1970 case TQEvent::MouseButtonRelease:
1971 case TQEvent::MouseButtonDblClick: {
1972 if ( (w->parentWidget() == view || ::tqt_cast<TQScrollView*>(c)) && !::tqt_cast<TQScrollBar *>(w)) {
1973 TQMouseEvent *me =
static_cast<TQMouseEvent*
>(e);
1974 TQPoint pt = w->mapTo( view, me->pos());
1975 TQMouseEvent me2(me->type(), pt, me->button(), me->state());
1977 if (e->type() == TQEvent::MouseMove)
1978 viewportMouseMoveEvent(&me2);
1979 else if(e->type() == TQEvent::MouseButtonPress)
1980 viewportMousePressEvent(&me2);
1981 else if(e->type() == TQEvent::MouseButtonRelease)
1982 viewportMouseReleaseEvent(&me2);
1984 viewportMouseDoubleClickEvent(&me2);
1989 case TQEvent::KeyPress:
1990 case TQEvent::KeyRelease:
1991 if (w->parentWidget() == view && !::tqt_cast<TQScrollBar *>(w)) {
1992 TQKeyEvent *ke =
static_cast<TQKeyEvent*
>(e);
1993 if (e->type() == TQEvent::KeyPress)
1996 keyReleaseEvent(ke);
2010 return TQScrollView::eventFilter(o, e);
2014 DOM::NodeImpl *TDEHTMLView::nodeUnderMouse()
const
2016 return d->underMouse;
2019 DOM::NodeImpl *TDEHTMLView::nonSharedNodeUnderMouse()
const
2021 return d->underMouseNonShared;
2024 bool TDEHTMLView::scrollTo(
const TQRect &bounds)
2026 d->scrollingSelf =
true;
2031 xe = bounds.right();
2032 ye = bounds.bottom();
2039 int curHeight = visibleHeight();
2040 int curWidth = visibleWidth();
2042 if (ye-y>curHeight-d->borderY)
2043 ye = y + curHeight - d->borderY;
2045 if (xe-x>curWidth-d->borderX)
2046 xe = x + curWidth - d->borderX;
2049 if (x < contentsX() + d->borderX )
2050 deltax = x - contentsX() - d->borderX;
2052 else if (xe + d->borderX > contentsX() + curWidth)
2053 deltax = xe + d->borderX - ( contentsX() + curWidth );
2058 if (y < contentsY() + d->borderY)
2059 deltay = y - contentsY() - d->borderY;
2061 else if (ye + d->borderY > contentsY() + curHeight)
2062 deltay = ye + d->borderY - ( contentsY() + curHeight );
2066 int maxx = curWidth-d->borderX;
2067 int maxy = curHeight-d->borderY;
2069 int scrollX,scrollY;
2071 scrollX = deltax > 0 ? (deltax > maxx ? maxx : deltax) : deltax == 0 ? 0 : (deltax>-maxx ? deltax : -maxx);
2072 scrollY = deltay > 0 ? (deltay > maxy ? maxy : deltay) : deltay == 0 ? 0 : (deltay>-maxy ? deltay : -maxy);
2074 if (contentsX() + scrollX < 0)
2075 scrollX = -contentsX();
2076 else if (contentsWidth() - visibleWidth() - contentsX() < scrollX)
2077 scrollX = contentsWidth() - visibleWidth() - contentsX();
2079 if (contentsY() + scrollY < 0)
2080 scrollY = -contentsY();
2081 else if (contentsHeight() - visibleHeight() - contentsY() < scrollY)
2082 scrollY = contentsHeight() - visibleHeight() - contentsY();
2084 scrollBy(scrollX, scrollY);
2086 d->scrollingSelf =
false;
2088 if ( (abs(deltax)<=maxx) && (abs(deltay)<=maxy) )
2094 bool TDEHTMLView::focusNextPrevNode(
bool next)
2103 DocumentImpl *doc = m_part->xmlDocImpl();
2104 NodeImpl *oldFocusNode = doc->focusNode();
2109 if (oldFocusNode && oldFocusNode->renderer() &&
2110 !oldFocusNode->renderer()->parent()) {
2111 doc->setFocusNode(0);
2119 if (d->scrollBarMoved)
2123 toFocus = doc->nextFocusNode(oldFocusNode);
2125 toFocus = doc->previousFocusNode(oldFocusNode);
2127 if (!toFocus && oldFocusNode)
2129 toFocus = doc->nextFocusNode(NULL);
2131 toFocus = doc->previousFocusNode(NULL);
2133 while (toFocus && toFocus != oldFocusNode)
2136 TQRect focusNodeRect = toFocus->getRect();
2137 if ((focusNodeRect.left() > contentsX()) && (focusNodeRect.right() < contentsX() + visibleWidth()) &&
2138 (focusNodeRect.top() > contentsY()) && (focusNodeRect.bottom() < contentsY() + visibleHeight())) {
2140 TQRect r = toFocus->getRect();
2141 ensureVisible( r.right(), r.bottom());
2142 ensureVisible( r.left(), r.top());
2143 d->scrollBarMoved =
false;
2144 d->tabMovePending =
false;
2145 d->lastTabbingDirection =
next;
2146 d->pseudoFocusNode = TDEHTMLViewPrivate::PFNone;
2147 m_part->xmlDocImpl()->setFocusNode(toFocus);
2148 Node guard(toFocus);
2149 if (!toFocus->hasOneRef() )
2157 toFocus = doc->nextFocusNode(toFocus);
2159 toFocus = doc->previousFocusNode(toFocus);
2161 if (!toFocus && oldFocusNode)
2163 toFocus = doc->nextFocusNode(NULL);
2165 toFocus = doc->previousFocusNode(NULL);
2168 d->scrollBarMoved =
false;
2172 if (!oldFocusNode && d->pseudoFocusNode == TDEHTMLViewPrivate::PFNone)
2174 ensureVisible(contentsX(), next?0:contentsHeight());
2175 d->scrollBarMoved =
false;
2176 d->pseudoFocusNode =
next?TDEHTMLViewPrivate::PFTop:TDEHTMLViewPrivate::PFBottom;
2180 NodeImpl *newFocusNode = NULL;
2182 if (d->tabMovePending && next != d->lastTabbingDirection)
2185 newFocusNode = oldFocusNode;
2189 if (oldFocusNode || d->pseudoFocusNode == TDEHTMLViewPrivate::PFTop )
2190 newFocusNode = doc->nextFocusNode(oldFocusNode);
2194 if (oldFocusNode || d->pseudoFocusNode == TDEHTMLViewPrivate::PFBottom )
2195 newFocusNode = doc->previousFocusNode(oldFocusNode);
2198 bool targetVisible =
false;
2203 targetVisible = scrollTo(TQRect(contentsX()+visibleWidth()/2,contentsHeight()-d->borderY,0,0));
2207 targetVisible = scrollTo(TQRect(contentsX()+visibleWidth()/2,d->borderY,0,0));
2212 #ifndef TDEHTML_NO_CARET
2215 && newFocusNode->contentEditable()) {
2216 d->caretViewContext();
2217 moveCaretTo(newFocusNode, 0L,
true);
2223 targetVisible = scrollTo(newFocusNode->getRect());
2229 d->tabMovePending =
false;
2231 m_part->xmlDocImpl()->setFocusNode(newFocusNode);
2234 Node guard(newFocusNode);
2235 if (!newFocusNode->hasOneRef() )
2243 d->pseudoFocusNode =
next?TDEHTMLViewPrivate::PFBottom:TDEHTMLViewPrivate::PFTop;
2249 if (!d->tabMovePending)
2250 d->lastTabbingDirection =
next;
2251 d->tabMovePending =
true;
2258 TQValueVector< TQChar > taken;
2265 TQMap< ElementImpl*, TQChar > fallbacks;
2267 fallbacks = buildFallbackAccessKeys();
2268 for( NodeImpl* n = m_part->xmlDocImpl(); n != NULL; n = n->traverseNextNode()) {
2269 if( n->isElementNode()) {
2270 ElementImpl* en =
static_cast< ElementImpl*
>( n );
2271 DOMString s = en->getAttribute( ATTR_ACCESSKEY );
2273 if( s.length() == 1 ) {
2274 TQChar a = s.string()[ 0 ].upper();
2275 if( tqFind( taken.begin(), taken.end(), a ) == taken.end())
2278 if( accesskey.isNull() && fallbacks.contains( en )) {
2279 TQChar a = fallbacks[ en ].upper();
2280 if( tqFind( taken.begin(), taken.end(), a ) == taken.end())
2281 accesskey = TQString(
"<qt><i>" ) + a +
"</i></qt>";
2283 if( !accesskey.isNull()) {
2284 TQRect rec=en->getRect();
2285 TQLabel *lab=
new TQLabel(accesskey,viewport(),0,(WFlags)WDestructiveClose);
2286 connect( origview, TQ_SIGNAL(hideAccessKeys()), lab, TQ_SLOT(
close()) );
2287 connect(
this, TQ_SIGNAL(repaintAccessKeys()), lab, TQ_SLOT(repaint()));
2288 lab->setPalette(TQToolTip::palette());
2289 lab->setLineWidth(2);
2290 lab->setFrameStyle(TQFrame::Box | TQFrame::Plain);
2294 KMIN(rec.left()+rec.width()/2, contentsWidth() - lab->width()),
2295 KMIN(rec.top()+rec.height()/2, contentsHeight() - lab->height()));
2297 taken.append( accesskey[ 0 ] );
2303 TQPtrList<KParts::ReadOnlyPart> frames = m_part->frames();
2304 for( TQPtrListIterator<KParts::ReadOnlyPart> it( frames );
2307 if( !(*it)->inherits(
"TDEHTMLPart" ))
2321 void TDEHTMLView::accessKeysTimeout()
2323 d->accessKeysActivated=
false;
2324 d->accessKeysPreActivate =
false;
2325 m_part->setStatusBarText(TQString::null, TDEHTMLPart::BarOverrideText);
2326 emit hideAccessKeys();
2330 bool TDEHTMLView::handleAccessKey(
const TQKeyEvent* ev )
2335 if( ev->key() >= Key_A && ev->key() <= Key_Z )
2336 c =
'A' + ev->key() - Key_A;
2337 else if( ev->key() >= Key_0 && ev->key() <= Key_9 )
2338 c =
'0' + ev->key() - Key_0;
2342 if( ev->text().length() == 1 )
2343 c = ev->text()[ 0 ];
2347 return focusNodeWithAccessKey( c );
2350 bool TDEHTMLView::focusNodeWithAccessKey( TQChar c,
TDEHTMLView* caller )
2352 DocumentImpl *doc = m_part->xmlDocImpl();
2355 ElementImpl* node = doc->findAccessKeyElement( c );
2357 TQPtrList<KParts::ReadOnlyPart> frames = m_part->frames();
2358 for( TQPtrListIterator<KParts::ReadOnlyPart> it( frames );
2361 if( !(*it)->inherits(
"TDEHTMLPart" ))
2365 &&
part->
view()->focusNodeWithAccessKey( c,
this ))
2371 && m_part->
parentPart()->
view()->focusNodeWithAccessKey( c,
this ))
2373 if( caller == NULL ) {
2374 TQMap< ElementImpl*, TQChar > fallbacks = buildFallbackAccessKeys();
2375 for( TQMap< ElementImpl*, TQChar >::ConstIterator it = fallbacks.begin();
2376 it != fallbacks.end();
2388 #ifndef TDEHTML_NO_CARET
2391 && node->contentEditable()) {
2392 d->caretViewContext();
2393 moveCaretTo(node, 0L,
true);
2399 TQRect r = node->getRect();
2400 ensureVisible( r.right(), r.bottom());
2401 ensureVisible( r.left(), r.top());
2404 if( node->isFocusable()) {
2405 if (node->id()==ID_LABEL) {
2407 node=
static_cast<ElementImpl *
>(
static_cast< HTMLLabelElementImpl*
>( node )->getFormElement());
2408 if (!node)
return true;
2412 TQFocusEvent::setReason( TQFocusEvent::Shortcut );
2413 m_part->xmlDocImpl()->setFocusNode(node);
2414 TQFocusEvent::resetReason();
2415 if( node != NULL && node->hasOneRef())
2418 if( node != NULL && node->hasOneRef())
2422 switch( node->id()) {
2424 static_cast< HTMLAnchorElementImpl*
>( node )->click();
2427 static_cast< HTMLInputElementImpl*
>( node )->click();
2430 static_cast< HTMLButtonElementImpl*
>( node )->click();
2433 static_cast< HTMLAreaElementImpl*
>( node )->click();
2444 static TQString getElementText( NodeImpl* start,
bool after )
2447 for( NodeImpl* n = after ? start->nextSibling() : start->traversePreviousNode();
2449 n = after ? n->traverseNextNode() : n->traversePreviousNode()) {
2450 if( n->isTextNode()) {
2452 ret +=
static_cast< TextImpl*
>( n )->toString().string();
2454 ret.prepend(
static_cast< TextImpl*
>( n )->toString().string());
2484 if( ret.stripWhiteSpace().isEmpty())
2488 return ret.simplifyWhiteSpace();
2492 return ret.simplifyWhiteSpace();
2495 static TQMap< NodeImpl*, TQString > buildLabels( NodeImpl* start )
2497 TQMap< NodeImpl*, TQString > ret;
2498 for( NodeImpl* n = start;
2500 n = n->traverseNextNode()) {
2501 if( n->id() == ID_LABEL ) {
2502 HTMLLabelElementImpl*
label =
static_cast< HTMLLabelElementImpl*
>( n );
2503 NodeImpl* labelfor =
label->getFormElement();
2505 ret[ labelfor ] =
label->innerText().string().simplifyWhiteSpace();
2512 struct AccessKeyData {
2513 ElementImpl* element;
2520 TQMap< ElementImpl*, TQChar > TDEHTMLView::buildFallbackAccessKeys()
const
2523 TQValueList< AccessKeyData > data;
2524 TQMap< NodeImpl*, TQString > labels = buildLabels( m_part->xmlDocImpl());
2525 for( NodeImpl* n = m_part->xmlDocImpl();
2527 n = n->traverseNextNode()) {
2528 if( n->isElementNode()) {
2529 ElementImpl* element =
static_cast< ElementImpl*
>( n );
2530 if( element->getAttribute( ATTR_ACCESSKEY ).length() == 1 )
2532 if( element->renderer() == NULL )
2537 bool ignore =
false;
2538 bool text_after =
false;
2539 bool text_before =
false;
2540 switch( element->id()) {
2542 url = tdehtml::parseURL(element->getAttribute(ATTR_HREF)).string();
2545 text =
static_cast< HTMLElementImpl*
>( element )->innerText().string().simplifyWhiteSpace();
2549 HTMLInputElementImpl* in =
static_cast< HTMLInputElementImpl*
>( element );
2550 switch( in->inputType()) {
2551 case HTMLInputElementImpl::SUBMIT:
2552 text = in->value().string();
2554 text = i18n(
"Submit" );
2557 case HTMLInputElementImpl::IMAGE:
2558 text = in->altText().string();
2561 case HTMLInputElementImpl::BUTTON:
2562 text = in->value().string();
2565 case HTMLInputElementImpl::RESET:
2566 text = in->value().string();
2568 text = i18n(
"Reset" );
2571 case HTMLInputElementImpl::HIDDEN:
2574 case HTMLInputElementImpl::CHECKBOX:
2575 case HTMLInputElementImpl::RADIO:
2579 case HTMLInputElementImpl::TEXT:
2580 case HTMLInputElementImpl::PASSWORD:
2581 case HTMLInputElementImpl::FILE:
2592 text =
static_cast< HTMLElementImpl*
>( element )->innerText().string().simplifyWhiteSpace();
2593 switch(
static_cast< HTMLButtonElementImpl*
>( element )->buttonType()) {
2594 case HTMLButtonElementImpl::SUBMIT:
2596 text = i18n(
"Submit" );
2599 case HTMLButtonElementImpl::RESET:
2601 text = i18n(
"Reset" );
2618 ignore = !element->isFocusable();
2624 if( text.isNull() && labels.contains( element ))
2625 text = labels[ element ];
2626 if( text.isNull() && text_before )
2627 text = getElementText( element,
false );
2628 if( text.isNull() && text_after )
2629 text = getElementText( element,
true );
2630 text = text.stripWhiteSpace();
2632 TQValueList< TQPair< TQString, TQChar > > priorities
2633 = m_part->settings()->fallbackAccessKeysAssignments();
2634 for( TQValueList< TQPair< TQString, TQChar > >::ConstIterator it = priorities.begin();
2635 it != priorities.end();
2637 if( text == (*it).first )
2640 AccessKeyData tmp = { element, text, url, priority };
2645 TQValueList< TQChar > keys;
2646 for(
char c =
'A'; c <=
'Z'; ++c )
2648 for(
char c =
'0'; c <=
'9'; ++c )
2650 for( NodeImpl* n = m_part->xmlDocImpl();
2652 n = n->traverseNextNode()) {
2653 if( n->isElementNode()) {
2654 ElementImpl* en =
static_cast< ElementImpl*
>( n );
2655 DOMString s = en->getAttribute( ATTR_ACCESSKEY );
2656 if( s.length() == 1 ) {
2657 TQChar c = s.string()[ 0 ].upper();
2663 TQMap< ElementImpl*, TQChar > ret;
2664 for(
int priority = 10;
2667 for( TQValueList< AccessKeyData >::Iterator it = data.begin();
2670 if( (*it).priority != priority ) {
2676 TQString text = (*it).text;
2678 if(
key.isNull() && !text.isEmpty()) {
2679 TQValueList< TQPair< TQString, TQChar > > priorities
2680 = m_part->settings()->fallbackAccessKeysAssignments();
2681 for( TQValueList< TQPair< TQString, TQChar > >::ConstIterator it = priorities.begin();
2682 it != priorities.end();
2684 if( text == (*it).first && keys.contains( (*it).second )) {
2692 if(
key.isNull() && !text.isEmpty()) {
2693 TQStringList words = TQStringList::split(
' ', text );
2694 for( TQStringList::ConstIterator it = words.begin();
2697 if( keys.contains( (*it)[ 0 ].upper())) {
2698 key = (*it)[ 0 ].upper();
2703 if(
key.isNull() && !text.isEmpty()) {
2704 for(
unsigned int i = 0;
2707 if( keys.contains( text[ i ].upper())) {
2708 key = text[ i ].upper();
2715 ret[ (*it).element ] =
key;
2717 TQString url = (*it).url;
2718 it = data.remove( it );
2720 if( !url.isEmpty() && !url.startsWith(
"javascript:",
false )) {
2721 for( TQValueList< AccessKeyData >::Iterator it2 = data.begin();
2724 if( (*it2).url == url ) {
2725 ret[ (*it2).element ] =
key;
2728 it2 = data.remove( it2 );
2738 void TDEHTMLView::setMediaType(
const TQString &medium )
2743 TQString TDEHTMLView::mediaType()
const
2748 bool TDEHTMLView::pagedMode()
const
2753 void TDEHTMLView::setWidgetVisible(RenderWidget* w,
bool vis)
2756 d->visibleWidgets.replace(w, w->widget());
2759 d->visibleWidgets.remove(w);
2762 bool TDEHTMLView::needsFullRepaint()
const
2764 return d->needsFullRepaint;
2774 if(!m_part->xmlDocImpl())
return;
2775 tdehtml::RenderCanvas *root =
static_cast<tdehtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer());
2778 KPrinter *printer =
new KPrinter(
true, TQPrinter::ScreenResolution);
2779 printer->addDialogPage(
new TDEHTMLPrintSettings());
2780 TQString docname = m_part->xmlDocImpl()->URL().prettyURL();
2781 if ( !docname.isEmpty() )
2783 if(quick || printer->setup(
this, i18n(
"Print %1").arg(docname))) {
2784 viewport()->setCursor( TQt::waitCursor );
2786 printer->setFullPage(
false);
2787 printer->setCreator(TQString(
"TDE %1.%2.%3 HTML Library").arg(TDE_VERSION_MAJOR).arg(TDE_VERSION_MINOR).arg(TDE_VERSION_RELEASE));
2788 printer->setDocName(docname);
2790 TQPainter *p =
new TQPainter;
2791 p->
begin( printer );
2792 tdehtml::setPrintPainter( p );
2794 m_part->xmlDocImpl()->setPaintDevice( printer );
2795 TQString oldMediaType = mediaType();
2796 setMediaType(
"print" );
2800 m_part->xmlDocImpl()->setPrintStyleSheet( printer->option(
"app-khtml-printfriendly") ==
"true" ?
2801 "* { background-image: none !important;"
2802 " background-color: white !important;"
2803 " color: black !important; }"
2804 "body { margin: 0px !important; }"
2805 "html { margin: 0px !important; }" :
2806 "body { margin: 0px !important; }"
2807 "html { margin: 0px !important; }"
2810 TQPaintDeviceMetrics metrics( printer );
2812 kdDebug(6000) <<
"printing: physical page width = " << metrics.width()
2813 <<
" height = " << metrics.height() <<
endl;
2814 root->setStaticMode(
true);
2815 root->setPagedMode(
true);
2816 root->setWidth(metrics.width());
2818 root->setPageTop(0);
2819 root->setPageBottom(0);
2822 m_part->xmlDocImpl()->styleSelector()->computeFontSizes(&metrics, 100);
2823 m_part->xmlDocImpl()->updateStyleSelector();
2824 root->setPrintImages( printer->option(
"app-khtml-printimages") ==
"true");
2825 root->makePageBreakAvoidBlocks();
2827 root->setNeedsLayoutAndMinMaxRecalc();
2829 tdehtml::RenderWidget::flushWidgetResizes();
2833 bool printHeader = (printer->option(
"app-khtml-printheader") ==
"true");
2835 int headerHeight = 0;
2836 TQFont headerFont(
"Sans Serif", 8);
2839 TQString headerMid = docname;
2840 TQString headerRight;
2844 p->setFont(headerFont);
2845 headerHeight = (p->fontMetrics().lineSpacing() * 3) / 2;
2849 kdDebug(6000) <<
"printing: html page width = " << root->docWidth()
2850 <<
" height = " << root->docHeight() <<
endl;
2851 kdDebug(6000) <<
"printing: margins left = " << printer->margins().width()
2852 <<
" top = " << printer->margins().height() <<
endl;
2853 kdDebug(6000) <<
"printing: paper width = " << metrics.width()
2854 <<
" height = " << metrics.height() <<
endl;
2857 int pageWidth = metrics.width();
2858 int pageHeight = metrics.height();
2859 p->setClipRect(0,0, pageWidth, pageHeight);
2861 pageHeight -= headerHeight;
2863 bool scalePage =
false;
2865 #ifndef TQT_NO_TRANSFORMATIONS
2866 if(root->docWidth() > metrics.width()) {
2868 scale = ((double) metrics.width())/((
double) root->docWidth());
2869 pageHeight = (int) (pageHeight/scale);
2870 pageWidth = (int) (pageWidth/scale);
2871 headerHeight = (int) (headerHeight/scale);
2874 kdDebug(6000) <<
"printing: scaled html width = " << pageWidth
2875 <<
" height = " << pageHeight <<
endl;
2877 root->setHeight(pageHeight);
2878 root->setPageBottom(pageHeight);
2879 root->setNeedsLayout(
true);
2880 root->layoutIfNeeded();
2886 int available_width = metrics.width() - 10 -
2887 2 * kMax(p->boundingRect(0, 0, metrics.width(), p->fontMetrics().lineSpacing(), TQt::AlignLeft, headerLeft).width(),
2888 p->boundingRect(0, 0, metrics.width(), p->fontMetrics().lineSpacing(), TQt::AlignLeft, headerRight).width());
2889 if (available_width < 150)
2890 available_width = 150;
2895 mid_width = p->boundingRect(0, 0, metrics.width(), p->fontMetrics().lineSpacing(), TQt::AlignLeft, headerMid).width();
2897 }
while (mid_width > available_width);
2903 while(top < root->docHeight()) {
2904 if(top > 0) printer->newPage();
2905 p->setClipRect(0, 0, pageWidth, headerHeight, TQPainter::CoordDevice);
2908 int dy = p->fontMetrics().lineSpacing();
2909 p->setPen(TQt::black);
2910 p->setFont(headerFont);
2912 headerRight = TQString(
"#%1").arg(page);
2914 p->drawText(0, 0, metrics.width(), dy, TQt::AlignLeft, headerLeft);
2915 p->drawText(0, 0, metrics.width(), dy, TQt::AlignHCenter, headerMid);
2916 p->drawText(0, 0, metrics.width(), dy, TQt::AlignRight, headerRight);
2920 #ifndef TQT_NO_TRANSFORMATIONS
2922 p->scale(scale, scale);
2925 p->setClipRect(0, headerHeight, pageWidth, pageHeight, TQPainter::CoordDevice);
2926 p->translate(0, headerHeight-top);
2928 bottom = top+pageHeight;
2930 root->setPageTop(top);
2931 root->setPageBottom(bottom);
2932 root->setPageNumber(page);
2934 root->layer()->paint(p, TQRect(0, top, pageWidth, pageHeight));
2938 kdDebug(6000) <<
"printed: page " << page <<
" bottom At = " << bottom <<
endl;
2949 root->setPagedMode(
false);
2950 root->setStaticMode(
false);
2952 tdehtml::setPrintPainter( 0 );
2953 setMediaType( oldMediaType );
2954 m_part->xmlDocImpl()->setPaintDevice(
this );
2955 m_part->xmlDocImpl()->styleSelector()->computeFontSizes(m_part->xmlDocImpl()->paintDeviceMetrics(), m_part->
zoomFactor());
2956 m_part->xmlDocImpl()->updateStyleSelector();
2957 viewport()->unsetCursor();
2962 void TDEHTMLView::slotPaletteChanged()
2964 if(!m_part->xmlDocImpl())
return;
2965 DOM::DocumentImpl *document = m_part->xmlDocImpl();
2966 if (!document->isHTMLDocument())
return;
2967 tdehtml::RenderCanvas *root =
static_cast<tdehtml::RenderCanvas *
>(document->renderer());
2969 root->style()->resetPalette();
2970 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(document)->body();
2972 body->setChanged(
true);
2973 body->recalcStyle( NodeImpl::Force );
2976 void TDEHTMLView::paint(TQPainter *p,
const TQRect &rc,
int yOff,
bool *more)
2978 if(!m_part->xmlDocImpl())
return;
2979 tdehtml::RenderCanvas *root =
static_cast<tdehtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer());
2982 m_part->xmlDocImpl()->setPaintDevice(p->device());
2983 root->setPagedMode(
true);
2984 root->setStaticMode(
true);
2985 root->setWidth(rc.width());
2989 p->translate(rc.left(), rc.top());
2990 double scale = ((double) rc.width()/(double) root->docWidth());
2991 int height = (int) ((
double) rc.height() / scale);
2992 #ifndef TQT_NO_TRANSFORMATIONS
2993 p->scale(scale, scale);
2995 root->setPageTop(yOff);
2996 root->setPageBottom(yOff+height);
2998 root->layer()->paint(p, TQRect(0, yOff, root->docWidth(), height));
3000 *more = yOff + height < root->docHeight();
3003 root->setPagedMode(
false);
3004 root->setStaticMode(
false);
3005 m_part->xmlDocImpl()->setPaintDevice(
this );
3009 void TDEHTMLView::useSlowRepaints()
3011 d->useSlowRepaints =
true;
3012 setStaticBackground(
true);
3018 #ifndef TDEHTML_NO_SCROLLBARS
3020 TQScrollView::setVScrollBarMode(mode);
3028 #ifndef TDEHTML_NO_SCROLLBARS
3030 TQScrollView::setHScrollBarMode(mode);
3036 void TDEHTMLView::restoreScrollBar()
3038 int ow = visibleWidth();
3039 TQScrollView::setVScrollBarMode(d->vmode);
3040 if (visibleWidth() != ow)
3042 d->prevScrollbarVisible = verticalScrollBar()->isVisible();
3045 TQStringList TDEHTMLView::formCompletionItems(
const TQString &name)
const
3047 if (!m_part->settings()->isFormCompletionEnabled())
3048 return TQStringList();
3049 if (!d->formCompletions)
3051 return d->formCompletions->readListEntry(name);
3054 void TDEHTMLView::clearCompletionHistory(
const TQString& name)
3056 if (!d->formCompletions)
3060 d->formCompletions->writeEntry(name,
"");
3061 d->formCompletions->sync();
3064 void TDEHTMLView::addFormCompletionItem(
const TQString &name,
const TQString &value)
3066 if (!m_part->settings()->isFormCompletionEnabled())
3071 bool cc_number(
true);
3072 for (
unsigned int i = 0; i < value.length(); ++i)
3075 if (!c.isNumber() && c !=
'-' && !c.isSpace())
3083 TQStringList items = formCompletionItems(name);
3084 if (!items.contains(value))
3085 items.prepend(value);
3086 while ((
int)items.count() > m_part->settings()->maxFormCompletionItems())
3087 items.remove(items.fromLast());
3088 d->formCompletions->writeEntry(name, items);
3091 void TDEHTMLView::removeFormCompletionItem(
const TQString &name,
const TQString &value)
3093 if (!m_part->settings()->isFormCompletionEnabled())
3096 TQStringList items = formCompletionItems(name);
3097 if (items.remove(value))
3098 d->formCompletions->writeEntry(name, items);
3101 void TDEHTMLView::addNonPasswordStorableSite(
const TQString& host)
3103 if (!d->formCompletions) {
3107 d->formCompletions->setGroup(
"NonPasswordStorableSites");
3108 TQStringList sites = d->formCompletions->readListEntry(
"Sites");
3110 d->formCompletions->writeEntry(
"Sites", sites);
3111 d->formCompletions->sync();
3112 d->formCompletions->setGroup(TQString::null);
3115 bool TDEHTMLView::nonPasswordStorableSite(
const TQString& host)
const
3117 if (!d->formCompletions) {
3120 d->formCompletions->setGroup(
"NonPasswordStorableSites");
3121 TQStringList sites = d->formCompletions->readListEntry(
"Sites");
3122 d->formCompletions->setGroup(TQString::null);
3124 return (sites.find(host) != sites.end());
3128 bool TDEHTMLView::dispatchMouseEvent(
int eventId, DOM::NodeImpl *targetNode,
3129 DOM::NodeImpl *targetNodeNonShared,
bool cancelable,
3130 int detail,TQMouseEvent *_mouse,
bool setUnder,
3134 if (targetNode && targetNode->isTextNode())
3135 targetNode = targetNode->parentNode();
3138 d->underMouse->deref();
3139 d->underMouse = targetNode;
3141 d->underMouse->ref();
3143 if (d->underMouseNonShared)
3144 d->underMouseNonShared->deref();
3145 d->underMouseNonShared = targetNodeNonShared;
3146 if (d->underMouseNonShared)
3147 d->underMouseNonShared->ref();
3149 int exceptioncode = 0;
3152 viewportToContents(_mouse->x(), _mouse->y(), pageX, pageY);
3153 int clientX = pageX - contentsX();
3154 int clientY = pageY - contentsY();
3155 int screenX = _mouse->globalX();
3156 int screenY = _mouse->globalY();
3158 switch (_mouse->button()) {
3159 case TQt::LeftButton:
3162 case TQt::MidButton:
3165 case TQt::RightButton:
3171 if (d->accessKeysEnabled && d->accessKeysPreActivate && button!=-1)
3172 d->accessKeysPreActivate=
false;
3174 bool ctrlKey = (_mouse->state() & ControlButton);
3175 bool altKey = (_mouse->state() & AltButton);
3176 bool shiftKey = (_mouse->state() & ShiftButton);
3177 bool metaKey = (_mouse->state() & MetaButton);
3180 if (setUnder && (d->prevMouseX != pageX || d->prevMouseY != pageY)) {
3184 NodeImpl *oldUnder = 0;
3185 if (d->prevMouseX >= 0 && d->prevMouseY >= 0) {
3186 NodeImpl::MouseEvent mev( _mouse->stateAfter(),
static_cast<NodeImpl::MouseEventType
>(mouseEventType));
3187 m_part->xmlDocImpl()->prepareMouseEvent(
true, d->prevMouseX, d->prevMouseY, &mev );
3188 oldUnder = mev.innerNode.handle();
3190 if (oldUnder && oldUnder->isTextNode())
3191 oldUnder = oldUnder->parentNode();
3194 if (oldUnder != targetNode) {
3198 MouseEventImpl *me =
new MouseEventImpl(EventImpl::MOUSEOUT_EVENT,
3199 true,
true,m_part->xmlDocImpl()->defaultView(),
3200 0,screenX,screenY,clientX,clientY,pageX, pageY,
3201 ctrlKey,altKey,shiftKey,metaKey,
3204 oldUnder->dispatchEvent(me,exceptioncode,
true);
3210 MouseEventImpl *me =
new MouseEventImpl(EventImpl::MOUSEOVER_EVENT,
3211 true,
true,m_part->xmlDocImpl()->defaultView(),
3212 0,screenX,screenY,clientX,clientY,pageX, pageY,
3213 ctrlKey,altKey,shiftKey,metaKey,
3217 targetNode->dispatchEvent(me,exceptioncode,
true);
3226 bool swallowEvent =
false;
3230 bool dblclick = ( eventId == EventImpl::CLICK_EVENT &&
3231 _mouse->type() == TQEvent::MouseButtonDblClick );
3232 MouseEventImpl *me =
new MouseEventImpl(
static_cast<EventImpl::EventId
>(eventId),
3233 true,cancelable,m_part->xmlDocImpl()->defaultView(),
3234 detail,screenX,screenY,clientX,clientY,pageX, pageY,
3235 ctrlKey,altKey,shiftKey,metaKey,
3236 button,0, _mouse, dblclick );
3238 targetNode->dispatchEvent(me,exceptioncode,
true);
3239 bool defaultHandled = me->defaultHandled();
3240 if (defaultHandled || me->defaultPrevented())
3241 swallowEvent =
true;
3244 if (eventId == EventImpl::MOUSEDOWN_EVENT) {
3249 DOM::NodeImpl* nodeImpl = targetNode;
3250 for ( ; nodeImpl && !nodeImpl->isFocusable(); nodeImpl = nodeImpl->parentNode());
3251 if (nodeImpl && nodeImpl->isMouseFocusable())
3252 m_part->xmlDocImpl()->setFocusNode(nodeImpl);
3253 else if (!nodeImpl || !nodeImpl->focused())
3254 m_part->xmlDocImpl()->setFocusNode(0);
3258 return swallowEvent;
3261 void TDEHTMLView::setIgnoreWheelEvents(
bool e )
3263 d->ignoreWheelEvents = e;
3266 #ifndef TQT_NO_WHEELEVENT
3268 void TDEHTMLView::viewportWheelEvent(TQWheelEvent* e)
3270 if (d->accessKeysEnabled && d->accessKeysPreActivate) d->accessKeysPreActivate=
false;
3272 if ( ( e->state() & ControlButton) == ControlButton )
3274 emit zoomView( - e->delta() );
3277 else if (d->firstRelayout)
3281 else if( ( (e->orientation() == TQt::Vertical &&
3282 ((d->ignoreWheelEvents && !verticalScrollBar()->isVisible())
3283 || e->delta() > 0 && contentsY() <= 0
3284 || e->delta() < 0 && contentsY() >= contentsHeight() - visibleHeight()))
3286 (e->orientation() == TQt::Horizontal &&
3287 ((d->ignoreWheelEvents && !horizontalScrollBar()->isVisible())
3288 || e->delta() > 0 && contentsX() <=0
3289 || e->delta() < 0 && contentsX() >= contentsWidth() - visibleWidth())))
3298 d->scrollBarMoved =
true;
3299 #ifndef NO_SMOOTH_SCROLL_HACK
3300 scrollViewWheelEvent( e );
3302 TQScrollView::viewportWheelEvent( e );
3305 TQMouseEvent *tempEvent =
new TQMouseEvent( TQEvent::MouseMove, TQPoint(-1,-1), TQPoint(-1,-1), TQt::NoButton, e->state() );
3306 emit viewportMouseMoveEvent ( tempEvent );
3313 void TDEHTMLView::dragEnterEvent( TQDragEnterEvent* ev )
3323 TQScrollView::dragEnterEvent( ev );
3326 void TDEHTMLView::dropEvent( TQDropEvent *ev )
3336 TQScrollView::dropEvent( ev );
3339 void TDEHTMLView::focusInEvent( TQFocusEvent *e )
3341 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
3342 m_part->enableFindAheadActions(
true );
3344 DOM::NodeImpl* fn = m_part->xmlDocImpl() ? m_part->xmlDocImpl()->focusNode() : 0;
3345 if (fn && fn->renderer() && fn->renderer()->isWidget() &&
3346 (e->reason() != TQFocusEvent::Mouse) &&
3347 static_cast<tdehtml::RenderWidget*
>(fn->renderer())->widget())
3348 static_cast<tdehtml::RenderWidget*
>(fn->renderer())->widget()->setFocus();
3349 #ifndef TDEHTML_NO_CARET
3352 if (d->m_caretViewContext &&
3353 d->m_caretViewContext->freqTimerId == -1 &&
3357 || (fn && fn->renderer()
3358 && fn->renderer()->style()->userInput()
3360 d->m_caretViewContext->freqTimerId = startTimer(500);
3361 d->m_caretViewContext->visible =
true;
3366 TQScrollView::focusInEvent( e );
3369 void TDEHTMLView::focusOutEvent( TQFocusEvent *e )
3371 if(m_part) m_part->stopAutoScroll();
3373 #ifndef TDEHTML_NO_TYPE_AHEAD_FIND
3374 if(d->typeAheadActivated)
3378 m_part->enableFindAheadActions(
false );
3381 #ifndef TDEHTML_NO_CARET
3382 if (d->m_caretViewContext) {
3383 switch (d->m_caretViewContext->displayNonFocused) {
3384 case TDEHTMLPart::CaretInvisible:
3387 case TDEHTMLPart::CaretVisible: {
3388 killTimer(d->m_caretViewContext->freqTimerId);
3389 d->m_caretViewContext->freqTimerId = -1;
3390 NodeImpl *caretNode = m_part->xmlDocImpl()->focusNode();
3391 if (!d->m_caretViewContext->visible && (m_part->
isCaretMode()
3393 || (caretNode && caretNode->renderer()
3394 && caretNode->renderer()->style()->userInput()
3396 d->m_caretViewContext->visible =
true;
3401 case TDEHTMLPart::CaretBlink:
3408 if ( d->cursor_icon_widget )
3409 d->cursor_icon_widget->hide();
3411 TQScrollView::focusOutEvent( e );
3414 void TDEHTMLView::slotScrollBarMoved()
3416 if ( !d->firstRelayout && !d->complete && m_part->xmlDocImpl() &&
3417 d->layoutSchedulingEnabled) {
3419 tdehtml::RenderCanvas* root =
static_cast<tdehtml::RenderCanvas *
>( m_part->xmlDocImpl()->renderer() );
3420 if (root && root->needsLayout()) {
3421 unscheduleRelayout();
3425 if (!d->scrollingSelf) {
3426 d->scrollBarMoved =
true;
3427 d->contentsMoving =
true;
3429 scheduleRepaint(0, 0, 0, 0);
3432 if (m_part->xmlDocImpl() && m_part->xmlDocImpl()->documentElement())
3433 m_part->xmlDocImpl()->documentElement()->dispatchHTMLEvent(EventImpl::SCROLL_EVENT,
true,
false);
3436 void TDEHTMLView::timerEvent ( TQTimerEvent *e )
3439 if ( e->timerId() == d->scrollTimerId ) {
3440 if( d->scrollSuspended )
3442 switch (d->scrollDirection) {
3443 case TDEHTMLViewPrivate::ScrollDown:
3444 if (contentsY() + visibleHeight () >= contentsHeight())
3445 d->newScrollTimer(
this, 0);
3447 scrollBy( 0, d->scrollBy );
3449 case TDEHTMLViewPrivate::ScrollUp:
3450 if (contentsY() <= 0)
3451 d->newScrollTimer(
this, 0);
3453 scrollBy( 0, -d->scrollBy );
3455 case TDEHTMLViewPrivate::ScrollRight:
3456 if (contentsX() + visibleWidth () >= contentsWidth())
3457 d->newScrollTimer(
this, 0);
3459 scrollBy( d->scrollBy, 0 );
3461 case TDEHTMLViewPrivate::ScrollLeft:
3462 if (contentsX() <= 0)
3463 d->newScrollTimer(
this, 0);
3465 scrollBy( -d->scrollBy, 0 );
3470 else if ( e->timerId() == d->layoutTimerId ) {
3471 d->dirtyLayout =
true;
3473 if (d->firstRelayout) {
3474 d->firstRelayout =
false;
3475 verticalScrollBar()->setEnabled(
true );
3476 horizontalScrollBar()->setEnabled(
true );
3479 #ifndef TDEHTML_NO_CARET
3480 else if (d->m_caretViewContext
3481 && e->timerId() == d->m_caretViewContext->freqTimerId) {
3482 d->m_caretViewContext->visible = !d->m_caretViewContext->visible;
3483 if (d->m_caretViewContext->displayed) {
3484 updateContents(d->m_caretViewContext->x, d->m_caretViewContext->y,
3485 d->m_caretViewContext->width,
3486 d->m_caretViewContext->height);
3494 d->contentsMoving =
false;
3495 if( m_part->xmlDocImpl() ) {
3496 DOM::DocumentImpl *document = m_part->xmlDocImpl();
3497 tdehtml::RenderCanvas* root =
static_cast<tdehtml::RenderCanvas *
>(document->renderer());
3499 if ( root && root->needsLayout() ) {
3500 killTimer(d->repaintTimerId);
3501 d->repaintTimerId = 0;
3507 setStaticBackground(d->useSlowRepaints);
3510 killTimer(d->repaintTimerId);
3511 d->repaintTimerId = 0;
3513 TQRect updateRegion;
3514 TQMemArray<TQRect> rects = d->updateRegion.rects();
3516 d->updateRegion = TQRegion();
3519 updateRegion = rects[0];
3521 for (
unsigned i = 1; i < rects.size(); ++i ) {
3522 TQRect newRegion = updateRegion.unite(rects[i]);
3523 if (2*newRegion.height() > 3*updateRegion.height() )
3525 repaintContents( updateRegion );
3526 updateRegion = rects[i];
3529 updateRegion = newRegion;
3532 if ( !updateRegion.isNull() )
3533 repaintContents( updateRegion );
3540 if (d->dirtyLayout && !d->visibleWidgets.isEmpty()) {
3542 d->dirtyLayout =
false;
3544 TQRect visibleRect(contentsX(), contentsY(), visibleWidth(), visibleHeight());
3545 TQPtrList<RenderWidget> toRemove;
3546 for (TQPtrDictIterator<TQWidget> it(d->visibleWidgets); it.current(); ++it) {
3549 RenderWidget* rw =
static_cast<RenderWidget*
>( it.currentKey() );
3550 if (!rw->absolutePosition(xp, yp) ||
3551 !visibleRect.intersects(TQRect(xp, yp, w->width(), w->height())))
3552 toRemove.append(rw);
3554 for (RenderWidget* r = toRemove.first(); r; r = toRemove.next())
3555 if ( (w = d->visibleWidgets.take(r) ) )
3556 addChild(w, 0, -500000);
3559 emit repaintAccessKeys();
3560 if (d->emitCompletedAfterRepaint) {
3561 bool full = d->emitCompletedAfterRepaint == TDEHTMLViewPrivate::CSFull;
3562 d->emitCompletedAfterRepaint = TDEHTMLViewPrivate::CSNone;
3570 void TDEHTMLView::scheduleRelayout(tdehtml::RenderObject * )
3572 if (!d->layoutSchedulingEnabled || d->layoutTimerId)
3575 d->layoutTimerId = startTimer( m_part->xmlDocImpl() && m_part->xmlDocImpl()->parsing()
3579 void TDEHTMLView::unscheduleRelayout()
3581 if (!d->layoutTimerId)
3584 killTimer(d->layoutTimerId);
3585 d->layoutTimerId = 0;
3588 void TDEHTMLView::unscheduleRepaint()
3590 if (!d->repaintTimerId)
3593 killTimer(d->repaintTimerId);
3594 d->repaintTimerId = 0;
3597 void TDEHTMLView::scheduleRepaint(
int x,
int y,
int w,
int h,
bool asap)
3599 bool parsing = !m_part->xmlDocImpl() || m_part->xmlDocImpl()->parsing();
3604 int time = parsing ? 300 : (!asap ? ( !d->complete ? 100 : 20 ) : 0);
3606 #ifdef DEBUG_FLICKER
3608 p.begin( viewport() );
3611 contentsToViewport( x, y, vx, vy );
3612 p.fillRect( vx, vy, w, h, TQt::red );
3616 d->updateRegion = d->updateRegion.unite(TQRect(x,y,w,h));
3618 if (asap && !parsing)
3619 unscheduleRepaint();
3621 if ( !d->repaintTimerId )
3622 d->repaintTimerId = startTimer( time );
3627 void TDEHTMLView::complete(
bool pendingAction )
3634 if (d->layoutTimerId)
3638 killTimer(d->layoutTimerId);
3639 d->layoutTimerId = startTimer( 0 );
3640 d->emitCompletedAfterRepaint = pendingAction ?
3641 TDEHTMLViewPrivate::CSActionPending : TDEHTMLViewPrivate::CSFull;
3645 if (d->repaintTimerId)
3649 killTimer(d->repaintTimerId);
3650 d->repaintTimerId = startTimer( 20 );
3651 d->emitCompletedAfterRepaint = pendingAction ?
3652 TDEHTMLViewPrivate::CSActionPending : TDEHTMLViewPrivate::CSFull;
3655 if (!d->emitCompletedAfterRepaint)
3665 void TDEHTMLView::slotMouseScrollTimer()
3667 scrollBy( d->m_mouseScroll_byX, d->m_mouseScroll_byY );
3670 #ifndef TDEHTML_NO_CARET
3675 #include "tdehtml_caret.cpp"
3677 void TDEHTMLView::initCaret(
bool keepSelection)
3679 #if DEBUG_CARETMODE > 0
3683 if (m_part->xmlDocImpl()) {
3685 ElementImpl *listitem = m_part->xmlDocImpl()->getElementById(
"__test_element__");
3686 if (listitem) dumpLineBoxes(
static_cast<RenderFlow *
>(listitem->renderer()));
3688 d->caretViewContext();
3689 bool cmoved = d->m_caretViewContext->caretMoved;
3690 if (m_part->d->caretNode().isNull()) {
3692 m_part->d->caretNode() = m_part->
document();
3693 m_part->d->caretOffset() = 0L;
3697 if (!m_part->d->caretNode().handle()->renderer())
return;
3702 moveCaretTo(m_part->d->caretNode().handle(), m_part->d->caretOffset(), !keepSelection);
3705 d->m_caretViewContext->caretMoved = cmoved;
3707 #if DEBUG_CARETMODE > 0
3712 bool TDEHTMLView::caretOverrides()
const
3716 return cm && !dm ? false
3717 : (dm || m_part->d->caretNode().handle()->contentEditable())
3718 && d->editorContext()->override;
3721 void TDEHTMLView::ensureNodeHasFocus(NodeImpl *node)
3724 if (node->focused())
return;
3727 NodeImpl *firstAncestor = 0;
3729 if (node->renderer()
3730 && node->renderer()->style()->userInput() != UI_ENABLED)
3732 firstAncestor = node;
3733 node = node->parentNode();
3736 if (!node) firstAncestor = 0;
3738 DocumentImpl *doc = m_part->xmlDocImpl();
3740 if (!firstAncestor && doc->focusNode() && doc->focusNode()->renderer()
3741 && doc->focusNode()->renderer()->isWidget())
3745 #if DEBUG_CARETMODE > 1
3746 kdDebug(6200) << k_funcinfo <<
"firstAncestor " << firstAncestor <<
": "
3747 << (firstAncestor ? firstAncestor->nodeName().string() : TQString::null) <<
endl;
3749 doc->setFocusNode(firstAncestor);
3753 void TDEHTMLView::recalcAndStoreCaretPos(CaretBox *hintBox)
3755 if (!m_part || m_part->d->caretNode().isNull())
return;
3756 d->caretViewContext();
3757 NodeImpl *caretNode = m_part->d->caretNode().handle();
3758 #if DEBUG_CARETMODE > 0
3759 kdDebug(6200) <<
"recalcAndStoreCaretPos: caretNode=" << caretNode << (caretNode ?
" "+caretNode->nodeName().string() : TQString::null) <<
" r@" << caretNode->renderer() << (caretNode->renderer() && caretNode->renderer()->isText() ?
" \"" + TQConstString(
static_cast<RenderText *
>(caretNode->renderer())->str->s, kMin(
static_cast<RenderText *
>(caretNode->renderer())->str->l, 15u)).string() +
"\"" : TQString::null) <<
endl;
3761 caretNode->getCaret(m_part->d->caretOffset(), caretOverrides(),
3762 d->m_caretViewContext->x, d->m_caretViewContext->y,
3763 d->m_caretViewContext->width,
3764 d->m_caretViewContext->height);
3766 if (hintBox && d->m_caretViewContext->x == -1) {
3767 #if DEBUG_CARETMODE > 1
3768 kdDebug(6200) <<
"using hint inline box coordinates" <<
endl;
3770 RenderObject *r = caretNode->renderer();
3771 const TQFontMetrics &fm = r->style()->fontMetrics();
3773 r->containingBlock()->absolutePosition(absx, absy,
3775 d->m_caretViewContext->x = absx + hintBox->xPos();
3776 d->m_caretViewContext->y = absy + hintBox->yPos();
3778 d->m_caretViewContext->width = 1;
3781 d->m_caretViewContext->height = fm.height();
3784 #if DEBUG_CARETMODE > 4
3787 #if DEBUG_CARETMODE > 0
3788 kdDebug(6200) <<
"caret: ofs="<<m_part->d->caretOffset()<<
" "
3789 <<
" x="<<d->m_caretViewContext->x<<
" y="<<d->m_caretViewContext->y
3790 <<
" h="<<d->m_caretViewContext->height<<
endl;
3794 void TDEHTMLView::caretOn()
3796 if (d->m_caretViewContext) {
3797 killTimer(d->m_caretViewContext->freqTimerId);
3799 if (hasFocus() || d->m_caretViewContext->displayNonFocused
3800 == TDEHTMLPart::CaretBlink) {
3801 d->m_caretViewContext->freqTimerId = startTimer(500);
3803 d->m_caretViewContext->freqTimerId = -1;
3806 d->m_caretViewContext->visible =
true;
3807 if ((d->m_caretViewContext->displayed = (hasFocus()
3808 || d->m_caretViewContext->displayNonFocused
3809 != TDEHTMLPart::CaretInvisible))) {
3810 updateContents(d->m_caretViewContext->x, d->m_caretViewContext->y,
3811 d->m_caretViewContext->width,
3812 d->m_caretViewContext->height);
3818 void TDEHTMLView::caretOff()
3820 if (d->m_caretViewContext) {
3821 killTimer(d->m_caretViewContext->freqTimerId);
3822 d->m_caretViewContext->freqTimerId = -1;
3823 d->m_caretViewContext->displayed =
false;
3824 if (d->m_caretViewContext->visible) {
3825 d->m_caretViewContext->visible =
false;
3826 updateContents(d->m_caretViewContext->x, d->m_caretViewContext->y,
3827 d->m_caretViewContext->width,
3828 d->m_caretViewContext->height);
3834 void TDEHTMLView::showCaret(
bool forceRepaint)
3836 if (d->m_caretViewContext) {
3837 d->m_caretViewContext->displayed =
true;
3838 if (d->m_caretViewContext->visible) {
3839 if (!forceRepaint) {
3840 updateContents(d->m_caretViewContext->x, d->m_caretViewContext->y,
3841 d->m_caretViewContext->width,
3842 d->m_caretViewContext->height);
3844 repaintContents(d->m_caretViewContext->x, d->m_caretViewContext->y,
3845 d->m_caretViewContext->width,
3846 d->m_caretViewContext->height);
3853 bool TDEHTMLView::foldSelectionToCaret(NodeImpl *startNode,
long startOffset,
3854 NodeImpl *endNode,
long endOffset)
3856 m_part->d->m_selectionStart = m_part->d->m_selectionEnd = m_part->d->caretNode();
3857 m_part->d->m_startOffset = m_part->d->m_endOffset = m_part->d->caretOffset();
3858 m_part->d->m_extendAtEnd =
true;
3860 bool folded = startNode != endNode || startOffset != endOffset;
3864 m_part->xmlDocImpl()->clearSelection();
3870 void TDEHTMLView::hideCaret()
3872 if (d->m_caretViewContext) {
3873 if (d->m_caretViewContext->visible) {
3875 d->m_caretViewContext->visible =
false;
3878 repaintContents(d->m_caretViewContext->x, d->m_caretViewContext->y,
3879 d->m_caretViewContext->width,
3880 d->m_caretViewContext->height);
3881 d->m_caretViewContext->visible =
true;
3883 d->m_caretViewContext->displayed =
false;
3888 int TDEHTMLView::caretDisplayPolicyNonFocused()
const
3890 if (d->m_caretViewContext)
3891 return d->m_caretViewContext->displayNonFocused;
3893 return TDEHTMLPart::CaretInvisible;
3896 void TDEHTMLView::setCaretDisplayPolicyNonFocused(
int policy)
3898 d->caretViewContext();
3904 switch (d->m_caretViewContext->displayNonFocused) {
3905 case TDEHTMLPart::CaretInvisible:
3908 case TDEHTMLPart::CaretBlink:
3909 if (d->m_caretViewContext->freqTimerId != -1)
break;
3910 d->m_caretViewContext->freqTimerId = startTimer(500);
3912 case TDEHTMLPart::CaretVisible:
3913 d->m_caretViewContext->displayed =
true;
3920 bool TDEHTMLView::placeCaret(CaretBox *hintBox)
3922 CaretViewContext *cv = d->caretViewContext();
3924 NodeImpl *caretNode = m_part->d->caretNode().handle();
3926 if (!caretNode || !caretNode->renderer())
return false;
3927 ensureNodeHasFocus(caretNode);
3929 || caretNode->renderer()->style()->userInput() == UI_ENABLED) {
3930 recalcAndStoreCaretPos(hintBox);
3940 void TDEHTMLView::ensureCaretVisible()
3942 CaretViewContext *cv = d->m_caretViewContext;
3944 ensureVisible(cv->x, cv->y, cv->width, cv->height);
3945 d->scrollBarMoved =
false;
3948 bool TDEHTMLView::extendSelection(NodeImpl *oldStartSel,
long oldStartOfs,
3949 NodeImpl *oldEndSel,
long oldEndOfs)
3951 bool changed =
false;
3952 if (m_part->d->m_selectionStart == m_part->d->m_selectionEnd
3953 && m_part->d->m_startOffset == m_part->d->m_endOffset) {
3954 changed = foldSelectionToCaret(oldStartSel, oldStartOfs, oldEndSel, oldEndOfs);
3955 m_part->d->m_extendAtEnd =
true;
3957 changed = m_part->d->m_selectionStart.handle() != oldStartSel
3958 || m_part->d->m_startOffset != oldStartOfs
3959 || m_part->d->m_selectionEnd.handle() != oldEndSel
3960 || m_part->d->m_endOffset != oldEndOfs;
3961 if (!changed)
break;
3964 NodeImpl *startNode;
3966 if (m_part->d->m_extendAtEnd) {
3967 startNode = m_part->d->m_selectionStart.handle();
3968 startOffset = m_part->d->m_startOffset;
3970 startNode = m_part->d->m_selectionEnd.handle();
3971 startOffset = m_part->d->m_endOffset;
3972 m_part->d->m_selectionEnd = m_part->d->m_selectionStart;
3973 m_part->d->m_endOffset = m_part->d->m_startOffset;
3974 m_part->d->m_extendAtEnd =
true;
3977 bool swapNeeded =
false;
3978 if (!m_part->d->m_selectionEnd.isNull() && startNode) {
3979 swapNeeded = RangeImpl::compareBoundaryPoints(startNode, startOffset,
3980 m_part->d->m_selectionEnd.handle(),
3981 m_part->d->m_endOffset) >= 0;
3984 m_part->d->m_selectionStart = startNode;
3985 m_part->d->m_startOffset = startOffset;
3988 m_part->xmlDocImpl()->setSelection(m_part->d->m_selectionEnd.handle(),
3989 m_part->d->m_endOffset, m_part->d->m_selectionStart.handle(),
3990 m_part->d->m_startOffset);
3992 m_part->xmlDocImpl()->setSelection(m_part->d->m_selectionStart.handle(),
3993 m_part->d->m_startOffset, m_part->d->m_selectionEnd.handle(),
3994 m_part->d->m_endOffset);
4000 void TDEHTMLView::updateSelection(NodeImpl *oldStartSel,
long oldStartOfs,
4001 NodeImpl *oldEndSel,
long oldEndOfs)
4003 if (m_part->d->m_selectionStart == m_part->d->m_selectionEnd
4004 && m_part->d->m_startOffset == m_part->d->m_endOffset) {
4005 if (foldSelectionToCaret(oldStartSel, oldStartOfs, oldEndSel, oldEndOfs)) {
4006 m_part->emitSelectionChanged();
4008 m_part->d->m_extendAtEnd =
true;
4011 if (!m_part->d->m_selectionEnd.isNull() && !m_part->d->m_selectionEnd.isNull()) {
4012 bool swapNeeded = RangeImpl::compareBoundaryPoints(
4013 m_part->d->m_selectionStart.handle(), m_part->d->m_startOffset,
4014 m_part->d->m_selectionEnd.handle(), m_part->d->m_endOffset) >= 0;
4016 DOM::Node tmpNode = m_part->d->m_selectionStart;
4017 long tmpOffset = m_part->d->m_startOffset;
4018 m_part->d->m_selectionStart = m_part->d->m_selectionEnd;
4019 m_part->d->m_startOffset = m_part->d->m_endOffset;
4020 m_part->d->m_selectionEnd = tmpNode;
4021 m_part->d->m_endOffset = tmpOffset;
4022 m_part->d->m_startBeforeEnd =
true;
4023 m_part->d->m_extendAtEnd = !m_part->d->m_extendAtEnd;
4027 m_part->xmlDocImpl()->setSelection(m_part->d->m_selectionStart.handle(),
4028 m_part->d->m_startOffset, m_part->d->m_selectionEnd.handle(),
4029 m_part->d->m_endOffset);
4030 m_part->emitSelectionChanged();
4034 void TDEHTMLView::caretKeyPressEvent(TQKeyEvent *_ke)
4036 NodeImpl *oldStartSel = m_part->d->m_selectionStart.handle();
4037 long oldStartOfs = m_part->d->m_startOffset;
4038 NodeImpl *oldEndSel = m_part->d->m_selectionEnd.handle();
4039 long oldEndOfs = m_part->d->m_endOffset;
4041 NodeImpl *oldCaretNode = m_part->d->caretNode().handle();
4042 long oldOffset = m_part->d->caretOffset();
4044 bool ctrl = _ke->state() & ControlButton;
4047 switch(_ke->key()) {
4052 moveCaretNextLine(1);
4056 moveCaretPrevLine(1);
4060 moveCaretBy(
false, ctrl ? CaretByWord : CaretByCharacter, 1);
4064 moveCaretBy(
true, ctrl ? CaretByWord : CaretByCharacter, 1);
4068 moveCaretNextPage();
4072 moveCaretPrevPage();
4077 moveCaretToDocumentBoundary(
false);
4079 moveCaretToLineBegin();
4084 moveCaretToDocumentBoundary(
true);
4086 moveCaretToLineEnd();
4091 if ((m_part->d->caretNode().handle() != oldCaretNode
4092 || m_part->d->caretOffset() != oldOffset)
4094 && !m_part->d->caretNode().isNull()) {
4096 d->m_caretViewContext->caretMoved =
true;
4098 if (_ke->state() & ShiftButton) {
4099 updateSelection(oldStartSel, oldStartOfs, oldEndSel, oldEndOfs);
4101 if (foldSelectionToCaret(oldStartSel, oldStartOfs, oldEndSel, oldEndOfs))
4102 m_part->emitSelectionChanged();
4105 m_part->emitCaretPositionChanged(m_part->d->caretNode(), m_part->d->caretOffset());
4111 bool TDEHTMLView::moveCaretTo(NodeImpl *node,
long offset,
bool clearSel)
4113 if (!node)
return false;
4114 ElementImpl *baseElem = determineBaseElement(node);
4115 RenderFlow *base =
static_cast<RenderFlow *
>(baseElem ? baseElem->renderer() : 0);
4116 if (!node)
return false;
4121 CaretBoxLineDeleter cblDeleter;
4124 CaretBoxIterator cbit;
4125 CaretBoxLine *cbl = findCaretBoxLine(node, offset, &cblDeleter, base, r_ofs, cbit);
4127 kdWarning() <<
"TDEHTMLView::moveCaretTo - findCaretBoxLine() returns NULL" <<
endl;
4131 #if DEBUG_CARETMODE > 3
4132 if (cbl)
kdDebug(6200) << cbl->information() <<
endl;
4134 CaretBox *box = *cbit;
4135 if (cbit != cbl->end() && box->object() != node->renderer()) {
4136 if (box->object()->element()) {
4137 mapRenderPosToDOMPos(box->object(), r_ofs, box->isOutside(),
4138 box->isOutsideEnd(), node, offset);
4140 #if DEBUG_CARETMODE > 1
4141 kdDebug(6200) <<
"set new node " << node->nodeName().string() <<
"@" << node <<
endl;
4146 kdError(6200) <<
"Box contains no node! Crash imminent" <<
endl;
4150 NodeImpl *oldStartSel = m_part->d->m_selectionStart.handle();
4151 long oldStartOfs = m_part->d->m_startOffset;
4152 NodeImpl *oldEndSel = m_part->d->m_selectionEnd.handle();
4153 long oldEndOfs = m_part->d->m_endOffset;
4156 bool posChanged = m_part->d->caretNode().handle() != node
4157 || m_part->d->caretOffset() != offset;
4158 bool selChanged =
false;
4160 m_part->d->caretNode() = node;
4161 m_part->d->caretOffset() = offset;
4162 if (clearSel || !oldStartSel || !oldEndSel) {
4163 selChanged = foldSelectionToCaret(oldStartSel, oldStartOfs, oldEndSel, oldEndOfs);
4167 selChanged = extendSelection(oldStartSel, oldStartOfs, oldEndSel, oldEndOfs);
4172 d->caretViewContext()->caretMoved =
true;
4174 bool visible_caret = placeCaret(box);
4180 m_part->emitCaretPositionChanged(visible_caret ? node : 0, offset);
4186 void TDEHTMLView::moveCaretByLine(
bool next,
int count)
4188 Node &caretNodeRef = m_part->d->caretNode();
4189 if (caretNodeRef.
isNull())
return;
4191 NodeImpl *caretNode = caretNodeRef.handle();
4193 long offset = m_part->d->caretOffset();
4195 CaretViewContext *cv = d->caretViewContext();
4197 ElementImpl *baseElem = determineBaseElement(caretNode);
4198 LinearDocument ld(m_part, caretNode, offset, LeafsOnly, baseElem);
4200 ErgonomicEditableLineIterator it(ld.current(), cv->origX);
4203 while (count > 0 && it != ld.end() && it != ld.preBegin()) {
4205 if (next) ++it;
else --it;
4209 if (it == ld.end() || it == ld.preBegin())
return;
4212 CaretBox *caretBox = nearestCaretBox(it, d->m_caretViewContext, x, absx, absy);
4214 placeCaretOnLine(caretBox, x, absx, absy);
4217 void TDEHTMLView::placeCaretOnLine(CaretBox *caretBox,
int x,
int absx,
int absy)
4220 if (!caretBox)
return;
4222 RenderObject *caretRender = caretBox->object();
4224 #if DEBUG_CARETMODE > 0
4225 kdDebug(6200) <<
"got valid caretBox " << caretBox <<
endl;
4226 kdDebug(6200) <<
"xPos: " << caretBox->xPos() <<
" yPos: " << caretBox->yPos()
4227 <<
" width: " << caretBox->width() <<
" height: " << caretBox->height() <<
endl;
4228 InlineTextBox *tb =
static_cast<InlineTextBox *
>(caretBox->inlineBox());
4229 if (caretBox->isInlineTextBox()) {
kdDebug(6200) <<
"contains \"" << TQString(
static_cast<RenderText *
>(tb->object())->str->s + tb->m_start, tb->m_len) <<
"\"" <<
endl;}
4232 int caretHeight = caretBox->height();
4233 bool isText = caretBox->isInlineTextBox();
4237 RenderText *t =
static_cast<RenderText *
>(caretRender);
4238 const TQFontMetrics &fm = t->metrics(caretBox->inlineBox()->m_firstLine);
4239 caretHeight = fm.height();
4240 yOfs = caretBox->inlineBox()->baseline() - fm.ascent();
4246 NodeImpl *caretNode;
4247 long &offset = m_part->d->caretOffset();
4248 mapRenderPosToDOMPos(caretRender, offset, caretBox->isOutside(),
4249 caretBox->isOutsideEnd(), caretNode, offset);
4252 d->m_caretViewContext->y = caretBox->yPos() + yOfs;
4253 d->m_caretViewContext->height = caretHeight;
4254 d->m_caretViewContext->width = 1;
4256 int xPos = caretBox->xPos();
4257 int caretBoxWidth = caretBox->width();
4258 d->m_caretViewContext->x = xPos;
4260 if (!caretBox->isOutside()) {
4264 r_ofs = caretBox->minOffset();
4266 }
else if (x > xPos && x <= xPos + caretBoxWidth) {
4268 r_ofs =
static_cast<InlineTextBox *
>(caretBox->inlineBox())
4269 ->offsetForPoint(x, d->m_caretViewContext->x);
4270 #if DEBUG_CARETMODE > 2
4271 kdDebug(6200) <<
"deviation from origX " << d->m_caretViewContext->x - x <<
endl;
4275 if (xPos + caretBoxWidth - x < x - xPos) {
4276 d->m_caretViewContext->x = xPos + caretBoxWidth;
4277 r_ofs = caretNode ? caretNode->maxOffset() : 1;
4279 d->m_caretViewContext->x = xPos;
4280 r_ofs = caretNode ? caretNode->minOffset() : 0;
4285 d->m_caretViewContext->x = xPos + caretBoxWidth;
4286 r_ofs = caretBox->maxOffset();
4290 #if DEBUG_CARETMODE > 0
4291 kdDebug(6200) <<
"new offset: " << offset <<
endl;
4294 m_part->d->caretNode() = caretNode;
4295 m_part->d->caretOffset() = offset;
4297 d->m_caretViewContext->x += absx;
4298 d->m_caretViewContext->y += absy;
4300 #if DEBUG_CARETMODE > 1
4301 kdDebug(6200) <<
"new caret position: x " << d->m_caretViewContext->x <<
" y " << d->m_caretViewContext->y <<
" w " << d->m_caretViewContext->width <<
" h " << d->m_caretViewContext->height <<
" absx " << absx <<
" absy " << absy <<
endl;
4304 ensureVisible(d->m_caretViewContext->x, d->m_caretViewContext->y,
4305 d->m_caretViewContext->width, d->m_caretViewContext->height);
4306 d->scrollBarMoved =
false;
4308 ensureNodeHasFocus(caretNode);
4312 void TDEHTMLView::moveCaretToLineBoundary(
bool end)
4314 Node &caretNodeRef = m_part->d->caretNode();
4315 if (caretNodeRef.
isNull())
return;
4317 NodeImpl *caretNode = caretNodeRef.handle();
4319 long offset = m_part->d->caretOffset();
4321 ElementImpl *baseElem = determineBaseElement(caretNode);
4322 LinearDocument ld(m_part, caretNode, offset, LeafsOnly, baseElem);
4324 EditableLineIterator it = ld.current();
4325 if (it == ld.end())
return;
4327 EditableCaretBoxIterator fbit(it, end);
4328 Q_ASSERT(fbit != (*it)->end() && fbit != (*it)->preBegin());
4329 CaretBox *b = *fbit;
4331 RenderObject *cb = b->containingBlock();
4334 if (cb) cb->absolutePosition(absx,absy);
4335 else absx = absy = 0;
4337 int x = b->xPos() + (
end && !b->isOutside() ? b->width() : 0);
4338 d->m_caretViewContext->origX = absx + x;
4339 placeCaretOnLine(b, x, absx, absy);
4342 void TDEHTMLView::moveCaretToDocumentBoundary(
bool end)
4344 Node &caretNodeRef = m_part->d->caretNode();
4345 if (caretNodeRef.
isNull())
return;
4347 NodeImpl *caretNode = caretNodeRef.handle();
4349 long offset = m_part->d->caretOffset();
4351 ElementImpl *baseElem = determineBaseElement(caretNode);
4352 LinearDocument ld(m_part, caretNode, offset, IndicatedFlows, baseElem);
4354 EditableLineIterator it(end ? ld.preEnd() : ld.begin(), end);
4355 if (it == ld.end() || it == ld.preBegin())
return;
4357 EditableCaretBoxIterator fbit = it;
4358 Q_ASSERT(fbit != (*it)->end() && fbit != (*it)->preBegin());
4359 CaretBox *b = *fbit;
4361 RenderObject *cb = (*it)->containingBlock();
4364 if (cb) cb->absolutePosition(absx, absy);
4365 else absx = absy = 0;
4368 d->m_caretViewContext->origX = absx + x;
4369 placeCaretOnLine(b, x, absx, absy);
4372 void TDEHTMLView::moveCaretBy(
bool next, CaretMovement cmv,
int count)
4374 if (!m_part)
return;
4375 Node &caretNodeRef = m_part->d->caretNode();
4376 if (caretNodeRef.
isNull())
return;
4378 NodeImpl *caretNode = caretNodeRef.handle();
4380 long &offset = m_part->d->caretOffset();
4382 ElementImpl *baseElem = determineBaseElement(caretNode);
4383 CaretAdvancePolicy advpol = cmv != CaretByWord ? IndicatedFlows : LeafsOnly;
4384 LinearDocument ld(m_part, caretNode, offset, advpol, baseElem);
4386 EditableCharacterIterator it(&ld);
4387 while (!it.isEnd() && count > 0) {
4389 if (cmv == CaretByCharacter) {
4392 }
else if (cmv == CaretByWord) {
4393 if (next) moveItToNextWord(it);
4394 else moveItToPrevWord(it);
4398 CaretBox *hintBox = 0;
4400 NodeImpl *node = caretNodeRef.handle();
4401 hintBox = it.caretBox();
4404 mapRenderPosToDOMPos(it.renderer(), it.offset(), hintBox->isOutside(),
4405 hintBox->isOutsideEnd(), node, offset);
4407 caretNodeRef = node;
4408 #if DEBUG_CARETMODE > 2
4409 kdDebug(6200) <<
"set by valid node " << node <<
" " << (node?node->nodeName().string():TQString::null) <<
" offset: " << offset <<
endl;
4412 offset =
next ? caretNode->maxOffset() : caretNode->minOffset();
4413 #if DEBUG_CARETMODE > 0
4414 kdDebug(6200) <<
"set by INvalid node. offset: " << offset <<
endl;
4417 placeCaretOnChar(hintBox);
4420 void TDEHTMLView::placeCaretOnChar(CaretBox *hintBox)
4423 recalcAndStoreCaretPos(hintBox);
4424 ensureVisible(d->m_caretViewContext->x, d->m_caretViewContext->y,
4425 d->m_caretViewContext->width, d->m_caretViewContext->height);
4426 d->m_caretViewContext->origX = d->m_caretViewContext->x;
4427 d->scrollBarMoved =
false;
4428 #if DEBUG_CARETMODE > 3
4431 ensureNodeHasFocus(m_part->d->caretNode().handle());
4435 void TDEHTMLView::moveCaretByPage(
bool next)
4437 Node &caretNodeRef = m_part->d->caretNode();
4438 if (caretNodeRef.
isNull())
return;
4440 NodeImpl *caretNode = caretNodeRef.handle();
4442 long offset = m_part->d->caretOffset();
4444 int offs = (clipper()->height() < 30) ? clipper()->height() : 30;
4446 int mindist = clipper()->height() - offs;
4448 CaretViewContext *cv = d->caretViewContext();
4451 ElementImpl *baseElem = determineBaseElement(caretNode);
4452 LinearDocument ld(m_part, caretNode, offset, LeafsOnly, baseElem);
4454 ErgonomicEditableLineIterator it(ld.current(), cv->origX);
4456 moveIteratorByPage(ld, it, mindist, next);
4459 CaretBox *caretBox = nearestCaretBox(it, d->m_caretViewContext, x, absx, absy);
4461 placeCaretOnLine(caretBox, x, absx, absy);
4464 void TDEHTMLView::moveCaretPrevWord()
4466 moveCaretBy(
false, CaretByWord, 1);
4469 void TDEHTMLView::moveCaretNextWord()
4471 moveCaretBy(
true, CaretByWord, 1);
4474 void TDEHTMLView::moveCaretPrevLine(
int n)
4476 moveCaretByLine(
false, n);
4479 void TDEHTMLView::moveCaretNextLine(
int n)
4481 moveCaretByLine(
true, n);
4484 void TDEHTMLView::moveCaretPrevPage()
4486 moveCaretByPage(
false);
4489 void TDEHTMLView::moveCaretNextPage()
4491 moveCaretByPage(
true);
4494 void TDEHTMLView::moveCaretToLineBegin()
4496 moveCaretToLineBoundary(
false);
4499 void TDEHTMLView::moveCaretToLineEnd()
4501 moveCaretToLineBoundary(
true);
4506 #ifndef NO_SMOOTH_SCROLL_HACK
4507 #define timer timer2
4510 static const int SCROLL_TIME = 240;
4512 static const int SCROLL_TICK = 20;
4514 void TDEHTMLView::scrollBy(
int dx,
int dy)
4517 if( !cfg.readBoolEntry(
"SmoothScrolling",
false )) {
4518 TQScrollView::scrollBy( dx, dy );
4522 int full_dx = d->dx + dx;
4523 int full_dy = d->dy + dy;
4529 int steps = SCROLL_TIME/SCROLL_TICK;
4531 ddx = (full_dx*16)/steps;
4532 ddy = (full_dy*16)/steps;
4535 if (ddx > 0 && ddx < 16) ddx = 16;
4536 if (ddy > 0 && ddy < 16) ddy = 16;
4537 if (ddx < 0 && ddx > -16) ddx = -16;
4538 if (ddy < 0 && ddy > -16) ddy = -16;
4545 if (!d->scrolling) {
4551 void TDEHTMLView::scrollTick() {
4552 if (d->dx == 0 && d->dy == 0) {
4557 int tddx = d->ddx + d->rdx;
4558 int tddy = d->ddy + d->rdy;
4560 int ddx = tddx / 16;
4561 int ddy = tddy / 16;
4565 if (d->dx > 0 && ddx > d->dx) ddx = d->dx;
4567 if (d->dx < 0 && ddx < d->dx) ddx = d->dx;
4569 if (d->dy > 0 && ddy > d->dy) ddy = d->dy;
4571 if (d->dy < 0 && ddy < d->dy) ddy = d->dy;
4578 TQScrollView::scrollBy(ddx, ddy);
4585 void TDEHTMLView::startScrolling()
4587 d->scrolling =
true;
4588 d->timer.start(SCROLL_TICK,
false);
4591 void TDEHTMLView::stopScrolling()
4595 d->scrolling =
false;
4599 void TDEHTMLView::scrollViewWheelEvent( TQWheelEvent *e )
4601 int pageStep = verticalScrollBar()->pageStep();
4602 int lineStep = verticalScrollBar()->lineStep();
4603 int step = TQMIN( TQApplication::wheelScrollLines()*lineStep, pageStep );
4604 if ( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) )
4607 if(e->orientation() == TQt::Horizontal)
4608 scrollBy(-((e->delta()*step)/120), 0);
4609 else if(e->orientation() == TQt::Vertical)
4610 scrollBy(0,-((e->delta()*step)/120));
4619 #undef DEBUG_CARETMODE
This class implements the basic string we use in the DOM.
The Node interface is the primary datatype for the entire Document Object Model.
bool isNull() const
tests if this Node is 0.
static TQCursor arrowCursor()
static TQCursor sizeHorCursor()
static TQCursor sizeAllCursor()
static TQCursor crossCursor()
static TQCursor sizeFDiagCursor()
static TQCursor waitCursor()
static TQCursor whatsThisCursor()
static TQCursor workingCursor()
static TQCursor ibeamCursor()
static TQCursor sizeVerCursor()
static TQCursor sizeBDiagCursor()
virtual TQWidget * widget()
static TQString csqueeze(const TQString &str, uint maxlen=40)
static ButtonState keyboardMouseState()
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
static TDEIconLoader * iconLoader()
static TDEConfig * config()
static TDELocale * locale()
This class is tdehtml's main class.
DOM::Document document() const
Returns a reference to the DOM document.
CaretDisplayPolicy
Enumeration for displaying the caret.
int zoomFactor() const
Returns the current zoom factor.
TQCursor urlCursor() const
Returns the cursor which is used when the cursor is on a link.
bool isCaretMode() const
Returns whether caret mode is on/off.
TDEHTMLView * view() const
Returns a pointer to the HTML document's view.
bool findTextNext(const TQString &str, bool forward, bool caseSensitive, bool isRegExp)
Finds the next occurrence of the string or expression.
virtual void begin(const KURL &url=KURL(), int xOffset=0, int yOffset=0)
Clears the widget and prepares it for new content.
void findTextBegin()
Initiates a text search.
bool isEditable() const
Returns true if the document is editable, false otherwise.
bool frameExists(const TQString &frameName)
Returns whether a frame with the specified name is exists or not.
void nodeActivated(const DOM::Node &)
This signal is emitted when an element retrieves the keyboard focus.
void findText()
Starts a new search by popping up a dialog asking the user what he wants to search for.
TDEHTMLPart * parentPart()
Returns a pointer to the parent TDEHTMLPart if the part is a frame in an HTML frameset.
Renders and displays HTML in a TQScrollView.
void layout()
ensure the display is up to date
void displayAccessKeys()
Display all accesskeys in small tooltips.
virtual void setVScrollBarMode(ScrollBarMode mode)
Sets verticals scrollbar mode.
void print()
Prints the HTML document.
void setMarginWidth(int x)
Sets a margin in x direction.
virtual void setHScrollBarMode(ScrollBarMode mode)
Sets horizontal scrollbar mode.
TDEHTMLView(TDEHTMLPart *part, TQWidget *parent, const char *name=0)
Constructs a TDEHTMLView.
TDEHTMLPart * part() const
Returns a pointer to the TDEHTMLPart that is rendering the page.
void finishedLayout()
This signal is used for internal layouting.
TQPixmap loadIcon(const TQString &name, TDEIcon::Group group, int size=0, int state=TDEIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
TQString formatDate(const TQDate &pDate, bool shortFormat=false) const
kndbgstream & endl(kndbgstream &s)
kdbgstream kdWarning(int area=0)
kdbgstream kdError(int area=0)
kdbgstream kdDebug(int area=0)
TQString locateLocal(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
The Document Object Model (DOM) is divided into two parts, the COREDOM core DOM, specifying some core...
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED
void beep(const TQString &reason=TQString::null)
const TDEShortcut & next()
const TDEShortcut & end()
const TDEShortcut & close()
TQString label(StdAccel id)