31 #include "khtmlview.moc"
36 #include <qx11info_x11.h>
39 #include "html/html_documentimpl.h"
40 #include "html/html_inlineimpl.h"
41 #include "html/html_formimpl.h"
42 #include "html/htmltokenizer.h"
44 #include "rendering/render_arena.h"
45 #include "rendering/render_canvas.h"
46 #include "rendering/render_frames.h"
47 #include "rendering/render_replaced.h"
48 #include "rendering/render_form.h"
49 #include "rendering/render_layer.h"
50 #include "rendering/render_line.h"
51 #include "rendering/render_table.h"
53 #define protected public
54 #include "rendering/render_text.h"
56 #include "xml/dom2_eventsimpl.h"
57 #include "css/cssstyleselector.h"
58 #include "css/csshelper.h"
59 #include "misc/helper.h"
60 #include "misc/loader.h"
80 #include <QtGui/QBitmap>
81 #include <QtGui/QLabel>
82 #include <QtCore/QObject>
83 #include <QtGui/QPainter>
84 #include <QtCore/QHash>
85 #include <QtGui/QToolTip>
86 #include <QtCore/QString>
87 #include <QtGui/QTextDocument>
88 #include <QtCore/QTimer>
89 #include <QtCore/QAbstractEventDispatcher>
90 #include <QtCore/QVector>
91 #include <QtGui/QAbstractScrollArea>
92 #include <QtGui/QPrinter>
93 #include <QtGui/QPrintDialog>
101 #elif defined(Q_WS_WIN)
107 void dumpLineBoxes(RenderFlow *flow);
112 using namespace khtml;
133 class KHTMLViewPrivate {
137 enum PseudoFocusNodes {
143 enum StaticBackgroundState {
149 enum CompletedState {
156 : underMouse( 0 ), underMouseNonShared( 0 ), oldUnderMouse( 0 )
158 postponed_autorepeat = NULL;
159 scrollingFromWheelTimerId = 0;
163 vpolicy = Qt::ScrollBarAsNeeded;
164 hpolicy = Qt::ScrollBarAsNeeded;
166 prevScrollbarVisible =
true;
168 possibleTripleClick =
false;
169 emitCompletedAfterRepaint = CSNone;
170 cursorIconWidget = 0;
171 cursorIconType = KHTMLView::LINK_NORMAL;
172 m_mouseScrollTimer = 0;
173 m_mouseScrollIndicator = 0;
180 delete formCompletions;
181 delete postponed_autorepeat;
184 if (underMouseNonShared)
185 underMouseNonShared->deref();
187 oldUnderMouse->deref();
189 delete cursorIconWidget;
190 delete m_mouseScrollTimer;
191 delete m_mouseScrollIndicator;
198 if (underMouseNonShared)
199 underMouseNonShared->deref();
200 underMouseNonShared = 0;
202 oldUnderMouse->deref();
205 staticWidget = SBNone;
206 fixedObjectsCount = 0;
207 staticObjectsCount = 0;
208 tabMovePending =
false;
209 lastTabbingDirection =
true;
210 pseudoFocusNode = PFNone;
212 #ifndef KHTML_NO_SCROLLBARS
218 vpolicy = ScrollBarAlwaysOff;
219 hpolicy = ScrollBarAlwaysOff;
221 scrollBarMoved =
false;
222 contentsMoving =
false;
223 ignoreWheelEvents =
false;
224 scrollingFromWheel =
QPoint(-1,-1);
233 isDoubleClick =
false;
234 scrollingSelf =
false;
235 delete postponed_autorepeat;
236 postponed_autorepeat = NULL;
240 scrollSuspended =
false;
241 scrollSuspendPreActivate =
false;
242 smoothScrolling =
false;
243 smoothScrollModeIsDefault =
true;
244 shouldSmoothScroll =
false;
245 smoothScrollMissedDeadlines = 0;
248 firstLayoutPending =
true;
250 firstRepaintPending =
true;
252 needsFullRepaint =
true;
254 layoutSchedulingEnabled =
true;
257 layoutAttemptCounter = 0;
258 scheduledLayoutCounter = 0;
259 updateRegion = QRegion();
260 m_dialogsAllowed =
true;
261 accessKeysActivated =
false;
262 accessKeysPreActivate =
false;
269 KHTMLGlobal::deref();
271 emitCompletedAfterRepaint = CSNone;
272 m_mouseEventsTarget = 0;
275 void newScrollTimer(
QWidget *view,
int tid)
278 view->killTimer(scrollTimerId);
280 scrollSuspended =
false;
282 enum ScrollDirection { ScrollLeft, ScrollRight, ScrollUp, ScrollDown };
284 void adjustScroller(
QWidget *view, ScrollDirection direction, ScrollDirection oppositedir)
286 static const struct {
int msec, pixels; } timings [] = {
287 {320,1}, {224,1}, {160,1}, {112,1}, {80,1}, {56,1}, {40,1},
288 {28,1}, {20,1}, {20,2}, {20,3}, {20,4}, {20,6}, {20,8}, {0,0}
290 if (!scrollTimerId ||
291 (static_cast<int>(scrollDirection) != direction &&
292 (static_cast<int>(scrollDirection) != oppositedir || scrollSuspended))) {
294 scrollBy = timings[scrollTiming].pixels;
295 scrollDirection = direction;
296 newScrollTimer(view, view->startTimer(timings[scrollTiming].msec));
297 }
else if (scrollDirection == direction &&
298 timings[scrollTiming+1].msec && !scrollSuspended) {
299 scrollBy = timings[++scrollTiming].pixels;
300 newScrollTimer(view, view->startTimer(timings[scrollTiming].msec));
301 }
else if (scrollDirection == oppositedir) {
303 scrollBy = timings[--scrollTiming].pixels;
304 newScrollTimer(view, view->startTimer(timings[scrollTiming].msec));
307 scrollSuspended =
false;
310 bool haveZoom()
const {
return zoomLevel != 100; }
312 void startScrolling()
314 smoothScrolling =
true;
316 shouldSmoothScroll =
false;
321 smoothScrollTimer.stop();
325 smoothScrolling =
false;
326 shouldSmoothScroll =
false;
329 void updateContentsXY()
331 contentsX = QApplication::isRightToLeft() ?
332 view->horizontalScrollBar()->maximum()-view->horizontalScrollBar()->value() : view->horizontalScrollBar()->value();
333 contentsY = view->verticalScrollBar()->value();
335 void scrollAccessKeys(
int dx,
int dy)
337 QList<QLabel*> wl = qFindChildren<QLabel*>(view->widget(),
"KHTMLAccessKey");
339 w->move( w->pos() +
QPoint(dx, dy) );
342 void scrollExternalWidgets(
int dx,
int dy)
344 if (visibleWidgets.isEmpty())
347 QHashIterator<void*, QWidget*> it(visibleWidgets);
348 while (it.hasNext()) {
350 it.value()->move( it.value()->pos() +
QPoint(dx, dy) );
354 NodeImpl *underMouse;
355 NodeImpl *underMouseNonShared;
356 NodeImpl *oldUnderMouse;
360 bool tabMovePending:1;
361 bool lastTabbingDirection:1;
362 PseudoFocusNodes pseudoFocusNode:3;
363 bool scrollBarMoved:1;
364 bool contentsMoving:1;
366 Qt::ScrollBarPolicy vpolicy;
367 Qt::ScrollBarPolicy hpolicy;
368 bool prevScrollbarVisible:1;
370 bool ignoreWheelEvents:1;
371 StaticBackgroundState staticWidget: 3;
372 int staticObjectsCount;
373 int fixedObjectsCount;
376 int borderX, borderY;
381 int clickX, clickY, clickCount;
387 int contentsX, contentsY;
389 QKeyEvent* postponed_autorepeat;
395 ScrollDirection scrollDirection :3;
396 bool scrollSuspended :1;
397 bool scrollSuspendPreActivate :1;
399 bool smoothScrolling :1;
400 bool smoothScrollModeIsDefault :1;
401 bool shouldSmoothScroll :1;
404 bool firstLayoutPending :1;
406 bool firstRepaintPending :1;
408 bool layoutSchedulingEnabled :1;
409 bool needsFullRepaint :1;
411 bool possibleTripleClick :1;
413 bool m_dialogsAllowed :1;
414 short smoothScrollMissedDeadlines;
416 int layoutAttemptCounter;
417 int scheduledLayoutCounter;
418 QRegion updateRegion;
419 QTimer smoothScrollTimer;
420 QTime smoothScrollStopwatch;
422 bool accessKeysEnabled;
423 bool accessKeysActivated;
424 bool accessKeysPreActivate;
425 CompletedState emitCompletedAfterRepaint;
428 KHTMLView::LinkCursor cursorIconType;
431 short m_mouseScroll_byX;
432 short m_mouseScroll_byY;
433 QPoint scrollingFromWheel;
434 int scrollingFromWheelTimerId;
435 QTimer *m_mouseScrollTimer;
436 QWidget *m_mouseScrollIndicator;
437 QPointer<QWidget> m_mouseEventsTarget;
442 #ifndef QT_NO_TOOLTIP
456 HTMLMapElementImpl* map;
457 if (img && img->document()->isHTMLDocument() &&
458 (map =
static_cast<HTMLDocumentImpl*
>(img->document())->getMap(img->imageMap()))) {
459 RenderObject::NodeInfo info(
true,
false);
460 RenderObject *rend = img->renderer();
462 if (!rend || !rend->absolutePosition(ax, ay))
465 bool inside = map->mapMouseEvent(p.x() - ax + scrollOfs.x(),
466 p.y() - ay + scrollOfs.y(), rend->contentWidth(),
467 rend->contentHeight(), info);
468 if (inside && info.URLElement()) {
469 HTMLAreaElementImpl *area =
static_cast<HTMLAreaElementImpl *
>(info.URLElement());
470 Q_ASSERT(area->id() == ID_AREA);
471 s = area->getAttribute(ATTR_TITLE).string();
472 QRegion reg = area->cachedRegion();
473 if (!s.isEmpty() && !reg.isEmpty()) {
474 r = reg.boundingRect();
485 switch ( e->type() ) {
486 case QEvent::ToolTip: {
487 QHelpEvent *he =
static_cast<QHelpEvent*
>(e);
490 DOM::NodeImpl *node =
d->underMouseNonShared;
493 if ( node->isElementNode() ) {
494 DOM::ElementImpl *e =
static_cast<DOM::ElementImpl*
>( node );
500 if (e->id() == ID_IMG && !e->getAttribute( ATTR_USEMAP ).isEmpty()) {
502 viewportToContents(
QPoint(0, 0)), p, r, s);
505 s = e->getAttribute( ATTR_TITLE ).string();
508 region |=
QRect( contentsToViewport( r.topLeft() ), r.size() );
509 if ( !s.isEmpty() ) {
510 QToolTip::showText( he->globalPos(),
511 Qt::convertFromPlainText( s, Qt::WhiteSpaceNormal ),
516 node = node->parentNode();
524 case QEvent::DragEnter:
525 case QEvent::DragMove:
526 case QEvent::DragLeave:
536 return QWidget::event(e);
537 case QEvent::StyleChange:
538 case QEvent::LayoutRequest: {
540 return QAbstractScrollArea::event(e);
542 case QEvent::PaletteChange:
543 slotPaletteChanged();
544 return QScrollArea::event(e);
546 return QScrollArea::event(e);
552 :
QScrollArea( parent ),
d( new KHTMLViewPrivate( this ) )
558 QScrollArea::setVerticalScrollBarPolicy(d->vpolicy);
559 QScrollArea::setHorizontalScrollBarPolicy(d->hpolicy);
562 widget()->setMouseTracking(
true);
570 DOM::DocumentImpl *doc = m_part->xmlDocImpl();
583 void KHTMLView::init()
587 setFrameStyle(QFrame::NoFrame);
588 setFocusPolicy(Qt::StrongFocus);
589 viewport()->setFocusProxy(
this);
598 setAcceptDrops(
true);
600 setWidget(
new QWidget(
this) );
601 widget()->setAttribute( Qt::WA_NoSystemBackground );
607 widget()->setAttribute( Qt::WA_OpaquePaintEvent );
609 verticalScrollBar()->setCursor( Qt::ArrowCursor );
610 horizontalScrollBar()->setCursor( Qt::ArrowCursor );
612 connect(&d->smoothScrollTimer, SIGNAL(
timeout()),
this, SLOT(scrollTick()));
615 void KHTMLView::resizeContentsToViewport()
617 QSize s = viewport()->size();
625 if (d->accessKeysEnabled && d->accessKeysActivated)
627 viewport()->unsetCursor();
628 if ( d->cursorIconWidget )
629 d->cursorIconWidget->hide();
630 if (d->smoothScrolling)
633 QAbstractEventDispatcher::instance()->unregisterTimers(
this);
636 QScrollArea::setHorizontalScrollBarPolicy(d->hpolicy);
637 QScrollArea::setVerticalScrollBarPolicy(d->vpolicy);
638 verticalScrollBar()->setEnabled(
false );
639 horizontalScrollBar()->setEnabled(
false );
645 QScrollArea::hideEvent(e);
650 QScrollArea::showEvent(e);
653 void KHTMLView::setMouseEventsTarget(
QWidget* w )
655 d->m_mouseEventsTarget = w;
658 QWidget* KHTMLView::mouseEventsTarget()
const
660 return d->m_mouseEventsTarget;
665 d->m_clipHolder = ch;
670 return d->m_clipHolder;
675 return widget() ? widget()->width() : 0;
680 return widget() ? widget()->height() : 0;
687 widget()->resize(w, h);
688 if (!widget()->isVisible())
704 if (
m_kwp->isRedirected()) {
706 if (RenderWidget* rw =
m_kwp->renderWidget()) {
707 int ret = rw->width()-rw->paddingLeft()-rw->paddingRight()-rw->borderLeft()-rw->borderRight();
708 if (verticalScrollBar()->isVisible()) {
709 ret -= verticalScrollBar()->sizeHint().width();
715 return viewport()->width();
720 if (
m_kwp->isRedirected()) {
722 if (RenderWidget* rw =
m_kwp->renderWidget()) {
723 int ret = rw->height()-rw->paddingBottom()-rw->paddingTop()-rw->borderTop()-rw->borderBottom();
724 if (horizontalScrollBar()->isVisible()) {
725 ret -= horizontalScrollBar()->sizeHint().height();
731 return viewport()->height();
736 horizontalScrollBar()->setValue( QApplication::isRightToLeft() ?
737 horizontalScrollBar()->maximum()-x : x );
738 verticalScrollBar()->setValue( y );
743 if (d->scrollTimerId)
744 d->newScrollTimer(
this, 0);
745 horizontalScrollBar()->setValue( horizontalScrollBar()->value()+x );
746 verticalScrollBar()->setValue( verticalScrollBar()->value()+y );
777 applyTransforms(x, y, w, h);
778 if (
m_kwp->isRedirected()) {
783 widget()->update(x, y, w, h);
793 applyTransforms(x, y, w, h);
794 if (
m_kwp->isRedirected()) {
799 widget()->repaint(x, y, w, h);
807 void KHTMLView::applyTransforms(
int& x,
int& y,
int& w,
int& h)
const
810 const int z = d->zoomLevel;
820 void KHTMLView::revertTransforms(
int& x,
int& y,
int& w,
int& h)
const
825 const int z = d->zoomLevel;
833 void KHTMLView::revertTransforms(
int& x,
int& y )
const
836 revertTransforms(x, y, dummy, dummy);
844 if (!m_part->xmlDocImpl())
845 resizeContentsToViewport();
848 if (m_part->xmlDocImpl() && m_part->xmlDocImpl()->styleSelector()->affectedByViewportChange()) {
849 m_part->xmlDocImpl()->updateStyleSelector();
852 if (d->layoutSchedulingEnabled)
855 QApplication::sendPostedEvents(viewport(), QEvent::Paint);
857 if ( m_part && m_part->xmlDocImpl() ) {
865 HTMLPartContainerElementImpl::sendPostedResizeEvents();
866 m_part->xmlDocImpl()->dispatchWindowEvent( EventImpl::RESIZE_EVENT,
false,
false );
878 if (!r.isValid() || r.isEmpty())
return;
880 QPainter p(widget());
884 p.scale( d->zoomLevel/100., d->zoomLevel/100.);
886 r.setX(r.x()*100/d->zoomLevel);
887 r.setY(r.y()*100/d->zoomLevel);
888 r.setWidth(r.width()*100/d->zoomLevel);
889 r.setHeight(r.height()*100/d->zoomLevel);
899 if(!m_part || !m_part->xmlDocImpl() || !m_part->xmlDocImpl()->renderer()) {
900 p.fillRect(ex, ey, ew, eh, palette().brush(QPalette::Active, QPalette::Base));
902 }
else if ( d->complete && static_cast<RenderCanvas*>(m_part->xmlDocImpl()->renderer())->needsLayout() ) {
904 unscheduleRelayout();
906 }
else if (m_part->xmlDocImpl()->tokenizer()) {
907 m_part->xmlDocImpl()->tokenizer()->setNormalYieldDelay();
911 kDebug( 6000 ) <<
"WARNING: paintEvent reentered! ";
912 kDebug( 6000 ) << kBacktrace();
917 m_part->xmlDocImpl()->renderer()->layer()->paint(&p, r);
919 if (d->hasFrameset) {
920 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(m_part->xmlDocImpl())->body();
921 if(body && body->renderer() && body->id() == ID_FRAMESET)
922 static_cast<RenderFrameSet*>(body->renderer())->paintFrameSetRules(&p, r);
924 d->hasFrameset =
false;
928 QApplication::sendEvent( m_part, &event );
930 if (d->contentsMoving && !d->smoothScrolling && widget()->underMouse()) {
931 QMouseEvent *tempEvent =
new QMouseEvent( QEvent::MouseMove, widget()->mapFromGlobal( QCursor::pos() ),
932 Qt::NoButton, Qt::NoButton, Qt::NoModifier );
933 QApplication::postEvent(widget(), tempEvent);
936 if (d->firstRepaintPending && !m_part->
parentPart()) {
939 d->firstRepaintPending =
false;
958 if( m_part && m_part->xmlDocImpl() ) {
959 DOM::DocumentImpl *document = m_part->xmlDocImpl();
961 khtml::RenderCanvas* canvas =
static_cast<khtml::RenderCanvas *
>(document->renderer());
962 if ( !canvas )
return;
964 d->layoutSchedulingEnabled=
false;
965 d->dirtyLayout =
true;
968 RenderObject *
ref = 0;
969 RenderObject* root = document->documentElement() ? document->documentElement()->renderer() : 0;
971 if (document->isHTMLDocument()) {
972 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(document)->body();
973 if(body && body->renderer() && body->id() == ID_FRAMESET) {
974 QScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
975 QScrollArea::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
976 body->renderer()->setNeedsLayout(
true);
977 d->hasFrameset =
true;
980 ref = (!body || root->style()->hidesOverflow()) ? root : body->renderer();
985 if( ref->style()->overflowX() == OHIDDEN ) {
986 if (d->hpolicy == Qt::ScrollBarAsNeeded) QScrollArea::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
987 }
else if (ref->style()->overflowX() == OSCROLL ) {
988 if (d->hpolicy == Qt::ScrollBarAsNeeded) QScrollArea::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
989 }
else if (horizontalScrollBarPolicy() != d->hpolicy) {
990 QScrollArea::setHorizontalScrollBarPolicy(d->hpolicy);
992 if ( ref->style()->overflowY() == OHIDDEN ) {
993 if (d->vpolicy == Qt::ScrollBarAsNeeded) QScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
994 }
else if (ref->style()->overflowY() == OSCROLL ) {
995 if (d->vpolicy == Qt::ScrollBarAsNeeded) QScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
996 }
else if (verticalScrollBarPolicy() != d->vpolicy) {
997 QScrollArea::setVerticalScrollBarPolicy(d->vpolicy);
1000 d->needsFullRepaint = d->firstLayoutPending;
1002 d->needsFullRepaint =
true;
1010 if (d->firstLayoutPending) {
1013 d->firstLayoutPending =
false;
1014 verticalScrollBar()->setEnabled(
true );
1015 horizontalScrollBar()->setEnabled(
true );
1019 if (d->accessKeysEnabled && d->accessKeysActivated) {
1027 if (d->layoutTimerId)
1028 killTimer(d->layoutTimerId);
1029 d->layoutTimerId = 0;
1030 d->layoutSchedulingEnabled=
true;
1033 void KHTMLView::closeChildDialogs()
1040 if ( dlgbase->testAttribute( Qt::WA_ShowModal ) ) {
1041 kDebug(6000) <<
"closeChildDialogs: closing dialog " << dlgbase;
1049 kWarning() <<
"closeChildDialogs: not a KDialog! Don't use QDialogs in KDE! " <<
static_cast<QWidget*
>(dlg);
1050 static_cast<QWidget*
>(dlg)->hide();
1053 d->m_dialogsAllowed =
false;
1056 bool KHTMLView::dialogsAllowed() {
1057 bool allowed = d->m_dialogsAllowed;
1060 allowed &= p->
view()->dialogsAllowed();
1066 closeChildDialogs();
1067 QScrollArea::closeEvent( ev );
1072 percent = percent < 20 ? 20 : (percent > 800 ? 800 : percent);
1073 int oldpercent = d->zoomLevel;
1074 d->zoomLevel = percent;
1075 if (percent != oldpercent) {
1076 if (d->layoutSchedulingEnabled)
1084 return d->zoomLevel;
1089 d->smoothScrollMode = m;
1090 d->smoothScrollModeIsDefault =
false;
1091 if (d->smoothScrolling && !m)
1098 if (!d->smoothScrollModeIsDefault)
1100 d->smoothScrollMode = m;
1101 if (d->smoothScrolling && !m)
1107 return d->smoothScrollMode;
1117 if (!m_part->xmlDocImpl())
return;
1118 if (d->possibleTripleClick && ( _mouse->button() & Qt::MouseButtonMask ) == Qt::LeftButton)
1124 int xm = _mouse->x();
1125 int ym = _mouse->y();
1126 revertTransforms(xm, ym);
1130 d->isDoubleClick =
false;
1132 DOM::NodeImpl::MouseEvent mev( _mouse->buttons(), DOM::NodeImpl::MousePress );
1133 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1137 if ( (_mouse->button() == Qt::MidButton) &&
1139 mev.url.isNull() && (mev.innerNode.elementId() != ID_INPUT) ) {
1140 QPoint point = mapFromGlobal( _mouse->globalPos() );
1142 d->m_mouseScroll_byX = 0;
1143 d->m_mouseScroll_byY = 0;
1145 d->m_mouseScrollTimer =
new QTimer(
this );
1146 connect( d->m_mouseScrollTimer, SIGNAL(
timeout()),
this, SLOT(slotMouseScrollTimer()) );
1148 if ( !d->m_mouseScrollIndicator ) {
1149 QPixmap pixmap( 48, 48 ), icon;
1150 pixmap.fill(
QColor( qRgba( 127, 127, 127, 127 ) ) );
1152 QPainter p( &pixmap );
1153 QStyleOption option;
1155 option.rect.setRect( 16, 0, 16, 16 );
1156 QApplication::style()->drawPrimitive( QStyle::PE_IndicatorArrowUp, &option, &p );
1157 option.rect.setRect( 0, 16, 16, 16 );
1158 QApplication::style()->drawPrimitive( QStyle::PE_IndicatorArrowLeft, &option, &p );
1159 option.rect.setRect( 16, 32, 16, 16 );
1160 QApplication::style()->drawPrimitive( QStyle::PE_IndicatorArrowDown, &option, &p );
1161 option.rect.setRect( 32, 16, 16, 16 );
1162 QApplication::style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p );
1163 p.drawEllipse( 23, 23, 2, 2 );
1165 d->m_mouseScrollIndicator =
new QWidget(
this );
1166 d->m_mouseScrollIndicator->setFixedSize( 48, 48 );
1168 palette.setBrush( d->m_mouseScrollIndicator->backgroundRole(), QBrush( pixmap ) );
1169 d->m_mouseScrollIndicator->setPalette( palette );
1171 d->m_mouseScrollIndicator->move( point.x()-24, point.y()-24 );
1177 if ( cg.
readEntry(
"ShowMouseScrollIndicator",
true ) ) {
1178 d->m_mouseScrollIndicator->show();
1179 d->m_mouseScrollIndicator->unsetCursor();
1181 QBitmap
mask = d->m_mouseScrollIndicator->palette().brush(d->m_mouseScrollIndicator->backgroundRole()).texture().createHeuristicMask(
true );
1183 if ( hasHorBar && !hasVerBar ) {
1184 QBitmap bm( 16, 16 );
1186 QPainter painter( &mask );
1187 painter.drawPixmap( QRectF( 16, 0, bm.width(), bm.height() ), bm, bm.rect() );
1188 painter.drawPixmap( QRectF( 16, 32, bm.width(), bm.height() ), bm, bm.rect() );
1189 d->m_mouseScrollIndicator->setCursor( Qt::SizeHorCursor );
1191 else if ( !hasHorBar && hasVerBar ) {
1192 QBitmap bm( 16, 16 );
1194 QPainter painter( &mask );
1195 painter.drawPixmap( QRectF( 0, 16, bm.width(), bm.height() ), bm, bm.rect() );
1196 painter.drawPixmap( QRectF( 32, 16, bm.width(), bm.height() ), bm, bm.rect() );
1197 d->m_mouseScrollIndicator->setCursor( Qt::SizeVerCursor );
1200 d->m_mouseScrollIndicator->setCursor( Qt::SizeAllCursor );
1202 d->m_mouseScrollIndicator->setMask( mask );
1205 if ( hasHorBar && !hasVerBar )
1206 viewport()->setCursor( Qt::SizeHorCursor );
1207 else if ( !hasHorBar && hasVerBar )
1208 viewport()->setCursor( Qt::SizeVerCursor );
1210 viewport()->setCursor( Qt::SizeAllCursor );
1215 else if ( d->m_mouseScrollTimer ) {
1216 delete d->m_mouseScrollTimer;
1217 d->m_mouseScrollTimer = 0;
1219 if ( d->m_mouseScrollIndicator )
1220 d->m_mouseScrollIndicator->hide();
1223 if (d->clickCount > 0 &&
1224 QPoint(d->clickX-xm,d->clickY-ym).manhattanLength() <= QApplication::startDragDistance())
1232 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1233 d->clickCount,_mouse,
true,DOM::NodeImpl::MousePress);
1235 if (!swallowEvent) {
1236 emit m_part->nodeActivated(mev.innerNode);
1239 QApplication::sendEvent( m_part, &event );
1246 if(!m_part->xmlDocImpl())
return;
1248 int xm = _mouse->x();
1249 int ym = _mouse->y();
1250 revertTransforms(xm, ym);
1254 d->isDoubleClick =
true;
1256 DOM::NodeImpl::MouseEvent mev( _mouse->buttons(), DOM::NodeImpl::MouseDblClick );
1257 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1261 if (d->clickCount > 0 &&
1262 QPoint(d->clickX-xm,d->clickY-ym).manhattanLength() <= QApplication::startDragDistance())
1269 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1270 d->clickCount,_mouse,
true,DOM::NodeImpl::MouseDblClick);
1272 if (!swallowEvent) {
1274 QApplication::sendEvent( m_part, &event );
1277 d->possibleTripleClick=
true;
1278 QTimer::singleShot(QApplication::doubleClickInterval(),
this,SLOT(tripleClickTimeout()));
1281 void KHTMLView::tripleClickTimeout()
1283 d->possibleTripleClick =
false;
1289 if (!target.isEmpty() && (target.toLower() !=
"_top") &&
1290 (target.toLower() !=
"_self") && (target.toLower() !=
"_parent")) {
1291 if (target.toLower() ==
"_blank")
1305 if ( d->m_mouseScrollTimer ) {
1306 QPoint point = mapFromGlobal( _mouse->globalPos() );
1308 int deltaX = point.x() - d->m_mouseScrollIndicator->x() - 24;
1309 int deltaY = point.y() - d->m_mouseScrollIndicator->y() - 24;
1311 (deltaX > 0) ? d->m_mouseScroll_byX = 1 : d->m_mouseScroll_byX = -1;
1312 (deltaY > 0) ? d->m_mouseScroll_byY = 1 : d->m_mouseScroll_byY = -1;
1314 double adX = qAbs(deltaX)/30.0;
1315 double adY = qAbs(deltaY)/30.0;
1317 d->m_mouseScroll_byX = qMax(qMin(d->m_mouseScroll_byX *
int(adX*adX), SHRT_MAX), SHRT_MIN);
1318 d->m_mouseScroll_byY = qMax(qMin(d->m_mouseScroll_byY *
int(adY*adY), SHRT_MAX), SHRT_MIN);
1320 if (d->m_mouseScroll_byX == 0 && d->m_mouseScroll_byY == 0) {
1321 d->m_mouseScrollTimer->stop();
1323 else if (!d->m_mouseScrollTimer->isActive()) {
1324 d->m_mouseScrollTimer->start( 20 );
1328 if(!m_part->xmlDocImpl())
return;
1330 int xm = _mouse->x();
1331 int ym = _mouse->y();
1332 revertTransforms(xm, ym);
1334 DOM::NodeImpl::MouseEvent mev( _mouse->buttons(), DOM::NodeImpl::MouseMove );
1336 m_part->xmlDocImpl()->prepareMouseEvent( _mouse->buttons() , xm, ym, &mev );
1342 DOM::NodeImpl* target = mev.innerNode.handle();
1343 DOM::NodeImpl* fn = m_part->xmlDocImpl()->focusNode();
1346 if (d->m_mouseEventsTarget && fn && fn->renderer() && fn->renderer()->isWidget())
1349 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEMOVE_EVENT,target,mev.innerNonSharedNode.handle(),
false,
1350 0,_mouse,
true,DOM::NodeImpl::MouseMove);
1352 if (d->clickCount > 0 &&
1353 QPoint(d->clickX-xm,d->clickY-ym).manhattanLength() > QApplication::startDragDistance()) {
1357 khtml::RenderObject* r = target ? target->renderer() : 0;
1358 bool setCursor =
true;
1359 bool forceDefault =
false;
1360 if (r && r->isWidget()) {
1361 RenderWidget* rw =
static_cast<RenderWidget*
>(r);
1362 KHTMLWidget* kw = qobject_cast<
KHTMLView*>(rw->widget())? dynamic_cast<KHTMLWidget*>(rw->widget()) : 0;
1363 if (kw && kw->
m_kwp->isRedirected())
1365 else if (
QLineEdit* le = qobject_cast<QLineEdit*>(rw->widget())) {
1366 QList<QWidget*> wl = qFindChildren<QWidget *>( le,
"KLineEditButton" );
1369 if (w->underMouse()) {
1370 forceDefault =
true;
1375 else if (
QTextEdit* te = qobject_cast<QTextEdit*>(rw->widget())) {
1376 if (te->verticalScrollBar()->underMouse() || te->horizontalScrollBar()->underMouse())
1377 forceDefault =
true;
1380 khtml::RenderStyle* style = (r && r->style()) ? r->style() : 0;
1382 LinkCursor linkCursor = LINK_NORMAL;
1383 switch (!forceDefault ? (style ? style->cursor() : CURSOR_AUTO) : CURSOR_DEFAULT) {
1386 !r->isPointInsideSelection(xm, ym, m_part->caret())) )
1390 if (mev.url.string().startsWith(
"mailto:") && mev.url.string().indexOf(
'@')>0)
1391 linkCursor = LINK_MAILTO;
1394 linkCursor = LINK_NEWWINDOW;
1397 if (r && r->isFrameSet() && !
static_cast<RenderFrameSet*
>(r)->noResize())
1398 c =
QCursor(static_cast<RenderFrameSet*>(r)->cursorShape());
1404 case CURSOR_POINTER:
1406 if (mev.url.string().startsWith(
"mailto:") && mev.url.string().indexOf(
'@')>0)
1407 linkCursor = LINK_MAILTO;
1410 linkCursor = LINK_NEWWINDOW;
1412 case CURSOR_PROGRESS:
1416 case CURSOR_ALL_SCROLL:
1417 c =
QCursor(Qt::SizeAllCursor);
1419 case CURSOR_E_RESIZE:
1420 case CURSOR_W_RESIZE:
1421 case CURSOR_EW_RESIZE:
1422 c =
QCursor(Qt::SizeHorCursor);
1424 case CURSOR_N_RESIZE:
1425 case CURSOR_S_RESIZE:
1426 case CURSOR_NS_RESIZE:
1427 c =
QCursor(Qt::SizeVerCursor);
1429 case CURSOR_NE_RESIZE:
1430 case CURSOR_SW_RESIZE:
1431 case CURSOR_NESW_RESIZE:
1432 c =
QCursor(Qt::SizeBDiagCursor);
1434 case CURSOR_NW_RESIZE:
1435 case CURSOR_SE_RESIZE:
1436 case CURSOR_NWSE_RESIZE:
1437 c =
QCursor(Qt::SizeFDiagCursor);
1446 c =
QCursor(Qt::WhatsThisCursor);
1448 case CURSOR_DEFAULT:
1451 case CURSOR_NOT_ALLOWED:
1452 c =
QCursor(Qt::ForbiddenCursor);
1454 case CURSOR_ROW_RESIZE:
1455 c =
QCursor(Qt::SplitVCursor);
1457 case CURSOR_COL_RESIZE:
1458 c =
QCursor(Qt::SplitHCursor);
1460 case CURSOR_VERTICAL_TEXT:
1461 case CURSOR_CONTEXT_MENU:
1462 case CURSOR_NO_DROP:
1470 if (!setCursor && style && style->cursor() != CURSOR_AUTO)
1476 vp = p->
view()->viewport();
1477 if ( setCursor && vp->cursor().handle() != c.handle() ) {
1478 if( c.shape() == Qt::ArrowCursor) {
1480 p->
view()->viewport()->unsetCursor();
1487 if ( linkCursor!=LINK_NORMAL && isVisible() && hasFocus() ) {
1490 if( !d->cursorIconWidget ) {
1492 d->cursorIconWidget =
new QLabel( 0, Qt::X11BypassWindowManagerHint );
1493 XSetWindowAttributes attr;
1494 attr.save_under = True;
1495 XChangeWindowAttributes( QX11Info::display(), d->cursorIconWidget->winId(), CWSaveUnder, &attr );
1497 d->cursorIconWidget =
new QLabel( NULL, NULL );
1503 if (linkCursor != d->cursorIconType) {
1504 d->cursorIconType = linkCursor;
1508 case LINK_MAILTO: cursorIcon =
"mail-message-new";
break;
1509 case LINK_NEWWINDOW: cursorIcon =
"window-new";
break;
1510 default: cursorIcon =
"dialog-error";
break;
1515 d->cursorIconWidget->resize( icon_pixmap.width(), icon_pixmap.height());
1516 d->cursorIconWidget->setMask( icon_pixmap.createMaskFromColor(Qt::transparent));
1517 d->cursorIconWidget->setPixmap( icon_pixmap);
1518 d->cursorIconWidget->update();
1521 QPoint c_pos = QCursor::pos();
1522 d->cursorIconWidget->move( c_pos.x() + 15, c_pos.y() + 15 );
1524 XRaiseWindow( QX11Info::display(), d->cursorIconWidget->winId());
1525 QApplication::flush();
1526 #elif defined(Q_WS_WIN)
1527 SetWindowPos( d->cursorIconWidget->winId(), HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
1531 d->cursorIconWidget->show();
1534 else if ( d->cursorIconWidget )
1535 d->cursorIconWidget->hide();
1537 if (r && r->isWidget()) {
1541 if (!swallowEvent) {
1543 QApplication::sendEvent( m_part, &event );
1549 bool swallowEvent =
false;
1551 int xm = _mouse->x();
1552 int ym = _mouse->y();
1553 revertTransforms(xm, ym);
1555 DOM::NodeImpl::MouseEvent mev( _mouse->buttons(), DOM::NodeImpl::MouseRelease );
1557 if ( m_part->xmlDocImpl() )
1559 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1561 DOM::NodeImpl* target = mev.innerNode.handle();
1562 DOM::NodeImpl* fn = m_part->xmlDocImpl()->focusNode();
1565 if (d->m_mouseEventsTarget && fn && fn->renderer() && fn->renderer()->isWidget())
1568 swallowEvent = dispatchMouseEvent(EventImpl::MOUSEUP_EVENT,target,mev.innerNonSharedNode.handle(),
true,
1569 d->clickCount,_mouse,
false,DOM::NodeImpl::MouseRelease);
1572 if (d->m_mouseEventsTarget)
1573 d->m_mouseEventsTarget = 0;
1575 if (d->clickCount > 0 &&
1576 QPoint(d->clickX-xm,d->clickY-ym).manhattanLength() <= QApplication::startDragDistance()) {
1577 QMouseEvent me(d->isDoubleClick ? QEvent::MouseButtonDblClick : QEvent::MouseButtonRelease,
1578 _mouse->pos(), _mouse->button(), _mouse->buttons(), _mouse->modifiers());
1579 dispatchMouseEvent(EventImpl::CLICK_EVENT, mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1580 d->clickCount, &me,
true, DOM::NodeImpl::MouseRelease);
1583 khtml::RenderObject* r = target ? target->renderer() : 0;
1584 if (r && r->isWidget())
1588 if (!swallowEvent) {
1590 QApplication::sendEvent( m_part, &event );
1595 bool KHTMLView::dispatchKeyEvent( QKeyEvent *_ke )
1597 if (!m_part->xmlDocImpl())
1619 if( _ke == d->postponed_autorepeat )
1624 if( _ke->type() == QEvent::KeyPress )
1626 if( !_ke->isAutoRepeat())
1628 bool ret = dispatchKeyEventHelper( _ke,
false );
1630 if( !ret && dispatchKeyEventHelper( _ke,
true ))
1636 bool ret = dispatchKeyEventHelper( _ke,
true );
1637 if( !ret && d->postponed_autorepeat )
1639 delete d->postponed_autorepeat;
1640 d->postponed_autorepeat = NULL;
1648 delete d->postponed_autorepeat;
1649 d->postponed_autorepeat = 0;
1651 if( !_ke->isAutoRepeat()) {
1652 return dispatchKeyEventHelper( _ke,
false );
1656 d->postponed_autorepeat =
new QKeyEvent( _ke->type(), _ke->key(), _ke->modifiers(),
1657 _ke->text(), _ke->isAutoRepeat(), _ke->count());
1658 if( _ke->isAccepted())
1659 d->postponed_autorepeat->accept();
1661 d->postponed_autorepeat->ignore();
1668 bool KHTMLView::dispatchKeyEventHelper( QKeyEvent *_ke,
bool keypress )
1670 DOM::NodeImpl* keyNode = m_part->xmlDocImpl()->focusNode();
1672 return keyNode->dispatchKeyEvent(_ke, keypress);
1674 return m_part->xmlDocImpl()->dispatchKeyEvent(_ke, keypress);
1681 if (d->accessKeysEnabled && _ke->key() == Qt::Key_Control && !(_ke->modifiers() & ~Qt::ControlModifier) && !d->accessKeysActivated)
1683 d->accessKeysPreActivate=
true;
1688 if (_ke->key() == Qt::Key_Shift && !(_ke->modifiers() & ~Qt::ShiftModifier))
1689 d->scrollSuspendPreActivate=
true;
1694 if (d->accessKeysEnabled && d->accessKeysActivated)
1696 int state = ( _ke->modifiers() & ( Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ));
1697 if ( state==0 || state==Qt::ShiftModifier ) {
1698 if (_ke->key() != Qt::Key_Shift)
1699 accessKeysTimeout();
1700 handleAccessKey( _ke );
1704 accessKeysTimeout();
1709 if ( dispatchKeyEvent( _ke )) {
1715 int offs = (viewport()->height() < 30) ? viewport()->height() : 30;
1716 if (_ke->modifiers() & Qt::ShiftModifier)
1720 verticalScrollBar()->setValue( verticalScrollBar()->value() -viewport()->height() + offs );
1721 if(d->scrollSuspended)
1722 d->newScrollTimer(
this, 0);
1727 d->adjustScroller(
this, KHTMLViewPrivate::ScrollDown, KHTMLViewPrivate::ScrollUp);
1732 d->adjustScroller(
this, KHTMLViewPrivate::ScrollUp, KHTMLViewPrivate::ScrollDown);
1737 d->adjustScroller(
this, KHTMLViewPrivate::ScrollLeft, KHTMLViewPrivate::ScrollRight);
1742 d->adjustScroller(
this, KHTMLViewPrivate::ScrollRight, KHTMLViewPrivate::ScrollLeft);
1746 switch ( _ke->key() )
1750 if (!d->scrollTimerId || d->scrollSuspended)
1751 verticalScrollBar()->setValue( verticalScrollBar()->value()+10 );
1752 if (d->scrollTimerId)
1753 d->newScrollTimer(
this, 0);
1757 case Qt::Key_PageDown:
1758 d->shouldSmoothScroll =
true;
1759 verticalScrollBar()->setValue( verticalScrollBar()->value() +viewport()->height() - offs );
1760 if(d->scrollSuspended)
1761 d->newScrollTimer(
this, 0);
1766 if (!d->scrollTimerId || d->scrollSuspended)
1767 verticalScrollBar()->setValue( verticalScrollBar()->value()-10 );
1768 if (d->scrollTimerId)
1769 d->newScrollTimer(
this, 0);
1772 case Qt::Key_PageUp:
1773 d->shouldSmoothScroll =
true;
1774 verticalScrollBar()->setValue( verticalScrollBar()->value() -viewport()->height() + offs );
1775 if(d->scrollSuspended)
1776 d->newScrollTimer(
this, 0);
1780 if (!d->scrollTimerId || d->scrollSuspended)
1781 horizontalScrollBar()->setValue( horizontalScrollBar()->value()+10 );
1782 if (d->scrollTimerId)
1783 d->newScrollTimer(
this, 0);
1788 if (!d->scrollTimerId || d->scrollSuspended)
1789 horizontalScrollBar()->setValue( horizontalScrollBar()->value()-10 );
1790 if (d->scrollTimerId)
1791 d->newScrollTimer(
this, 0);
1794 case Qt::Key_Return:
1797 if (m_part->xmlDocImpl()) {
1798 NodeImpl *n = m_part->xmlDocImpl()->focusNode();
1804 verticalScrollBar()->setValue( 0 );
1805 horizontalScrollBar()->setValue( 0 );
1806 if(d->scrollSuspended)
1807 d->newScrollTimer(
this, 0);
1811 if(d->scrollSuspended)
1812 d->newScrollTimer(
this, 0);
1819 if (d->scrollTimerId)
1820 d->newScrollTimer(
this, 0);
1830 if( d->scrollSuspendPreActivate && _ke->key() != Qt::Key_Shift )
1831 d->scrollSuspendPreActivate =
false;
1832 if( _ke->key() == Qt::Key_Shift && d->scrollSuspendPreActivate && !(_ke->modifiers() & Qt::ShiftModifier))
1833 if (d->scrollTimerId) {
1834 d->scrollSuspended = !d->scrollSuspended;
1835 if (d->scrollSuspended)
1839 if (d->accessKeysEnabled)
1841 if (d->accessKeysPreActivate && _ke->key() != Qt::Key_Control)
1842 d->accessKeysPreActivate=
false;
1843 if (d->accessKeysPreActivate && !(_ke->modifiers() & Qt::ControlModifier))
1846 m_part->setStatusBarText(
i18n(
"Access Keys activated"),KHTMLPart::BarOverrideText);
1847 d->accessKeysActivated =
true;
1848 d->accessKeysPreActivate =
false;
1852 else if (d->accessKeysActivated)
1854 accessKeysTimeout();
1861 if ( dispatchKeyEvent( _ke ) )
1867 QScrollArea::keyReleaseEvent(_ke);
1873 if (m_part->xmlDocImpl() && focusNextPrevNode(next))
1875 if (m_part->xmlDocImpl()->focusNode())
1876 kDebug() <<
"focusNode.name: "
1877 << m_part->xmlDocImpl()->focusNode()->nodeName().string() << endl;
1882 d->pseudoFocusNode = KHTMLViewPrivate::PFNone;
1886 return QWidget::focusNextPrevChild(next);
1891 QPoint pos = QCursor::pos();
1894 pos = v->viewport()->mapFromGlobal( pos );
1899 pos =
QPoint(pos.x() - viewport()->x(), pos.y() - viewport()->y());
1903 ensureVisible( xm, ym, 0, 5 );
1905 #ifndef KHTML_NO_SELECTION
1908 if (m_part->isExtendingSelection()) {
1909 RenderObject::NodeInfo renderInfo(
true,
false);
1910 m_part->xmlDocImpl()->renderer()->layer()
1911 ->nodeAtPoint(renderInfo, xm, ym);
1912 innerNode = renderInfo.innerNode();
1915 if (innerNode.
handle() && innerNode.
handle()->renderer()
1916 && innerNode.
handle()->renderer()->shouldSelect()) {
1917 m_part->extendSelectionTo(xm, ym, innerNode);
1919 #endif // KHTML_NO_SELECTION
1945 if (!qobject_cast<QFrame*>(w))
1946 w->setAttribute( Qt::WA_NoSystemBackground );
1948 w->setAttribute(Qt::WA_WState_InPaintEvent);
1950 if (!(w->objectName() ==
"KLineEditButton"))
1951 w->setAttribute(Qt::WA_OpaquePaintEvent);
1953 w->installEventFilter(view);
1957 if (qobject_cast<KHTMLView*>(w)) {
1958 handleWidget(static_cast<KHTMLView*>(w)->widget(), view,
false);
1959 handleWidget(static_cast<KHTMLView*>(w)->horizontalScrollBar(), view,
false);
1960 handleWidget(static_cast<KHTMLView*>(w)->verticalScrollBar(), view,
false);
1964 QObjectList children = w->children();
1965 foreach (
QObject*
object, children) {
1972 class KHTMLBackingStoreHackWidget :
public QWidget
1975 void publicEvent(
QEvent *e)
1983 switch (e->type()) {
1986 case QEvent::MouseButtonPress:
1987 case QEvent::MouseButtonRelease:
1988 case QEvent::MouseButtonDblClick:
1989 case QEvent::MouseMove:
1990 #ifndef QT_NO_WHEELEVENT
1993 case QEvent::ContextMenu:
1994 case QEvent::DragEnter:
1995 case QEvent::DragMove:
1996 case QEvent::DragLeave:
2002 return QScrollArea::viewportEvent(e);
2007 w->setAttribute(Qt::WA_WState_InPaintEvent, b);
2011 if (qobject_cast<KHTMLView*>(w)) {
2018 foreach(
QObject* cw, w->children()) {
2019 if (cw->isWidgetType() && !
static_cast<QWidget*
>(cw)->isWindow()
2020 && !(
static_cast<QWidget*
>(cw)->windowModality() & Qt::ApplicationModal)) {
2028 if ( e->type() == QEvent::ShortcutOverride ) {
2029 QKeyEvent* ke = (QKeyEvent*) e;
2031 || (m_part->xmlDocImpl() && m_part->xmlDocImpl()->focusNode()
2032 && m_part->xmlDocImpl()->focusNode()->isContentEditable())) {
2033 if ( (ke->modifiers() & Qt::ControlModifier) || (ke->modifiers() & Qt::ShiftModifier) ) {
2034 switch ( ke->key() ) {
2050 if ( e->type() == QEvent::Leave ) {
2051 if ( d->cursorIconWidget )
2052 d->cursorIconWidget->hide();
2053 m_part->resetHoverText();
2060 else if (e->type() == QEvent::Resize) {
2064 }
else if (o->isWidgetType()) {
2067 while (v && v != view) {
2069 v = v->parentWidget();
2072 if (v && k && k->
m_kwp->isRedirected()) {
2074 bool isUpdate =
false;
2077 case QEvent::UpdateRequest: {
2079 static_cast<KHTMLBackingStoreHackWidget *
>(w)->publicEvent(e);
2083 case QEvent::UpdateLater:
2087 if (!allowWidgetPaintEvents) {
2093 while (v && v->parentWidget() != view) {
2096 v = v->parentWidget();
2103 QRect pr = isUpdate ?
static_cast<QUpdateLaterEvent*
>(e)->region().boundingRect() :
static_cast<QPaintEvent*
>(e)->rect();
2104 bool asap = !d->contentsMoving && qobject_cast<QAbstractScrollArea*>(c);
2109 w->repaint(static_cast<QUpdateLaterEvent*>(e)->region());
2111 w->update(static_cast<QUpdateLaterEvent*>(e)->region());
2116 if ( asap && !isUpdate && !d->painting && m_part->xmlDocImpl() && m_part->xmlDocImpl()->renderer() &&
2117 !
static_cast<khtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer())->needsLayout() ) {
2119 pr.width(), pr.height()+1);
2121 }
else if (!d->painting) {
2122 scheduleRepaint(x + pr.x(), y + pr.y(),
2123 pr.width(), pr.height()+1, asap);
2127 case QEvent::MouseMove:
2128 case QEvent::MouseButtonPress:
2129 case QEvent::MouseButtonRelease:
2130 case QEvent::MouseButtonDblClick: {
2132 if (0 && w->parentWidget() == view && !qobject_cast<QScrollBar*>(w) && !::qobject_cast<QScrollBar *>(w)) {
2133 QMouseEvent *me =
static_cast<QMouseEvent *
>(e);
2134 QPoint pt = w->mapTo( view, me->pos());
2135 QMouseEvent me2(me->type(), pt, me->button(), me->buttons(), me->modifiers());
2137 if (e->type() == QEvent::MouseMove)
2139 else if(e->type() == QEvent::MouseButtonPress)
2141 else if(e->type() == QEvent::MouseButtonRelease)
2149 case QEvent::KeyPress:
2150 case QEvent::KeyRelease:
2151 if (w->parentWidget() == view && !qobject_cast<QScrollBar*>(w)) {
2152 QKeyEvent *ke =
static_cast<QKeyEvent *
>(e);
2153 if (e->type() == QEvent::KeyPress) {
2163 if (qobject_cast<KUrlRequester*>(w->parentWidget()) &&
2164 e->type() == QEvent::KeyPress) {
2174 case QEvent::FocusIn:
2175 case QEvent::FocusOut: {
2180 block =
static_cast<QFocusEvent*
>(e)->reason() != Qt::MouseFocusReason || root->underMouse();
2194 return QScrollArea::eventFilter(o, e);
2199 switch (e->type()) {
2200 case QEvent::MouseButtonPress:
2201 case QEvent::MouseButtonRelease:
2202 case QEvent::MouseButtonDblClick:
2203 case QEvent::MouseMove:
2205 #ifndef QT_NO_WHEELEVENT
2208 case QEvent::ContextMenu:
2209 case QEvent::DragEnter:
2210 case QEvent::DragMove:
2211 case QEvent::DragLeave:
2213 return QFrame::event(e);
2214 case QEvent::ChildPolished: {
2217 QObject *c =
static_cast<QChildEvent *
>(e)->child();
2218 if (c->isWidgetType()) {
2221 if (!(w->windowFlags() & Qt::Window) && !(w->windowModality() & Qt::ApplicationModal)) {
2223 if (k && k->
m_kwp->isRedirected()) {
2231 case QEvent::Move: {
2232 if (static_cast<QMoveEvent*>(e)->pos() !=
QPoint(0,0)) {
2233 widget()->move(0,0);
2245 bool KHTMLView::hasLayoutPending()
2247 return d->layoutTimerId && !d->firstLayoutPending;
2250 DOM::NodeImpl *KHTMLView::nodeUnderMouse()
const
2252 return d->underMouse;
2255 DOM::NodeImpl *KHTMLView::nonSharedNodeUnderMouse()
const
2257 return d->underMouseNonShared;
2260 bool KHTMLView::scrollTo(
const QRect &bounds)
2262 d->scrollingSelf =
true;
2267 xe = bounds.right();
2268 ye = bounds.bottom();
2278 if (ye-y>curHeight-d->borderY)
2279 ye = y + curHeight - d->borderY;
2281 if (xe-x>curWidth-d->borderX)
2282 xe = x + curWidth - d->borderX;
2288 else if (xe + d->borderX >
contentsX() + curWidth)
2289 deltax = xe + d->borderX - (
contentsX() + curWidth );
2297 else if (ye + d->borderY >
contentsY() + curHeight)
2298 deltay = ye + d->borderY - (
contentsY() + curHeight );
2302 int maxx = curWidth-d->borderX;
2303 int maxy = curHeight-d->borderY;
2305 int scrollX, scrollY;
2307 scrollX = deltax > 0 ? (deltax > maxx ? maxx : deltax) : deltax == 0 ? 0 : (deltax>-maxx ? deltax : -maxx);
2308 scrollY = deltay > 0 ? (deltay > maxy ? maxy : deltay) : deltay == 0 ? 0 : (deltay>-maxy ? deltay : -maxy);
2320 horizontalScrollBar()->setValue( horizontalScrollBar()->value()+scrollX );
2321 verticalScrollBar()->setValue( verticalScrollBar()->value()+scrollY );
2323 d->scrollingSelf =
false;
2325 if ( (abs(deltax)<=maxx) && (abs(deltay)<=maxy) )
2331 bool KHTMLView::focusNextPrevNode(
bool next)
2340 DocumentImpl *doc = m_part->xmlDocImpl();
2341 NodeImpl *oldFocusNode = doc->focusNode();
2348 if ((oldFocusNode->renderer() && !oldFocusNode->renderer()->parent())
2349 || !oldFocusNode->isTabFocusable()) {
2350 doc->quietResetFocus();
2359 if (d->scrollBarMoved)
2363 toFocus = doc->nextFocusNode(oldFocusNode);
2365 toFocus = doc->previousFocusNode(oldFocusNode);
2367 if (!toFocus && oldFocusNode) {
2369 toFocus = doc->nextFocusNode(NULL);
2371 toFocus = doc->previousFocusNode(NULL);
2374 while (toFocus && toFocus != oldFocusNode)
2377 QRect focusNodeRect = toFocus->getRect();
2381 QRect r = toFocus->getRect();
2382 ensureVisible( r.right(), r.bottom());
2383 ensureVisible( r.left(), r.top());
2384 d->scrollBarMoved =
false;
2385 d->tabMovePending =
false;
2386 d->lastTabbingDirection = next;
2387 d->pseudoFocusNode = KHTMLViewPrivate::PFNone;
2388 m_part->xmlDocImpl()->setFocusNode(toFocus);
2389 Node guard(toFocus);
2390 if (!toFocus->hasOneRef() )
2398 toFocus = doc->nextFocusNode(toFocus);
2400 toFocus = doc->previousFocusNode(toFocus);
2402 if (!toFocus && oldFocusNode)
2406 toFocus = doc->nextFocusNode(NULL);
2410 toFocus = doc->previousFocusNode(NULL);
2415 d->scrollBarMoved =
false;
2419 if (!oldFocusNode && d->pseudoFocusNode == KHTMLViewPrivate::PFNone)
2422 d->scrollBarMoved =
false;
2423 d->pseudoFocusNode = next?KHTMLViewPrivate::PFTop:KHTMLViewPrivate::PFBottom;
2427 NodeImpl *newFocusNode = NULL;
2429 if (d->tabMovePending && next != d->lastTabbingDirection)
2432 newFocusNode = oldFocusNode;
2436 if (oldFocusNode || d->pseudoFocusNode == KHTMLViewPrivate::PFTop )
2437 newFocusNode = doc->nextFocusNode(oldFocusNode);
2441 if (oldFocusNode || d->pseudoFocusNode == KHTMLViewPrivate::PFBottom )
2442 newFocusNode = doc->previousFocusNode(oldFocusNode);
2445 bool targetVisible =
false;
2460 if (!m_part->
isCaretMode() && newFocusNode->isContentEditable()) {
2461 kDebug(6200) <<
"show caret! fn: " << newFocusNode->nodeName().string() << endl;
2462 m_part->clearCaretRectIfNeeded();
2467 kDebug(6200) <<
"hide caret! fn: " << newFocusNode->nodeName().string() << endl;
2469 m_part->notifySelectionChanged();
2471 targetVisible = scrollTo(newFocusNode->getRect());
2477 d->tabMovePending =
false;
2479 m_part->xmlDocImpl()->setFocusNode(newFocusNode);
2482 Node guard(newFocusNode);
2483 if (!newFocusNode->hasOneRef() )
2491 d->pseudoFocusNode = next?KHTMLViewPrivate::PFBottom:KHTMLViewPrivate::PFTop;
2497 if (!d->tabMovePending)
2498 d->lastTabbingDirection = next;
2499 d->tabMovePending =
true;
2515 fallbacks = buildFallbackAccessKeys();
2516 for( NodeImpl* n = m_part->xmlDocImpl(); n != NULL; n = n->traverseNextNode()) {
2517 if( n->isElementNode()) {
2518 ElementImpl* en =
static_cast< ElementImpl*
>( n );
2519 DOMString s = en->getAttribute( ATTR_ACCESSKEY );
2522 QChar a = s.
string()[ 0 ].toUpper();
2523 if( qFind( taken.begin(), taken.end(), a ) == taken.end())
2526 if( accesskey.isNull() && fallbacks.contains( en )) {
2527 QChar a = fallbacks[ en ].toUpper();
2528 if( qFind( taken.begin(), taken.end(), a ) == taken.end())
2529 accesskey =
QString(
"<qt><i>" ) + a +
"</i></qt>";
2531 if( !accesskey.isNull()) {
2532 QRect rec=en->getRect();
2534 lab->setAttribute(Qt::WA_DeleteOnClose);
2535 lab->setObjectName(
"KHTMLAccessKey");
2538 lab->setPalette(QToolTip::palette());
2539 lab->setLineWidth(2);
2540 lab->setFrameStyle(QFrame::Box | QFrame::Plain);
2543 lab->setParent( widget() );
2544 lab->setAutoFillBackground(
true);
2549 taken.append( accesskey[ 0 ] );
2558 if( !qobject_cast<KHTMLPart*>(cur) )
2561 if( part->
view() && part->
view() != caller )
2571 bool KHTMLView::isScrollingFromMouseWheel()
const
2573 return d->scrollingFromWheel !=
QPoint(-1,-1);
2576 void KHTMLView::accessKeysTimeout()
2578 d->accessKeysActivated=
false;
2579 d->accessKeysPreActivate =
false;
2580 m_part->setStatusBarText(
QString(), KHTMLPart::BarOverrideText);
2585 bool KHTMLView::handleAccessKey(
const QKeyEvent* ev )
2590 if( ev->key() >= Qt::Key_A && ev->key() <= Qt::Key_Z )
2591 c =
'A' + ev->key() - Qt::Key_A;
2592 else if( ev->key() >= Qt::Key_0 && ev->key() <= Qt::Key_9 )
2593 c =
'0' + ev->key() - Qt::Key_0;
2597 if( ev->text().length() == 1 )
2598 c = ev->text()[ 0 ];
2602 return focusNodeWithAccessKey( c );
2605 bool KHTMLView::focusNodeWithAccessKey( QChar c,
KHTMLView* caller )
2607 DocumentImpl *doc = m_part->xmlDocImpl();
2610 ElementImpl* node = doc->findAccessKeyElement( c );
2614 if( !qobject_cast<KHTMLPart*>(cur) )
2617 if( part->
view() && part->
view() != caller
2618 && part->
view()->focusNodeWithAccessKey( c,
this ))
2624 && m_part->
parentPart()->
view()->focusNodeWithAccessKey( c,
this ))
2626 if( caller == NULL ) {
2629 it != fallbacks.end();
2642 QRect r = node->getRect();
2643 ensureVisible( r.right(), r.bottom());
2644 ensureVisible( r.left(), r.top());
2647 if( node->isFocusable()) {
2648 if (node->id()==ID_LABEL) {
2650 node=
static_cast<ElementImpl *
>(
static_cast< HTMLLabelElementImpl*
>( node )->getFormElement());
2651 if (!node)
return true;
2655 m_part->xmlDocImpl()->setFocusNode(node);
2657 if( node != NULL && node->hasOneRef())
2660 if( node != NULL && node->hasOneRef())
2664 switch( node->id()) {
2666 static_cast< HTMLAnchorElementImpl*
>( node )->click();
2669 static_cast< HTMLInputElementImpl*
>( node )->click();
2672 static_cast< HTMLButtonElementImpl*
>( node )->click();
2675 static_cast< HTMLAreaElementImpl*
>( node )->click();
2689 for( NodeImpl* n = after ? start->nextSibling() : start->traversePreviousNode();
2691 n = after ? n->traverseNextNode() : n->traversePreviousNode()) {
2692 if( n->isTextNode()) {
2694 ret +=
static_cast< TextImpl*
>( n )->toString().string();
2696 ret.prepend( static_cast< TextImpl* >( n )->toString().
string());
2726 if( ret.trimmed().isEmpty())
2730 return ret.simplified();
2734 return ret.simplified();
2740 for( NodeImpl* n = start;
2742 n = n->traverseNextNode()) {
2743 if( n->id() == ID_LABEL ) {
2744 HTMLLabelElementImpl*
label =
static_cast< HTMLLabelElementImpl*
>( n );
2745 NodeImpl* labelfor = label->getFormElement();
2747 ret[ labelfor ] = label->innerText().string().simplified();
2754 struct AccessKeyData {
2755 ElementImpl* element;
2765 QLinkedList< AccessKeyData > data;
2770 for( NodeImpl* n = m_part->xmlDocImpl();
2772 n = n->traverseNextNode()) {
2773 if( n->isElementNode()) {
2774 ElementImpl* element =
static_cast< ElementImpl*
>( n );
2775 if( element->renderer() == NULL )
2780 bool ignore =
false;
2781 bool text_after =
false;
2782 bool text_before =
false;
2783 switch( element->id()) {
2785 url = khtml::parseURL(element->getAttribute(ATTR_HREF)).
string();
2788 text =
static_cast< HTMLElementImpl*
>( element )->innerText().string().simplified();
2792 HTMLInputElementImpl* in =
static_cast< HTMLInputElementImpl*
>( element );
2793 switch( in->inputType()) {
2794 case HTMLInputElementImpl::SUBMIT:
2795 text = in->value().string();
2797 text =
i18n(
"Submit" );
2800 case HTMLInputElementImpl::IMAGE:
2801 text = in->altText().string();
2804 case HTMLInputElementImpl::BUTTON:
2805 text = in->value().string();
2808 case HTMLInputElementImpl::RESET:
2809 text = in->value().string();
2811 text =
i18n(
"Reset" );
2814 case HTMLInputElementImpl::HIDDEN:
2817 case HTMLInputElementImpl::CHECKBOX:
2818 case HTMLInputElementImpl::RADIO:
2822 case HTMLInputElementImpl::TEXT:
2823 case HTMLInputElementImpl::PASSWORD:
2824 case HTMLInputElementImpl::FILE:
2835 text =
static_cast< HTMLElementImpl*
>( element )->innerText().string().simplified();
2836 switch( static_cast< HTMLButtonElementImpl* >( element )->buttonType()) {
2837 case HTMLButtonElementImpl::SUBMIT:
2839 text =
i18n(
"Submit" );
2842 case HTMLButtonElementImpl::RESET:
2844 text =
i18n(
"Reset" );
2861 ignore = !element->isFocusable();
2869 DOMString akey = element->getAttribute( ATTR_ACCESSKEY );
2870 if( akey.
length() == 1 ) {
2871 hrefs[url] = akey.
string()[ 0 ].toUpper();
2874 if( text.isNull() && labels.contains( element ))
2875 text = labels[ element ];
2876 if( text.isNull() && text_before )
2878 if( text.isNull() && text_after )
2880 text = text.trimmed();
2885 it != priorities.end();
2887 if( text == (*it).first )
2890 AccessKeyData tmp = { element, text, url, priority };
2896 for(
char c =
'A'; c <=
'Z'; ++c )
2898 for(
char c =
'0'; c <=
'9'; ++c )
2900 for( NodeImpl* n = m_part->xmlDocImpl();
2902 n = n->traverseNextNode()) {
2903 if( n->isElementNode()) {
2904 ElementImpl* en =
static_cast< ElementImpl*
>( n );
2905 DOMString s = en->getAttribute( ATTR_ACCESSKEY );
2907 QChar c = s.
string()[ 0 ].toUpper();
2908 keys.removeAll( c );
2914 for(
int priority = 10; priority >= 0; --priority ) {
2915 for( QLinkedList< AccessKeyData >::Iterator it = data.begin();
2918 if( (*it).priority != priority ) {
2926 const QString url = (*it).url;
2928 if( hrefs.contains( url ) ) {
2929 it = data.erase( it );
2932 if( !text.isEmpty()) {
2936 it != priorities.end();
2938 if( text == (*it).first && keys.contains( (*it).second )) {
2946 if( key.isNull() && !text.isEmpty()) {
2948 for( QStringList::ConstIterator it = words.begin();
2951 if( keys.contains( (*it)[ 0 ].toUpper())) {
2952 key = (*it)[ 0 ].toUpper();
2957 if( key.isNull() && !text.isEmpty()) {
2958 for(
int i = 0; i < text.length(); ++i ) {
2959 if( keys.contains( text[ i ].toUpper())) {
2960 key = text[ i ].toUpper();
2967 ret[ (*it).element ] = key;
2968 keys.removeAll( key );
2969 it = data.erase( it );
2971 if( !url.isEmpty() && !url.startsWith(
"javascript:", Qt::CaseInsensitive )) {
2972 for( QLinkedList< AccessKeyData >::Iterator it2 = data.begin();
2975 if( (*it2).url == url ) {
2976 ret[ (*it2).element ] = key;
2979 it2 = data.erase( it2 );
2989 void KHTMLView::setMediaType(
const QString &medium )
2994 QString KHTMLView::mediaType()
const
2999 bool KHTMLView::pagedMode()
const
3004 void KHTMLView::setWidgetVisible(RenderWidget* w,
bool vis)
3007 d->visibleWidgets.insert(w, w->widget());
3010 d->visibleWidgets.remove(w);
3013 bool KHTMLView::needsFullRepaint()
const
3015 return d->needsFullRepaint;
3019 class QPointerDeleter
3022 explicit QPointerDeleter(
QObject* o) : obj(o) {}
3023 ~QPointerDeleter() {
delete obj; }
3025 const QPointer<QObject> obj;
3031 if(!m_part->xmlDocImpl())
return;
3032 khtml::RenderCanvas *root =
static_cast<khtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer());
3036 const QPointerDeleter settingsDeleter(printSettings);
3040 const QPointerDeleter dialogDeleter(dialog);
3042 QString docname = m_part->xmlDocImpl()->URL().prettyUrl();
3043 if ( !docname.isEmpty() )
3046 if(quick || (dialog->exec() && dialog)) {
3047 viewport()->setCursor( Qt::WaitCursor );
3049 printer.setFullPage(
false);
3051 printer.setDocName(docname);
3053 QPainter *p =
new QPainter;
3054 p->
begin( &printer );
3055 khtml::setPrintPainter( p );
3057 m_part->xmlDocImpl()->setPaintDevice( &printer );
3058 QString oldMediaType = mediaType();
3059 setMediaType(
"print" );
3063 m_part->xmlDocImpl()->setPrintStyleSheet( printSettings->printFriendly() ?
3064 "* { background-image: none !important;"
3065 " background-color: white !important;"
3066 " color: black !important; }"
3067 "body { margin: 0px !important; }"
3068 "html { margin: 0px !important; }" :
3069 "body { margin: 0px !important; }"
3070 "html { margin: 0px !important; }"
3073 kDebug(6000) <<
"printing: physical page width = " << printer.width()
3074 <<
" height = " << printer.height() << endl;
3075 root->setStaticMode(
true);
3076 root->setPagedMode(
true);
3077 root->setWidth(printer.width());
3079 root->setPageTop(0);
3080 root->setPageBottom(0);
3083 m_part->xmlDocImpl()->styleSelector()->computeFontSizes(printer.logicalDpiY(), 100);
3084 m_part->xmlDocImpl()->updateStyleSelector();
3085 root->setPrintImages(printSettings->printImages());
3086 root->makePageBreakAvoidBlocks();
3088 root->setNeedsLayoutAndMinMaxRecalc();
3093 bool printHeader = printSettings->printHeader();
3095 int headerHeight = 0;
3096 QFont headerFont(
"Sans Serif", 8);
3104 p->setFont(headerFont);
3105 headerHeight = (p->fontMetrics().lineSpacing() * 3) / 2;
3109 kDebug(6000) <<
"printing: html page width = " << root->docWidth()
3110 <<
" height = " << root->docHeight() << endl;
3111 kDebug(6000) <<
"printing: margins left = " << printer.pageRect().left() - printer.paperRect().left()
3112 <<
" top = " << printer.pageRect().top() - printer.paperRect().top() << endl;
3113 kDebug(6000) <<
"printing: paper width = " << printer.width()
3114 <<
" height = " << printer.height() << endl;
3117 int pageWidth = printer.width();
3118 int pageHeight = printer.height();
3119 p->setClipRect(0,0, pageWidth, pageHeight);
3121 pageHeight -= headerHeight;
3123 #ifndef QT_NO_TRANSFORMATIONS
3124 bool scalePage =
false;
3126 if(root->docWidth() > printer.width()) {
3128 scale = ((
double) printer.width())/((
double) root->docWidth());
3129 pageHeight = (int) (pageHeight/scale);
3130 pageWidth = (int) (pageWidth/scale);
3131 headerHeight = (int) (headerHeight/scale);
3134 kDebug(6000) <<
"printing: scaled html width = " << pageWidth
3135 <<
" height = " << pageHeight << endl;
3137 root->setHeight(pageHeight);
3138 root->setPageBottom(pageHeight);
3139 root->setNeedsLayout(
true);
3140 root->layoutIfNeeded();
3146 int available_width = printer.width() - 10 -
3147 2 * qMax(p->boundingRect(0, 0, printer.width(), p->fontMetrics().lineSpacing(), Qt::AlignLeft, headerLeft).width(),
3148 p->boundingRect(0, 0, printer.width(), p->fontMetrics().lineSpacing(), Qt::AlignLeft, headerRight).width());
3149 if (available_width < 150)
3150 available_width = 150;
3155 mid_width = p->boundingRect(0, 0, printer.width(), p->fontMetrics().lineSpacing(), Qt::AlignLeft, headerMid).width();
3157 }
while (mid_width > available_width);
3163 while(top < root->docHeight()) {
3164 if(top > 0) printer.newPage();
3165 #ifndef QT_NO_TRANSFORMATIONS
3167 p->scale(scale, scale);
3170 p->setClipRect(0, 0, pageWidth, headerHeight);
3173 int dy = p->fontMetrics().lineSpacing();
3174 p->setPen(Qt::black);
3175 p->setFont(headerFont);
3177 headerRight =
QString(
"#%1").arg(page);
3179 p->drawText(0, 0, printer.width(), dy, Qt::AlignLeft, headerLeft);
3180 p->drawText(0, 0, printer.width(), dy, Qt::AlignHCenter, headerMid);
3181 p->drawText(0, 0, printer.width(), dy, Qt::AlignRight, headerRight);
3185 p->translate(0, headerHeight-top);
3187 bottom = top+pageHeight;
3189 root->setPageTop(top);
3190 root->setPageBottom(bottom);
3191 root->setPageNumber(page);
3193 root->layer()->paint(p,
QRect(0, top, pageWidth, pageHeight));
3194 kDebug(6000) <<
"printed: page " << page <<
" bottom At = " << bottom;
3197 p->resetTransform();
3205 root->setPagedMode(
false);
3206 root->setStaticMode(
false);
3208 khtml::setPrintPainter( 0 );
3209 setMediaType( oldMediaType );
3210 m_part->xmlDocImpl()->setPaintDevice(
this );
3211 m_part->xmlDocImpl()->styleSelector()->computeFontSizes(m_part->xmlDocImpl()->logicalDpiY(), m_part->
fontScaleFactor());
3212 m_part->xmlDocImpl()->updateStyleSelector();
3213 viewport()->unsetCursor();
3219 if(!m_part->xmlDocImpl())
return;
3220 DOM::DocumentImpl *document = m_part->xmlDocImpl();
3221 if (!document->isHTMLDocument())
return;
3222 khtml::RenderCanvas *root =
static_cast<khtml::RenderCanvas *
>(document->renderer());
3224 root->style()->resetPalette();
3225 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(document)->body();
3227 body->setChanged(
true);
3228 body->recalcStyle( NodeImpl::Force );
3231 void KHTMLView::paint(QPainter *p,
const QRect &rc,
int yOff,
bool *more)
3233 if(!m_part->xmlDocImpl())
return;
3234 khtml::RenderCanvas *root =
static_cast<khtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer());
3237 d->firstRepaintPending =
false;
3240 QPaintDevice* opd = m_part->xmlDocImpl()->paintDevice();
3241 m_part->xmlDocImpl()->setPaintDevice(p->device());
3242 root->setPagedMode(
true);
3243 root->setStaticMode(
true);
3244 root->setWidth(rc.width());
3247 QRegion creg = p->clipRegion();
3248 QTransform t = p->worldTransform();
3249 QRect w = p->window();
3250 QRect v = p->viewport();
3251 bool vte = p->viewTransformEnabled();
3252 bool wme = p->worldMatrixEnabled();
3255 p->translate(rc.left(), rc.top());
3256 double scale = ((
double) rc.width()/(
double) root->docWidth());
3257 int height = (int) ((
double) rc.height() / scale);
3258 #ifndef QT_NO_TRANSFORMATIONS
3259 p->scale(scale, scale);
3261 root->setPageTop(yOff);
3262 root->setPageBottom(yOff+height);
3264 root->layer()->paint(p,
QRect(0, yOff, root->docWidth(), height));
3266 *more = yOff + height < root->docHeight();
3269 p->setWorldTransform(t);
3272 p->setViewTransformEnabled( vte );
3273 p->setWorldMatrixEnabled( wme );
3274 if (!creg.isEmpty())
3275 p->setClipRegion( creg );
3277 p->setClipRegion(QRegion(), Qt::NoClip);
3279 root->setPagedMode(
false);
3280 root->setStaticMode(
false);
3281 m_part->xmlDocImpl()->setPaintDevice( opd );
3284 void KHTMLView::render(QPainter* p,
const QRect& r,
const QPoint& off)
3287 d->firstRepaintPending =
false;
3289 QRect clip(off.x()+r.x(), off.y()+r.y(),r.width(),r.height());
3290 if(!m_part || !m_part->xmlDocImpl() || !m_part->xmlDocImpl()->renderer()) {
3291 p->fillRect(clip, palette().brush(QPalette::Active, QPalette::Base));
3294 QPaintDevice* opd = m_part->xmlDocImpl()->paintDevice();
3295 m_part->xmlDocImpl()->setPaintDevice(p->device());
3298 QRegion creg = p->clipRegion();
3299 QTransform t = p->worldTransform();
3300 QRect w = p->window();
3301 QRect v = p->viewport();
3302 bool vte = p->viewTransformEnabled();
3303 bool wme = p->worldMatrixEnabled();
3305 p->setClipRect(clip);
3309 m_part->xmlDocImpl()->renderer()->layer()->paint(p, rect);
3312 p->setWorldTransform(t);
3315 p->setViewTransformEnabled( vte );
3316 p->setWorldMatrixEnabled( wme );
3317 if (!creg.isEmpty())
3318 p->setClipRegion( creg );
3320 p->setClipRegion(QRegion(), Qt::NoClip);
3322 m_part->xmlDocImpl()->setPaintDevice( opd );
3325 void KHTMLView::setHasStaticBackground(
bool partial)
3328 if (d->staticWidget == KHTMLViewPrivate::SBFull &&
m_kwp->isRedirected())
3331 d->staticWidget = partial ?
3332 KHTMLViewPrivate::SBPartial : KHTMLViewPrivate::SBFull;
3335 void KHTMLView::setHasNormalBackground()
3338 if (d->staticWidget == KHTMLViewPrivate::SBFull &&
m_kwp->isRedirected())
3341 d->staticWidget = KHTMLViewPrivate::SBNone;
3344 void KHTMLView::addStaticObject(
bool fixed)
3347 d->fixedObjectsCount++;
3349 d->staticObjectsCount++;
3351 setHasStaticBackground(
true );
3354 void KHTMLView::removeStaticObject(
bool fixed)
3357 d->fixedObjectsCount--;
3359 d->staticObjectsCount--;
3361 assert( d->fixedObjectsCount >= 0 && d->staticObjectsCount >= 0 );
3363 if (!d->staticObjectsCount && !d->fixedObjectsCount)
3364 setHasNormalBackground();
3366 setHasStaticBackground(
true );
3371 #ifndef KHTML_NO_SCROLLBARS
3372 d->vpolicy = policy;
3373 QScrollArea::setVerticalScrollBarPolicy(policy);
3381 #ifndef KHTML_NO_SCROLLBARS
3382 d->hpolicy = policy;
3383 QScrollArea::setHorizontalScrollBarPolicy(policy);
3389 void KHTMLView::restoreScrollBar()
3392 QScrollArea::setVerticalScrollBarPolicy(d->vpolicy);
3395 d->prevScrollbarVisible = verticalScrollBar()->isVisible();
3402 if (!d->formCompletions)
3404 return d->formCompletions->group(
"").readEntry(name,
QStringList());
3407 void KHTMLView::clearCompletionHistory(
const QString& name)
3409 if (!d->formCompletions)
3413 d->formCompletions->group(
"").writeEntry(name,
"");
3414 d->formCompletions->sync();
3417 void KHTMLView::addFormCompletionItem(
const QString &name,
const QString &value)
3424 bool cc_number(
true);
3425 for (
int i = 0; i < value.length(); ++i)
3428 if (!c.isNumber() && c !=
'-' && !c.isSpace())
3437 if (!items.contains(value))
3438 items.prepend(value);
3440 items.erase(items.isEmpty() ? items.end() : --items.end());
3441 d->formCompletions->group(
"").writeEntry(name, items);
3444 void KHTMLView::addNonPasswordStorableSite(
const QString& host)
3446 if (!d->formCompletions) {
3450 KConfigGroup cg( d->formCompletions,
"NonPasswordStorableSites");
3453 cg.writeEntry(
"Sites", sites);
3458 void KHTMLView::delNonPasswordStorableSite(
const QString& host)
3460 if (!d->formCompletions) {
3464 KConfigGroup cg( d->formCompletions,
"NonPasswordStorableSites");
3466 sites.removeOne(host);
3467 cg.writeEntry(
"Sites", sites);
3471 bool KHTMLView::nonPasswordStorableSite(
const QString& host)
const
3473 if (!d->formCompletions) {
3476 QStringList sites = d->formCompletions->group(
"NonPasswordStorableSites" ).readEntry(
"Sites",
QStringList());
3477 return (sites.indexOf(host) != -1);
3481 bool KHTMLView::dispatchMouseEvent(
int eventId, DOM::NodeImpl *targetNode,
3482 DOM::NodeImpl *targetNodeNonShared,
bool cancelable,
3483 int detail,QMouseEvent *_mouse,
bool setUnder,
3484 int mouseEventType,
int orient)
3487 if (targetNode && targetNode->isTextNode())
3488 targetNode = targetNode->parentNode();
3491 d->underMouse->deref();
3492 d->underMouse = targetNode;
3494 d->underMouse->ref();
3496 if (d->underMouseNonShared)
3497 d->underMouseNonShared->deref();
3498 d->underMouseNonShared = targetNodeNonShared;
3499 if (d->underMouseNonShared)
3500 d->underMouseNonShared->ref();
3502 bool isWheelEvent = (mouseEventType == DOM::NodeImpl::MouseWheel);
3504 int exceptioncode = 0;
3505 int pageX = _mouse->x();
3506 int pageY = _mouse->y();
3507 revertTransforms(pageX, pageY);
3510 int screenX = _mouse->globalX();
3511 int screenY = _mouse->globalY();
3513 switch (_mouse->button()) {
3514 case Qt::LeftButton:
3520 case Qt::RightButton:
3526 if (d->accessKeysEnabled && d->accessKeysPreActivate && button!=-1)
3527 d->accessKeysPreActivate=
false;
3529 bool ctrlKey = (_mouse->modifiers() & Qt::ControlModifier);
3530 bool altKey = (_mouse->modifiers() & Qt::AltModifier);
3531 bool shiftKey = (_mouse->modifiers() & Qt::ShiftModifier);
3532 bool metaKey = (_mouse->modifiers() & Qt::MetaModifier);
3535 if (setUnder && d->oldUnderMouse != targetNode) {
3536 if (d->oldUnderMouse && d->oldUnderMouse->document() != m_part->xmlDocImpl()) {
3537 d->oldUnderMouse->deref();
3538 d->oldUnderMouse = 0;
3541 if (d->oldUnderMouse) {
3543 MouseEventImpl *me =
new MouseEventImpl(EventImpl::MOUSEOUT_EVENT,
3544 true,
true,m_part->xmlDocImpl()->defaultView(),
3545 0,screenX,screenY,clientX,clientY,pageX, pageY,
3546 ctrlKey,altKey,shiftKey,metaKey,
3549 d->oldUnderMouse->dispatchEvent(me,exceptioncode,
true);
3554 MouseEventImpl *me =
new MouseEventImpl(EventImpl::MOUSEOVER_EVENT,
3555 true,
true,m_part->xmlDocImpl()->defaultView(),
3556 0,screenX,screenY,clientX,clientY,pageX, pageY,
3557 ctrlKey,altKey,shiftKey,metaKey,
3558 button,d->oldUnderMouse);
3561 targetNode->dispatchEvent(me,exceptioncode,
true);
3564 if (d->oldUnderMouse)
3565 d->oldUnderMouse->deref();
3566 d->oldUnderMouse = targetNode;
3567 if (d->oldUnderMouse)
3568 d->oldUnderMouse->ref();
3571 bool swallowEvent =
false;
3575 if (targetNode->isGenericFormElement()
3576 &&
static_cast<HTMLGenericFormElementImpl*
>(targetNode)->disabled())
3580 bool dblclick = ( eventId == EventImpl::CLICK_EVENT &&
3581 _mouse->type() == QEvent::MouseButtonDblClick );
3582 MouseEventImpl *me =
new MouseEventImpl(static_cast<EventImpl::EventId>(eventId),
3583 true,cancelable,m_part->xmlDocImpl()->defaultView(),
3584 detail,screenX,screenY,clientX,clientY,pageX, pageY,
3585 ctrlKey,altKey,shiftKey,metaKey,
3586 button,0, isWheelEvent ? 0 : _mouse, dblclick,
3587 isWheelEvent ?
static_cast<MouseEventImpl::Orientation
>(orient) : MouseEventImpl::ONone );
3589 if ( !d->m_mouseEventsTarget && RenderLayer::gScrollBar && eventId == EventImpl::MOUSEDOWN_EVENT )
3591 d->m_mouseEventsTarget = RenderLayer::gScrollBar;
3592 if ( d->m_mouseEventsTarget && qobject_cast<QScrollBar*>(d->m_mouseEventsTarget) &&
3593 dynamic_cast<KHTMLWidget*>(static_cast<QWidget*>(d->m_mouseEventsTarget)) ) {
3598 QMouseEvent fw(_mouse->type(),
QPoint(pageX, pageY)-p, _mouse->button(), _mouse->buttons(), _mouse->modifiers());
3599 static_cast<RenderWidget::EventPropagator *
>(
static_cast<QWidget*
>(d->m_mouseEventsTarget))->sendEvent(&fw);
3600 if (_mouse->type() == QMouseEvent::MouseButtonPress && _mouse->button() == Qt::RightButton) {
3601 QContextMenuEvent cme(QContextMenuEvent::Mouse, p);
3602 static_cast<RenderWidget::EventPropagator *
>(
static_cast<QWidget*
>(d->m_mouseEventsTarget))->sendEvent(&cme);
3603 d->m_mouseEventsTarget = 0;
3605 swallowEvent =
true;
3607 targetNode->dispatchEvent(me,exceptioncode,
true);
3608 bool defaultHandled = me->defaultHandled();
3609 if (defaultHandled || me->defaultPrevented())
3610 swallowEvent =
true;
3612 if (eventId == EventImpl::MOUSEDOWN_EVENT && !me->defaultPrevented()) {
3617 DOM::NodeImpl* nodeImpl = targetNode;
3618 for ( ; nodeImpl && !nodeImpl->isFocusable(); nodeImpl = nodeImpl->parentNode())
3620 if (nodeImpl && nodeImpl->isMouseFocusable())
3621 m_part->xmlDocImpl()->setFocusNode(nodeImpl);
3622 else if (!nodeImpl || !nodeImpl->focused())
3623 m_part->xmlDocImpl()->setFocusNode(0);
3628 return swallowEvent;
3631 void KHTMLView::setIgnoreWheelEvents(
bool e )
3633 d->ignoreWheelEvents = e;
3636 #ifndef QT_NO_WHEELEVENT
3642 if (d->scrollingFromWheel !=
QPoint(-1,-1) && d->scrollingFromWheel != QCursor::pos())
3643 d->scrollingFromWheel = d->scrollingFromWheelTimerId ? QCursor::pos() :
QPoint(-1,-1);
3645 if (d->accessKeysEnabled && d->accessKeysPreActivate) d->accessKeysPreActivate=
false;
3647 if ( ( e->modifiers() & Qt::ControlModifier) == Qt::ControlModifier )
3652 else if (d->firstLayoutPending)
3656 else if( !
m_kwp->isRedirected() &&
3657 ( (e->orientation() == Qt::Vertical &&
3658 ((d->ignoreWheelEvents && !verticalScrollBar()->isVisible())
3662 (e->orientation() == Qt::Horizontal &&
3663 ((d->ignoreWheelEvents && !horizontalScrollBar()->isVisible())
3676 revertTransforms(xm, ym);
3678 DOM::NodeImpl::MouseEvent mev( e->buttons(), DOM::NodeImpl::MouseWheel );
3679 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
3681 MouseEventImpl::Orientation o = MouseEventImpl::OVertical;
3682 if (e->orientation() == Qt::Horizontal)
3683 o = MouseEventImpl::OHorizontal;
3685 QMouseEvent _mouse(QEvent::MouseMove, e->pos(), Qt::NoButton, e->buttons(), e->modifiers());
3686 bool swallow = dispatchMouseEvent(EventImpl::KHTML_MOUSEWHEEL_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
3687 true,-e->delta()/40,&_mouse,
true,DOM::NodeImpl::MouseWheel,o);
3692 d->scrollBarMoved =
true;
3693 d->scrollingFromWheel = QCursor::pos();
3695 d->shouldSmoothScroll =
true;
3696 if (d->scrollingFromWheelTimerId)
3697 killTimer(d->scrollingFromWheelTimerId);
3698 d->scrollingFromWheelTimerId = startTimer(400);
3702 bool h = (
static_cast<QWheelEvent*
>(e)->orientation() == Qt::Horizontal);
3703 bool d = (
static_cast<QWheelEvent*
>(e)->delta() < 0);
3704 QScrollBar* hsb = horizontalScrollBar();
3705 QScrollBar* vsb = verticalScrollBar();
3706 if ( (h && ((d && hsb->value() == hsb->maximum()) || (!d && hsb->value() == hsb->minimum()))) ||
3707 (!h && ((d && vsb->value() == vsb->maximum()) || (!d && vsb->value() == vsb->minimum()))) ) {
3712 QScrollArea::wheelEvent( e );
3721 QScrollArea::dragEnterEvent( ev );
3727 QScrollArea::dropEvent( ev );
3732 DOM::NodeImpl* fn = m_part->xmlDocImpl() ? m_part->xmlDocImpl()->focusNode() : 0;
3733 if (fn && fn->renderer() && fn->renderer()->isWidget() &&
3734 (e->reason() != Qt::MouseFocusReason) &&
3735 static_cast<khtml::RenderWidget*>(fn->renderer())->widget())
3736 static_cast<khtml::RenderWidget*>(fn->renderer())->widget()->setFocus();
3737 m_part->setSelectionVisible();
3738 QScrollArea::focusInEvent( e );
3744 m_part->stopAutoScroll();
3745 m_part->setSelectionVisible(
false);
3748 if ( d->cursorIconWidget )
3749 d->cursorIconWidget->hide();
3751 QScrollArea::focusOutEvent( e );
3756 if (!dx && !dy)
return;
3758 if ( !d->firstLayoutPending && !d->complete && m_part->xmlDocImpl() &&
3759 d->layoutSchedulingEnabled) {
3761 khtml::RenderCanvas* root =
static_cast<khtml::RenderCanvas *
>( m_part->xmlDocImpl()->renderer() );
3762 if (root && root->needsLayout()) {
3763 unscheduleRelayout();
3768 if ( d->shouldSmoothScroll && d->smoothScrollMode !=
SSMDisabled && m_part->xmlDocImpl() &&
3771 bool doSmoothScroll = (!d->staticWidget || d->smoothScrollMode ==
SSMEnabled);
3773 int numStaticPixels = 0;
3774 QRegion r =
static_cast<RenderCanvas*
>(m_part->xmlDocImpl()->renderer())->staticRegion();
3777 if (!doSmoothScroll && d->staticWidget == KHTMLViewPrivate::SBPartial && r.rects().size() <= 10) {
3778 foreach(
const QRect &rr, r.rects())
3779 numStaticPixels += rr.width()*rr.height();
3781 doSmoothScroll =
true;
3783 if (doSmoothScroll) {
3784 setupSmoothScrolling(dx, dy);
3789 if ( underMouse() && QToolTip::isVisible() )
3790 QToolTip::hideText();
3792 if (!d->scrollingSelf) {
3793 d->scrollBarMoved =
true;
3794 d->contentsMoving =
true;
3796 scheduleRepaint(0, 0, 0, 0);
3799 if (m_part->xmlDocImpl() && m_part->xmlDocImpl()->documentElement()) {
3800 m_part->xmlDocImpl()->documentElement()->dispatchHTMLEvent(EventImpl::SCROLL_EVENT,
true,
false);
3803 if (QApplication::isRightToLeft())
3806 if (!d->smoothScrolling) {
3807 d->updateContentsXY();
3812 if (widget()->pos() !=
QPoint(0,0)) {
3813 kDebug(6000) <<
"Static widget wasn't positioned at (0,0). This should NOT happen. Please report this event to developers.";
3814 kDebug(6000) << kBacktrace();
3815 widget()->move(0,0);
3820 if (
m_kwp->isRedirected()) {
3825 off = viewport()->mapTo(
this, off);
3828 if ( d->staticWidget ) {
3832 if (!d->visibleWidgets.isEmpty())
3833 checkExternalWidgetsPosition();
3835 if ( d->staticWidget == KHTMLViewPrivate::SBPartial
3836 && m_part->xmlDocImpl() && m_part->xmlDocImpl()->renderer() ) {
3838 QRegion r =
static_cast<RenderCanvas*
>(m_part->xmlDocImpl()->renderer())->staticRegion();
3842 for (
int i = 0; i < ar.size() ; ++i) {
3843 widget()->update( ar[i] );
3847 for (
int i = 0; i < ar.size() ; ++i) {
3848 w->scroll( dx, dy, ar[i].translated(off) );
3850 d->scrollExternalWidgets(dx, dy);
3855 if (d->accessKeysActivated)
3856 d->scrollAccessKeys(dx, dy);
3861 if (
m_kwp->isRedirected()) {
3863 w->scroll(dx, dy, rect);
3864 if (d->zoomLevel != 100) {
3868 widget()->scroll(dx, dy, widget()->rect() & viewport()->rect());
3871 d->scrollExternalWidgets(dx, dy);
3872 if (d->accessKeysActivated)
3873 d->scrollAccessKeys(dx, dy);
3876 void KHTMLView::setupSmoothScrolling(
int dx,
int dy)
3879 int ddx = qMax(d->steps ? abs(d->dx)/d->steps : 0,3);
3880 int ddy = qMax(d->steps ? abs(d->dy)/d->steps : 0,3);
3886 if (d->dx == 0 && d->dy == 0) {
3893 if (qMax(abs(d->dx), abs(d->dy)) / d->steps < qMax(ddx,ddy)) {
3896 d->steps = qMax((abs(d->dx)+ddx-1)/ddx, (abs(d->dy)+ddy-1)/ddy);
3897 if (d->steps < 1) d->steps = 1;
3900 d->smoothScrollStopwatch.start();
3901 if (!d->smoothScrolling) {
3902 d->startScrolling();
3907 void KHTMLView::scrollTick() {
3908 if (d->dx == 0 && d->dy == 0) {
3913 if (d->steps < 1) d->steps = 1;
3917 if (takesteps < 1) takesteps = 1;
3918 if (takesteps > d->steps) takesteps = d->steps;
3919 for(
int i = 0; i < takesteps; i++) {
3920 int ddx = (d->dx / (d->steps+1)) * 2;
3921 int ddy = (d->dy / (d->steps+1)) * 2;
3924 if (abs(ddx) > abs(d->dx)) ddx = d->dx;
3925 if (abs(ddy) > abs(d->dy)) ddy = d->dy;
3935 d->shouldSmoothScroll =
false;
3938 if (takesteps < 2) {
3939 d->smoothScrollMissedDeadlines = 0;
3941 if (d->smoothScrollMissedDeadlines !=
sWayTooMany &&
3942 (!m_part->xmlDocImpl() || !m_part->xmlDocImpl()->parsing())) {
3943 d->smoothScrollMissedDeadlines++;
3959 if (child->parent() != widget())
3960 child->setParent( widget() );
3970 if ( e->timerId() == d->scrollTimerId ) {
3971 if( d->scrollSuspended )
3973 switch (d->scrollDirection) {
3974 case KHTMLViewPrivate::ScrollDown:
3976 d->newScrollTimer(
this, 0);
3978 verticalScrollBar()->setValue( verticalScrollBar()->value() +d->scrollBy );
3980 case KHTMLViewPrivate::ScrollUp:
3982 d->newScrollTimer(
this, 0);
3984 verticalScrollBar()->setValue( verticalScrollBar()->value() -d->scrollBy );
3986 case KHTMLViewPrivate::ScrollRight:
3988 d->newScrollTimer(
this, 0);
3990 horizontalScrollBar()->setValue( horizontalScrollBar()->value() +d->scrollBy );
3992 case KHTMLViewPrivate::ScrollLeft:
3994 d->newScrollTimer(
this, 0);
3996 horizontalScrollBar()->setValue( horizontalScrollBar()->value() -d->scrollBy );
4001 else if ( e->timerId() == d->scrollingFromWheelTimerId ) {
4002 killTimer( d->scrollingFromWheelTimerId );
4003 d->scrollingFromWheelTimerId = 0;
4004 }
else if ( e->timerId() == d->layoutTimerId ) {
4005 if (d->firstLayoutPending && d->layoutAttemptCounter < 4
4006 && (!m_part->xmlDocImpl() || !m_part->xmlDocImpl()->readyForLayout())) {
4007 d->layoutAttemptCounter++;
4008 killTimer(d->layoutTimerId);
4009 d->layoutTimerId = 0;
4014 d->scheduledLayoutCounter++;
4015 if (d->firstLayoutPending) {
4016 d->firstLayoutPending =
false;
4017 verticalScrollBar()->setEnabled(
true );
4018 horizontalScrollBar()->setEnabled(
true );
4022 d->contentsMoving =
false;
4023 if( m_part->xmlDocImpl() ) {
4024 DOM::DocumentImpl *document = m_part->xmlDocImpl();
4025 khtml::RenderCanvas* root =
static_cast<khtml::RenderCanvas *
>(document->renderer());
4027 if ( root && root->needsLayout() ) {
4028 if (d->repaintTimerId)
4029 killTimer(d->repaintTimerId);
4030 d->repaintTimerId = 0;
4036 if (d->repaintTimerId)
4037 killTimer(d->repaintTimerId);
4038 d->repaintTimerId = 0;
4043 d->updateRegion = QRegion();
4046 updateRegion = rects[0];
4048 for (
int i = 1; i < rects.size(); ++i ) {
4049 QRect newRegion = updateRegion.unite(rects[i]);
4050 if (2*newRegion.height() > 3*updateRegion.height() )
4053 updateRegion = rects[i];
4056 updateRegion = newRegion;
4059 if ( !updateRegion.isNull() )
4067 if (d->dirtyLayout && !d->visibleWidgets.isEmpty())
4068 checkExternalWidgetsPosition();
4070 d->dirtyLayout =
false;
4073 if (d->emitCompletedAfterRepaint) {
4074 bool full = d->emitCompletedAfterRepaint == KHTMLViewPrivate::CSFull;
4075 d->emitCompletedAfterRepaint = KHTMLViewPrivate::CSNone;
4083 void KHTMLView::checkExternalWidgetsPosition()
4088 QHashIterator<void*, QWidget*> it(d->visibleWidgets);
4089 while (it.hasNext()) {
4092 RenderWidget* rw =
static_cast<RenderWidget*
>( it.key() );
4093 if (!rw->absolutePosition(xp, yp) ||
4094 !visibleRect.intersects(
QRect(xp, yp, it.value()->width(), it.value()->height())))
4095 toRemove.append(rw);
4097 foreach (RenderWidget* r, toRemove)
4098 if ( (w = d->visibleWidgets.take(r) ) )
4099 w->move( 0, -500000);
4102 void KHTMLView::scheduleRelayout(khtml::RenderObject * )
4104 if (!d->layoutSchedulingEnabled || d->layoutTimerId)
4108 if (d->firstLayoutPending) {
4112 time = d->layoutAttemptCounter ?
4114 }
else if (m_part->xmlDocImpl() && m_part->xmlDocImpl()->parsing()) {
4119 d->layoutTimerId = startTimer( time );
4122 void KHTMLView::unscheduleRelayout()
4124 if (!d->layoutTimerId)
4127 killTimer(d->layoutTimerId);
4128 d->layoutTimerId = 0;
4131 void KHTMLView::unscheduleRepaint()
4133 if (!d->repaintTimerId)
4136 killTimer(d->repaintTimerId);
4137 d->repaintTimerId = 0;
4140 void KHTMLView::scheduleRepaint(
int x,
int y,
int w,
int h,
bool asap)
4142 bool parsing = !m_part->xmlDocImpl() || m_part->xmlDocImpl()->parsing();
4147 int time = parsing && !d->firstLayoutPending ? 150 : (!asap ? ( !d->complete ? 80 : 20 ) : 0);
4149 #ifdef DEBUG_FLICKER
4151 p.begin( viewport() );
4155 p.fillRect( vx, vy, w, h, Qt::red );
4159 d->updateRegion = d->updateRegion.unite(
QRect(x,y,w,h));
4161 if (asap && !parsing)
4162 unscheduleRepaint();
4164 if ( !d->repaintTimerId )
4165 d->repaintTimerId = startTimer( time );
4170 void KHTMLView::complete(
bool pendingAction )
4177 if (d->layoutTimerId)
4181 killTimer(d->layoutTimerId);
4182 d->layoutTimerId = startTimer( 0 );
4183 d->emitCompletedAfterRepaint = pendingAction ?
4184 KHTMLViewPrivate::CSActionPending : KHTMLViewPrivate::CSFull;
4188 if (d->repaintTimerId)
4192 killTimer(d->repaintTimerId);
4193 d->repaintTimerId = startTimer( 0 );
4194 d->emitCompletedAfterRepaint = pendingAction ?
4195 KHTMLViewPrivate::CSActionPending : KHTMLViewPrivate::CSFull;
4198 if (!d->emitCompletedAfterRepaint)
4208 void KHTMLView::updateScrollBars()
4210 const QWidget *view = widget();
4214 QSize p = viewport()->size();
4215 QSize m = maximumViewportSize();
4217 if (m.expandedTo(view->size()) == m)
4220 QSize v = view->size();
4221 horizontalScrollBar()->setRange(0, v.width() - p.width());
4222 horizontalScrollBar()->setPageStep(p.width());
4223 verticalScrollBar()->setRange(0, v.height() - p.height());
4224 verticalScrollBar()->setPageStep(p.height());
4225 if (!d->smoothScrolling) {
4226 d->updateContentsXY();
4230 void KHTMLView::slotMouseScrollTimer()
4232 horizontalScrollBar()->setValue( horizontalScrollBar()->value() +d->m_mouseScroll_byX );
4233 verticalScrollBar()->setValue( verticalScrollBar()->value() +d->m_mouseScroll_byY);
4239 Selection sel = pos;
4240 sel.expandUsingGranularity(Selection::LINE);
4241 return toEnd ? sel.end() : sel.start();
4254 bool KHTMLView::caretKeyPressEvent(QKeyEvent *_ke)
4258 Position old_pos = caret.caretPos();
4259 Position pos = old_pos;
4260 bool recalcXPos =
true;
4261 bool handled =
true;
4263 bool ctrl = _ke->modifiers() & Qt::ControlModifier;
4264 bool shift = _ke->modifiers() & Qt::ShiftModifier;
4266 switch(_ke->key()) {
4270 pos = old_pos.nextLinePosition(caret.xPosForVerticalArrowNavigation(Selection::EXTENT));
4275 pos = old_pos.previousLinePosition(caret.xPosForVerticalArrowNavigation(Selection::EXTENT));
4280 pos = ctrl ? old_pos.previousWordPosition() : old_pos.previousCharacterPosition();
4284 pos = ctrl ? old_pos.nextWordPosition() : old_pos.nextCharacterPosition();
4287 case Qt::Key_PageDown:
4291 case Qt::Key_PageUp:
4314 if (pos != old_pos) {
4315 m_part->clearCaretRectIfNeeded();
4317 caret.moveTo(shift ? caret.nonCaretPos() : pos, pos);
4318 int old_x = caret.xPosForVerticalArrowNavigation(Selection::CARETPOS);
4320 m_part->selectionLayoutChanged();
4326 m_part->emitCaretPositionChanged(pos);
4328 m_part->notifySelectionChanged();
4332 if (handled) _ke->accept();
4336 #undef DEBUG_CARETMODE
QString i18n(const char *text)
SmoothScrollingMode smoothScrollingMode() const
Retrieve the current smooth scrolling mode.
Contextual information about the caret and the built-in editor.
bool changeCursor() const
void updateContents(const QRect &r)
Requests an update of the content area.
SmoothScrollingMode
Smooth Scrolling Mode enumeration.
void setSmoothScrollingModeDefault(SmoothScrollingMode m)
QList< QPair< QString, QChar > > fallbackAccessKeysAssignments() const
static const int sSmoothScrollMinStaticPixels
virtual void mouseDoubleClickEvent(QMouseEvent *)
QCursor urlCursor() const
Returns the cursor which is used when the cursor is on a link.
DOM::Selection m_selection
static QMap< NodeImpl *, QString > buildLabels(NodeImpl *start)
bool isFormCompletionEnabled() const
The Node interface is the primary datatype for the entire Document Object Model.
void setSmoothScrollingMode(SmoothScrollingMode m)
Set the smooth scrolling mode.
static QString getElementText(NodeImpl *start, bool after)
int maxFormCompletionItems() const
khtml::EditorContext editor_context
static const int sLayoutAttemptDelay
static DOM::Position positionOfLineEnd(const DOM::Position &pos)
QString label(StandardShortcut id)
int contentsY() const
Returns the y coordinate of the contents area point that is currently located at the top left in the ...
virtual void focusOutEvent(QFocusEvent *)
QPoint contentsToViewport(const QPoint &p) const
Returns a point translated to viewport coordinates.
void addChild(QWidget *child, int dx, int dy)
bool frameExists(const QString &frameName)
Returns whether a frame with the specified name is exists or not.
This class is khtml's main class.
static bool findImageMapRect(HTMLImageElementImpl *img, const QPoint &scrollOfs, const QPoint &p, QRect &r, QString &s)
calculates the client-side image map rectangle for the given image element
Renders and displays HTML in a QScrollArea.
virtual bool eventFilter(QObject *, QEvent *)
static KHTMLSettings * defaultHTMLSettings()
static const int sSmoothScrollTick
QPrintDialog * createPrintDialog(QPrinter *printer, PageSelectPolicy pageSelectPolicy, const QList< QWidget * > &customTabs, QWidget *parent=0)
void setContentsPos(int x, int y)
Place the contents area point x/y at the top left of the viewport.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
bool m_beganSelectingText
static DOM::Position positionOfLineBegin(const DOM::Position &pos)
virtual bool focusNextPrevChild(bool next)
KSharedConfigPtr config()
virtual void closeEvent(QCloseEvent *)
KHTMLView * view() const
Returns a pointer to the HTML document's view.
virtual void mousePressEvent(QMouseEvent *)
KHTMLPart * part() const
Returns a pointer to the KHTMLPart that is rendering the page.
virtual void scrollContentsBy(int dx, int dy)
int visibleWidth() const
Returns the width of the viewport.
QList< KParts::ReadOnlyPart * > frames() const
int visibleHeight() const
Returns the height of the viewport.
void layout()
ensure the display is up to date
QPixmap loadIcon(const QString &name, KIconLoader::Group group, int size=0, int state=KIconLoader::DefaultState, const QStringList &overlays=QStringList(), QString *path_store=0L, bool canReturnNull=false) const
virtual void focusInEvent(QFocusEvent *)
void setCaretVisible(bool show)
Sets the visibility of the caret.
static const int sParsingLayoutsInterval
virtual void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
Sets vertical scrollbar mode.
int contentsHeight() const
Returns the contents area's height.
int m_xPosForVerticalArrowNavigation
virtual void dragEnterEvent(QDragEnterEvent *)
virtual void hideEvent(QHideEvent *)
This class implements the basic string we use in the DOM.
virtual void begin(const KUrl &url=KUrl(), int xOffset=0, int yOffset=0)
Clears the widget and prepares it for new content.
void keyPressEvent(QKeyEvent *_ke)
QString csqueeze(const QString &str, int maxlen=40)
static void handleWidget(QWidget *w, KHTMLView *view, bool recurse=true)
static const int sFirstLayoutDelay
static const int sLayoutAttemptIncrement
virtual void paintEvent(QPaintEvent *)
static KIconLoader * iconLoader()
void setMarginWidth(int x)
Sets a margin in x direction.
static const int sMaxMissedDeadlines
void scrollBy(int x, int y)
Scrolls the content area by a given amount.
friend class KHTMLViewPrivate
static const int sParsingLayoutsIncrement
bool accessKeysEnabled() const
virtual void mouseMoveEvent(QMouseEvent *)
void timerEvent(QTimerEvent *)
QPoint viewportToContents(const QPoint &p) const
Returns a point translated to contents area coordinates.
virtual void resizeEvent(QResizeEvent *event)
void setZoomLevel(int percent)
Apply a zoom level to the content area.
virtual void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
Sets horizontal scrollbar mode.
static const int sSmoothScrollTime
virtual bool event(QEvent *event)
static const int sWayTooMany
virtual bool widgetEvent(QEvent *)
static QString locateLocal(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
bool isEditable() const
Returns true if the document is editable, false otherwise.
void finishedLayout()
This signal is used for internal layouting.
virtual bool viewportEvent(QEvent *e)
int contentsX() const
Returns the x coordinate of the contents area point that is currently located at the top left in the ...
bool isCaretMode() const
Returns whether caret mode is on/off.
void installEventFilter(QWidget *filter)
void setMarginHeight(int y)
QWeakPointer< DOM::HTMLPartContainerElementImpl > m_partContainerElement
#define KDE_VERSION_MAJOR
int fontScaleFactor() const
Returns the current font scale factor.
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void print(bool quick=false)
Prints the HTML document.
QString formatDate(const QDate &date, DateFormat format=LongDate) const
virtual void wheelEvent(QWheelEvent *)
int contentsWidth() const
Returns the contents area's width.
#define KDE_VERSION_MINOR
void nodeActivated(const DOM::Node &)
This signal is emitted when an element retrieves the keyboard focus.
void repaintContents(const QRect &r)
Requests an immediate repaint of the content area.
virtual void dropEvent(QDropEvent *)
NodeImpl * handle() const
T readEntry(const QString &key, const T &aDefault) const
void keyReleaseEvent(QKeyEvent *_ke)
const KHTMLSettings * settings() const
virtual void showEvent(QShowEvent *)
static DOM::Position positionOfLineBoundary(const DOM::Position &pos, bool toEnd)
KHTMLView(KHTMLPart *part, QWidget *parent)
Constructs a KHTMLView.
static bool targetOpensNewWindow(KHTMLPart *part, QString target)
int zoomLevel() const
Retrieve the current zoom level.
KAction * close(const QObject *recvr, const char *slot, QObject *parent)
virtual void resizeContents(int w, int h)
Resize the contents area.
virtual void mouseReleaseEvent(QMouseEvent *)
void displayAccessKeys()
Display all accesskeys in small tooltips.
KHTMLPart * parentPart()
Returns a pointer to the parent KHTMLPart if the part is a frame in an HTML frameset.
#define KDE_VERSION_RELEASE
static void setInPaintEventFlag(QWidget *w, bool b=true, bool recurse=true)
void slotPaletteChanged()