Commit 6f41c96c authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

2009-12-11 Pavel Feldman <pfeldman@chromium.org>

        Reviewed by Timothy Hatcher.

        Web Inspector: Do not use ContextMenuItem as value type in custom
        context menu implementation.

        https://bugs.webkit.org/show_bug.cgi?id=32411

        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/JSInspectorFrontendHostCustom.cpp:
        (WebCore::JSInspectorFrontendHost::showContextMenu):
        * inspector/InspectorFrontendHost.cpp:
        (WebCore::InspectorFrontendHost::InspectorFrontendHost):
        (WebCore::InspectorFrontendHost::~InspectorFrontendHost):
        (WebCore::InspectorFrontendHost::showContextMenu):
        (WebCore::InspectorFrontendHost::contextMenuCleared):
        * inspector/InspectorFrontendHost.h:
        (WebCore::InspectorFrontendHost::MenuProvider::create):
        (WebCore::InspectorFrontendHost::MenuProvider::~MenuProvider):
        (WebCore::InspectorFrontendHost::MenuProvider::disconnect):
        (WebCore::InspectorFrontendHost::MenuProvider::populateContextMenu):
        (WebCore::InspectorFrontendHost::MenuProvider::contextMenuCleared):
        (WebCore::InspectorFrontendHost::MenuProvider::MenuProvider):
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::ContextMenuController):
        (WebCore::ContextMenuController::clearContextMenu):
        (WebCore::ContextMenuController::showContextMenu):
        (WebCore::ContextMenuController::contextMenuItemSelected):
        * page/ContextMenuController.h:
        * page/ContextMenuProvider.h: Added.
        (WebCore::ContextMenuProvider::~ContextMenuProvider):
        * page/ContextMenuSelectionHandler.h: Removed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51993 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fda388a5
