Restructure the context menu classes for the Qt port. ContextMenu and ContextMenuItem...
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:29:19 +0000 (14:29 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:29:19 +0000 (14:29 +0000)
QActions/QMenus anymore but just store the action type, tag, title and optionally submenu as created
in ContextMenu::populate().
For the actual Qt context menu we traverse this structure after sendContextMenuEvent and create a QMenu
out of it. That menu is currently not functional anymore though.

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

WebCore/ChangeLog
WebCore/platform/ContextMenu.h
WebCore/platform/ContextMenuItem.h
WebCore/platform/PlatformMenuDescription.h
WebCore/platform/qt/ContextMenuItemQt.cpp
WebCore/platform/qt/ContextMenuQt.cpp
WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage_p.h
WebKit/qt/ChangeLog

index a6ed67a00bce41011ac69dc6e60051693ef4c6f6..e072bd7d9b9c6842db4a273dd591cd608056900d 100644 (file)
@@ -1,3 +1,40 @@
+2007-11-07  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Restructure the context menu classes for the Qt port. ContextMenu and ContextMenuItem don't store
+        QActions/QMenus anymore but just store the action type, tag, title and optionally submenu as created
+        in ContextMenu::populate().
+        For the actual Qt context menu we traverse this structure after sendContextMenuEvent and create a QMenu
+        out of it. That menu is currently not functional anymore though.
+
+        WARNING: NO TEST CASES ADDED OR CHANGED
+
+        * platform/ContextMenu.h:
+        * platform/ContextMenuItem.h:
+        (WebCore::PlatformMenuItemDescription::PlatformMenuItemDescription):
+        * platform/PlatformMenuDescription.h:
+        * platform/qt/ContextMenuItemQt.cpp:
+        (WebCore::ContextMenuItem::ContextMenuItem):
+        (WebCore::ContextMenuItem::type):
+        (WebCore::ContextMenuItem::setType):
+        (WebCore::ContextMenuItem::action):
+        (WebCore::ContextMenuItem::setAction):
+        (WebCore::ContextMenuItem::title):
+        (WebCore::ContextMenuItem::setTitle):
+        (WebCore::ContextMenuItem::platformSubMenu):
+        (WebCore::ContextMenuItem::setSubMenu):
+        (WebCore::ContextMenuItem::setChecked):
+        (WebCore::ContextMenuItem::setEnabled):
+        * platform/qt/ContextMenuQt.cpp:
+        (WebCore::ContextMenu::ContextMenu):
+        (WebCore::ContextMenu::~ContextMenu):
+        (WebCore::ContextMenu::appendItem):
+        (WebCore::ContextMenu::itemCount):
+        (WebCore::ContextMenu::insertItem):
+        (WebCore::ContextMenu::setPlatformDescription):
+        (WebCore::ContextMenu::platformDescription):
+
 2007-11-07  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Lars.
index f39c5f9c1d6a5b4deef693e5b048bf010eed2bff..986b13b6730a670510f58fcb362d3c5ce65790a5 100644 (file)
@@ -77,8 +77,7 @@ class MenuEventProxy;
         // Keep this in sync with the PlatformMenuDescription typedef
         RetainPtr<NSMutableArray> m_platformDescription;
 #elif PLATFORM(QT)
-        QMenu *m_menu;
-        MenuEventProxy *m_proxy;
+        PlatformMenuDescription m_items;
 #else
         PlatformMenuDescription m_platformDescription;
 #endif
index 4c4b9952798b3de5c4b10153ad6bd286a7792e4b..3c6cdb8c86b071b0add6d45029d9b00aa8c0e5df 100644 (file)
@@ -128,16 +128,22 @@ namespace WebCore {
 #elif PLATFORM(WIN)
     typedef LPMENUITEMINFO PlatformMenuItemDescription;
 #elif PLATFORM(QT)
-    struct PlatformMenuItemDescriptionType {
-        PlatformMenuItemDescriptionType() : qaction(0), menu(0), action(ContextMenuItemTagNoAction), type(ActionType), subMenu(0) {}
-        QAction *qaction;
-        QMenu *menu;
-        ContextMenuAction action;
-        QString title;
+    struct PlatformMenuItemDescription {
+        PlatformMenuItemDescription()
+            : type(ActionType),
+              action(ContextMenuItemTagNoAction),
+              subMenu(0),
+              checked(false),
+              enabled(true)
+        {}
+
         ContextMenuItemType type;
-        PlatformMenuDescription subMenu;
+        ContextMenuAction action;
+        String title;
+        ContextMenu *subMenu;
+        bool checked;
+        bool enabled;
     };
-    typedef PlatformMenuItemDescriptionType* PlatformMenuItemDescription;
 #elif PLATFORM(GTK)
     typedef GtkMenuItem* PlatformMenuItemDescription;
 #elif PLATFORM(WX)
index 4892968e2d948e3662ccb55858d41c3ac4f5bdd5..164f47f2e2b2a00c6e8203893056b4baa2f9b563 100644 (file)
@@ -35,7 +35,7 @@ class NSMutableArray;
 #elif PLATFORM(WIN)
 typedef struct HMENU__* HMENU;
 #elif PLATFORM(QT)
-class QMenu;
+#include <qlist.h>
 #elif PLATFORM(GTK)
 typedef struct _GtkMenu GtkMenu;
 #elif PLATFORM(WX)
@@ -49,7 +49,8 @@ namespace WebCore {
 #elif PLATFORM(WIN)
     typedef HMENU PlatformMenuDescription;
 #elif PLATFORM(QT)
-    typedef QMenu* PlatformMenuDescription;
+    class ContextMenuItem;
+    typedef QList<ContextMenuItem>* PlatformMenuDescription;
 #elif PLATFORM(GTK)
     typedef GtkMenu* PlatformMenuDescription;
 #elif PLATFORM(WX)
index 52841a84356da456cf243e7cb6fda6e5e23ea689..dbfb1c3515e15a6b2d9f4fc276d63adbd2152f80 100644 (file)
@@ -32,21 +32,22 @@ namespace WebCore {
 
 ContextMenuItem::ContextMenuItem(ContextMenu* subMenu)
 {
-    m_platformDescription = new PlatformMenuItemDescriptionType;
+    m_platformDescription.type = SubmenuType;
+    m_platformDescription.action = ContextMenuItemTagNoAction;
+    m_platformDescription.subMenu = subMenu;
 }
 
 ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action,
                                  const String& title, ContextMenu* subMenu)
 {
-    m_platformDescription = new PlatformMenuItemDescriptionType;
-    m_platformDescription->type = type;
-    m_platformDescription->action = action;
-    m_platformDescription->title = title;
+    m_platformDescription.type = type;
+    m_platformDescription.action = action;
+    m_platformDescription.title = title;
+    m_platformDescription.subMenu = subMenu;
 }
 
 ContextMenuItem::~ContextMenuItem()
 {
-    delete m_platformDescription;
 }
 
 PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
@@ -56,76 +57,58 @@ PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
 
 ContextMenuItemType ContextMenuItem::type() const
 {
-    return m_platformDescription->type;
+    return m_platformDescription.type;
 }
 
 void ContextMenuItem::setType(ContextMenuItemType type)
 {
-    m_platformDescription->type = type;
+    m_platformDescription.type = type;
 }
 
 ContextMenuAction ContextMenuItem::action() const
 { 
-    return m_platformDescription->action;
+    return m_platformDescription.action;
 }
 
 void ContextMenuItem::setAction(ContextMenuAction action)
 {
-    m_platformDescription->action = action;
+    m_platformDescription.action = action;
 }
 
 String ContextMenuItem::title() const 
 {
-    return m_platformDescription->title;
+    return m_platformDescription.title;
 }
 
 void ContextMenuItem::setTitle(const String& title)
 {
-#ifndef QT_NO_MENU
-    m_platformDescription->title = title;
-    if (m_platformDescription->qaction)
-        m_platformDescription->qaction->setText(title);
-#endif
+    m_platformDescription.title = title;
 }
 
 
 PlatformMenuDescription ContextMenuItem::platformSubMenu() const
 {
-    return m_platformDescription->subMenu;
+    return m_platformDescription.subMenu->platformDescription();
 }
 
 void ContextMenuItem::setSubMenu(ContextMenu* menu)
 {
-#ifndef QT_NO_MENU
-    m_platformDescription->subMenu = menu->platformDescription();
-#endif
+    m_platformDescription.subMenu = menu;
 }
 
 void ContextMenuItem::setChecked(bool on)
 {
-#ifndef QT_NO_MENU
-    if (m_platformDescription->qaction) {
-        m_platformDescription->qaction->setCheckable(true);
-        m_platformDescription->qaction->setChecked(on);
-    }
-#endif
+    m_platformDescription.checked = on;
 }
 
 void ContextMenuItem::setEnabled(bool on)
 {
-#ifndef QT_NO_MENU
-    if (m_platformDescription->qaction)
-        m_platformDescription->qaction->setEnabled(on);
-#endif
+    m_platformDescription.enabled = on;
 }
 
 bool ContextMenuItem::enabled() const
 {
-#ifndef QT_NO_MENU
-    if (m_platformDescription->qaction)
-        return m_platformDescription->qaction->isEnabled();
-#endif
-    return false;
+    return m_platformDescription.enabled;
 }
 
 }
index 39784ca587a898cc7c380fbf6e2dd64d5d04a9a0..658eca7bcefffc5d7ec9cf399abdb4e11fc464c3 100644 (file)
@@ -41,101 +41,42 @@ namespace WebCore {
 ContextMenu::ContextMenu(const HitTestResult& result)
     : m_hitTestResult(result)
 {
-#ifndef QT_NO_MENU
-    m_menu = new QMenu;
-    //qDebug("Create menu(%p) %p", this, (QMenu*)m_menu);
-    m_proxy = new MenuEventProxy(this);
-    QObject::connect(m_menu, SIGNAL(triggered(QAction *)), m_proxy, SLOT(trigger(QAction *)));
-#endif
+    m_items = new QList<ContextMenuItem>();
 }
 
 ContextMenu::~ContextMenu()
 {
-#ifndef QT_NO_MENU
-    //qDebug("Destroy menu(%p) %p", this, (QMenu*)m_menu);
-    delete m_menu;
-    m_menu = 0;
-    delete m_proxy;
-    m_proxy = 0;
-#endif
+    delete m_items;
 }
 
 void ContextMenu::appendItem(ContextMenuItem& item)
 {
-    insertItem(999999, item); // yuck!  Fix this API!!
+    m_items->append(item);
 }
 
 unsigned ContextMenu::itemCount() const
 {
-#ifndef QT_NO_MENU
-    return m_menu->actions().count();
-#else
-    return 0;
-#endif
+    return m_items->count();
 }
 
 void ContextMenu::insertItem(unsigned position, ContextMenuItem& item)
 {
-#ifndef QT_NO_MENU
-    int id;
-    QAction *action;
-    QAction *before = 0;
-    int p = position;
-    if (p == 999999)
-        p = -1;
-    if (p >= 0)
-        before = m_menu->actions()[p];
-
-    switch (item.type()) {
-        case ActionType:
-            if (!item.title().isEmpty()) {
-                action = m_menu->addAction((QString)item.title());
-                m_menu->removeAction(action);
-                m_menu->insertAction(before, action);
-            }
-            break;
-        case SeparatorType:
-            action = m_menu->insertSeparator(before);
-            break;
-        case SubmenuType:
-            if (!item.title().isEmpty()) {
-                QMenu *m = item.platformSubMenu();
-                if (!m)
-                    return;
-                action = m_menu->insertMenu(before, m);
-                action->setText(item.title());
-            }
-            break;
-        default:
-            return;
-    }
-    if (action) {
-        m_proxy->map(action, item.action());
-        item.releasePlatformDescription()->qaction = action;
-    }
-#endif
+    m_items->insert(position, item);
 }
 
 void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)
 {
-#ifndef QT_NO_MENU
-    if (menu != m_menu) {
-        delete m_menu;
-        m_menu = menu;
-    }
-#endif
+    // doesn't make sense
 }
 
 PlatformMenuDescription ContextMenu::platformDescription() const
 {
-    return m_menu;
+    return m_items;
 }
 
 PlatformMenuDescription ContextMenu::releasePlatformDescription()
 {
-    QMenu* tmp = m_menu;
-    m_menu = 0;
-    return tmp;
+    return PlatformMenuDescription();
 }
 
 
index 602f0cb5a2bb98645989908e3020dc0d9c25127e..951c45e3bf54c16c20a3bb7682a87f18a640dc45 100644 (file)
@@ -124,6 +124,29 @@ void QWebPagePrivate::createMainFrame()
     }
 }
 
+QMenu *QWebPagePrivate::createContextMenu(QList<WebCore::ContextMenuItem> *items)
+{
+    QMenu *menu = new QMenu;
+    for (int i = 0; i < items->count(); ++i) {
+        const ContextMenuItem &item = items->at(i);
+        switch (item.type()) {
+            case WebCore::ActionType:
+                menu->addAction(item.title());
+                break;
+            case WebCore::SeparatorType:
+                menu->addSeparator();
+                break;
+            case WebCore::SubmenuType: {
+                QMenu *subMenu = createContextMenu(item.platformSubMenu());
+                subMenu->setTitle(item.title());
+                menu->addAction(subMenu->menuAction());
+                break;
+            }
+        }
+    }
+    return menu;
+}
+
 QWebFrame *QWebPagePrivate::frameAt(const QPoint &pos) const
 {
     QWebFrame *frame = mainFrame;
@@ -474,7 +497,9 @@ void QWebPage::contextMenuEvent(QContextMenuEvent *ev)
     d->page->contextMenuController()->clearContextMenu();
     frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
     ContextMenu *menu = d->page->contextMenuController()->contextMenu();
-    QMenu *qmenu = menu->releasePlatformDescription();
+
+    QList<ContextMenuItem> *items = menu->platformDescription();
+    QMenu *qmenu = d->createContextMenu(items);
     if (qmenu) {
         qmenu->exec(ev->globalPos());
         delete qmenu;
index 20f6aef9a9369927c32b9f9281fb540cafee2cca..368a2332107a917d1093157d2eec5ca9ddd94943 100644 (file)
@@ -32,11 +32,13 @@ namespace WebCore
 {
     class ChromeClientQt;
     class ContextMenuClientQt;
+    class ContextMenuItem;
     class EditorClientQt;
     class Page;
 }
 
 class QUndoStack;
+class QMenu;
 
 class QWebPagePrivate
 {
@@ -44,6 +46,7 @@ public:
     QWebPagePrivate(QWebPage *);
     ~QWebPagePrivate();
     void createMainFrame();
+    QMenu *createContextMenu(QList<WebCore::ContextMenuItem> *items);
 
     QWebFrame *frameAt(const QPoint &pos) const;
 
index f5facb737e54a40eb18311c8548a142d146675c3..09cf3f503c9296e88f48882d7667837c9c46da15 100644 (file)
@@ -1,3 +1,18 @@
+2007-11-07  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Restructure the context menu classes for the Qt port. ContextMenu and ContextMenuItem don't store
+        QActions/QMenus anymore but just store the action type, tag, title and optionally submenu as created
+        in ContextMenu::populate().
+        For the actual Qt context menu we traverse this structure after sendContextMenuEvent and create a QMenu
+        out of it. That menu is currently not functional anymore though.
+
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::createContextMenu):
+        (QWebPage::contextMenuEvent):
+        * Api/qwebpage_p.h:
+
 2007-11-07  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Lars.