Changeset 74964 in webkit


Ignore:
Timestamp:
Jan 4, 2011 3:53:24 AM (13 years ago)
Author:
benjamin.poulain@nokia.com
Message:

2011-01-04 Benjamin Poulain <benjamin.poulain@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@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:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r74963 r74964  
     12011-01-04  Benjamin Poulain  <benjamin.poulain@nokia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] [WK2] create an initial implementation of the context menu handling for WebKit 2
     6        https://bugs.webkit.org/show_bug.cgi?id=51825
     7
     8        Implement contextMenuItemVector() for Qt, this method is used in WebKit 2 to get the
     9        platform independent menu informations.
     10
     11        * platform/qt/ContextMenuQt.cpp:
     12        (WebCore::contextMenuItemVector):
     13
    1142011-01-04  Sheriff Bot  <webkit.review.bot@gmail.com>
    215
  • trunk/WebCore/platform/qt/ContextMenuQt.cpp

    r73535 r74964  
    7474}
    7575
    76 Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription)
     76Vector<ContextMenuItem> contextMenuItemVector(const QList<ContextMenuItem>* items)
    7777{
    78     // FIXME - Implement   
    79     return Vector<ContextMenuItem>();
     78    int itemCount = items->size();
     79    Vector<ContextMenuItem> menuItemVector(itemCount);
     80    for (int i = 0; i < itemCount; ++i)
     81        menuItemVector.append(items->at(i));
     82    return menuItemVector;
    8083}
    8184
  • trunk/WebKit2/ChangeLog

    r74941 r74964  
     12011-01-04  Benjamin Poulain  <benjamin.poulain@nokia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] [WK2] create an initial implementation of the context menu handling for WebKit 2
     6        https://bugs.webkit.org/show_bug.cgi?id=51825
     7
     8        Implement the necessary methods to get a basic context menu working for Qt.
     9
     10        Only 4 basic WebAction have been added on the UIProcess side: back, forward, stop and reload.
     11
     12        * UIProcess/API/qt/qgraphicswkview.cpp:
     13        (QGraphicsWKView::QGraphicsWKView):
     14        (QGraphicsWKView::showContextMenu):
     15        (QGraphicsWKViewPrivate::QGraphicsWKViewPrivate):
     16        * UIProcess/API/qt/qgraphicswkview.h:
     17        * UIProcess/API/qt/qwkpage.cpp:
     18        (QWKPagePrivate::createContextMenuProxy):
     19        * UIProcess/API/qt/qwkpage.h:
     20        * UIProcess/qt/WebContextMenuProxyQt.cpp:
     21        (WebKit::webActionForContextMenuAction):
     22        (WebKit::WebContextMenuProxyQt::WebContextMenuProxyQt):
     23        (WebKit::WebContextMenuProxyQt::create):
     24        (WebKit::WebContextMenuProxyQt::showContextMenu):
     25        (WebKit::WebContextMenuProxyQt::hideContextMenu):
     26        (WebKit::WebContextMenuProxyQt::createContextMenu):
     27        * UIProcess/qt/WebContextMenuProxyQt.h:
     28
    1292011-01-03  Yi Shen  <yi.4.shen@nokia.com>
    230
  • trunk/WebKit2/UIProcess/API/qt/qgraphicswkview.cpp

    r74284 r74964  
    2929#include "qwkpage.h"
    3030#include "qwkpage_p.h"
     31#include <QApplication>
    3132#include <QCursor>
    3233#include <QGraphicsSceneMouseEvent>
    3334#include <QGraphicsView>
     35#include <QMenu>
    3436#include <QPainter>
    3537#include <QScrollBar>
     
    5355    QGraphicsWKView* q;
    5456    QWKPage* page;
     57    QMenu* activeMenu;
    5558    RunLoop::Timer<QGraphicsWKViewPrivate> m_scaleCommitTimer;
    5659    bool m_isChangingScale;
     
    9093    connect(d->page, SIGNAL(cursorChanged(const QCursor&)), this, SLOT(updateCursor(const QCursor&)));
    9194    connect(d->page, SIGNAL(focusNextPrevChild(bool)), this, SLOT(focusNextPrevChildCallback(bool)));
     95    connect(d->page, SIGNAL(showContextMenu(QMenu*)), this, SLOT(showContextMenu(QMenu*)));
    9296}
    9397
     
    323327}
    324328
     329void QGraphicsWKView::showContextMenu(QMenu* menu)
     330{
     331    // Remove the active menu in case this function is called twice.
     332    if (d->activeMenu)
     333        d->activeMenu->hide();
     334
     335    d->activeMenu = menu;
     336
     337    QWidget* view = 0;
     338    if (QGraphicsScene* myScene = scene()) {
     339        const QList<QGraphicsView*> views = myScene->views();
     340        for (unsigned i = 0; i < views.size(); ++i) {
     341            if (views.at(i) == QApplication::focusWidget()) {
     342                view = views.at(i);
     343                break;
     344            }
     345        }
     346        if (!view)
     347            view = views.value(0, 0);
     348    }
     349    if (view)
     350        menu->setParent(view, menu->windowFlags());
     351    menu->exec(view->mapToGlobal(menu->pos()));
     352    if (d->activeMenu == menu)
     353        d->activeMenu = 0;
     354}
     355
    325356void QGraphicsWKView::takeSnapshot(const QSize& size, const QRect& contentsRect)
    326357{
     
    336367QGraphicsWKViewPrivate::QGraphicsWKViewPrivate(QGraphicsWKView* view)
    337368    : q(view)
     369    , activeMenu(0)
    338370    , m_scaleCommitTimer(RunLoop::current(), this, &QGraphicsWKViewPrivate::commitScale)
    339371    , m_isChangingScale(false)
  • trunk/WebKit2/UIProcess/API/qt/qgraphicswkview.h

    r73716 r74964  
    8989    virtual void focusOutEvent(QFocusEvent*);
    9090
     91private Q_SLOTS:
     92    void showContextMenu(QMenu*);
     93
    9194private:
    9295    Q_PRIVATE_SLOT(d, void onScaleChanged());
  • trunk/WebKit2/UIProcess/API/qt/qwkpage.cpp

    r74418 r74964  
    144144PassRefPtr<WebContextMenuProxy> QWKPagePrivate::createContextMenuProxy(WebPageProxy*)
    145145{
    146     return WebContextMenuProxyQt::create();
     146    return WebContextMenuProxyQt::create(q);
    147147}
    148148
  • trunk/WebKit2/UIProcess/API/qt/qwkpage.h

    r73716 r74964  
    122122    Q_SIGNAL void zoomableAreaFound(const QRect&);
    123123    Q_SIGNAL void focusNextPrevChild(bool);
     124    Q_SIGNAL void showContextMenu(QMenu*);
    124125
    125126protected:
  • trunk/WebKit2/UIProcess/qt/WebContextMenuProxyQt.cpp

    r71585 r74964  
    2727#include "WebContextMenuProxyQt.h"
    2828
    29 #include "NotImplemented.h"
     29#include <IntPoint.h>
     30#include <WebContextMenuItemData.h>
     31#include <qmenu.h>
     32#include <qwkpage.h>
    3033
    3134using namespace WebCore;
     
    3336namespace WebKit {
    3437
    35 inline WebContextMenuProxyQt::WebContextMenuProxyQt()
     38static QWKPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAction action)
     39{
     40    switch (action) {
     41    case WebCore::ContextMenuItemTagGoBack:
     42        return QWKPage::Back;
     43    case WebCore::ContextMenuItemTagGoForward:
     44        return QWKPage::Forward;
     45    case WebCore::ContextMenuItemTagStop:
     46        return QWKPage::Stop;
     47    case WebCore::ContextMenuItemTagReload:
     48        return QWKPage::Reload;
     49    default:
     50        break;
     51    }
     52    return QWKPage::NoWebAction;
     53}
     54
     55WebContextMenuProxyQt::WebContextMenuProxyQt(QWKPage* page)
     56    : m_page(page)
    3657{
    3758}
    3859
    39 PassRefPtr<WebContextMenuProxyQt> WebContextMenuProxyQt::create()
     60PassRefPtr<WebContextMenuProxyQt> WebContextMenuProxyQt::create(QWKPage* page)
    4061{
    41     return adoptRef(new WebContextMenuProxyQt);
     62    return adoptRef(new WebContextMenuProxyQt(page));
    4263}
    4364
    44 void WebContextMenuProxyQt::showContextMenu(const IntPoint&, const Vector<WebContextMenuItemData>&)
     65void WebContextMenuProxyQt::showContextMenu(const IntPoint& position, const Vector<WebContextMenuItemData>& items)
    4566{
    46     notImplemented();
     67    if (QMenu* menu = createContextMenu(items)) {
     68        menu->move(position);
     69        emit m_page->showContextMenu(menu);
     70    }
    4771}
    4872
    4973void WebContextMenuProxyQt::hideContextMenu()
    5074{
    51     notImplemented();
     75}
     76
     77QMenu* WebContextMenuProxyQt::createContextMenu(const Vector<WebContextMenuItemData>& items)
     78{
     79    QMenu* menu = new QMenu;
     80    for (int i = 0; i < items.size(); ++i) {
     81        const WebContextMenuItemData& item = items.at(i);
     82        switch (item.type()) {
     83        case WebCore::CheckableActionType: /* fall through */
     84        case WebCore::ActionType: {
     85            QWKPage::WebAction action = webActionForContextMenuAction(item.action());
     86            QAction* qtAction = m_page->action(action);
     87            if (qtAction) {
     88                qtAction->setEnabled(item.enabled());
     89                qtAction->setChecked(item.checked());
     90                qtAction->setCheckable(item.type() == WebCore::CheckableActionType);
     91
     92                menu->addAction(qtAction);
     93            }
     94            break;
     95        }
     96        case WebCore::SeparatorType:
     97            menu->addSeparator();
     98            break;
     99        case WebCore::SubmenuType:
     100            if (QMenu *subMenu = createContextMenu(item.submenu())) {
     101                subMenu->setTitle(item.title());
     102                menu->addAction(subMenu->menuAction());
     103            }
     104
     105            break;
     106        }
     107    }
     108
     109    // Do not show sub-menus with just disabled actions.
     110    if (menu->isEmpty()) {
     111        delete menu;
     112        return 0;
     113    }
     114    bool isAnyActionEnabled = false;
     115    QList<QAction *> actions = menu->actions();
     116    for (int i = 0; i < actions.count(); ++i) {
     117        if (actions.at(i)->isVisible())
     118            isAnyActionEnabled |= actions.at(i)->isEnabled();
     119    }
     120    if (!isAnyActionEnabled) {
     121        delete menu;
     122        return 0;
     123    }
     124
     125    return menu;
    52126}
    53127
  • trunk/WebKit2/UIProcess/qt/WebContextMenuProxyQt.h

    r71585 r74964  
    3030#include "WebContextMenuProxy.h"
    3131
     32class QMenu;
     33class QWKPage;
     34class WebContextMenuItemData;
     35
    3236namespace WebKit {
    3337
    3438class WebContextMenuProxyQt : public WebContextMenuProxy {
    3539public:
    36     static PassRefPtr<WebContextMenuProxyQt> create();
     40    static PassRefPtr<WebContextMenuProxyQt> create(QWKPage*);
    3741
    3842private:
    39     WebContextMenuProxyQt();
     43    WebContextMenuProxyQt(QWKPage*);
    4044
    4145    virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&);
    4246    virtual void hideContextMenu();
     47
     48    QMenu* createContextMenu(const Vector<WebContextMenuItemData>& items);
     49
     50    QWKPage* const m_page;
    4351};
    4452
Note: See TracChangeset for help on using the changeset viewer.