2009-12-11 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Timothy Hatcher.
Web Inspector: Do not use ContextMenuItem as value type in custom
context menu implementation.
https://bugs.webkit.org/show_bug.cgi?id=32411
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSInspectorFrontendHostCustom.cpp:
(WebCore::JSInspectorFrontendHost::showContextMenu):
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::InspectorFrontendHost):
(WebCore::InspectorFrontendHost::~InspectorFrontendHost):
(WebCore::InspectorFrontendHost::showContextMenu):
(WebCore::InspectorFrontendHost::contextMenuCleared):
* inspector/InspectorFrontendHost.h:
(WebCore::InspectorFrontendHost::MenuProvider::create):
(WebCore::InspectorFrontendHost::MenuProvider::~MenuProvider):
(WebCore::InspectorFrontendHost::MenuProvider::disconnect):
(WebCore::InspectorFrontendHost::MenuProvider::populateContextMenu):
(WebCore::InspectorFrontendHost::MenuProvider::contextMenuCleared):
(WebCore::InspectorFrontendHost::MenuProvider::MenuProvider):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::ContextMenuController):
(WebCore::ContextMenuController::clearContextMenu):
(WebCore::ContextMenuController::showContextMenu):
(WebCore::ContextMenuController::contextMenuItemSelected):
* page/ContextMenuController.h:
* page/ContextMenuProvider.h: Added.
(WebCore::ContextMenuProvider::~ContextMenuProvider):
* page/ContextMenuSelectionHandler.h: Removed.
2009-12-11 Simon Hausmann <hausmann@webkit.org>, Kim Grönholm <kim.gronholm@nomovok.com>
Reviewed by Antti Koivisto.
......@@ -1318,7 +1318,7 @@ webcore_sources += \
WebCore/page/ContextMenuClient.h \
WebCore/page/ContextMenuController.cpp \
WebCore/page/ContextMenuController.h \
WebCore/page/ContextMenuSelectionHandler.h \
WebCore/page/ContextMenuProvider.h \
WebCore/page/Coordinates.h \
WebCore/page/DOMSelection.cpp \
WebCore/page/DOMSelection.h \
......
......@@ -1759,7 +1759,7 @@
'page/ContextMenuClient.h',
'page/ContextMenuController.cpp',
'page/ContextMenuController.h',
'page/ContextMenuSelectionHandler.h',
'page/ContextMenuProvider.h',
'page/DOMSelection.cpp',
'page/DOMSelection.h',
'page/DOMTimer.cpp',
......
......@@ -1852,7 +1852,7 @@ HEADERS += \
page/Chrome.h \
page/Console.h \
page/ContextMenuController.h \
page/ContextMenuSelectionHandler.h \
page/ContextMenuProvider.h \
page/Coordinates.h \
page/DOMSelection.h \
page/DOMTimer.h \
......
......@@ -20527,7 +20527,7 @@
>
</File>
<File
RelativePath="..\page\ContextMenuSelectionHandler.h"
RelativePath="..\page\ContextMenuProvider.h"
>
</File>
<File
......
......@@ -1251,7 +1251,7 @@
7A74ECBA101839A600BF939E /* InspectorBackend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A74ECB8101839A500BF939E /* InspectorBackend.cpp */; };
7A74ECBB101839A600BF939E /* InspectorBackend.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A74ECB9101839A600BF939E /* InspectorBackend.h */; };
7A74ECBD101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A74ECBC101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp */; };
7ADE722610CBBB9B006B3B3A /* ContextMenuSelectionHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 7ADE722510CBBB9B006B3B3A /* ContextMenuSelectionHandler.h */; };
7ADE722610CBBB9B006B3B3A /* ContextMenuProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */; };
7AED3E050FBB1EAA00D2B03C /* InspectorFrontend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AED3E030FBB1EAA00D2B03C /* InspectorFrontend.cpp */; };
7AED3E060FBB1EAA00D2B03C /* InspectorFrontend.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AED3E040FBB1EAA00D2B03C /* InspectorFrontend.h */; };
84224183107E77F400766A87 /* JSSVGFEMorphologyElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84224181107E77F400766A87 /* JSSVGFEMorphologyElement.cpp */; };
......@@ -6591,7 +6591,7 @@
7A74ECB8101839A500BF939E /* InspectorBackend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorBackend.cpp; sourceTree = "<group>"; };
7A74ECB9101839A600BF939E /* InspectorBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorBackend.h; sourceTree = "<group>"; };
7A74ECBC101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInspectorFrontendHostCustom.cpp; sourceTree = "<group>"; };
7ADE722510CBBB9B006B3B3A /* ContextMenuSelectionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextMenuSelectionHandler.h; sourceTree = "<group>"; };
7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextMenuProvider.h; sourceTree = "<group>"; };
7AED3E030FBB1EAA00D2B03C /* InspectorFrontend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorFrontend.cpp; sourceTree = "<group>"; };
7AED3E040FBB1EAA00D2B03C /* InspectorFrontend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontend.h; sourceTree = "<group>"; };
84224181107E77F400766A87 /* JSSVGFEMorphologyElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGFEMorphologyElement.cpp; sourceTree = "<group>"; };
......@@ -11241,7 +11241,7 @@
065AD4F20B0C2EDA005A2B1D /* ContextMenuClient.h */,
065AD4F30B0C2EDA005A2B1D /* ContextMenuController.cpp */,
065AD4F40B0C2EDA005A2B1D /* ContextMenuController.h */,
7ADE722510CBBB9B006B3B3A /* ContextMenuSelectionHandler.h */,
7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */,
FE6FD4850F676E5700092873 /* Coordinates.h */,
FE6FD4860F676E5700092873 /* Coordinates.idl */,
BC5A86810C33676000EEA649 /* DOMSelection.cpp */,
......@@ -18243,7 +18243,7 @@
7A0E771F10C00DB100A0276E /* JSInspectorFrontendHost.h in Headers */,
F4EAF4AF10C742B1009100D3 /* OpenTypeSanitizer.h in Headers */,
599D1E3310C97D6E00E0EF12 /* jni_utility_private.h in Headers */,
7ADE722610CBBB9B006B3B3A /* ContextMenuSelectionHandler.h in Headers */,
7ADE722610CBBB9B006B3B3A /* ContextMenuProvider.h in Headers */,
0C3F1F5B10C8871200D72CE1 /* WebGLUniformLocation.h in Headers */,
0C45342810CDBBFA00869157 /* JSWebGLUniformLocation.h in Headers */,
);
......@@ -101,17 +101,17 @@ JSValue JSInspectorFrontendHost::showContextMenu(ExecState* execState, const Arg
Event* event = toEvent(args.at(0));
JSArray* array = asArray(args.at(1));
Vector<ContextMenuItem> items;
Vector<ContextMenuItem*> items;
for (size_t i = 0; i < array->length(); ++i) {
JSObject* item = asObject(array->getIndex(i));
JSValue label = item->get(execState, Identifier(execState, "label"));
JSValue id = item->get(execState, Identifier(execState, "id"));
if (label.isUndefined() || id.isUndefined())
items.append(ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
items.append(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
else {
ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(execState));
items.append(ContextMenuItem(ActionType, typedId, label.toString(execState)));
items.append(new ContextMenuItem(ActionType, typedId, label.toString(execState)));
}
}
......
......@@ -35,7 +35,7 @@
#include "ContextMenu.h"
#include "ContextMenuItem.h"
#include "ContextMenuController.h"
#include "ContextMenuSelectionHandler.h"
#include "ContextMenuProvider.h"
#include "Element.h"
#include "Frame.h"
#include "FrameLoader.h"
......@@ -56,13 +56,13 @@ namespace WebCore {
InspectorFrontendHost::InspectorFrontendHost(InspectorController* inspectorController, InspectorClient* client)
: m_inspectorController(inspectorController)
, m_client(client)
, m_menuSelectionHandler(MenuSelectionHandler::create(this))
{
}
InspectorFrontendHost::~InspectorFrontendHost()
{
m_menuSelectionHandler->disconnect();
if (m_menuProvider)
m_menuProvider->disconnect();
}
void InspectorFrontendHost::loaded()
......@@ -208,15 +208,17 @@ void InspectorFrontendHost::setSetting(const String& key, const String& value)
m_inspectorController->setSetting(key, value);
}
void InspectorFrontendHost::showContextMenu(Event* event, Vector<ContextMenuItem>& items)
void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMenuItem*>& items)
{
if (!m_inspectorController)
return;
if (!m_inspectorController->windowVisible())
return;
m_menuProvider = MenuProvider::create(this, items);
ContextMenuController* menuController = m_inspectorController->m_page->contextMenuController();
menuController->showContextMenu(event, items, m_menuSelectionHandler);
menuController->showContextMenu(event, m_menuProvider);
}
void InspectorFrontendHost::contextMenuItemSelected(ContextMenuItem* item)
......@@ -229,6 +231,7 @@ void InspectorFrontendHost::contextMenuItemSelected(ContextMenuItem* item)
void InspectorFrontendHost::contextMenuCleared()
{
m_menuProvider = 0;
if (m_inspectorController && m_inspectorController->windowVisible())
m_inspectorController->m_frontend->contextMenuCleared();
}
......
......@@ -30,7 +30,8 @@
#define InspectorFrontendHost_h
#include "Console.h"
#include "ContextMenuSelectionHandler.h"
#include "ContextMenu.h"
#include "ContextMenuProvider.h"
#include "InspectorController.h"
#include "PlatformString.h"
......@@ -79,21 +80,31 @@ public:
void setSetting(const String& key, const String& value);
// Called from [Custom] implementations.
void showContextMenu(Event*, Vector<ContextMenuItem>& items);
void contextMenuItemSelected(ContextMenuItem*);
void contextMenuCleared();
void showContextMenu(Event*, const Vector<ContextMenuItem*>& items);
private:
class MenuSelectionHandler : public ContextMenuSelectionHandler {
class MenuProvider : public ContextMenuProvider {
public:
static PassRefPtr<MenuSelectionHandler> create(InspectorFrontendHost* frontendHost)
static PassRefPtr<MenuProvider> create(InspectorFrontendHost* frontendHost, const Vector<ContextMenuItem*>& items)
{
return adoptRef(new MenuProvider(frontendHost, items));
}
virtual ~MenuProvider()
{
return adoptRef(new MenuSelectionHandler(frontendHost));
contextMenuCleared();
}
virtual ~MenuSelectionHandler() { }
void disconnect()
{
m_frontendHost = 0;
}
void disconnect() { m_frontendHost = 0; }
virtual void populateContextMenu(ContextMenu* menu)
{
for (size_t i = 0; i < m_items.size(); ++i)
menu->appendItem(*m_items[i]);
}
virtual void contextMenuItemSelected(ContextMenuItem* item)
{
......@@ -105,19 +116,26 @@ private:
{
if (m_frontendHost)
m_frontendHost->contextMenuCleared();
deleteAllValues(m_items);
m_items.clear();
}
private:
MenuSelectionHandler(InspectorFrontendHost* frontendHost)
: m_frontendHost(frontendHost) { }
MenuProvider(InspectorFrontendHost* frontendHost, const Vector<ContextMenuItem*>& items)
: m_frontendHost(frontendHost)
, m_items(items) { }
InspectorFrontendHost* m_frontendHost;
Vector<ContextMenuItem*> m_items;
};
InspectorFrontendHost(InspectorController* inspectorController, InspectorClient* client);
void contextMenuItemSelected(ContextMenuItem*);
void contextMenuCleared();
InspectorController* m_inspectorController;
InspectorClient* m_client;
RefPtr<MenuSelectionHandler> m_menuSelectionHandler;
RefPtr<MenuProvider> m_menuProvider;
};
} // namespace WebCore
......
......@@ -31,7 +31,7 @@
#include "Chrome.h"
#include "ContextMenu.h"
#include "ContextMenuClient.h"
#include "ContextMenuSelectionHandler.h"
#include "ContextMenuProvider.h"
#include "Document.h"
#include "DocumentFragment.h"
#include "DocumentLoader.h"
......@@ -67,7 +67,6 @@ ContextMenuController::ContextMenuController(Page* page, ContextMenuClient* clie
: m_page(page)
, m_client(client)
, m_contextMenu(0)
, m_selectionHandler(0)
{
ASSERT_ARG(page, page);
ASSERT_ARG(client, client);
......@@ -81,9 +80,9 @@ ContextMenuController::~ContextMenuController()
void ContextMenuController::clearContextMenu()
{
m_contextMenu.set(0);
if (m_selectionHandler)
m_selectionHandler->contextMenuCleared();
m_selectionHandler = 0;
if (m_menuProvider)
m_menuProvider->contextMenuCleared();
m_menuProvider = 0;
}
void ContextMenuController::handleContextMenuEvent(Event* event)
......@@ -95,19 +94,17 @@ void ContextMenuController::handleContextMenuEvent(Event* event)
showContextMenu(event);
}
void ContextMenuController::showContextMenu(Event* event, Vector<ContextMenuItem>& items, PassRefPtr<ContextMenuSelectionHandler> selectionHandler)
void ContextMenuController::showContextMenu(Event* event, PassRefPtr<ContextMenuProvider> menuProvider)
{
m_selectionHandler = selectionHandler;
m_menuProvider = menuProvider;
m_contextMenu.set(createContextMenu(event));
if (!m_contextMenu) {
clearContextMenu();
return;
}
for (size_t i = 0; i < items.size(); ++i) {
ContextMenuItem& item = items[i];
m_contextMenu->appendItem(item);
}
m_menuProvider->populateContextMenu(m_contextMenu.get());
showContextMenu(event);
}
......@@ -156,8 +153,8 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
}
if (item->action() >= ContextMenuItemBaseCustomTag) {
ASSERT(m_selectionHandler);
m_selectionHandler->contextMenuItemSelected(item);
ASSERT(m_menuProvider);
m_menuProvider->contextMenuItemSelected(item);
return;
}
......
......@@ -30,14 +30,13 @@
#include <wtf/OwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class ContextMenu;
class ContextMenuClient;
class ContextMenuItem;
class ContextMenuSelectionHandler;
class ContextMenuProvider;
class Event;
class Page;
......@@ -52,7 +51,7 @@ namespace WebCore {
void clearContextMenu();
void handleContextMenuEvent(Event*);
void showContextMenu(Event*, Vector<ContextMenuItem>&, PassRefPtr<ContextMenuSelectionHandler>);
void showContextMenu(Event*, PassRefPtr<ContextMenuProvider>);
void contextMenuItemSelected(ContextMenuItem*);
......@@ -63,7 +62,7 @@ namespace WebCore {
Page* m_page;
ContextMenuClient* m_client;
OwnPtr<ContextMenu> m_contextMenu;
RefPtr<ContextMenuSelectionHandler> m_selectionHandler;
RefPtr<ContextMenuProvider> m_menuProvider;
};
}
......
......@@ -28,24 +28,25 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ContextMenuSelectionHandler_h
#define ContextMenuSelectionHandler_h
#ifndef ContextMenuProvider_h
#define ContextMenuProvider_h
#include <wtf/RefCounted.h>
namespace WebCore {
class ContextMenuItem;
class ContextMenu;
class ContextMenuItem;
class ContextMenuSelectionHandler : public RefCounted<ContextMenuSelectionHandler> {
public:
ContextMenuSelectionHandler() { }
virtual ~ContextMenuSelectionHandler() { };
class ContextMenuProvider : public RefCounted<ContextMenuProvider> {
public:
virtual ~ContextMenuProvider() { };
virtual void contextMenuItemSelected(ContextMenuItem*) = 0;
virtual void contextMenuCleared() = 0;
};
virtual void populateContextMenu(ContextMenu*) = 0;
virtual void contextMenuItemSelected(ContextMenuItem*) = 0;
virtual void contextMenuCleared() = 0;
};
}
#endif // ContextMenuSelectionHandler_h
#endif // ContextMenuProvider_h
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