Changeset 24131 in webkit


Ignore:
Timestamp:
Jul 9, 2007 6:43:21 PM (17 years ago)
Author:
staikos
Message:

Patch from Qing Zhao to add context menu support for Qt.

Location:
trunk/WebCore
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r24127 r24131  
     12007-07-09  Qing Zhao  <qing@staikos.net>
     2
     3        Reviewed by George Staikos.
     4
     5        Add qt context menu support.
     6
     7        * WebCore.pro:
     8        * platform/ContextMenu.h:
     9        * platform/ContextMenuItem.h:
     10        (WebCore::PlatformMenuItemDescriptionType::PlatformMenuItemDescriptionType):
     11        * platform/qt/ContextMenuItemQt.cpp:
     12        (WebCore::ContextMenuItem::ContextMenuItem):
     13        (WebCore::ContextMenuItem::~ContextMenuItem):
     14        (WebCore::ContextMenuItem::releasePlatformDescription):
     15        (WebCore::ContextMenuItem::type):
     16        (WebCore::ContextMenuItem::setType):
     17        (WebCore::ContextMenuItem::action):
     18        (WebCore::ContextMenuItem::setAction):
     19        (WebCore::ContextMenuItem::title):
     20        (WebCore::ContextMenuItem::setTitle):
     21        (WebCore::ContextMenuItem::platformSubMenu):
     22        (WebCore::ContextMenuItem::setSubMenu):
     23        (WebCore::ContextMenuItem::setChecked):
     24        (WebCore::ContextMenuItem::setEnabled):
     25        (WebCore::ContextMenuItem::enabled):
     26        * platform/qt/ContextMenuQt.cpp:
     27        (WebCore::ContextMenu::ContextMenu):
     28        (WebCore::ContextMenu::~ContextMenu):
     29        (WebCore::ContextMenu::appendItem):
     30        (WebCore::ContextMenu::itemCount):
     31        (WebCore::ContextMenu::insertItem):
     32        (WebCore::ContextMenu::setPlatformDescription):
     33        (WebCore::ContextMenu::platformDescription):
     34
    1352007-07-09  Anders Carlsson  <andersca@apple.com>
    236
  • trunk/WebCore/WebCore.pro

    r24088 r24131  
    732732qt-port:HEADERS += \
    733733    $$PWD/platform/qt/QWebPopup.h \
     734    $$PWD/platform/qt/MenuEventProxy.h \
    734735    $$PWD/platform/qt/SharedTimerQt.h \
    735736    $$PWD/../WebKitQt/Api/qwebframe.h \
  • trunk/WebCore/platform/ContextMenu.h

    r23677 r24131  
    3737#elif PLATFORM(QT)
    3838#include <QMenu>
    39 typedef QMenu* PlatformMenuDescription;
    4039#endif
    4140
    4241namespace WebCore {
     42class MenuEventProxy;
    4343
    4444    class ContextMenuController;
     
    7676#elif PLATFORM(QT)
    7777        QMenu *m_menu;
     78        MenuEventProxy *m_proxy;
    7879#else
    7980        PlatformMenuDescription m_platformDescription;
  • trunk/WebCore/platform/ContextMenuItem.h

    r23677 r24131  
    4343#elif PLATFORM(GDK)
    4444typedef struct _GtkMenuItem GtkMenuItem;
     45#elif PLATFORM(QT)
     46#include <QAction>
    4547#endif
    4648
     
    4850
    4951    class ContextMenu;
    50 
    51 #if PLATFORM(MAC)
    52     typedef NSMenuItem* PlatformMenuItemDescription;
    53 #elif PLATFORM(WIN)
    54     typedef LPMENUITEMINFO PlatformMenuItemDescription;
    55 #elif PLATFORM(QT)
    56     typedef void* PlatformMenuItemDescription;
    57 #elif PLATFORM(GDK)
    58     typedef GtkMenuItem* PlatformMenuItemDescription;
    59 #endif
    6052
    6153    // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
     
    130122    };
    131123
     124#if PLATFORM(MAC)
     125    typedef NSMenuItem* PlatformMenuItemDescription;
     126#elif PLATFORM(WIN)
     127    typedef LPMENUITEMINFO PlatformMenuItemDescription;
     128#elif PLATFORM(QT)
     129    struct PlatformMenuItemDescriptionType {
     130        PlatformMenuItemDescriptionType() : qaction(0), menu(0), action(ContextMenuItemTagNoAction), type(ActionType), subMenu(0) {}
     131        QAction *qaction;
     132        QMenu *menu;
     133        ContextMenuAction action;
     134        QString title;
     135        ContextMenuItemType type;
     136        PlatformMenuDescription subMenu;
     137    };
     138    typedef PlatformMenuItemDescriptionType* PlatformMenuItemDescription;
     139#elif PLATFORM(GDK)
     140    typedef GtkMenuItem* PlatformMenuItemDescription;
     141#endif
     142
    132143    class ContextMenuItem {
    133144    public:
  • trunk/WebCore/platform/qt/ContextMenuItemQt.cpp

    r18975 r24131  
    11/*
    22 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
     3 * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2627#include "config.h"
    2728#include "ContextMenuItem.h"
    28 
    2929#include "ContextMenu.h"
    3030
     
    3333ContextMenuItem::ContextMenuItem(ContextMenu* subMenu)
    3434{
     35    m_platformDescription = new PlatformMenuItemDescriptionType;
    3536}
    3637
     
    3839                                 const String& title, ContextMenu* subMenu)
    3940{
     41    m_platformDescription = new PlatformMenuItemDescriptionType;
     42    m_platformDescription->type = type;
     43    m_platformDescription->action = action;
     44    m_platformDescription->title = title;
    4045}
    4146
    4247ContextMenuItem::~ContextMenuItem()
    4348{
     49    delete m_platformDescription;
    4450}
    4551
    4652PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
    4753{
    48     return PlatformMenuItemDescription();
     54    return m_platformDescription;
    4955}
    5056
    5157ContextMenuItemType ContextMenuItem::type() const
    5258{
    53     return ActionType;
     59    return m_platformDescription->type;
    5460}
    5561
    56 void ContextMenuItem::setType(ContextMenuItemType)
     62void ContextMenuItem::setType(ContextMenuItemType type)
    5763{
     64    m_platformDescription->type = type;
    5865}
    5966
    6067ContextMenuAction ContextMenuItem::action() const
    6168{
    62     return ContextMenuAction();
     69    return m_platformDescription->action;
    6370}
    6471
    6572void ContextMenuItem::setAction(ContextMenuAction action)
    6673{
     74    m_platformDescription->action = action;
    6775}
    6876
    6977String ContextMenuItem::title() const
    7078{
    71     return String();
     79    return m_platformDescription->title;
    7280}
    7381
    7482void ContextMenuItem::setTitle(const String& title)
    7583{
     84#ifndef QT_NO_MENU
     85    m_platformDescription->title = title;
     86    if (m_platformDescription->qaction)
     87        m_platformDescription->qaction->setText(title);
     88#endif
    7689}
    7790
     
    7992PlatformMenuDescription ContextMenuItem::platformSubMenu() const
    8093{
    81     return PlatformMenuDescription();
     94    return m_platformDescription->subMenu;
    8295}
    8396
    8497void ContextMenuItem::setSubMenu(ContextMenu* menu)
    8598{
     99#ifndef QT_NO_MENU
     100    m_platformDescription->subMenu = menu->platformDescription();
     101#endif
    86102}
    87103
    88 void ContextMenuItem::setChecked(bool)
     104void ContextMenuItem::setChecked(bool on)
    89105{
     106#ifndef QT_NO_MENU
     107    if (m_platformDescription->qaction) {
     108        m_platformDescription->qaction->setCheckable(true);
     109        m_platformDescription->qaction->setChecked(on);
     110    }
     111#endif
    90112}
    91113
    92 void ContextMenuItem::setEnabled(bool)
     114void ContextMenuItem::setEnabled(bool on)
    93115{
     116#ifndef QT_NO_MENU
     117    if (m_platformDescription->qaction)
     118        m_platformDescription->qaction->setEnabled(on);
     119#endif
    94120}
    95121
    96122bool ContextMenuItem::enabled() const
    97123{
    98     return true;
     124#ifndef QT_NO_MENU
     125    if (m_platformDescription->qaction)
     126        return m_platformDescription->qaction->isEnabled();
     127#endif
     128    return false;
    99129}
    100130
    101131}
     132// vim: ts=4 sw=4 et
  • trunk/WebCore/platform/qt/ContextMenuQt.cpp

    r23527 r24131  
    11/*
    22 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
     3 * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2627#include "config.h"
    2728#include "ContextMenu.h"
     29#include "MenuEventProxy.h"
    2830
    2931#include <wtf/Assertions.h>
    3032
    31 #include <QMenu>
    3233#include <QAction>
     34
     35#include <qwebframe.h>
     36#include <qwebpage.h>
     37#include <FrameLoaderClientQt.h>
     38#include <Document.h>
     39#include <Frame.h>
     40#include <FrameLoader.h>
     41#include <FrameLoaderClient.h>
    3342
    3443namespace WebCore {
    3544
    3645ContextMenu::ContextMenu(const HitTestResult& result)
    37     : m_hitTestResult(result), m_menu(0)
     46    : m_hitTestResult(result)
    3847{
     48#ifndef QT_NO_MENU
     49    m_menu = new QMenu;
     50    //qDebug("Create menu(%p) %p", this, (QMenu*)m_menu);
     51    m_proxy = new MenuEventProxy(this);
     52#endif
    3953}
    4054
    4155ContextMenu::~ContextMenu()
    4256{
     57#ifndef QT_NO_MENU
     58    //qDebug("Destroy menu(%p) %p", this, (QMenu*)m_menu);
     59    delete m_menu;
     60    m_menu = 0;
     61    delete m_proxy;
     62    m_proxy = 0;
     63#endif
    4364}
    4465
    4566void ContextMenu::appendItem(ContextMenuItem& item)
    4667{
    47     if (!m_menu)
    48         m_menu = new QMenu();
    49 
    50     QAction* action  = m_menu->addAction(item.title());
     68    insertItem(999999, item); // yuck!  Fix this API!!
    5169}
    5270
    5371unsigned ContextMenu::itemCount() const
    5472{
    55     // FIXME: This method is silly
    56     return 1;
     73#ifndef QT_NO_MENU
     74    return m_menu->actions().count();
     75#else
     76    return 0;
     77#endif
    5778}
    5879
    5980void ContextMenu::insertItem(unsigned position, ContextMenuItem& item)
    6081{
    61     // FIXME: Another silly method
    62     appendItem(item);
     82#ifndef QT_NO_MENU
     83    int id;
     84    QAction *action;
     85    QAction *before = 0;
     86    int p = position;
     87    if (p == 999999)
     88        p = -1;
     89    if (p >= 0)
     90        before = m_menu->actions()[p];
     91
     92    switch (item.type()) {
     93        case ActionType:
     94            if (!item.title().isEmpty()) {
     95                action = m_menu->addAction((QString)item.title());
     96                m_menu->removeAction(action);
     97                m_menu->insertAction(before, action);
     98                QObject::connect(m_menu, SIGNAL(triggered(QAction *)), m_proxy, SLOT(trigger(QAction *)));
     99            }
     100            break;
     101        case SeparatorType:
     102            action = m_menu->insertSeparator(before);
     103            break;
     104        case SubmenuType:
     105            if (!item.title().isEmpty()) {
     106                QMenu *m = item.platformSubMenu();
     107                if (!m)
     108                    return;
     109                action = m_menu->insertMenu(before, m);
     110                action->setText(item.title());
     111            }
     112            break;
     113        default:
     114            return;
     115    }
     116    if (action) {
     117        m_proxy->map(action, item.action());
     118        item.releasePlatformDescription()->qaction = action;
     119    }
     120#endif
    63121}
    64122
    65123void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)
    66124{
    67     delete m_menu;
    68     m_menu = static_cast<QMenu*>(menu);
     125#ifndef QT_NO_MENU
     126    //qDebug("Switch menu(%p) %p to %p", this, (QMenu*)m_menu, menu);
     127    if (menu == 0) {
     128        FrameLoaderClient *f = m_hitTestResult.innerNode()->document()->frame()->loader()->client();
     129        QWidget *page = static_cast<FrameLoaderClientQt*>(f)->webFrame()->page();
     130        m_menu->exec(page->mapToGlobal(m_hitTestResult.point()));
     131    }
     132    if (menu != m_menu) {
     133        delete m_menu;
     134        m_menu = menu;
     135    }
     136#endif
    69137}
    70138
     139PlatformMenuDescription ContextMenu::platformDescription() const
     140{
     141    return m_menu;
    71142}
     143
     144
     145}
     146// vim: ts=4 sw=4 et
Note: See TracChangeset for help on using the changeset viewer.