Commit 0c88dfa8 authored by hausmann's avatar hausmann
Browse files

Fix ContextMenu allocation in the Qt port.

Store all items and submenus value based in ContextMenu and ContextMenuItem.
That fixes the crashes when the context menu was populated with sub-menus because
of the use of temporary ContextMenu objects like this:

ContextMenu subMenu(...);
subMenu.appendItem(...);
subMenu.appendItem(...);

subMenuItem.setSubMenu(&subMenu); // temporary pointer, need to _copy_ contents

Signed-off-by: Holger


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27644 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4c654395
2007-11-09 Simon Hausmann <hausmann@kde.org>
Reviewed by Holger.
Fix ContextMenu allocation in the Qt port.
Store all items and submenus value based in ContextMenu and ContextMenuItem.
That fixes the crashes when the context menu was populated with sub-menus because
of the use of temporary ContextMenu objects like this:
ContextMenu subMenu(...);
subMenu.appendItem(...);
subMenu.appendItem(...);
subMenuItem.setSubMenu(&subMenu); // temporary pointer, need to _copy_ contents
* platform/ContextMenu.h:
* platform/ContextMenuItem.h:
* platform/PlatformMenuDescription.h:
* platform/qt/ContextMenuItemQt.cpp:
(WebCore::ContextMenuItem::ContextMenuItem):
(WebCore::ContextMenuItem::platformSubMenu):
* platform/qt/ContextMenuQt.cpp:
(WebCore::ContextMenu::ContextMenu):
(WebCore::ContextMenu::~ContextMenu):
(WebCore::ContextMenu::appendItem):
(WebCore::ContextMenu::itemCount):
2007-11-09 Peter Kasting <zerodpx@gmail.com>
Reviewed by Mark Rowe.
......
......@@ -77,7 +77,7 @@ class MenuEventProxy;
// Keep this in sync with the PlatformMenuDescription typedef
RetainPtr<NSMutableArray> m_platformDescription;
#elif PLATFORM(QT)
PlatformMenuDescription m_items;
QList<ContextMenuItem> m_items;
#else
PlatformMenuDescription m_platformDescription;
#endif
......
......@@ -132,7 +132,6 @@ namespace WebCore {
PlatformMenuItemDescription()
: type(ActionType),
action(ContextMenuItemTagNoAction),
subMenu(0),
checked(false),
enabled(true)
{}
......@@ -140,7 +139,7 @@ namespace WebCore {
ContextMenuItemType type;
ContextMenuAction action;
String title;
ContextMenu *subMenu;
QList<ContextMenuItem> subMenuItems;
bool checked;
bool enabled;
};
......
......@@ -50,7 +50,7 @@ namespace WebCore {
typedef HMENU PlatformMenuDescription;
#elif PLATFORM(QT)
class ContextMenuItem;
typedef QList<ContextMenuItem>* PlatformMenuDescription;
typedef const QList<ContextMenuItem>* PlatformMenuDescription;
#elif PLATFORM(GTK)
typedef GtkMenu* PlatformMenuDescription;
#elif PLATFORM(WX)
......
......@@ -34,7 +34,8 @@ ContextMenuItem::ContextMenuItem(ContextMenu* subMenu)
{
m_platformDescription.type = SubmenuType;
m_platformDescription.action = ContextMenuItemTagNoAction;
m_platformDescription.subMenu = subMenu;
if (subMenu)
setSubMenu(subMenu);
}
ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action,
......@@ -43,7 +44,8 @@ ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction act
m_platformDescription.type = type;
m_platformDescription.action = action;
m_platformDescription.title = title;
m_platformDescription.subMenu = subMenu;
if (subMenu)
setSubMenu(subMenu);
}
ContextMenuItem::~ContextMenuItem()
......@@ -88,12 +90,12 @@ void ContextMenuItem::setTitle(const String& title)
PlatformMenuDescription ContextMenuItem::platformSubMenu() const
{
return m_platformDescription.subMenu->platformDescription();
return &m_platformDescription.subMenuItems;
}
void ContextMenuItem::setSubMenu(ContextMenu* menu)
{
m_platformDescription.subMenu = menu;
m_platformDescription.subMenuItems = *menu->platformDescription();
}
void ContextMenuItem::setChecked(bool on)
......
......@@ -41,27 +41,25 @@ namespace WebCore {
ContextMenu::ContextMenu(const HitTestResult& result)
: m_hitTestResult(result)
{
m_items = new QList<ContextMenuItem>();
}
ContextMenu::~ContextMenu()
{
delete m_items;
}
void ContextMenu::appendItem(ContextMenuItem& item)
{
m_items->append(item);
m_items.append(item);
}
unsigned ContextMenu::itemCount() const
{
return m_items->count();
return m_items.count();
}
void ContextMenu::insertItem(unsigned position, ContextMenuItem& item)
{
m_items->insert(position, item);
m_items.insert(position, item);
}
void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)
......@@ -71,7 +69,7 @@ void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)
PlatformMenuDescription ContextMenu::platformDescription() const
{
return m_items;
return &m_items;
}
PlatformMenuDescription ContextMenu::releasePlatformDescription()
......
......@@ -159,7 +159,7 @@ static QWebPage::WebAction webActionForContextMenuAction(WebCore::ContextMenuAct
return QWebPage::NoWebAction;
}
QMenu *QWebPagePrivate::createContextMenu(QList<WebCore::ContextMenuItem> *items)
QMenu *QWebPagePrivate::createContextMenu(const QList<WebCore::ContextMenuItem> *items)
{
QMenu *menu = new QMenu;
for (int i = 0; i < items->count(); ++i) {
......@@ -845,7 +845,7 @@ void QWebPage::contextMenuEvent(QContextMenuEvent *ev)
QWebPageContext oldContext = d->currentContext;
d->currentContext = QWebPageContext(menu->hitTestResult());
QList<ContextMenuItem> *items = menu->platformDescription();
const QList<ContextMenuItem> *items = menu->platformDescription();
QMenu *qmenu = d->createContextMenu(items);
if (qmenu) {
qmenu->exec(ev->globalPos());
......
......@@ -81,7 +81,7 @@ public:
QWebPagePrivate(QWebPage *);
~QWebPagePrivate();
void createMainFrame();
QMenu *createContextMenu(QList<WebCore::ContextMenuItem> *items);
QMenu *createContextMenu(const QList<WebCore::ContextMenuItem> *items);
QWebFrame *frameAt(const QPoint &pos) const;
......
2007-11-09 Simon Hausmann <hausmann@kde.org>
Reviewed by Holger.
Fix ContextMenu allocation in the Qt port.
Store all items and submenus value based in ContextMenu and ContextMenuItem.
That fixes the crashes when the context menu was populated with sub-menus because
of the use of temporary ContextMenu objects like this:
ContextMenu subMenu(...);
subMenu.appendItem(...);
subMenu.appendItem(...);
subMenuItem.setSubMenu(&subMenu); // temporary pointer, need to _copy_ contents
* Api/qwebpage.cpp:
(QWebPage::contextMenuEvent):
* Api/qwebpage_p.h:
2007-11-09 Simon Hausmann <hausmann@kde.org>
Reviewed by Holger.
......
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