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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74964 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 33c79351
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 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r74960.
......
......@@ -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)
......
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:
2011-01-03 Yi Shen <yi.4.shen@nokia.com>
Reviewed by Adam Barth.
......@@ -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)
{
......
......@@ -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());
......
......@@ -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)
......
......@@ -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*);
......
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment