[SCM] WebKit Debian packaging branch, debian/experimental, updated. debian/1.3.8-1-1049-g2e11a8e

benjamin.poulain at nokia.com benjamin.poulain at nokia.com
Fri Jan 21 14:54:26 UTC 2011


The following commit has been merged in the debian/experimental branch:
commit 0d8f600a37a25ed9285a3cf1057e9871e594df79
Author: benjamin.poulain at nokia.com <benjamin.poulain at nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jan 4 11:53:24 2011 +0000

    2011-01-04  Benjamin Poulain  <benjamin.poulain at nokia.com>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] [WK2] create an initial implementation of the context menu handling for WebKit 2
            https://bugs.webkit.org/show_bug.cgi?id=51825
    
            Implement contextMenuItemVector() for Qt, this method is used in WebKit 2 to get the
            platform independent menu informations.
    
            * platform/qt/ContextMenuQt.cpp:
            (WebCore::contextMenuItemVector):
    2011-01-04  Benjamin Poulain  <benjamin.poulain at nokia.com>
    
            Reviewed by Kenneth Rohde Christiansen.
    
            [Qt] [WK2] create an initial implementation of the context menu handling for WebKit 2
            https://bugs.webkit.org/show_bug.cgi?id=51825
    
            Implement the necessary methods to get a basic context menu working for Qt.
    
            Only 4 basic WebAction have been added on the UIProcess side: back, forward, stop and reload.
    
            * UIProcess/API/qt/qgraphicswkview.cpp:
            (QGraphicsWKView::QGraphicsWKView):
            (QGraphicsWKView::showContextMenu):
            (QGraphicsWKViewPrivate::QGraphicsWKViewPrivate):
            * UIProcess/API/qt/qgraphicswkview.h:
            * UIProcess/API/qt/qwkpage.cpp:
            (QWKPagePrivate::createContextMenuProxy):
            * UIProcess/API/qt/qwkpage.h:
            * UIProcess/qt/WebContextMenuProxyQt.cpp:
            (WebKit::webActionForContextMenuAction):
            (WebKit::WebContextMenuProxyQt::WebContextMenuProxyQt):
            (WebKit::WebContextMenuProxyQt::create):
            (WebKit::WebContextMenuProxyQt::showContextMenu):
            (WebKit::WebContextMenuProxyQt::hideContextMenu):
            (WebKit::WebContextMenuProxyQt::createContextMenu):
            * UIProcess/qt/WebContextMenuProxyQt.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74964 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 300a53f..a4cf36c 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,16 @@
+2011-01-04  Benjamin Poulain  <benjamin.poulain at nokia.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] [WK2] create an initial implementation of the context menu handling for WebKit 2
+        https://bugs.webkit.org/show_bug.cgi?id=51825
+
+        Implement contextMenuItemVector() for Qt, this method is used in WebKit 2 to get the
+        platform independent menu informations.
+
+        * platform/qt/ContextMenuQt.cpp:
+        (WebCore::contextMenuItemVector):
+
 2011-01-04  Sheriff Bot  <webkit.review.bot at gmail.com>
 
         Unreviewed, rolling out r74960.
diff --git a/WebCore/platform/qt/ContextMenuQt.cpp b/WebCore/platform/qt/ContextMenuQt.cpp
index c877642..61aab6d 100644
--- a/WebCore/platform/qt/ContextMenuQt.cpp
+++ b/WebCore/platform/qt/ContextMenuQt.cpp
@@ -73,10 +73,13 @@ PlatformMenuDescription ContextMenu::releasePlatformDescription()
     return PlatformMenuDescription();
 }
 
-Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription)
+Vector<ContextMenuItem> contextMenuItemVector(const QList<ContextMenuItem>* items)
 {
-    // FIXME - Implement    
-    return Vector<ContextMenuItem>();
+    int itemCount = items->size();
+    Vector<ContextMenuItem> menuItemVector(itemCount);
+    for (int i = 0; i < itemCount; ++i)
+        menuItemVector.append(items->at(i));
+    return menuItemVector;
 }
 
 PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>& menuItemVector)
diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index 521dc87..ba7087a 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,31 @@
+2011-01-04  Benjamin Poulain  <benjamin.poulain at nokia.com>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] [WK2] create an initial implementation of the context menu handling for WebKit 2
+        https://bugs.webkit.org/show_bug.cgi?id=51825
+
+        Implement the necessary methods to get a basic context menu working for Qt.
+
+        Only 4 basic WebAction have been added on the UIProcess side: back, forward, stop and reload.
+
+        * UIProcess/API/qt/qgraphicswkview.cpp:
+        (QGraphicsWKView::QGraphicsWKView):
+        (QGraphicsWKView::showContextMenu):
+        (QGraphicsWKViewPrivate::QGraphicsWKViewPrivate):
+        * UIProcess/API/qt/qgraphicswkview.h:
+        * UIProcess/API/qt/qwkpage.cpp:
+        (QWKPagePrivate::createContextMenuProxy):
+        * UIProcess/API/qt/qwkpage.h:
+        * UIProcess/qt/WebContextMenuProxyQt.cpp:
+        (WebKit::webActionForContextMenuAction):
+        (WebKit::WebContextMenuProxyQt::WebContextMenuProxyQt):
+        (WebKit::WebContextMenuProxyQt::create):
+        (WebKit::WebContextMenuProxyQt::showContextMenu):
+        (WebKit::WebContextMenuProxyQt::hideContextMenu):
+        (WebKit::WebContextMenuProxyQt::createContextMenu):
+        * UIProcess/qt/WebContextMenuProxyQt.h:
+
 2011-01-03  Yi Shen  <yi.4.shen at nokia.com>
 
         Reviewed by Adam Barth.
diff --git a/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp b/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp
index e98d8db..7876614 100644
--- a/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp
+++ b/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp
@@ -28,9 +28,11 @@
 #include "WKAPICast.h"
 #include "qwkpage.h"
 #include "qwkpage_p.h"
+#include <QApplication>
 #include <QCursor>
 #include <QGraphicsSceneMouseEvent>
 #include <QGraphicsView>
+#include <QMenu>
 #include <QPainter>
 #include <QScrollBar>
 #include <QStyleOptionGraphicsItem>
@@ -52,6 +54,7 @@ struct QGraphicsWKViewPrivate {
 
     QGraphicsWKView* q;
     QWKPage* page;
+    QMenu* activeMenu;
     RunLoop::Timer<QGraphicsWKViewPrivate> m_scaleCommitTimer;
     bool m_isChangingScale;
 };
@@ -89,6 +92,7 @@ QGraphicsWKView::QGraphicsWKView(QWKContext* context, BackingStoreType backingSt
     connect(d->page, SIGNAL(urlChanged(const QUrl&)), this, SIGNAL(urlChanged(const QUrl&)));
     connect(d->page, SIGNAL(cursorChanged(const QCursor&)), this, SLOT(updateCursor(const QCursor&)));
     connect(d->page, SIGNAL(focusNextPrevChild(bool)), this, SLOT(focusNextPrevChildCallback(bool)));
+    connect(d->page, SIGNAL(showContextMenu(QMenu*)), this, SLOT(showContextMenu(QMenu*)));
 }
 
 QGraphicsWKView::~QGraphicsWKView()
@@ -322,6 +326,33 @@ void QGraphicsWKView::focusOutEvent(QFocusEvent*)
     page()->d->page->setActive(false);
 }
 
