Changeset 24131 in webkit
- Timestamp:
- Jul 9, 2007 6:43:21 PM (17 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r24127 r24131 1 2007-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 1 35 2007-07-09 Anders Carlsson <andersca@apple.com> 2 36 -
trunk/WebCore/WebCore.pro
r24088 r24131 732 732 qt-port:HEADERS += \ 733 733 $$PWD/platform/qt/QWebPopup.h \ 734 $$PWD/platform/qt/MenuEventProxy.h \ 734 735 $$PWD/platform/qt/SharedTimerQt.h \ 735 736 $$PWD/../WebKitQt/Api/qwebframe.h \ -
trunk/WebCore/platform/ContextMenu.h
r23677 r24131 37 37 #elif PLATFORM(QT) 38 38 #include <QMenu> 39 typedef QMenu* PlatformMenuDescription;40 39 #endif 41 40 42 41 namespace WebCore { 42 class MenuEventProxy; 43 43 44 44 class ContextMenuController; … … 76 76 #elif PLATFORM(QT) 77 77 QMenu *m_menu; 78 MenuEventProxy *m_proxy; 78 79 #else 79 80 PlatformMenuDescription m_platformDescription; -
trunk/WebCore/platform/ContextMenuItem.h
r23677 r24131 43 43 #elif PLATFORM(GDK) 44 44 typedef struct _GtkMenuItem GtkMenuItem; 45 #elif PLATFORM(QT) 46 #include <QAction> 45 47 #endif 46 48 … … 48 50 49 51 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 #endif60 52 61 53 // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the … … 130 122 }; 131 123 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 132 143 class ContextMenuItem { 133 144 public: -
trunk/WebCore/platform/qt/ContextMenuItemQt.cpp
r18975 r24131 1 1 /* 2 2 * Copyright (C) 2006 Zack Rusin <zack@kde.org> 3 * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net> 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 26 27 #include "config.h" 27 28 #include "ContextMenuItem.h" 28 29 29 #include "ContextMenu.h" 30 30 … … 33 33 ContextMenuItem::ContextMenuItem(ContextMenu* subMenu) 34 34 { 35 m_platformDescription = new PlatformMenuItemDescriptionType; 35 36 } 36 37 … … 38 39 const String& title, ContextMenu* subMenu) 39 40 { 41 m_platformDescription = new PlatformMenuItemDescriptionType; 42 m_platformDescription->type = type; 43 m_platformDescription->action = action; 44 m_platformDescription->title = title; 40 45 } 41 46 42 47 ContextMenuItem::~ContextMenuItem() 43 48 { 49 delete m_platformDescription; 44 50 } 45 51 46 52 PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription() 47 53 { 48 return PlatformMenuItemDescription();54 return m_platformDescription; 49 55 } 50 56 51 57 ContextMenuItemType ContextMenuItem::type() const 52 58 { 53 return ActionType;59 return m_platformDescription->type; 54 60 } 55 61 56 void ContextMenuItem::setType(ContextMenuItemType )62 void ContextMenuItem::setType(ContextMenuItemType type) 57 63 { 64 m_platformDescription->type = type; 58 65 } 59 66 60 67 ContextMenuAction ContextMenuItem::action() const 61 68 { 62 return ContextMenuAction();69 return m_platformDescription->action; 63 70 } 64 71 65 72 void ContextMenuItem::setAction(ContextMenuAction action) 66 73 { 74 m_platformDescription->action = action; 67 75 } 68 76 69 77 String ContextMenuItem::title() const 70 78 { 71 return String();79 return m_platformDescription->title; 72 80 } 73 81 74 82 void ContextMenuItem::setTitle(const String& title) 75 83 { 84 #ifndef QT_NO_MENU 85 m_platformDescription->title = title; 86 if (m_platformDescription->qaction) 87 m_platformDescription->qaction->setText(title); 88 #endif 76 89 } 77 90 … … 79 92 PlatformMenuDescription ContextMenuItem::platformSubMenu() const 80 93 { 81 return PlatformMenuDescription();94 return m_platformDescription->subMenu; 82 95 } 83 96 84 97 void ContextMenuItem::setSubMenu(ContextMenu* menu) 85 98 { 99 #ifndef QT_NO_MENU 100 m_platformDescription->subMenu = menu->platformDescription(); 101 #endif 86 102 } 87 103 88 void ContextMenuItem::setChecked(bool )104 void ContextMenuItem::setChecked(bool on) 89 105 { 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 90 112 } 91 113 92 void ContextMenuItem::setEnabled(bool )114 void ContextMenuItem::setEnabled(bool on) 93 115 { 116 #ifndef QT_NO_MENU 117 if (m_platformDescription->qaction) 118 m_platformDescription->qaction->setEnabled(on); 119 #endif 94 120 } 95 121 96 122 bool ContextMenuItem::enabled() const 97 123 { 98 return true; 124 #ifndef QT_NO_MENU 125 if (m_platformDescription->qaction) 126 return m_platformDescription->qaction->isEnabled(); 127 #endif 128 return false; 99 129 } 100 130 101 131 } 132 // vim: ts=4 sw=4 et -
trunk/WebCore/platform/qt/ContextMenuQt.cpp
r23527 r24131 1 1 /* 2 2 * Copyright (C) 2006 Zack Rusin <zack@kde.org> 3 * Copyright (C) 2007 Staikos Computing Services Inc. <info@staikos.net> 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 26 27 #include "config.h" 27 28 #include "ContextMenu.h" 29 #include "MenuEventProxy.h" 28 30 29 31 #include <wtf/Assertions.h> 30 32 31 #include <QMenu>32 33 #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> 33 42 34 43 namespace WebCore { 35 44 36 45 ContextMenu::ContextMenu(const HitTestResult& result) 37 : m_hitTestResult(result) , m_menu(0)46 : m_hitTestResult(result) 38 47 { 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 39 53 } 40 54 41 55 ContextMenu::~ContextMenu() 42 56 { 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 43 64 } 44 65 45 66 void ContextMenu::appendItem(ContextMenuItem& item) 46 67 { 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!! 51 69 } 52 70 53 71 unsigned ContextMenu::itemCount() const 54 72 { 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 57 78 } 58 79 59 80 void ContextMenu::insertItem(unsigned position, ContextMenuItem& item) 60 81 { 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 63 121 } 64 122 65 123 void ContextMenu::setPlatformDescription(PlatformMenuDescription menu) 66 124 { 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 69 137 } 70 138 139 PlatformMenuDescription ContextMenu::platformDescription() const 140 { 141 return m_menu; 71 142 } 143 144 145 } 146 // vim: ts=4 sw=4 et
Note: See TracChangeset
for help on using the changeset viewer.