EventHandler changes/fixes in QWebPage:
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2008 09:54:32 +0000 (09:54 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2008 09:54:32 +0000 (09:54 +0000)
    -mouse{Press,Move,Release}Event:
        Send the event always to the mainFrame of the QWebPage.

    -contextMenuEvent, key{Press,Release}Event:
        Send the event to the focused frame.

This is following the Windows port and fixes a issue with the
Web Inspector where we were sending the events to a wrong frame.

It is guaranteed that the mainFrame will always have an eventHandler
and frameView set. There is no need to check for this in QWebPage.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29517 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/qt/Api/qwebframe.cpp
WebKit/qt/Api/qwebframe_p.h
WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage_p.h
WebKit/qt/ChangeLog

index 7250956..46f4dc5 100644 (file)
@@ -92,7 +92,6 @@ void QWebFramePrivate::init(QWebFrame *qframe, WebCore::Page *webcorePage, QWebF
 
     frame->setView(frameView.get());
     frame->init();
 
     frame->setView(frameView.get());
     frame->init();
-    eventHandler = frame->eventHandler();
 
     QObject::connect(q, SIGNAL(hoveringOverLink(const QString&, const QString&, const QString&)),
                      page, SIGNAL(hoveringOverLink(const QString&, const QString&, const QString&)));
 
     QObject::connect(q, SIGNAL(hoveringOverLink(const QString&, const QString&, const QString&)),
                      page, SIGNAL(hoveringOverLink(const QString&, const QString&, const QString&)));
index 0a2131a..285c52d 100644 (file)
@@ -66,7 +66,6 @@ public:
         , frame(0)
         , frameView(0)
         , page(0)
         , frame(0)
         , frameView(0)
         , page(0)
-        , eventHandler(0)
         , lastHoverElement(0)
         {}
     void init(QWebFrame *qframe, WebCore::Page *page,
         , lastHoverElement(0)
         {}
     void init(QWebFrame *qframe, WebCore::Page *page,
@@ -88,7 +87,6 @@ public:
     WTF::RefPtr<WebCore::Frame> frame;
     WTF::RefPtr<WebCore::FrameView> frameView;
     QWebPage *page;
     WTF::RefPtr<WebCore::Frame> frame;
     WTF::RefPtr<WebCore::FrameView> frameView;
     QWebPage *page;
-    WebCore::EventHandler *eventHandler;
     WebCore::Element *lastHoverElement;
 };
 
     WebCore::Element *lastHoverElement;
 };
 
index 1bb3118..460a16e 100644 (file)
@@ -332,81 +332,41 @@ void QWebPagePrivate::updateEditorActions()
 
 void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
 {
 
 void QWebPagePrivate::mouseMoveEvent(QMouseEvent *ev)
 {
-    QWebFrame *f = currentFrame(ev->pos());
-    if (!f)
-        return;
-
-    QWebFramePrivate *frame = f->d;
-    if (!frame->frameView)
-        return;
-
-    frame->eventHandler->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
+    QWebFramePrivate::core(mainFrame)->eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
     const int xOffset =
     const int xOffset =
-        frame->horizontalScrollBar() ? frame->horizontalScrollBar()->value() : 0;
+        mainFrame->d->horizontalScrollBar() ? mainFrame->d->horizontalScrollBar()->value() : 0;
     const int yOffset =
     const int yOffset =
-        frame->verticalScrollBar() ? frame->verticalScrollBar()->value() : 0;
+        mainFrame->d->verticalScrollBar() ? mainFrame->d->verticalScrollBar()->value() : 0;
     IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
     IntPoint pt(ev->x() + xOffset, ev->y() + yOffset);
-    WebCore::HitTestResult result = frame->eventHandler->hitTestResultAtPoint(pt, false);
+    WebCore::HitTestResult result = QWebFramePrivate::core(mainFrame)->eventHandler()->hitTestResultAtPoint(pt, false);
     WebCore::Element *link = result.URLElement();
     WebCore::Element *link = result.URLElement();
-    if (link != frame->lastHoverElement) {
-        frame->lastHoverElement = link;
+    if (link != mainFrame->d->lastHoverElement) {
+        mainFrame->d->lastHoverElement = link;
         emit q->hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title(), result.textContent());
     }
 }
 
 void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
 {
         emit q->hoveringOverLink(result.absoluteLinkURL().prettyURL(), result.title(), result.textContent());
     }
 }
 
 void QWebPagePrivate::mousePressEvent(QMouseEvent *ev)
 {
-    frameUnderMouse = frameAt(ev->pos());
-    if (!frameUnderMouse)
-        return;
-
-    QWebFramePrivate *frame = frameUnderMouse->d;
-    if (!frame->eventHandler)
-        return;
-
-    frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
+    QWebFramePrivate::core(mainFrame)->eventHandler()->handleMousePressEvent(PlatformMouseEvent(ev, 1));
 }
 
 void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
 {
 }
 
 void QWebPagePrivate::mouseDoubleClickEvent(QMouseEvent *ev)
 {
-    QWebFrame *f = currentFrame(ev->pos());
-    if (!f)
-        return;
-
-    QWebFramePrivate *frame = f->d;
-    if (!frame->eventHandler)
-        return;
-
-    frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 2));
+    QWebFramePrivate::core(mainFrame)->eventHandler()->handleMousePressEvent(PlatformMouseEvent(ev, 2));
 }
 
 void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
 {
 }
 
 void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
 {
-    QWebFrame *f = currentFrame(ev->pos());
-    if (!f)
-        return;
-
-    QWebFramePrivate *frame = f->d;
-    if (!frame->frameView)
-        return;
-
-    frame->eventHandler->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
-
-    frameUnderMouse = 0;
+    QWebFramePrivate::core(mainFrame)->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
 }
 
 void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
 {
 }
 
 void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
 {
-    QWebFrame *f = currentFrame(ev->pos());
-    if (!f)
-        return;
-
-    QWebFramePrivate *frame = f->d;
-    if (!frame->eventHandler)
-        return;
-
     page->contextMenuController()->clearContextMenu();
     page->contextMenuController()->clearContextMenu();
-    frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
+
+    WebCore::Frame* focusedFrame = page->focusController()->focusedOrMainFrame();
+    focusedFrame->eventHandler()->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
     ContextMenu *menu = page->contextMenuController()->contextMenu();
 
     QWebPageContext oldContext = currentContext;
     ContextMenu *menu = page->contextMenuController()->contextMenu();
 
     QWebPageContext oldContext = currentContext;
@@ -423,25 +383,16 @@ void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
 
 void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
 {
 
 void QWebPagePrivate::wheelEvent(QWheelEvent *ev)
 {
-    QWebFramePrivate *frame = currentFrame(ev->pos())->d;
-
-    bool accepted = false;
-    if (frame->eventHandler) {
-        WebCore::PlatformWheelEvent pev(ev);
-        accepted = frame->eventHandler->handleWheelEvent(pev);
-    }
-
+    WebCore::PlatformWheelEvent pev(ev);
+    bool accepted = QWebFramePrivate::core(mainFrame)->eventHandler()->handleWheelEvent(pev);
     ev->setAccepted(accepted);
 }
 
 void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
 {
     ev->setAccepted(accepted);
 }
 
 void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
 {
-    if (!mainFrame->d->eventHandler)
-        return;
-
     bool handled = false;
     bool handled = false;
-    QWebFrame *frame = mainFrame;
-    WebCore::Editor *editor = frame->d->frame->editor();
+    WebCore::Frame *frame = page->focusController()->focusedOrMainFrame();
+    WebCore::Editor *editor = frame->editor();
     if (editor->canEdit()) {
         if (ev == QKeySequence::Cut) {
             q->triggerAction(QWebPage::Cut);
     if (editor->canEdit()) {
         if (ev == QKeySequence::Cut) {
             q->triggerAction(QWebPage::Cut);
@@ -544,7 +495,7 @@ void QWebPagePrivate::keyPressEvent(QKeyEvent *ev)
         }
     }
     if (!handled) 
         }
     }
     if (!handled) 
-        handled = frame->d->eventHandler->keyEvent(ev);
+        handled = frame->eventHandler()->keyEvent(ev);
     if (!handled) {
         handled = true;
         PlatformScrollbar *h, *v;
     if (!handled) {
         handled = true;
         PlatformScrollbar *h, *v;
@@ -592,24 +543,22 @@ void QWebPagePrivate::keyReleaseEvent(QKeyEvent *ev)
         return;
     }
 
         return;
     }
 
-    if (!mainFrame->d->eventHandler)
-        return;
-
-    bool handled = mainFrame->d->eventHandler->keyEvent(ev);
+    WebCore::Frame* frame = page->focusController()->focusedOrMainFrame();
+    bool handled = frame->eventHandler()->keyEvent(ev);
     ev->setAccepted(handled);
 }
 
 void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
 {
     if (ev->reason() != Qt::PopupFocusReason) 
     ev->setAccepted(handled);
 }
 
 void QWebPagePrivate::focusInEvent(QFocusEvent *ev)
 {
     if (ev->reason() != Qt::PopupFocusReason) 
-        mainFrame->d->frame->page()->focusController()->setFocusedFrame(mainFrame->d->frame);
+        page->focusController()->setFocusedFrame(QWebFramePrivate::core(mainFrame));
 }
 
 void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
 {
     if (ev->reason() != Qt::PopupFocusReason) {
 }
 
 void QWebPagePrivate::focusOutEvent(QFocusEvent *ev)
 {
     if (ev->reason() != Qt::PopupFocusReason) {
-        mainFrame->d->frame->selectionController()->clear();
-        mainFrame->d->frame->setIsActive(false);
+        QWebFramePrivate::core(mainFrame)->selectionController()->clear();
+        QWebFramePrivate::core(mainFrame)->setIsActive(false);
     }
 }
 
     }
 }
 
index b19418b..ab8f443 100644 (file)
@@ -121,10 +121,6 @@ public:
     WebCore::Page *page;
 
     QPointer<QWebFrame> mainFrame;
     WebCore::Page *page;
 
     QPointer<QWebFrame> mainFrame;
-    QPointer<QWebFrame> frameUnderMouse;
-
-    inline QWebFrame *currentFrame(const QPoint &pos) const
-    { return frameUnderMouse ? static_cast<QWebFrame *>(frameUnderMouse) : frameAt(pos); }
 
     QWebPage *q;
     QUndoStack *undoStack;
 
     QWebPage *q;
     QUndoStack *undoStack;
index f9708aa..410944d 100644 (file)
@@ -2,6 +2,41 @@
 
         Reviewed by Simon.
 
 
         Reviewed by Simon.
 
+        EventHandler changes/fixes in QWebPage:
+        -mouse{Press,Move,Release}Event:
+        Send the event always to the mainFrame of the QWebPage.
+        
+        -contextMenuEvent, key{Press,Release}Event:
+        Send the event to the focused frame.
+        
+        This is following the Windows port and fixes a issue with the
+        Web Inspector where we were sending the events to a wrong frame.
+        
+        It is guaranteed that the mainFrame will always have an eventHandler
+        and frameView set. There is no need to check for this in QWebPage.
+        
+
+        * Api/qwebframe.cpp:
+        (QWebFramePrivate::init):
+        * Api/qwebframe_p.h:
+        (QWebFramePrivate::QWebFramePrivate):
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::updateEditorActions):
+        (QWebPagePrivate::mouseMoveEvent):
+        (QWebPagePrivate::mousePressEvent):
+        (QWebPagePrivate::mouseDoubleClickEvent):
+        (QWebPagePrivate::mouseReleaseEvent):
+        (QWebPagePrivate::contextMenuEvent):
+        (QWebPagePrivate::wheelEvent):
+        (QWebPagePrivate::keyPressEvent):
+        (QWebPagePrivate::keyReleaseEvent):
+        (QWebPagePrivate::focusInEvent):
+        * Api/qwebpage_p.h:
+
+2008-01-16  Holger Freyther  <holger.freyther@trolltech.com>
+
+        Reviewed by Simon.
+
         * Add core and kit functions to QWebFramePrivate to convert from
         QWebFrame to WebCore::Frame and vice versa.
         
         * Add core and kit functions to QWebFramePrivate to convert from
         QWebFrame to WebCore::Frame and vice versa.