+void QGraphicsWKView::showContextMenu(QMenu* menu)
+{
+    // Remove the active menu in case this function is called twice.
+    if (d->activeMenu)
+        d->activeMenu->hide();
+
+    d->activeMenu = menu;
+
+    QWidget* view = 0;
+    if (QGraphicsScene* myScene = scene()) {
+        const QList<QGraphicsView*> views = myScene->views();
+        for (unsigned i = 0; i < views.size(); ++i) {
+            if (views.at(i) == QApplication::focusWidget()) {
+                view = views.at(i);
+                break;
+            }
+        }
+        if (!view)
+            view = views.value(0, 0);
+    }
+    if (view)
+        menu->setParent(view, menu->windowFlags());
+    menu->exec(view->mapToGlobal(menu->pos()));
+    if (d->activeMenu == menu)
+        d->activeMenu = 0;
+}
+
 void QGraphicsWKView::takeSnapshot(const QSize& size, const QRect& contentsRect)
 {
 #if ENABLE(TILED_BACKING_STORE)
@@ -335,6 +366,7 @@ void QGraphicsWKView::takeSnapshot(const QSize& size, const QRect& contentsRect)
 
 QGraphicsWKViewPrivate::QGraphicsWKViewPrivate(QGraphicsWKView* view)
     : q(view)
+    , activeMenu(0)
     , m_scaleCommitTimer(RunLoop::current(), this, &QGraphicsWKViewPrivate::commitScale)
     , m_isChangingScale(false)
 {
diff --git a/WebKit2/UIProcess/API/qt/qgraphicswkview.h b/WebKit2/UIProcess/API/qt/qgraphicswkview.h
index 6f4081e..caf8e0d 100644
--- a/WebKit2/UIProcess/API/qt/qgraphicswkview.h
+++ b/WebKit2/UIProcess/API/qt/qgraphicswkview.h
@@ -88,6 +88,9 @@ protected:
     virtual void focusInEvent(QFocusEvent*);
     virtual void focusOutEvent(QFocusEvent*);
 
+private Q_SLOTS:
+    void showContextMenu(QMenu*);
+
 private:
     Q_PRIVATE_SLOT(d, void onScaleChanged());
 
diff --git a/WebKit2/UIProcess/API/qt/qwkpage.cpp b/WebKit2/UIProcess/API/qt/qwkpage.cpp
index 4b526a0..ea7b3ab 100644
--- a/WebKit2/UIProcess/API/qt/qwkpage.cpp
+++ b/WebKit2/UIProcess/API/qt/qwkpage.cpp
@@ -143,7 +143,7 @@ PassRefPtr<WebPopupMenuProxy> QWKPagePrivate::createPopupMenuProxy(WebPageProxy*
 
 PassRefPtr<WebContextMenuProxy> QWKPagePrivate::createContextMenuProxy(WebPageProxy*)
 {
-    return WebContextMenuProxyQt::create();
+    return WebContextMenuProxyQt::create(q);
 }
 
 void QWKPagePrivate::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut)
diff --git a/WebKit2/UIProcess/API/qt/qwkpage.h b/WebKit2/UIProcess/API/qt/qwkpage.h
index 645c845..2c01f8d 100644
--- a/WebKit2/UIProcess/API/qt/qwkpage.h
+++ b/WebKit2/UIProcess/API/qt/qwkpage.h
@@ -121,6 +121,7 @@ public:
     Q_SIGNAL void windowCloseRequested();
     Q_SIGNAL void zoomableAreaFound(const QRect&);
     Q_SIGNAL void focusNextPrevChild(bool);
+    Q_SIGNAL void showContextMenu(QMenu*);
 
 protected:
     void timerEvent(QTimerEvent*);
diff --git a/WebKit2/UIProcess/qt/WebContextMenuProxyQt.cpp b/WebKit2/UIProcess/qt/WebContextMenuProxyQt.cpp
index 3f2e47e..f05dde6 100644
--- a/WebKit2/UIProcess/qt/WebContextMenuProxyQt.cpp
+++ b/WebKit2/UIProcess/qt/WebContextMenuProxyQt.cpp
@@ -26,29 +26,103 @@
 
 #include "WebContextMenuProxyQt.h"
 
-#include "NotImplemented.h"
+#include <IntPoint.h>
+#include <WebContextMenuItemData.h>
+#include <qmenu.h>
+#include <qwkpage.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
-inline WebContextMenuProxyQt::WebContextMenuProxyQt()
+static QWKPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
 {
+    switch (action) {
+    case WebCore::ContextMenuItemTagGoBack:
+        return QWKPage::Back;
+    case WebCore::ContextMenuItemTagGoForward:
+        return QWKPage::Forward;
+    case WebCore::ContextMenuItemTagStop:
+        return QWKPage::Stop;
+    case WebCore::ContextMenuItemTagReload:
+        return QWKPage::Reload;
+    default:
+        break;
+    }
+    return QWKPage::NoWebAction;
 }
 
-PassRefPtr<WebContextMenuProxyQt> WebContextMenuProxyQt::create()
+WebContextMenuProxyQt::WebContextMenuProxyQt(QWKPage* page)
+    : m_page(page)
 {
-    return adoptRef(new WebContextMenuProxyQt);
 }
 
-void WebContextMenuProxyQt::showContextMenu(const IntPoint&, const Vector<WebContextMenuItemData>&)
+PassRefPtr<WebContextMenuProxyQt> WebContextMenuProxyQt::create(QWKPage* page)
 {
-    notImplemented();
+    return adoptRef(new WebContextMenuProxyQt(page));
+}
+
+void WebContextMenuProxyQt::showContextMenu(const IntPoint& position, const Vector<WebContextMenuItemData>& items)
+{
+    if (QMenu* menu = createContextMenu(items)) {
+        menu->move(position);
+        emit m_page->showContextMenu(menu);
+    }
 }
 
 void WebContextMenuProxyQt::hideContextMenu()
 {
-    notImplemented();
+}
+
+QMenu* WebContextMenuProxyQt::createContextMenu(const Vector<WebContextMenuItemData>& items)
+{
+    QMenu* menu = new QMenu;
+    for (int i = 0; i < items.size(); ++i) {
+        const WebContextMenuItemData& item = items.at(i);
+        switch (item.type()) {
+        case WebCore::CheckableActionType: /* fall through */
+        case WebCore::ActionType: {
+            QWKPage::WebAction action = webActionForContextMenuAction(item.action());
+            QAction* qtAction = m_page->action(action);
+            if (qtAction) {
+                qtAction->setEnabled(item.enabled());
+                qtAction->setChecked(item.checked());
+                qtAction->setCheckable(item.type() == WebCore::CheckableActionType);
+
+                menu->addAction(qtAction);
+            }
+            break;
+        }
+        case WebCore::SeparatorType:
+            menu->addSeparator();
+            break;
+        case WebCore::SubmenuType:
+            if (QMenu *subMenu = createContextMenu(item.submenu())) {
+                subMenu->setTitle(item.title());
+                menu->addAction(subMenu->menuAction());
+            }
+
+            break;
+        }
+    }
+
+    // Do not show sub-menus with just disabled actions.
+    if (menu->isEmpty()) {
+        delete menu;
+        return 0;
+    }
+    bool isAnyActionEnabled = false;
+    QList<QAction *> actions = menu->actions();
+    for (int i = 0; i < actions.count(); ++i) {
+        if (actions.at(i)->isVisible())
+            isAnyActionEnabled |= actions.at(i)->isEnabled();
+    }
+    if (!isAnyActionEnabled) {
+        delete menu;
+        return 0;
+    }
+
+    return menu;
 }
 
 } // namespace WebKit
diff --git a/WebKit2/UIProcess/qt/WebContextMenuProxyQt.h b/WebKit2/UIProcess/qt/WebContextMenuProxyQt.h
index 383990f..435204f 100644
--- a/WebKit2/UIProcess/qt/WebContextMenuProxyQt.h
+++ b/WebKit2/UIProcess/qt/WebContextMenuProxyQt.h
@@ -29,17 +29,25 @@
 
 #include "WebContextMenuProxy.h"
 
+class QMenu;
+class QWKPage;
+class WebContextMenuItemData;
+
 namespace WebKit {
 
 class WebContextMenuProxyQt : public WebContextMenuProxy {
 public:
-    static PassRefPtr<WebContextMenuProxyQt> create();
+    static PassRefPtr<WebContextMenuProxyQt> create(QWKPage*);
 
 private:
-    WebContextMenuProxyQt();
+    WebContextMenuProxyQt(QWKPage*);
 
     virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&);
     virtual void hideContextMenu();
+
+    QMenu* createContextMenu(const Vector<WebContextMenuItemData>& items);
+
+    QWKPage* const m_page;
 };
 
 } // namespace WebKit

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list