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 "misc/loader.h"
78 #include <QtGui/QBitmap>
79 #include <QtGui/QLabel>
80 #include <QtCore/QObject>
81 #include <QtGui/QPainter>
82 #include <QtCore/QHash>
83 #include <QtGui/QToolTip>
84 #include <QtCore/QString>
85 #include <QtGui/QTextDocument>
86 #include <QtCore/QTimer>
87 #include <QtCore/QAbstractEventDispatcher>
88 #include <QtCore/QVector>
89 #include <QtGui/QAbstractScrollArea>
90 #include <QtGui/QPrinter>
91 #include <QtGui/QPrintDialog>
99 #elif defined(Q_WS_WIN)
105 void dumpLineBoxes(RenderFlow *flow);
110 using namespace khtml;
131 class KHTMLViewPrivate {
135 enum PseudoFocusNodes {
141 enum StaticBackgroundState {
147 enum CompletedState {
154 :
underMouse( 0 ), underMouseNonShared( 0 ), oldUnderMouse( 0 )
156 postponed_autorepeat = NULL;
157 scrollingFromWheelTimerId = 0;
161 vpolicy = Qt::ScrollBarAsNeeded;
162 hpolicy = Qt::ScrollBarAsNeeded;
164 prevScrollbarVisible =
true;
166 possibleTripleClick =
false;
167 emitCompletedAfterRepaint = CSNone;
168 cursorIconWidget = 0;
169 cursorIconType = KHTMLView::LINK_NORMAL;
170 m_mouseScrollTimer = 0;
171 m_mouseScrollIndicator = 0;
178 delete formCompletions;
179 delete postponed_autorepeat;
182 if (underMouseNonShared)
183 underMouseNonShared->deref();
185 oldUnderMouse->deref();
187 delete cursorIconWidget;
188 delete m_mouseScrollTimer;
189 delete m_mouseScrollIndicator;
196 if (underMouseNonShared)
197 underMouseNonShared->deref();
198 underMouseNonShared = 0;
200 oldUnderMouse->deref();
203 staticWidget = SBNone;
204 fixedObjectsCount = 0;
205 staticObjectsCount = 0;
206 tabMovePending =
false;
207 lastTabbingDirection =
true;
208 pseudoFocusNode = PFNone;
210 #ifndef KHTML_NO_SCROLLBARS
216 vpolicy = ScrollBarAlwaysOff;
217 hpolicy = ScrollBarAlwaysOff;
219 scrollBarMoved =
false;
220 contentsMoving =
false;
221 ignoreWheelEvents =
false;
222 scrollingFromWheel =
QPoint(-1,-1);
231 isDoubleClick =
false;
232 scrollingSelf =
false;
233 delete postponed_autorepeat;
234 postponed_autorepeat = NULL;
238 scrollSuspended =
false;
239 scrollSuspendPreActivate =
false;
240 smoothScrolling =
false;
241 smoothScrollModeIsDefault =
true;
242 shouldSmoothScroll =
false;
243 smoothScrollMissedDeadlines = 0;
246 firstLayoutPending =
true;
248 firstRepaintPending =
true;
250 needsFullRepaint =
true;
252 layoutSchedulingEnabled =
true;
255 layoutAttemptCounter = 0;
256 scheduledLayoutCounter = 0;
258 m_dialogsAllowed =
true;
259 accessKeysActivated =
false;
260 accessKeysPreActivate =
false;
267 KHTMLGlobal::deref();
269 emitCompletedAfterRepaint = CSNone;
270 m_mouseEventsTarget = 0;
273 void newScrollTimer(
QWidget *view,
int tid)
278 scrollSuspended =
false;
280 enum ScrollDirection { ScrollLeft, ScrollRight, ScrollUp, ScrollDown };
282 void adjustScroller(
QWidget *view, ScrollDirection direction, ScrollDirection oppositedir)
284 static const struct {
int msec, pixels; } timings [] = {
285 {320,1}, {224,1}, {160,1}, {112,1}, {80,1}, {56,1}, {40,1},
286 {28,1}, {20,1}, {20,2}, {20,3}, {20,4}, {20,6}, {20,8}, {0,0}
288 if (!scrollTimerId ||
289 (static_cast<int>(scrollDirection) != direction &&
290 (static_cast<int>(scrollDirection) != oppositedir || scrollSuspended))) {
292 scrollBy = timings[scrollTiming].pixels;
293 scrollDirection = direction;
294 newScrollTimer(view, view->
startTimer(timings[scrollTiming].msec));
295 }
else if (scrollDirection == direction &&
296 timings[scrollTiming+1].msec && !scrollSuspended) {
297 scrollBy = timings[++scrollTiming].pixels;
298 newScrollTimer(view, view->
startTimer(timings[scrollTiming].msec));
299 }
else if (scrollDirection == oppositedir) {
301 scrollBy = timings[--scrollTiming].pixels;
302 newScrollTimer(view, view->
startTimer(timings[scrollTiming].msec));
305 scrollSuspended =
false;
308 bool haveZoom()
const {
return zoomLevel != 100; }
310 void startScrolling()
312 smoothScrolling =
true;
314 shouldSmoothScroll =
false;
319 smoothScrollTimer.stop();
323 smoothScrolling =
false;
324 shouldSmoothScroll =
false;
327 void updateContentsXY()
330 view->horizontalScrollBar()->maximum()-view->horizontalScrollBar()->value() : view->horizontalScrollBar()->value();
331 contentsY = view->verticalScrollBar()->value();
333 void scrollAccessKeys(
int dx,
int dy)
335 QList<QLabel*> wl = qFindChildren<QLabel*>(view->widget(),
"KHTMLAccessKey");
340 void scrollExternalWidgets(
int dx,
int dy)
342 if (visibleWidgets.isEmpty())
352 NodeImpl *underMouse;
353 NodeImpl *underMouseNonShared;
354 NodeImpl *oldUnderMouse;
358 bool tabMovePending:1;
359 bool lastTabbingDirection:1;
360 PseudoFocusNodes pseudoFocusNode:3;
361 bool scrollBarMoved:1;
362 bool contentsMoving:1;
364 Qt::ScrollBarPolicy vpolicy;
365 Qt::ScrollBarPolicy hpolicy;
366 bool prevScrollbarVisible:1;
368 bool ignoreWheelEvents:1;
369 StaticBackgroundState staticWidget: 3;
370 int staticObjectsCount;
371 int fixedObjectsCount;
374 int borderX, borderY;
379 int clickX, clickY, clickCount;
385 int contentsX, contentsY;
393 ScrollDirection scrollDirection :3;
394 bool scrollSuspended :1;
395 bool scrollSuspendPreActivate :1;
397 bool smoothScrolling :1;
398 bool smoothScrollModeIsDefault :1;
399 bool shouldSmoothScroll :1;
402 bool firstLayoutPending :1;
404 bool firstRepaintPending :1;
406 bool layoutSchedulingEnabled :1;
407 bool needsFullRepaint :1;
409 bool possibleTripleClick :1;
411 bool m_dialogsAllowed :1;
412 short smoothScrollMissedDeadlines;
414 int layoutAttemptCounter;
415 int scheduledLayoutCounter;
418 QTime smoothScrollStopwatch;
420 bool accessKeysEnabled;
421 bool accessKeysActivated;
422 bool accessKeysPreActivate;
423 CompletedState emitCompletedAfterRepaint;
426 KHTMLView::LinkCursor cursorIconType;
429 short m_mouseScroll_byX;
430 short m_mouseScroll_byY;
431 QPoint scrollingFromWheel;
432 int scrollingFromWheelTimerId;
433 QTimer *m_mouseScrollTimer;
434 QWidget *m_mouseScrollIndicator;
440 #ifndef QT_NO_TOOLTIP
454 HTMLMapElementImpl* map;
455 if (img && img->document()->isHTMLDocument() &&
456 (map =
static_cast<HTMLDocumentImpl*
>(img->document())->getMap(img->imageMap()))) {
457 RenderObject::NodeInfo info(
true,
false);
458 RenderObject *rend = img->renderer();
460 if (!rend || !rend->absolutePosition(ax, ay))
463 bool inside = map->mapMouseEvent(p.
x() - ax + scrollOfs.
x(),
464 p.
y() - ay + scrollOfs.
y(), rend->contentWidth(),
465 rend->contentHeight(), info);
466 if (inside && info.URLElement()) {
467 HTMLAreaElementImpl *area =
static_cast<HTMLAreaElementImpl *
>(info.URLElement());
468 Q_ASSERT(area->id() == ID_AREA);
469 s = area->getAttribute(ATTR_TITLE).string();
470 QRegion reg = area->cachedRegion();
471 if (!s.isEmpty() && !reg.
isEmpty()) {
483 switch ( e->
type() ) {
484 case QEvent::ToolTip: {
488 DOM::NodeImpl *node =
d->underMouseNonShared;
491 if ( node->isElementNode() ) {
492 DOM::ElementImpl *e =
static_cast<DOM::ElementImpl*
>( node );
498 if (e->id() == ID_IMG && !e->getAttribute( ATTR_USEMAP ).isEmpty()) {
500 viewportToContents(
QPoint(0, 0)), p, r, s);
503 s = e->getAttribute(ATTR_TITLE).string().
trimmed();
514 node = node->parentNode();
522 case QEvent::DragEnter:
523 case QEvent::DragMove:
524 case QEvent::DragLeave:
535 case QEvent::StyleChange:
536 case QEvent::LayoutRequest: {
540 case QEvent::PaletteChange:
541 slotPaletteChanged();
550 :
QScrollArea( parent ),
d( new KHTMLViewPrivate( this ) )
568 DOM::DocumentImpl *doc = m_part->xmlDocImpl();
581 void KHTMLView::init()
610 connect(&d->smoothScrollTimer, SIGNAL(
timeout()),
this, SLOT(scrollTick()));
613 void KHTMLView::resizeContentsToViewport()
623 if (d->accessKeysEnabled && d->accessKeysActivated)
626 if ( d->cursorIconWidget )
627 d->cursorIconWidget->hide();
628 if (d->smoothScrolling)
651 void KHTMLView::setMouseEventsTarget(
QWidget* w )
653 d->m_mouseEventsTarget = w;
656 QWidget* KHTMLView::mouseEventsTarget()
const
658 return d->m_mouseEventsTarget;
663 d->m_clipHolder = ch;
668 return d->m_clipHolder;
702 if (
m_kwp->isRedirected()) {
704 if (RenderWidget* rw =
m_kwp->renderWidget()) {
705 int ret = rw->width()-rw->paddingLeft()-rw->paddingRight()-rw->borderLeft()-rw->borderRight();
718 if (
m_kwp->isRedirected()) {
720 if (RenderWidget* rw =
m_kwp->renderWidget()) {
721 int ret = rw->height()-rw->paddingBottom()-rw->paddingTop()-rw->borderTop()-rw->borderBottom();
741 if (d->scrollTimerId)
742 d->newScrollTimer(
this, 0);
775 applyTransforms(x, y, w, h);
776 if (
m_kwp->isRedirected()) {
791 applyTransforms(x, y, w, h);
792 if (
m_kwp->isRedirected()) {
805 void KHTMLView::applyTransforms(
int& x,
int& y,
int& w,
int& h)
const
808 const int z = d->zoomLevel;
818 void KHTMLView::revertTransforms(
int& x,
int& y,
int& w,
int& h)
const
823 const int z = d->zoomLevel;
831 void KHTMLView::revertTransforms(
int& x,
int& y )
const
834 revertTransforms(x, y, dummy, dummy);
842 if (!m_part->xmlDocImpl())
843 resizeContentsToViewport();
846 if (m_part->xmlDocImpl() && m_part->xmlDocImpl()->styleSelector()->affectedByViewportChange()) {
847 m_part->xmlDocImpl()->updateStyleSelector();
850 if (d->layoutSchedulingEnabled)
855 if ( m_part && m_part->xmlDocImpl() ) {
863 HTMLPartContainerElementImpl::sendPostedResizeEvents();
864 m_part->xmlDocImpl()->dispatchWindowEvent( EventImpl::RESIZE_EVENT,
false,
false );
882 p.
scale( d->zoomLevel/100., d->zoomLevel/100.);
884 r.
setX(r.
x()*100/d->zoomLevel);
885 r.
setY(r.
y()*100/d->zoomLevel);
897 if(!m_part || !m_part->xmlDocImpl() || !m_part->xmlDocImpl()->renderer()) {
898 p.
fillRect(ex, ey, ew, eh,
palette().brush(QPalette::Active, QPalette::Base));
900 }
else if ( d->complete && static_cast<RenderCanvas*>(m_part->xmlDocImpl()->renderer())->needsLayout() ) {
902 unscheduleRelayout();
904 }
else if (m_part->xmlDocImpl()->tokenizer()) {
905 m_part->xmlDocImpl()->tokenizer()->setNormalYieldDelay();
909 kDebug( 6000 ) <<
"WARNING: paintEvent reentered! ";
910 kDebug( 6000 ) << kBacktrace();
915 m_part->xmlDocImpl()->renderer()->layer()->paint(&p, r);
917 if (d->hasFrameset) {
918 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(m_part->xmlDocImpl())->body();
919 if(body && body->renderer() && body->id() == ID_FRAMESET)
920 static_cast<RenderFrameSet*>(body->renderer())->paintFrameSetRules(&p, r);
922 d->hasFrameset =
false;
930 Qt::NoButton, Qt::NoButton, Qt::NoModifier );
934 if (d->firstRepaintPending && !m_part->
parentPart()) {
937 d->firstRepaintPending =
false;
956 if( m_part && m_part->xmlDocImpl() ) {
957 DOM::DocumentImpl *document = m_part->xmlDocImpl();
959 khtml::RenderCanvas* canvas =
static_cast<khtml::RenderCanvas *
>(document->renderer());
960 if ( !canvas )
return;
962 d->layoutSchedulingEnabled=
false;
963 d->dirtyLayout =
true;
966 RenderObject *
ref = 0;
967 RenderObject* root = document->documentElement() ? document->documentElement()->renderer() : 0;
969 if (document->isHTMLDocument()) {
970 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(document)->body();
971 if(body && body->renderer() && body->id() == ID_FRAMESET) {
974 body->renderer()->setNeedsLayout(
true);
975 d->hasFrameset =
true;
978 ref = (!body || root->style()->hidesOverflow()) ? root : body->renderer();
983 if( ref->style()->overflowX() == OHIDDEN ) {
985 }
else if (ref->style()->overflowX() == OSCROLL ) {
990 if ( ref->style()->overflowY() == OHIDDEN ) {
992 }
else if (ref->style()->overflowY() == OSCROLL ) {
998 d->needsFullRepaint = d->firstLayoutPending;
1000 d->needsFullRepaint =
true;
1008 if (d->firstLayoutPending) {
1011 d->firstLayoutPending =
false;
1017 if (d->accessKeysEnabled && d->accessKeysActivated) {
1025 if (d->layoutTimerId)
1027 d->layoutTimerId = 0;
1028 d->layoutSchedulingEnabled=
true;
1031 void KHTMLView::closeChildDialogs()
1039 kDebug(6000) <<
"closeChildDialogs: closing dialog " << dlgbase;
1047 kWarning() <<
"closeChildDialogs: not a KDialog! Don't use QDialogs in KDE! " <<
static_cast<QWidget*
>(dlg);
1051 d->m_dialogsAllowed =
false;
1054 bool KHTMLView::dialogsAllowed() {
1055 bool allowed = d->m_dialogsAllowed;
1058 allowed &= p->
view()->dialogsAllowed();
1064 closeChildDialogs();
1070 percent = percent < 20 ? 20 : (percent > 800 ? 800 : percent);
1071 int oldpercent = d->zoomLevel;
1072 d->zoomLevel = percent;
1073 if (percent != oldpercent) {
1074 if (d->layoutSchedulingEnabled)
1082 return d->zoomLevel;
1087 d->smoothScrollMode = m;
1088 d->smoothScrollModeIsDefault =
false;
1089 if (d->smoothScrolling && !m)
1096 if (!d->smoothScrollModeIsDefault)
1098 d->smoothScrollMode = m;
1099 if (d->smoothScrolling && !m)
1105 return d->smoothScrollMode;
1115 if (!m_part->xmlDocImpl())
return;
1116 if (d->possibleTripleClick && ( _mouse->
button() & Qt::MouseButtonMask ) == Qt::LeftButton)
1122 int xm = _mouse->
x();
1123 int ym = _mouse->
y();
1124 revertTransforms(xm, ym);
1128 d->isDoubleClick =
false;
1130 DOM::NodeImpl::MouseEvent mev( _mouse->
buttons(), DOM::NodeImpl::MousePress );
1131 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1135 if ( (_mouse->
button() == Qt::MidButton) &&
1137 mev.url.isNull() && (mev.innerNode.elementId() != ID_INPUT) ) {
1140 d->m_mouseScroll_byX = 0;
1141 d->m_mouseScroll_byY = 0;
1143 d->m_mouseScrollTimer =
new QTimer(
this );
1144 connect( d->m_mouseScrollTimer, SIGNAL(
timeout()),
this, SLOT(slotMouseScrollTimer()) );
1146 if ( !d->m_mouseScrollIndicator ) {
1148 pixmap.
fill(
QColor( qRgba( 127, 127, 127, 127 ) ) );
1153 option.rect.setRect( 16, 0, 16, 16 );
1155 option.rect.setRect( 0, 16, 16, 16 );
1157 option.rect.setRect( 16, 32, 16, 16 );
1159 option.rect.setRect( 32, 16, 16, 16 );
1163 d->m_mouseScrollIndicator =
new QWidget(
this );
1164 d->m_mouseScrollIndicator->setFixedSize( 48, 48 );
1166 palette.
setBrush( d->m_mouseScrollIndicator->backgroundRole(),
QBrush( pixmap ) );
1167 d->m_mouseScrollIndicator->setPalette( palette );
1169 d->m_mouseScrollIndicator->move( point.
x()-24, point.
y()-24 );
1175 if ( cg.
readEntry(
"ShowMouseScrollIndicator",
true ) ) {
1176 d->m_mouseScrollIndicator->show();
1177 d->m_mouseScrollIndicator->unsetCursor();
1179 QBitmap mask = d->m_mouseScrollIndicator->palette().brush(d->m_mouseScrollIndicator->backgroundRole()).texture().createHeuristicMask(
true );
1181 if ( hasHorBar && !hasVerBar ) {
1187 d->m_mouseScrollIndicator->setCursor( Qt::SizeHorCursor );
1189 else if ( !hasHorBar && hasVerBar ) {
1195 d->m_mouseScrollIndicator->setCursor( Qt::SizeVerCursor );
1198 d->m_mouseScrollIndicator->setCursor( Qt::SizeAllCursor );
1200 d->m_mouseScrollIndicator->setMask( mask );
1203 if ( hasHorBar && !hasVerBar )
1205 else if ( !hasHorBar && hasVerBar )
1213 else if ( d->m_mouseScrollTimer ) {
1214 delete d->m_mouseScrollTimer;
1215 d->m_mouseScrollTimer = 0;
1217 if ( d->m_mouseScrollIndicator )
1218 d->m_mouseScrollIndicator->hide();
1221 if (d->clickCount > 0 &&
1230 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1231 d->clickCount,_mouse,
true,DOM::NodeImpl::MousePress);
1233 if (!swallowEvent) {
1234 emit m_part->nodeActivated(mev.innerNode);
1244 if(!m_part->xmlDocImpl())
return;
1246 int xm = _mouse->
x();
1247 int ym = _mouse->
y();
1248 revertTransforms(xm, ym);
1252 d->isDoubleClick =
true;
1254 DOM::NodeImpl::MouseEvent mev( _mouse->
buttons(), DOM::NodeImpl::MouseDblClick );
1255 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1259 if (d->clickCount > 0 &&
1267 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1268 d->clickCount,_mouse,
true,DOM::NodeImpl::MouseDblClick);
1270 if (!swallowEvent) {
1275 d->possibleTripleClick=
true;
1279 void KHTMLView::tripleClickTimeout()
1281 d->possibleTripleClick =
false;
1288 (target.
toLower() !=
"_self") && (target.
toLower() !=
"_parent")) {
1289 if (target.
toLower() ==
"_blank")
1303 if ( d->m_mouseScrollTimer ) {
1306 int deltaX = point.
x() - d->m_mouseScrollIndicator->x() - 24;
1307 int deltaY = point.
y() - d->m_mouseScrollIndicator->y() - 24;
1309 (deltaX > 0) ? d->m_mouseScroll_byX = 1 : d->m_mouseScroll_byX = -1;
1310 (deltaY > 0) ? d->m_mouseScroll_byY = 1 : d->m_mouseScroll_byY = -1;
1312 double adX = qAbs(deltaX)/30.0;
1313 double adY = qAbs(deltaY)/30.0;
1315 d->m_mouseScroll_byX = qMax(qMin(d->m_mouseScroll_byX *
int(adX*adX), SHRT_MAX), SHRT_MIN);
1316 d->m_mouseScroll_byY = qMax(qMin(d->m_mouseScroll_byY *
int(adY*adY), SHRT_MAX), SHRT_MIN);
1318 if (d->m_mouseScroll_byX == 0 && d->m_mouseScroll_byY == 0) {
1319 d->m_mouseScrollTimer->stop();
1321 else if (!d->m_mouseScrollTimer->isActive()) {
1322 d->m_mouseScrollTimer->start( 20 );
1326 if(!m_part->xmlDocImpl())
return;
1328 int xm = _mouse->
x();
1329 int ym = _mouse->
y();
1330 revertTransforms(xm, ym);
1332 DOM::NodeImpl::MouseEvent mev( _mouse->
buttons(), DOM::NodeImpl::MouseMove );
1334 m_part->xmlDocImpl()->prepareMouseEvent( _mouse->
buttons() , xm, ym, &mev );
1340 DOM::NodeImpl* target = mev.innerNode.handle();
1341 DOM::NodeImpl* fn = m_part->xmlDocImpl()->focusNode();
1344 if (d->m_mouseEventsTarget && fn && fn->renderer() && fn->renderer()->isWidget())
1347 bool swallowEvent = dispatchMouseEvent(EventImpl::MOUSEMOVE_EVENT,target,mev.innerNonSharedNode.handle(),
false,
1348 0,_mouse,
true,DOM::NodeImpl::MouseMove);
1350 if (d->clickCount > 0 &&
1355 khtml::RenderObject* r = target ? target->renderer() : 0;
1357 bool forceDefault =
false;
1358 if (r && r->isWidget()) {
1359 RenderWidget* rw =
static_cast<RenderWidget*
>(r);
1360 KHTMLWidget* kw = qobject_cast<
KHTMLView*>(rw->widget())? dynamic_cast<KHTMLWidget*>(rw->widget()) : 0;
1361 if (kw && kw->
m_kwp->isRedirected())
1363 else if (
QLineEdit* le = qobject_cast<QLineEdit*>(rw->widget())) {
1364 QList<QWidget*> wl = qFindChildren<QWidget *>( le,
"KLineEditButton" );
1368 forceDefault =
true;
1373 else if (
QTextEdit* te = qobject_cast<QTextEdit*>(rw->widget())) {
1374 if (te->verticalScrollBar()->underMouse() || te->horizontalScrollBar()->underMouse())
1375 forceDefault =
true;
1378 khtml::RenderStyle*
style = (r && r->style()) ? r->style() : 0;
1380 LinkCursor linkCursor = LINK_NORMAL;
1381 switch (!forceDefault ? (style ? style->cursor() : CURSOR_AUTO) : CURSOR_DEFAULT) {
1384 !r->isPointInsideSelection(xm, ym, m_part->caret())) )
1388 if (mev.url.string().startsWith(
"mailto:") && mev.url.string().indexOf(
'@')>0)
1389 linkCursor = LINK_MAILTO;
1392 linkCursor = LINK_NEWWINDOW;
1395 if (r && r->isFrameSet() && !
static_cast<RenderFrameSet*
>(r)->noResize())
1396 c =
QCursor(static_cast<RenderFrameSet*>(r)->cursorShape());
1402 case CURSOR_POINTER:
1404 if (mev.url.string().startsWith(
"mailto:") && mev.url.string().indexOf(
'@')>0)
1405 linkCursor = LINK_MAILTO;
1408 linkCursor = LINK_NEWWINDOW;
1410 case CURSOR_PROGRESS:
1414 case CURSOR_ALL_SCROLL:
1415 c =
QCursor(Qt::SizeAllCursor);
1417 case CURSOR_E_RESIZE:
1418 case CURSOR_W_RESIZE:
1419 case CURSOR_EW_RESIZE:
1420 c =
QCursor(Qt::SizeHorCursor);
1422 case CURSOR_N_RESIZE:
1423 case CURSOR_S_RESIZE:
1424 case CURSOR_NS_RESIZE:
1425 c =
QCursor(Qt::SizeVerCursor);
1427 case CURSOR_NE_RESIZE:
1428 case CURSOR_SW_RESIZE:
1429 case CURSOR_NESW_RESIZE:
1430 c =
QCursor(Qt::SizeBDiagCursor);
1432 case CURSOR_NW_RESIZE:
1433 case CURSOR_SE_RESIZE:
1434 case CURSOR_NWSE_RESIZE:
1435 c =
QCursor(Qt::SizeFDiagCursor);
1444 c =
QCursor(Qt::WhatsThisCursor);
1446 case CURSOR_DEFAULT:
1449 case CURSOR_NOT_ALLOWED:
1450 c =
QCursor(Qt::ForbiddenCursor);
1452 case CURSOR_ROW_RESIZE:
1453 c =
QCursor(Qt::SplitVCursor);
1455 case CURSOR_COL_RESIZE:
1456 c =
QCursor(Qt::SplitHCursor);
1458 case CURSOR_VERTICAL_TEXT:
1459 case CURSOR_CONTEXT_MENU:
1460 case CURSOR_NO_DROP:
1468 if (!setCursor && style && style->cursor() != CURSOR_AUTO)
1475 if ( setCursor && vp->
cursor().handle() != c.
handle() ) {
1476 if( c.
shape() == Qt::ArrowCursor) {
1488 if( !d->cursorIconWidget ) {
1490 d->cursorIconWidget =
new QLabel( 0, Qt::X11BypassWindowManagerHint );
1491 XSetWindowAttributes attr;
1492 attr.save_under = True;
1493 XChangeWindowAttributes(
QX11Info::display(), d->cursorIconWidget->winId(), CWSaveUnder, &attr );
1495 d->cursorIconWidget =
new QLabel( NULL, NULL );
1501 if (linkCursor != d->cursorIconType) {
1502 d->cursorIconType = linkCursor;
1506 case LINK_MAILTO: cursorIcon =
"mail-message-new";
break;
1507 case LINK_NEWWINDOW: cursorIcon =
"window-new";
break;
1508 default: cursorIcon =
"dialog-error";
break;
1513 d->cursorIconWidget->resize( icon_pixmap.
width(), icon_pixmap.
height());
1515 d->cursorIconWidget->setPixmap( icon_pixmap);
1516 d->cursorIconWidget->update();
1520 d->cursorIconWidget->move( c_pos.
x() + 15, c_pos.
y() + 15 );
1524 #elif defined(Q_WS_WIN)
1525 SetWindowPos( d->cursorIconWidget->winId(), HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
1529 d->cursorIconWidget->show();
1532 else if ( d->cursorIconWidget )
1533 d->cursorIconWidget->hide();
1535 if (r && r->isWidget()) {
1539 if (!swallowEvent) {
1547 bool swallowEvent =
false;
1549 int xm = _mouse->
x();
1550 int ym = _mouse->
y();
1551 revertTransforms(xm, ym);
1553 DOM::NodeImpl::MouseEvent mev( _mouse->
buttons(), DOM::NodeImpl::MouseRelease );
1555 if ( m_part->xmlDocImpl() )
1557 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
1559 DOM::NodeImpl* target = mev.innerNode.handle();
1560 DOM::NodeImpl* fn = m_part->xmlDocImpl()->focusNode();
1563 if (d->m_mouseEventsTarget && fn && fn->renderer() && fn->renderer()->isWidget())
1566 swallowEvent = dispatchMouseEvent(EventImpl::MOUSEUP_EVENT,target,mev.innerNonSharedNode.handle(),
true,
1567 d->clickCount,_mouse,
false,DOM::NodeImpl::MouseRelease);
1570 if (d->m_mouseEventsTarget)
1571 d->m_mouseEventsTarget = 0;
1573 if (d->clickCount > 0 &&
1575 QMouseEvent me(d->isDoubleClick ? QEvent::MouseButtonDblClick : QEvent::MouseButtonRelease,
1577 dispatchMouseEvent(EventImpl::CLICK_EVENT, mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
true,
1578 d->clickCount, &me,
true, DOM::NodeImpl::MouseRelease);
1581 khtml::RenderObject* r = target ? target->renderer() : 0;
1582 if (r && r->isWidget())
1586 if (!swallowEvent) {
1593 bool KHTMLView::dispatchKeyEvent(
QKeyEvent *_ke )
1595 if (!m_part->xmlDocImpl())
1617 if( _ke == d->postponed_autorepeat )
1622 if( _ke->
type() == QEvent::KeyPress )
1626 bool ret = dispatchKeyEventHelper( _ke,
false );
1628 if( !ret && dispatchKeyEventHelper( _ke,
true ))
1634 bool ret = dispatchKeyEventHelper( _ke,
true );
1635 if( !ret && d->postponed_autorepeat )
1637 delete d->postponed_autorepeat;
1638 d->postponed_autorepeat = NULL;
1646 delete d->postponed_autorepeat;
1647 d->postponed_autorepeat = 0;
1650 return dispatchKeyEventHelper( _ke,
false );
1657 d->postponed_autorepeat->accept();
1659 d->postponed_autorepeat->ignore();
1666 bool KHTMLView::dispatchKeyEventHelper(
QKeyEvent *_ke,
bool keypress )
1668 DOM::NodeImpl* keyNode = m_part->xmlDocImpl()->focusNode();
1670 return keyNode->dispatchKeyEvent(_ke, keypress);
1672 return m_part->xmlDocImpl()->dispatchKeyEvent(_ke, keypress);
1679 if (d->accessKeysEnabled && _ke->
key() == Qt::Key_Control && !(_ke->
modifiers() & ~Qt::ControlModifier) && !d->accessKeysActivated)
1681 d->accessKeysPreActivate=
true;
1686 if (_ke->
key() == Qt::Key_Shift && !(_ke->
modifiers() & ~Qt::ShiftModifier))
1687 d->scrollSuspendPreActivate=
true;
1692 if (d->accessKeysEnabled && d->accessKeysActivated)
1694 int state = ( _ke->
modifiers() & ( Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ));
1695 if ( state==0 || state==Qt::ShiftModifier ) {
1696 if (_ke->
key() != Qt::Key_Shift)
1697 accessKeysTimeout();
1698 handleAccessKey( _ke );
1702 accessKeysTimeout();
1707 if ( dispatchKeyEvent( _ke )) {
1714 if (_ke->
modifiers() & Qt::ShiftModifier)
1719 if(d->scrollSuspended)
1720 d->newScrollTimer(
this, 0);
1725 d->adjustScroller(
this, KHTMLViewPrivate::ScrollDown, KHTMLViewPrivate::ScrollUp);
1730 d->adjustScroller(
this, KHTMLViewPrivate::ScrollUp, KHTMLViewPrivate::ScrollDown);
1735 d->adjustScroller(
this, KHTMLViewPrivate::ScrollLeft, KHTMLViewPrivate::ScrollRight);
1740 d->adjustScroller(
this, KHTMLViewPrivate::ScrollRight, KHTMLViewPrivate::ScrollLeft);
1744 switch ( _ke->
key() )
1748 if (!d->scrollTimerId || d->scrollSuspended)
1750 if (d->scrollTimerId)
1751 d->newScrollTimer(
this, 0);
1755 case Qt::Key_PageDown:
1756 d->shouldSmoothScroll =
true;
1758 if(d->scrollSuspended)
1759 d->newScrollTimer(
this, 0);
1764 if (!d->scrollTimerId || d->scrollSuspended)
1766 if (d->scrollTimerId)
1767 d->newScrollTimer(
this, 0);
1770 case Qt::Key_PageUp:
1771 d->shouldSmoothScroll =
true;
1773 if(d->scrollSuspended)
1774 d->newScrollTimer(
this, 0);
1778 if (!d->scrollTimerId || d->scrollSuspended)
1780 if (d->scrollTimerId)
1781 d->newScrollTimer(
this, 0);
1786 if (!d->scrollTimerId || d->scrollSuspended)
1788 if (d->scrollTimerId)
1789 d->newScrollTimer(
this, 0);
1792 case Qt::Key_Return:
1795 if (m_part->xmlDocImpl()) {
1796 NodeImpl *n = m_part->xmlDocImpl()->focusNode();
1804 if(d->scrollSuspended)
1805 d->newScrollTimer(
this, 0);
1809 if(d->scrollSuspended)
1810 d->newScrollTimer(
this, 0);
1817 if (d->scrollTimerId)
1818 d->newScrollTimer(
this, 0);
1828 if( d->scrollSuspendPreActivate && _ke->
key() != Qt::Key_Shift )
1829 d->scrollSuspendPreActivate =
false;
1830 if( _ke->
key() == Qt::Key_Shift && d->scrollSuspendPreActivate && !(_ke->
modifiers() & Qt::ShiftModifier))
1831 if (d->scrollTimerId) {
1832 d->scrollSuspended = !d->scrollSuspended;
1833 if (d->scrollSuspended)
1837 if (d->accessKeysEnabled)
1839 if (d->accessKeysPreActivate && _ke->
key() != Qt::Key_Control)
1840 d->accessKeysPreActivate=
false;
1841 if (d->accessKeysPreActivate && !(_ke->
modifiers() & Qt::ControlModifier))
1844 m_part->setStatusBarText(
i18n(
"Access Keys activated"),KHTMLPart::BarOverrideText);
1845 d->accessKeysActivated =
true;
1846 d->accessKeysPreActivate =
false;
1850 else if (d->accessKeysActivated)
1852 accessKeysTimeout();
1859 if ( dispatchKeyEvent( _ke ) )
1871 if (m_part->xmlDocImpl() && focusNextPrevNode(next))
1873 if (m_part->xmlDocImpl()->focusNode())
1874 kDebug() <<
"focusNode.name: "
1875 << m_part->xmlDocImpl()->focusNode()->nodeName().string() << endl;
1880 d->pseudoFocusNode = KHTMLViewPrivate::PFNone;
1903 #ifndef KHTML_NO_SELECTION
1906 if (m_part->isExtendingSelection()) {
1907 RenderObject::NodeInfo renderInfo(
true,
false);
1908 m_part->xmlDocImpl()->renderer()->layer()
1909 ->nodeAtPoint(renderInfo, xm, ym);
1910 innerNode = renderInfo.innerNode();
1913 if (innerNode.
handle() && innerNode.
handle()->renderer()
1914 && innerNode.
handle()->renderer()->shouldSelect()) {
1915 m_part->extendSelectionTo(xm, ym, innerNode);
1917 #endif // KHTML_NO_SELECTION
1943 if (!qobject_cast<QFrame*>(w))
1955 if (qobject_cast<KHTMLView*>(w)) {
1956 handleWidget(static_cast<KHTMLView*>(w)->widget(), view,
false);
1957 handleWidget(static_cast<KHTMLView*>(w)->horizontalScrollBar(), view,
false);
1958 handleWidget(static_cast<KHTMLView*>(w)->verticalScrollBar(), view,
false);
1962 QObjectList children = w->
children();
1963 foreach (
QObject*
object, children) {
1970 class KHTMLBackingStoreHackWidget :
public QWidget
1973 void publicEvent(
QEvent *e)
1981 switch (e->
type()) {
1984 case QEvent::MouseButtonPress:
1985 case QEvent::MouseButtonRelease:
1986 case QEvent::MouseButtonDblClick:
1987 case QEvent::MouseMove:
1988 #ifndef QT_NO_WHEELEVENT
1991 case QEvent::ContextMenu:
1992 case QEvent::DragEnter:
1993 case QEvent::DragMove:
1994 case QEvent::DragLeave:
2009 if (qobject_cast<KHTMLView*>(w)) {
2018 && !(
static_cast<QWidget*
>(cw)->windowModality() & Qt::ApplicationModal)) {
2026 if ( e->
type() == QEvent::ShortcutOverride ) {
2029 || (m_part->xmlDocImpl() && m_part->xmlDocImpl()->focusNode()
2030 && m_part->xmlDocImpl()->focusNode()->isContentEditable())) {
2031 if ( (ke->
modifiers() & Qt::ControlModifier) || (ke->
modifiers() & Qt::ShiftModifier) ) {
2032 switch ( ke->
key() ) {
2048 if ( e->
type() == QEvent::Leave ) {
2049 if ( d->cursorIconWidget )
2050 d->cursorIconWidget->hide();
2051 m_part->resetHoverText();
2058 else if (e->
type() == QEvent::Resize) {
2065 while (v && v != view) {
2070 if (v && k && k->
m_kwp->isRedirected()) {
2072 bool isUpdate =
false;
2075 case QEvent::UpdateRequest: {
2077 static_cast<KHTMLBackingStoreHackWidget *
>(w)->publicEvent(e);
2081 case QEvent::UpdateLater:
2085 if (!allowWidgetPaintEvents) {
2101 QRect pr = isUpdate ?
static_cast<QUpdateLaterEvent*
>(e)->region().boundingRect() :
static_cast<QPaintEvent*
>(e)->
rect();
2107 w->
repaint(static_cast<QUpdateLaterEvent*>(e)->region());
2109 w->
update(static_cast<QUpdateLaterEvent*>(e)->region());
2114 if ( asap && !isUpdate && !d->painting && m_part->xmlDocImpl() && m_part->xmlDocImpl()->renderer() &&
2115 !
static_cast<khtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer())->needsLayout() ) {
2119 }
else if (!d->painting) {
2120 scheduleRepaint(x + pr.
x(), y + pr.
y(),
2125 case QEvent::MouseMove:
2126 case QEvent::MouseButtonPress:
2127 case QEvent::MouseButtonRelease:
2128 case QEvent::MouseButtonDblClick: {
2130 if (0 && w->
parentWidget() == view && !qobject_cast<
QScrollBar*>(w) && !::qobject_cast<QScrollBar *>(w)) {
2135 if (e->
type() == QEvent::MouseMove)
2137 else if(e->
type() == QEvent::MouseButtonPress)
2139 else if(e->
type() == QEvent::MouseButtonRelease)
2147 case QEvent::KeyPress:
2148 case QEvent::KeyRelease:
2151 if (e->
type() == QEvent::KeyPress) {
2162 e->
type() == QEvent::KeyPress) {
2172 case QEvent::FocusIn:
2173 case QEvent::FocusOut: {
2197 switch (e->
type()) {
2198 case QEvent::MouseButtonPress:
2199 case QEvent::MouseButtonRelease:
2200 case QEvent::MouseButtonDblClick:
2201 case QEvent::MouseMove:
2203 #ifndef QT_NO_WHEELEVENT
2206 case QEvent::ContextMenu:
2207 case QEvent::DragEnter:
2208 case QEvent::DragMove:
2209 case QEvent::DragLeave:
2212 case QEvent::ChildPolished: {
2221 if (k && k->
m_kwp->isRedirected()) {
2229 case QEvent::Move: {
2230 if (static_cast<QMoveEvent*>(e)->
pos() !=
QPoint(0,0)) {
2243 bool KHTMLView::hasLayoutPending()
2245 return d->layoutTimerId && !d->firstLayoutPending;
2248 DOM::NodeImpl *KHTMLView::nodeUnderMouse()
const
2250 return d->underMouse;
2253 DOM::NodeImpl *KHTMLView::nonSharedNodeUnderMouse()
const
2255 return d->underMouseNonShared;
2258 bool KHTMLView::scrollTo(
const QRect &bounds)
2260 d->scrollingSelf =
true;
2265 xe = bounds.
right();
2276 if (ye-y>curHeight-d->borderY)
2277 ye = y + curHeight - d->borderY;
2279 if (xe-x>curWidth-d->borderX)
2280 xe = x + curWidth - d->borderX;
2286 else if (xe + d->borderX >
contentsX() + curWidth)
2287 deltax = xe + d->borderX - (
contentsX() + curWidth );
2295 else if (ye + d->borderY >
contentsY() + curHeight)
2296 deltay = ye + d->borderY - (
contentsY() + curHeight );
2300 int maxx = curWidth-d->borderX;
2301 int maxy = curHeight-d->borderY;
2303 int scrollX, scrollY;
2305 scrollX = deltax > 0 ? (deltax > maxx ? maxx : deltax) : deltax == 0 ? 0 : (deltax>-maxx ? deltax : -maxx);
2306 scrollY = deltay > 0 ? (deltay > maxy ? maxy : deltay) : deltay == 0 ? 0 : (deltay>-maxy ? deltay : -maxy);
2321 d->scrollingSelf =
false;
2323 if ( (abs(deltax)<=maxx) && (abs(deltay)<=maxy) )
2329 bool KHTMLView::focusNextPrevNode(
bool next)
2338 DocumentImpl *doc = m_part->xmlDocImpl();
2339 NodeImpl *oldFocusNode = doc->focusNode();
2346 if ((oldFocusNode->renderer() && !oldFocusNode->renderer()->parent())
2347 || !oldFocusNode->isTabFocusable()) {
2348 doc->quietResetFocus();
2357 if (d->scrollBarMoved)
2361 toFocus = doc->nextFocusNode(oldFocusNode);
2363 toFocus = doc->previousFocusNode(oldFocusNode);
2365 if (!toFocus && oldFocusNode) {
2367 toFocus = doc->nextFocusNode(NULL);
2369 toFocus = doc->previousFocusNode(NULL);
2372 while (toFocus && toFocus != oldFocusNode)
2382 d->scrollBarMoved =
false;
2383 d->tabMovePending =
false;
2384 d->lastTabbingDirection = next;
2385 d->pseudoFocusNode = KHTMLViewPrivate::PFNone;
2386 m_part->xmlDocImpl()->setFocusNode(toFocus);
2387 Node guard(toFocus);
2388 if (!toFocus->hasOneRef() )
2396 toFocus = doc->nextFocusNode(toFocus);
2398 toFocus = doc->previousFocusNode(toFocus);
2400 if (!toFocus && oldFocusNode)
2404 toFocus = doc->nextFocusNode(NULL);
2408 toFocus = doc->previousFocusNode(NULL);
2413 d->scrollBarMoved =
false;
2417 if (!oldFocusNode && d->pseudoFocusNode == KHTMLViewPrivate::PFNone)
2420 d->scrollBarMoved =
false;
2421 d->pseudoFocusNode = next?KHTMLViewPrivate::PFTop:KHTMLViewPrivate::PFBottom;
2425 NodeImpl *newFocusNode = NULL;
2427 if (d->tabMovePending && next != d->lastTabbingDirection)
2430 newFocusNode = oldFocusNode;
2434 if (oldFocusNode || d->pseudoFocusNode == KHTMLViewPrivate::PFTop )
2435 newFocusNode = doc->nextFocusNode(oldFocusNode);
2439 if (oldFocusNode || d->pseudoFocusNode == KHTMLViewPrivate::PFBottom )
2440 newFocusNode = doc->previousFocusNode(oldFocusNode);
2443 bool targetVisible =
false;
2458 if (!m_part->
isCaretMode() && newFocusNode->isContentEditable()) {
2459 kDebug(6200) <<
"show caret! fn: " << newFocusNode->nodeName().string() << endl;
2460 m_part->clearCaretRectIfNeeded();
2465 kDebug(6200) <<
"hide caret! fn: " << newFocusNode->nodeName().string() << endl;
2467 m_part->notifySelectionChanged();
2469 targetVisible = scrollTo(newFocusNode->getRect());
2475 d->tabMovePending =
false;
2477 m_part->xmlDocImpl()->setFocusNode(newFocusNode);
2480 Node guard(newFocusNode);
2481 if (!newFocusNode->hasOneRef() )
2489 d->pseudoFocusNode = next?KHTMLViewPrivate::PFBottom:KHTMLViewPrivate::PFTop;
2495 if (!d->tabMovePending)
2496 d->lastTabbingDirection = next;
2497 d->tabMovePending =
true;
2513 fallbacks = buildFallbackAccessKeys();
2514 for( NodeImpl* n = m_part->xmlDocImpl(); n != NULL; n = n->traverseNextNode()) {
2515 if( n->isElementNode()) {
2516 ElementImpl* en =
static_cast< ElementImpl*
>( n );
2517 DOMString s = en->getAttribute( ATTR_ACCESSKEY );
2521 if( qFind( taken.
begin(), taken.
end(), a ) == taken.
end())
2525 QChar a = fallbacks[ en ].toUpper();
2526 if( qFind( taken.
begin(), taken.
end(), a ) == taken.
end())
2527 accesskey =
QString(
"<qt><i>" ) + a +
"</i></qt>";
2529 if( !accesskey.
isNull()) {
2547 taken.
append( accesskey[ 0 ] );
2556 if( !qobject_cast<KHTMLPart*>(cur) )
2559 if( part->
view() && part->
view() != caller )
2569 bool KHTMLView::isScrollingFromMouseWheel()
const
2571 return d->scrollingFromWheel !=
QPoint(-1,-1);
2574 void KHTMLView::accessKeysTimeout()
2576 d->accessKeysActivated=
false;
2577 d->accessKeysPreActivate =
false;
2578 m_part->setStatusBarText(
QString(), KHTMLPart::BarOverrideText);
2583 bool KHTMLView::handleAccessKey(
const QKeyEvent* ev )
2588 if( ev->
key() >= Qt::Key_A && ev->
key() <= Qt::Key_Z )
2589 c =
'A' + ev->
key() - Qt::Key_A;
2590 else if( ev->
key() >= Qt::Key_0 && ev->
key() <= Qt::Key_9 )
2591 c =
'0' + ev->
key() - Qt::Key_0;
2596 c = ev->
text()[ 0 ];
2600 return focusNodeWithAccessKey( c );
2603 bool KHTMLView::focusNodeWithAccessKey(
QChar c,
KHTMLView* caller )
2605 DocumentImpl *doc = m_part->xmlDocImpl();
2608 ElementImpl* node = doc->findAccessKeyElement( c );
2612 if( !qobject_cast<KHTMLPart*>(cur) )
2615 if( part->
view() && part->
view() != caller
2616 && part->
view()->focusNodeWithAccessKey( c,
this ))
2622 && m_part->
parentPart()->
view()->focusNodeWithAccessKey( c,
this ))
2624 if( caller == NULL ) {
2627 it != fallbacks.
end();
2645 if( node->isFocusable()) {
2646 if (node->id()==ID_LABEL) {
2648 node=
static_cast<ElementImpl *
>(
static_cast< HTMLLabelElementImpl*
>( node )->getFormElement());
2649 if (!node)
return true;
2653 m_part->xmlDocImpl()->setFocusNode(node);
2655 if( node != NULL && node->hasOneRef())
2658 if( node != NULL && node->hasOneRef())
2662 switch( node->id()) {
2664 static_cast< HTMLAnchorElementImpl*
>( node )->click();
2667 static_cast< HTMLInputElementImpl*
>( node )->click();
2670 static_cast< HTMLButtonElementImpl*
>( node )->click();
2673 static_cast< HTMLAreaElementImpl*
>( node )->click();
2687 for( NodeImpl* n = after ? start->nextSibling() : start->traversePreviousNode();
2689 n = after ? n->traverseNextNode() : n->traversePreviousNode()) {
2690 if( n->isTextNode()) {
2692 ret +=
static_cast< TextImpl*
>( n )->toString().string();
2694 ret.
prepend( static_cast< TextImpl* >( n )->toString().
string());
2738 for( NodeImpl* n = start;
2740 n = n->traverseNextNode()) {
2741 if( n->id() == ID_LABEL ) {
2742 HTMLLabelElementImpl*
label =
static_cast< HTMLLabelElementImpl*
>( n );
2743 NodeImpl* labelfor = label->getFormElement();
2745 ret[ labelfor ] = label->innerText().string().simplified();
2752 struct AccessKeyData {
2753 ElementImpl* element;
2768 for( NodeImpl* n = m_part->xmlDocImpl();
2770 n = n->traverseNextNode()) {
2771 if( n->isElementNode()) {
2772 ElementImpl* element =
static_cast< ElementImpl*
>( n );
2773 if( element->renderer() == NULL )
2778 bool ignore =
false;
2779 bool text_after =
false;
2780 bool text_before =
false;
2781 switch( element->id()) {
2783 url = element->getAttribute(ATTR_HREF).parsedUrl().string();
2786 text =
static_cast< HTMLElementImpl*
>( element )->innerText().string().
simplified();
2790 HTMLInputElementImpl* in =
static_cast< HTMLInputElementImpl*
>( element );
2791 switch( in->inputType()) {
2792 case HTMLInputElementImpl::SUBMIT:
2793 text = in->value().string();
2795 text =
i18n(
"Submit" );
2798 case HTMLInputElementImpl::IMAGE:
2799 text = in->altText().string();
2802 case HTMLInputElementImpl::BUTTON:
2803 text = in->value().string();
2806 case HTMLInputElementImpl::RESET:
2807 text = in->value().string();
2809 text =
i18n(
"Reset" );
2812 case HTMLInputElementImpl::HIDDEN:
2815 case HTMLInputElementImpl::CHECKBOX:
2816 case HTMLInputElementImpl::RADIO:
2820 case HTMLInputElementImpl::TEXT:
2821 case HTMLInputElementImpl::PASSWORD:
2822 case HTMLInputElementImpl::FILE:
2833 text =
static_cast< HTMLElementImpl*
>( element )->innerText().string().
simplified();
2834 switch( static_cast< HTMLButtonElementImpl* >( element )->buttonType()) {
2835 case HTMLButtonElementImpl::SUBMIT:
2837 text =
i18n(
"Submit" );
2840 case HTMLButtonElementImpl::RESET:
2842 text =
i18n(
"Reset" );
2859 ignore = !element->isFocusable();
2867 DOMString akey = element->getAttribute( ATTR_ACCESSKEY );
2868 if( akey.
length() == 1 ) {
2873 text = labels[ element ];
2874 if( text.
isNull() && text_before )
2876 if( text.
isNull() && text_after )
2883 it != priorities.
end();
2885 if( text == (*it).first )
2888 AccessKeyData tmp = { element, text, url, priority };
2894 for(
char c =
'A'; c <=
'Z'; ++c )
2896 for(
char c =
'0'; c <=
'9'; ++c )
2898 for( NodeImpl* n = m_part->xmlDocImpl();
2900 n = n->traverseNextNode()) {
2901 if( n->isElementNode()) {
2902 ElementImpl* en =
static_cast< ElementImpl*
>( n );
2903 DOMString s = en->getAttribute( ATTR_ACCESSKEY );
2912 for(
int priority = 10; priority >= 0; --priority ) {
2916 if( (*it).priority != priority ) {
2924 const QString url = (*it).url;
2926 if( hrefs.contains( url ) ) {
2927 it = data.
erase( it );
2934 it != priorities.
end();
2936 if( text == (*it).first && keys.
contains( (*it).second )) {
2949 if( keys.
contains( (*it)[ 0 ].toUpper())) {
2956 for(
int i = 0; i < text.
length(); ++i ) {
2965 ret[ (*it).element ] = key;
2967 it = data.
erase( it );
2973 if( (*it2).url == url ) {
2974 ret[ (*it2).element ] = key;
2977 it2 = data.
erase( it2 );
2987 void KHTMLView::setMediaType(
const QString &medium )
2992 QString KHTMLView::mediaType()
const
2997 bool KHTMLView::pagedMode()
const
3002 void KHTMLView::setWidgetVisible(RenderWidget* w,
bool vis)
3005 d->visibleWidgets.insert(w, w->widget());
3008 d->visibleWidgets.remove(w);
3011 bool KHTMLView::needsFullRepaint()
const
3013 return d->needsFullRepaint;
3017 class QPointerDeleter
3020 explicit QPointerDeleter(
QObject* o) : obj(o) {}
3021 ~QPointerDeleter() {
delete obj; }
3029 if(!m_part->xmlDocImpl())
return;
3030 khtml::RenderCanvas *root =
static_cast<khtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer());
3034 const QPointerDeleter settingsDeleter(printSettings);
3038 const QPointerDeleter dialogDeleter(dialog);
3040 QString docname = m_part->xmlDocImpl()->URL().prettyUrl();
3044 if(quick || (dialog->exec() && dialog)) {
3052 p->
begin( &printer );
3053 khtml::setPrintPainter( p );
3055 m_part->xmlDocImpl()->setPaintDevice( &printer );
3056 QString oldMediaType = mediaType();
3057 setMediaType(
"print" );
3061 m_part->xmlDocImpl()->setPrintStyleSheet( printSettings->printFriendly() ?
3062 "* { background-image: none !important;"
3063 " background-color: white !important;"
3064 " color: black !important; }"
3065 "body { margin: 0px !important; }"
3066 "html { margin: 0px !important; }" :
3067 "body { margin: 0px !important; }"
3068 "html { margin: 0px !important; }"
3071 kDebug(6000) <<
"printing: physical page width = " << printer.
width()
3072 <<
" height = " << printer.
height() << endl;
3073 root->setStaticMode(
true);
3074 root->setPagedMode(
true);
3075 root->setWidth(printer.
width());
3077 root->setPageTop(0);
3078 root->setPageBottom(0);
3081 m_part->xmlDocImpl()->styleSelector()->computeFontSizes(printer.
logicalDpiY(), 100);
3082 m_part->xmlDocImpl()->updateStyleSelector();
3083 root->setPrintImages(printSettings->printImages());
3084 root->makePageBreakAvoidBlocks();
3086 root->setNeedsLayoutAndMinMaxRecalc();
3091 bool printHeader = printSettings->printHeader();
3093 int headerHeight = 0;
3094 QFont headerFont(
"Sans Serif", 8);
3107 kDebug(6000) <<
"printing: html page width = " << root->docWidth()
3108 <<
" height = " << root->docHeight() << endl;
3111 kDebug(6000) <<
"printing: paper width = " << printer.
width()
3112 <<
" height = " << printer.
height() << endl;
3115 int pageWidth = printer.
width();
3116 int pageHeight = printer.
height();
3119 pageHeight -= headerHeight;
3121 #ifndef QT_NO_TRANSFORMATIONS
3122 bool scalePage =
false;
3124 if(root->docWidth() > printer.
width()) {
3126 scale = ((
double) printer.
width())/((
double) root->docWidth());
3127 pageHeight = (int) (pageHeight/scale);
3128 pageWidth = (int) (pageWidth/scale);
3129 headerHeight = (int) (headerHeight/scale);
3132 kDebug(6000) <<
"printing: scaled html width = " << pageWidth
3133 <<
" height = " << pageHeight << endl;
3135 root->setHeight(pageHeight);
3136 root->setPageBottom(pageHeight);
3137 root->setNeedsLayout(
true);
3138 root->layoutIfNeeded();
3144 int available_width = printer.
width() - 10 -
3147 if (available_width < 150)
3148 available_width = 150;
3155 }
while (mid_width > available_width);
3161 while(top < root->docHeight()) {
3162 if(top > 0) printer.
newPage();
3163 #ifndef QT_NO_TRANSFORMATIONS
3165 p->
scale(scale, scale);
3177 p->
drawText(0, 0, printer.
width(), dy, Qt::AlignLeft, headerLeft);
3178 p->
drawText(0, 0, printer.
width(), dy, Qt::AlignHCenter, headerMid);
3179 p->
drawText(0, 0, printer.
width(), dy, Qt::AlignRight, headerRight);
3185 bottom = top+pageHeight;
3187 root->setPageTop(top);
3188 root->setPageBottom(bottom);
3189 root->setPageNumber(page);
3191 root->layer()->paint(p,
QRect(0, top, pageWidth, pageHeight));
3192 kDebug(6000) <<
"printed: page " << page <<
" bottom At = " << bottom;
3203 root->setPagedMode(
false);
3204 root->setStaticMode(
false);
3206 khtml::setPrintPainter( 0 );
3207 setMediaType( oldMediaType );
3208 m_part->xmlDocImpl()->setPaintDevice(
this );
3209 m_part->xmlDocImpl()->styleSelector()->computeFontSizes(m_part->xmlDocImpl()->logicalDpiY(), m_part->
fontScaleFactor());
3210 m_part->xmlDocImpl()->updateStyleSelector();
3217 if(!m_part->xmlDocImpl())
return;
3218 DOM::DocumentImpl *document = m_part->xmlDocImpl();
3219 if (!document->isHTMLDocument())
return;
3220 khtml::RenderCanvas *root =
static_cast<khtml::RenderCanvas *
>(document->renderer());
3222 root->style()->resetPalette();
3223 NodeImpl *body =
static_cast<HTMLDocumentImpl*
>(document)->body();
3225 body->setChanged(
true);
3226 body->recalcStyle( NodeImpl::Force );
3229 void KHTMLView::paint(
QPainter *p,
const QRect &rc,
int yOff,
bool *more)
3231 if(!m_part->xmlDocImpl())
return;
3232 khtml::RenderCanvas *root =
static_cast<khtml::RenderCanvas *
>(m_part->xmlDocImpl()->renderer());
3235 d->firstRepaintPending =
false;
3238 QPaintDevice* opd = m_part->xmlDocImpl()->paintDevice();
3239 m_part->xmlDocImpl()->setPaintDevice(p->
device());
3240 root->setPagedMode(
true);
3241 root->setStaticMode(
true);
3242 root->setWidth(rc.
width());
3256 #ifndef QT_NO_TRANSFORMATIONS
3257 p->
scale(scale, scale);
3259 root->setPageTop(yOff);
3260 root->setPageBottom(yOff+height);
3262 root->layer()->paint(p,
QRect(0, yOff, root->docWidth(),
height));
3264 *more = yOff + height < root->docHeight();
3277 root->setPagedMode(
false);
3278 root->setStaticMode(
false);
3279 m_part->xmlDocImpl()->setPaintDevice( opd );
3285 d->firstRepaintPending =
false;
3288 if(!m_part || !m_part->xmlDocImpl() || !m_part->xmlDocImpl()->renderer()) {
3292 QPaintDevice* opd = m_part->xmlDocImpl()->paintDevice();
3293 m_part->xmlDocImpl()->setPaintDevice(p->
device());
3307 m_part->xmlDocImpl()->renderer()->layer()->paint(p, rect);
3320 m_part->xmlDocImpl()->setPaintDevice( opd );
3323 void KHTMLView::setHasStaticBackground(
bool partial)
3326 if (d->staticWidget == KHTMLViewPrivate::SBFull &&
m_kwp->isRedirected())
3329 d->staticWidget = partial ?
3330 KHTMLViewPrivate::SBPartial : KHTMLViewPrivate::SBFull;
3333 void KHTMLView::setHasNormalBackground()
3336 if (d->staticWidget == KHTMLViewPrivate::SBFull &&
m_kwp->isRedirected())
3339 d->staticWidget = KHTMLViewPrivate::SBNone;
3342 void KHTMLView::addStaticObject(
bool fixed)
3345 d->fixedObjectsCount++;
3347 d->staticObjectsCount++;
3349 setHasStaticBackground(
true );
3352 void KHTMLView::removeStaticObject(
bool fixed)
3355 d->fixedObjectsCount--;
3357 d->staticObjectsCount--;
3359 assert( d->fixedObjectsCount >= 0 && d->staticObjectsCount >= 0 );
3361 if (!d->staticObjectsCount && !d->fixedObjectsCount)
3362 setHasNormalBackground();
3364 setHasStaticBackground(
true );
3369 #ifndef KHTML_NO_SCROLLBARS
3370 d->vpolicy = policy;
3379 #ifndef KHTML_NO_SCROLLBARS
3380 d->hpolicy = policy;
3387 void KHTMLView::restoreScrollBar()
3400 if (!d->formCompletions)
3402 return d->formCompletions->group(
"").readEntry(name,
QStringList());
3405 void KHTMLView::clearCompletionHistory(
const QString& name)
3407 if (!d->formCompletions)
3411 d->formCompletions->group(
"").writeEntry(name,
"");
3412 d->formCompletions->sync();
3415 void KHTMLView::addFormCompletionItem(
const QString &name,
const QString &value)
3422 bool cc_number(
true);
3423 for (
int i = 0; i < value.
length(); ++i)
3439 d->formCompletions->group(
"").writeEntry(name, items);
3442 void KHTMLView::addNonPasswordStorableSite(
const QString& host)
3444 if (!d->formCompletions) {
3448 KConfigGroup cg( d->formCompletions,
"NonPasswordStorableSites");
3451 cg.writeEntry(
"Sites", sites);
3456 void KHTMLView::delNonPasswordStorableSite(
const QString& host)
3458 if (!d->formCompletions) {
3462 KConfigGroup cg( d->formCompletions,
"NonPasswordStorableSites");
3465 cg.writeEntry(
"Sites", sites);
3469 bool KHTMLView::nonPasswordStorableSite(
const QString& host)
const
3471 if (!d->formCompletions) {
3474 QStringList sites = d->formCompletions->group(
"NonPasswordStorableSites" ).readEntry(
"Sites",
QStringList());
3475 return (sites.
indexOf(host) != -1);
3479 bool KHTMLView::dispatchMouseEvent(
int eventId, DOM::NodeImpl *targetNode,
3480 DOM::NodeImpl *targetNodeNonShared,
bool cancelable,
3482 int mouseEventType,
int orient)
3485 if (targetNode && targetNode->isTextNode())
3486 targetNode = targetNode->parentNode();
3489 d->underMouse->deref();
3490 d->underMouse = targetNode;
3492 d->underMouse->ref();
3494 if (d->underMouseNonShared)
3495 d->underMouseNonShared->deref();
3496 d->underMouseNonShared = targetNodeNonShared;
3497 if (d->underMouseNonShared)
3498 d->underMouseNonShared->ref();
3500 bool isWheelEvent = (mouseEventType == DOM::NodeImpl::MouseWheel);
3502 int exceptioncode = 0;
3503 int pageX = _mouse->
x();
3504 int pageY = _mouse->
y();
3505 revertTransforms(pageX, pageY);
3508 int screenX = _mouse->
globalX();
3509 int screenY = _mouse->
globalY();
3511 switch (_mouse->
button()) {
3512 case Qt::LeftButton:
3518 case Qt::RightButton:
3524 if (d->accessKeysEnabled && d->accessKeysPreActivate && button!=-1)
3525 d->accessKeysPreActivate=
false;
3527 bool ctrlKey = (_mouse->
modifiers() & Qt::ControlModifier);
3528 bool altKey = (_mouse->
modifiers() & Qt::AltModifier);
3529 bool shiftKey = (_mouse->
modifiers() & Qt::ShiftModifier);
3530 bool metaKey = (_mouse->
modifiers() & Qt::MetaModifier);
3533 if (setUnder && d->oldUnderMouse != targetNode) {
3534 if (d->oldUnderMouse && d->oldUnderMouse->document() != m_part->xmlDocImpl()) {
3535 d->oldUnderMouse->deref();
3536 d->oldUnderMouse = 0;
3539 if (d->oldUnderMouse) {
3541 MouseEventImpl *me =
new MouseEventImpl(EventImpl::MOUSEOUT_EVENT,
3542 true,
true,m_part->xmlDocImpl()->defaultView(),
3543 0,screenX,screenY,clientX,clientY,pageX, pageY,
3544 ctrlKey,altKey,shiftKey,metaKey,
3547 d->oldUnderMouse->dispatchEvent(me,exceptioncode,
true);
3552 MouseEventImpl *me =
new MouseEventImpl(EventImpl::MOUSEOVER_EVENT,
3553 true,
true,m_part->xmlDocImpl()->defaultView(),
3554 0,screenX,screenY,clientX,clientY,pageX, pageY,
3555 ctrlKey,altKey,shiftKey,metaKey,
3556 button,d->oldUnderMouse);
3559 targetNode->dispatchEvent(me,exceptioncode,
true);
3562 if (d->oldUnderMouse)
3563 d->oldUnderMouse->deref();
3564 d->oldUnderMouse = targetNode;
3565 if (d->oldUnderMouse)
3566 d->oldUnderMouse->ref();
3569 bool swallowEvent =
false;
3573 if (targetNode->isGenericFormElement()
3574 &&
static_cast<HTMLGenericFormElementImpl*
>(targetNode)->disabled())
3578 bool dblclick = ( eventId == EventImpl::CLICK_EVENT &&
3579 _mouse->
type() == QEvent::MouseButtonDblClick );
3580 MouseEventImpl *me =
new MouseEventImpl(static_cast<EventImpl::EventId>(eventId),
3581 true,cancelable,m_part->xmlDocImpl()->defaultView(),
3582 detail,screenX,screenY,clientX,clientY,pageX, pageY,
3583 ctrlKey,altKey,shiftKey,metaKey,
3584 button,0, isWheelEvent ? 0 : _mouse, dblclick,
3585 isWheelEvent ?
static_cast<MouseEventImpl::Orientation
>(orient) : MouseEventImpl::ONone );
3587 if ( !d->m_mouseEventsTarget && RenderLayer::gScrollBar && eventId == EventImpl::MOUSEDOWN_EVENT )
3589 d->m_mouseEventsTarget = RenderLayer::gScrollBar;
3590 if ( d->m_mouseEventsTarget && qobject_cast<QScrollBar*>(d->m_mouseEventsTarget) &&
3591 dynamic_cast<KHTMLWidget*>(static_cast<QWidget*>(d->m_mouseEventsTarget)) ) {
3597 static_cast<RenderWidget::EventPropagator *
>(
static_cast<QWidget*
>(d->m_mouseEventsTarget))->sendEvent(&fw);
3598 if (_mouse->
type() == QMouseEvent::MouseButtonPress && _mouse->
button() == Qt::RightButton) {
3600 static_cast<RenderWidget::EventPropagator *
>(
static_cast<QWidget*
>(d->m_mouseEventsTarget))->sendEvent(&cme);
3601 d->m_mouseEventsTarget = 0;
3603 swallowEvent =
true;
3605 targetNode->dispatchEvent(me,exceptioncode,
true);
3606 bool defaultHandled = me->defaultHandled();
3607 if (defaultHandled || me->defaultPrevented())
3608 swallowEvent =
true;
3610 if (eventId == EventImpl::MOUSEDOWN_EVENT && !me->defaultPrevented()) {
3615 DOM::NodeImpl* nodeImpl = targetNode;
3616 for ( ; nodeImpl && !nodeImpl->isFocusable(); nodeImpl = nodeImpl->parentNode())
3618 if (nodeImpl && nodeImpl->isMouseFocusable())
3619 m_part->xmlDocImpl()->setFocusNode(nodeImpl);
3620 else if (!nodeImpl || !nodeImpl->focused())
3621 m_part->xmlDocImpl()->setFocusNode(0);
3626 return swallowEvent;
3629 void KHTMLView::setIgnoreWheelEvents(
bool e )
3631 d->ignoreWheelEvents = e;
3634 #ifndef QT_NO_WHEELEVENT
3640 if (d->scrollingFromWheel !=
QPoint(-1,-1) && d->scrollingFromWheel !=
QCursor::pos())
3641 d->scrollingFromWheel = d->scrollingFromWheelTimerId ?
QCursor::pos() :
QPoint(-1,-1);
3643 if (d->accessKeysEnabled && d->accessKeysPreActivate) d->accessKeysPreActivate=
false;
3645 if ( ( e->
modifiers() & Qt::ControlModifier) == Qt::ControlModifier )
3650 else if (d->firstLayoutPending)
3654 else if( !
m_kwp->isRedirected() &&
3674 revertTransforms(xm, ym);
3676 DOM::NodeImpl::MouseEvent mev( e->
buttons(), DOM::NodeImpl::MouseWheel );
3677 m_part->xmlDocImpl()->prepareMouseEvent(
false, xm, ym, &mev );
3679 MouseEventImpl::Orientation o = MouseEventImpl::OVertical;
3681 o = MouseEventImpl::OHorizontal;
3684 bool swallow = dispatchMouseEvent(EventImpl::KHTML_MOUSEWHEEL_EVENT,mev.innerNode.handle(),mev.innerNonSharedNode.handle(),
3685 true,-e->
delta()/40,&_mouse,
true,DOM::NodeImpl::MouseWheel,o);
3690 d->scrollBarMoved =
true;
3693 d->shouldSmoothScroll =
true;
3694 if (d->scrollingFromWheelTimerId)
3695 killTimer(d->scrollingFromWheelTimerId);
3696 d->scrollingFromWheelTimerId =
startTimer(400);
3700 bool h = (
static_cast<QWheelEvent*
>(e)->orientation() == Qt::Horizontal);
3701 bool d = (
static_cast<QWheelEvent*
>(e)->delta() < 0);
3730 DOM::NodeImpl* fn = m_part->xmlDocImpl() ? m_part->xmlDocImpl()->focusNode() : 0;
3731 if (fn && fn->renderer() && fn->renderer()->isWidget() &&
3732 (e->
reason() != Qt::MouseFocusReason) &&
3733 static_cast<khtml::RenderWidget*>(fn->renderer())->
widget())
3734 static_cast<khtml::RenderWidget*>(fn->renderer())->
widget()->
setFocus();
3735 m_part->setSelectionVisible();
3742 m_part->stopAutoScroll();
3743 m_part->setSelectionVisible(
false);
3746 if ( d->cursorIconWidget )
3747 d->cursorIconWidget->hide();
3754 if (!dx && !dy)
return;
3756 if ( !d->firstLayoutPending && !d->complete && m_part->xmlDocImpl() &&
3757 d->layoutSchedulingEnabled) {
3759 khtml::RenderCanvas* root =
static_cast<khtml::RenderCanvas *
>( m_part->xmlDocImpl()->renderer() );
3760 if (root && root->needsLayout()) {
3761 unscheduleRelayout();
3766 if ( d->shouldSmoothScroll && d->smoothScrollMode !=
SSMDisabled && m_part->xmlDocImpl() &&
3769 bool doSmoothScroll = (!d->staticWidget || d->smoothScrollMode ==
SSMEnabled);
3771 int numStaticPixels = 0;
3772 QRegion r =
static_cast<RenderCanvas*
>(m_part->xmlDocImpl()->renderer())->staticRegion();
3775 if (!doSmoothScroll && d->staticWidget == KHTMLViewPrivate::SBPartial && r.
rects().size() <= 10) {
3779 doSmoothScroll =
true;
3781 if (doSmoothScroll) {
3782 setupSmoothScrolling(dx, dy);
3790 if (!d->scrollingSelf) {
3791 d->scrollBarMoved =
true;
3792 d->contentsMoving =
true;
3794 scheduleRepaint(0, 0, 0, 0);
3797 if (m_part->xmlDocImpl() && m_part->xmlDocImpl()->documentElement()) {
3798 m_part->xmlDocImpl()->documentElement()->dispatchHTMLEvent(EventImpl::SCROLL_EVENT,
true,
false);
3804 if (!d->smoothScrolling) {
3805 d->updateContentsXY();
3811 kDebug(6000) <<
"Static widget wasn't positioned at (0,0). This should NOT happen. Please report this event to developers.";
3812 kDebug(6000) << kBacktrace();
3818 if (
m_kwp->isRedirected()) {
3826 if ( d->staticWidget ) {
3830 if (!d->visibleWidgets.isEmpty())
3831 checkExternalWidgetsPosition();
3833 if ( d->staticWidget == KHTMLViewPrivate::SBPartial
3834 && m_part->xmlDocImpl() && m_part->xmlDocImpl()->renderer() ) {
3836 QRegion r =
static_cast<RenderCanvas*
>(m_part->xmlDocImpl()->renderer())->staticRegion();
3840 for (
int i = 0; i < ar.
size() ; ++i) {
3845 for (
int i = 0; i < ar.
size() ; ++i) {
3846 w->
scroll( dx, dy, ar[i].translated(off) );
3848 d->scrollExternalWidgets(dx, dy);
3853 if (d->accessKeysActivated)
3854 d->scrollAccessKeys(dx, dy);
3859 if (
m_kwp->isRedirected()) {
3862 if (d->zoomLevel != 100) {
3869 d->scrollExternalWidgets(dx, dy);
3870 if (d->accessKeysActivated)
3871 d->scrollAccessKeys(dx, dy);
3874 void KHTMLView::setupSmoothScrolling(
int dx,
int dy)
3877 int ddx = qMax(d->steps ? abs(d->dx)/d->steps : 0,3);
3878 int ddy = qMax(d->steps ? abs(d->dy)/d->steps : 0,3);
3884 if (d->dx == 0 && d->dy == 0) {
3891 if (qMax(abs(d->dx), abs(d->dy)) / d->steps < qMax(ddx,ddy)) {
3894 d->steps = qMax((abs(d->dx)+ddx-1)/ddx, (abs(d->dy)+ddy-1)/ddy);
3895 if (d->steps < 1) d->steps = 1;
3898 d->smoothScrollStopwatch.start();
3899 if (!d->smoothScrolling) {
3900 d->startScrolling();
3905 void KHTMLView::scrollTick() {
3906 if (d->dx == 0 && d->dy == 0) {
3911 if (d->steps < 1) d->steps = 1;
3915 if (takesteps < 1) takesteps = 1;
3916 if (takesteps > d->steps) takesteps = d->steps;
3917 for(
int i = 0; i < takesteps; i++) {
3918 int ddx = (d->dx / (d->steps+1)) * 2;
3919 int ddy = (d->dy / (d->steps+1)) * 2;
3922 if (abs(ddx) > abs(d->dx)) ddx = d->dx;
3923 if (abs(ddy) > abs(d->dy)) ddy = d->dy;
3933 d->shouldSmoothScroll =
false;
3936 if (takesteps < 2) {
3937 d->smoothScrollMissedDeadlines = 0;
3939 if (d->smoothScrollMissedDeadlines !=
sWayTooMany &&
3940 (!m_part->xmlDocImpl() || !m_part->xmlDocImpl()->parsing())) {
3941 d->smoothScrollMissedDeadlines++;
3968 if ( e->
timerId() == d->scrollTimerId ) {
3969 if( d->scrollSuspended )
3971 switch (d->scrollDirection) {
3972 case KHTMLViewPrivate::ScrollDown:
3974 d->newScrollTimer(
this, 0);
3978 case KHTMLViewPrivate::ScrollUp:
3980 d->newScrollTimer(
this, 0);
3984 case KHTMLViewPrivate::ScrollRight:
3986 d->newScrollTimer(
this, 0);
3990 case KHTMLViewPrivate::ScrollLeft:
3992 d->newScrollTimer(
this, 0);
3999 else if ( e->
timerId() == d->scrollingFromWheelTimerId ) {
4000 killTimer( d->scrollingFromWheelTimerId );
4001 d->scrollingFromWheelTimerId = 0;
4002 }
else if ( e->
timerId() == d->layoutTimerId ) {
4003 if (d->firstLayoutPending && d->layoutAttemptCounter < 4
4004 && (!m_part->xmlDocImpl() || !m_part->xmlDocImpl()->readyForLayout())) {
4005 d->layoutAttemptCounter++;
4007 d->layoutTimerId = 0;
4012 d->scheduledLayoutCounter++;
4013 if (d->firstLayoutPending) {
4014 d->firstLayoutPending =
false;
4020 d->contentsMoving =
false;
4021 if( m_part->xmlDocImpl() ) {
4022 DOM::DocumentImpl *document = m_part->xmlDocImpl();
4023 khtml::RenderCanvas* root =
static_cast<khtml::RenderCanvas *
>(document->renderer());
4025 if ( root && root->needsLayout() ) {
4026 if (d->repaintTimerId)
4028 d->repaintTimerId = 0;
4034 if (d->repaintTimerId)
4036 d->repaintTimerId = 0;
4044 updateRegion = rects[0];
4046 for (
int i = 1; i < rects.
size(); ++i ) {
4047 QRect newRegion = updateRegion.
unite(rects[i]);
4051 updateRegion = rects[i];
4054 updateRegion = newRegion;
4057 if ( !updateRegion.
isNull() )
4065 if (d->dirtyLayout && !d->visibleWidgets.isEmpty())
4066 checkExternalWidgetsPosition();
4068 d->dirtyLayout =
false;
4071 if (d->emitCompletedAfterRepaint) {
4072 bool full = d->emitCompletedAfterRepaint == KHTMLViewPrivate::CSFull;
4073 d->emitCompletedAfterRepaint = KHTMLViewPrivate::CSNone;
4081 void KHTMLView::checkExternalWidgetsPosition()
4087 while (it.hasNext()) {
4090 RenderWidget* rw =
static_cast<RenderWidget*
>( it.key() );
4091 if (!rw->absolutePosition(xp, yp) ||
4095 foreach (RenderWidget* r, toRemove)
4096 if ( (w = d->visibleWidgets.take(r) ) )
4097 w->
move( 0, -500000);
4100 void KHTMLView::scheduleRelayout(khtml::RenderObject * )
4102 if (!d->layoutSchedulingEnabled || d->layoutTimerId)
4106 if (d->firstLayoutPending) {
4110 time = d->layoutAttemptCounter ?
4112 }
else if (m_part->xmlDocImpl() && m_part->xmlDocImpl()->parsing()) {
4120 void KHTMLView::unscheduleRelayout()
4122 if (!d->layoutTimerId)
4126 d->layoutTimerId = 0;
4129 void KHTMLView::unscheduleRepaint()
4131 if (!d->repaintTimerId)
4135 d->repaintTimerId = 0;
4138 void KHTMLView::scheduleRepaint(
int x,
int y,
int w,
int h,
bool asap)
4140 bool parsing = !m_part->xmlDocImpl() || m_part->xmlDocImpl()->parsing();
4145 int time = parsing && !d->firstLayoutPending ? 150 : (!asap ? ( !d->complete ? 80 : 20 ) : 0);
4147 #ifdef DEBUG_FLICKER
4153 p.
fillRect( vx, vy, w, h, Qt::red );
4157 d->updateRegion = d->updateRegion.unite(
QRect(x,y,w,h));
4159 if (asap && !parsing)
4160 unscheduleRepaint();
4162 if ( !d->repaintTimerId )
4168 void KHTMLView::complete(
bool pendingAction )
4175 if (d->layoutTimerId)
4181 d->emitCompletedAfterRepaint = pendingAction ?
4182 KHTMLViewPrivate::CSActionPending : KHTMLViewPrivate::CSFull;
4186 if (d->repaintTimerId)
4192 d->emitCompletedAfterRepaint = pendingAction ?
4193 KHTMLViewPrivate::CSActionPending : KHTMLViewPrivate::CSFull;
4196 if (!d->emitCompletedAfterRepaint)
4206 void KHTMLView::updateScrollBars()
4223 if (!d->smoothScrolling) {
4224 d->updateContentsXY();
4228 void KHTMLView::slotMouseScrollTimer()
4237 Selection sel = pos;
4238 sel.expandUsingGranularity(Selection::LINE);
4239 return toEnd ? sel.end() : sel.start();
4252 bool KHTMLView::caretKeyPressEvent(
QKeyEvent *_ke)
4256 Position old_pos = caret.caretPos();
4257 Position
pos = old_pos;
4258 bool recalcXPos =
true;
4259 bool handled =
true;
4261 bool ctrl = _ke->
modifiers() & Qt::ControlModifier;
4262 bool shift = _ke->
modifiers() & Qt::ShiftModifier;
4264 switch(_ke->
key()) {
4268 pos = old_pos.nextLinePosition(caret.xPosForVerticalArrowNavigation(Selection::EXTENT));
4273 pos = old_pos.previousLinePosition(caret.xPosForVerticalArrowNavigation(Selection::EXTENT));
4278 pos = ctrl ? old_pos.previousWordPosition() : old_pos.previousCharacterPosition();
4282 pos = ctrl ? old_pos.nextWordPosition() : old_pos.nextCharacterPosition();
4285 case Qt::Key_PageDown:
4289 case Qt::Key_PageUp:
4312 if (pos != old_pos) {
4313 m_part->clearCaretRectIfNeeded();
4315 caret.moveTo(shift ? caret.nonCaretPos() :
pos,
pos);
4316 int old_x = caret.xPosForVerticalArrowNavigation(Selection::CARETPOS);
4318 m_part->selectionLayoutChanged();
4324 m_part->emitCaretPositionChanged(pos);
4326 m_part->notifySelectionChanged();
4330 if (handled) _ke->
accept();
4334 #undef DEBUG_CARETMODE
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
void setBrush(ColorRole role, const QBrush &brush)
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
Qt::KeyboardModifiers modifiers() const
void setViewport(const QRect &rectangle)
int doubleClickInterval()
iterator erase(iterator pos)
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.
bool contains(const Key &key) const
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setSmoothScrollingMode(SmoothScrollingMode m)
Set the smooth scrolling mode.
QAbstractEventDispatcher * instance(QThread *thread)
static QString getElementText(NodeImpl *start, bool after)
int maxFormCompletionItems() const
void translate(int dx, int dy)
void append(const T &value)
void fill(const QColor &color)
khtml::EditorContext editor_context
void setRange(int min, int max)
static const int sLayoutAttemptDelay
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString & prepend(QChar ch)
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 ...
void scale(qreal sx, qreal sy)
virtual void focusOutEvent(QFocusEvent *)
QPoint contentsToViewport(const QPoint &p) const
Returns a point translated to viewport coordinates.
const QObjectList & children() const
void addChild(QWidget *child, int dx, int dy)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QString simplified() const
bool frameExists(const QString &frameName)
Returns whether a frame with the specified name is exists or not.
This class is khtml's main class.
void translate(int dx, int dy)
bool intersects(const QRect &rectangle) const
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
QRect unite(const QRect &rectangle) const
const QPoint & pos() const
Renders and displays HTML in a QScrollArea.
iterator erase(iterator pos)
QRect boundingRect() const
void setClipRegion(const QRegion ®ion, Qt::ClipOperation operation)
virtual bool eventFilter(QObject *, QEvent *)
bool isAutoRepeat() const
const QPoint & pos() const
static KHTMLSettings * defaultHTMLSettings()
static const int sSmoothScrollTick
void setFrameStyle(int style)
QBitmap createMaskFromColor(const QColor &maskColor) const
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)
void showText(const QPoint &pos, const QString &text, QWidget *w)
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)
const QRect & rect() const
void setWindow(const QRect &rectangle)
QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode)
Qt::FocusReason reason() const
int visibleWidth() const
Returns the width of the viewport.
QList< KParts::ReadOnlyPart * > frames() const
int visibleHeight() const
Returns the height of the viewport.
void setFont(const QFont &font)
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
int count(const T &value) const
void append(const T &value)
const QPoint & globalPos() const
virtual void focusInEvent(QFocusEvent *)
void setCaretVisible(bool show)
Sets the visibility of the caret.
static const int sParsingLayoutsInterval
void installEventFilter(QObject *filterObj)
void setCreator(const QString &creator)
QRectF boundingRect(const QRectF &rectangle, int flags, const QString &text)
virtual void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy)
Sets vertical scrollbar mode.
Qt::Orientation orientation() const
QRegion clipRegion() const
void setPen(const QColor &color)
const QPoint & globalPos() const
void drawEllipse(const QRectF &rectangle)
int contentsHeight() const
Returns the contents area's height.
int m_xPosForVerticalArrowNavigation
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
virtual void dragEnterEvent(QDragEnterEvent *)
int removeAll(const T &value)
virtual void hideEvent(QHideEvent *)
bool sendEvent(QObject *receiver, QEvent *event)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QPaintDevice * device() const
void drawText(const QPointF &position, const QString &text)
void setDocName(const QString &name)
This class implements the basic string we use in the DOM.
QRect translated(int dx, int dy) const
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
int manhattanLength() const
bool accessKeysEnabled() const
void setFullPage(bool fp)
virtual void mouseMoveEvent(QMouseEvent *)
void timerEvent(QTimerEvent *)
bool contains(const T &value) const
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.
int startTimer(int interval)
virtual void setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy policy)
Sets horizontal scrollbar mode.
static const int sSmoothScrollTime
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
virtual bool event(QEvent *event)
static const int sWayTooMany
QSize expandedTo(const QSize &otherSize) const
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.
QFontMetrics fontMetrics() const
void setHeight(int height)
HCURSOR_or_HANDLE handle() const
void finishedLayout()
This signal is used for internal layouting.
virtual bool viewportEvent(QEvent *e)
void setWorldMatrixEnabled(bool enable)
int contentsX() const
Returns the x coordinate of the contents area point that is currently located at the top left in the ...
QVector< QRect > rects() const
void adjust(int dx1, int dy1, int dx2, int dy2)
bool worldMatrixEnabled() const
bool isCaretMode() const
Returns whether caret mode is on/off.
void setMarginHeight(int y)
void translate(const QPointF &offset)
QWeakPointer< DOM::HTMLPartContainerElementImpl > m_partContainerElement
#define KDE_VERSION_MAJOR
int fontScaleFactor() const
Returns the current font scale factor.
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const =0
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QRect intersect(const QRect &rectangle) const
void print(bool quick=false)
Prints the HTML document.
QString formatDate(const QDate &date, DateFormat format=LongDate) const
virtual void wheelEvent(QWheelEvent *)
int indexOf(const QRegExp &rx, int from) const
void prepend(const T &value)
int contentsWidth() const
Returns the contents area's width.
const QPoint & pos() const
#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.
void postEvent(QObject *receiver, QEvent *event)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual void dropEvent(QDropEvent *)
NodeImpl * handle() const
bool begin(QPaintDevice *device)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
T readEntry(const QString &key, const T &aDefault) const
bool removeOne(const T &value)
void keyReleaseEvent(QKeyEvent *_ke)
virtual bool event(QEvent *e)
void getRect(int *x, int *y, int *width, int *height) const
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.
virtual void resizeContents(int w, int h)
Resize the contents area.
virtual void mouseReleaseEvent(QMouseEvent *)
void displayAccessKeys()
Display all accesskeys in small tooltips.
void append(const T &value)
KHTMLPart * parentPart()
Returns a pointer to the parent KHTMLPart if the part is a frame in an HTML frameset.
Qt::CursorShape shape() const
virtual bool unregisterTimers(QObject *object)=0
#define KDE_VERSION_RELEASE
static void setInPaintEventFlag(QWidget *w, bool b=true, bool recurse=true)
void slotPaletteChanged()