Changeset 51839 in webkit


Ignore:
Timestamp:
Dec 8, 2009 2:19:28 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

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

Reviewed by Timothy Hatcher.

Web Inspector: provide custom context menu in the front-end window.

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

  • English.lproj/localizedStrings.js:
  • GNUmakefile.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSInspectorFrontendHostCustom.cpp: (WebCore::JSInspectorFrontendHost::showContextMenu):
  • inspector/InspectorFrontend.cpp: (WebCore::InspectorFrontend::contextMenuItemSelected): (WebCore::InspectorFrontend::contextMenuCleared):
  • inspector/InspectorFrontend.h:
  • inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::InspectorFrontendHost): (WebCore::InspectorFrontendHost::~InspectorFrontendHost): (WebCore::InspectorFrontendHost::showContextMenu): (WebCore::InspectorFrontendHost::contextMenuItemSelected): (WebCore::InspectorFrontendHost::contextMenuCleared):
  • inspector/InspectorFrontendHost.h: (WebCore::InspectorFrontendHost::MenuSelectionHandler::create): (WebCore::InspectorFrontendHost::MenuSelectionHandler::~MenuSelectionHandler): (WebCore::InspectorFrontendHost::MenuSelectionHandler::disconnect): (WebCore::InspectorFrontendHost::MenuSelectionHandler::contextMenuItemSelected): (WebCore::InspectorFrontendHost::MenuSelectionHandler::contextMenuCleared): (WebCore::InspectorFrontendHost::MenuSelectionHandler::MenuSelectionHandler):
  • inspector/InspectorFrontendHost.idl:
  • inspector/front-end/ContextMenu.js: Added.
  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/inspector.html:
  • inspector/front-end/inspector.js: (WebInspector.loaded): (WebInspector.documentContextMenu):
  • page/ContextMenuController.cpp: (WebCore::ContextMenuController::ContextMenuController): (WebCore::ContextMenuController::clearContextMenu): (WebCore::ContextMenuController::handleContextMenuEvent): (WebCore::ContextMenuController::showContextMenu): (WebCore::ContextMenuController::createContextMenu): (WebCore::ContextMenuController::contextMenuItemSelected):
  • page/ContextMenuController.h:
  • page/ContextMenuSelectionHandler.h: Added. (WebCore::ContextMenuSelectionHandler::ContextMenuSelectionHandler): (WebCore::ContextMenuSelectionHandler::~ContextMenuSelectionHandler):
  • platform/ContextMenu.cpp: (WebCore::ContextMenu::checkOrEnableIfNeeded):
  • platform/ContextMenuItem.h:
Location:
trunk/WebCore
Files:
22 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r51838 r51839  
     12009-12-06  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: provide custom context menu in the front-end window.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=32200
     8
     9        * English.lproj/localizedStrings.js:
     10        * GNUmakefile.am:
     11        * WebCore.gypi:
     12        * WebCore.pro:
     13        * WebCore.vcproj/WebCore.vcproj:
     14        * WebCore.xcodeproj/project.pbxproj:
     15        * bindings/js/JSInspectorFrontendHostCustom.cpp:
     16        (WebCore::JSInspectorFrontendHost::showContextMenu):
     17        * inspector/InspectorFrontend.cpp:
     18        (WebCore::InspectorFrontend::contextMenuItemSelected):
     19        (WebCore::InspectorFrontend::contextMenuCleared):
     20        * inspector/InspectorFrontend.h:
     21        * inspector/InspectorFrontendHost.cpp:
     22        (WebCore::InspectorFrontendHost::InspectorFrontendHost):
     23        (WebCore::InspectorFrontendHost::~InspectorFrontendHost):
     24        (WebCore::InspectorFrontendHost::showContextMenu):
     25        (WebCore::InspectorFrontendHost::contextMenuItemSelected):
     26        (WebCore::InspectorFrontendHost::contextMenuCleared):
     27        * inspector/InspectorFrontendHost.h:
     28        (WebCore::InspectorFrontendHost::MenuSelectionHandler::create):
     29        (WebCore::InspectorFrontendHost::MenuSelectionHandler::~MenuSelectionHandler):
     30        (WebCore::InspectorFrontendHost::MenuSelectionHandler::disconnect):
     31        (WebCore::InspectorFrontendHost::MenuSelectionHandler::contextMenuItemSelected):
     32        (WebCore::InspectorFrontendHost::MenuSelectionHandler::contextMenuCleared):
     33        (WebCore::InspectorFrontendHost::MenuSelectionHandler::MenuSelectionHandler):
     34        * inspector/InspectorFrontendHost.idl:
     35        * inspector/front-end/ContextMenu.js: Added.
     36        * inspector/front-end/WebKit.qrc:
     37        * inspector/front-end/inspector.html:
     38        * inspector/front-end/inspector.js:
     39        (WebInspector.loaded):
     40        (WebInspector.documentContextMenu):
     41        * page/ContextMenuController.cpp:
     42        (WebCore::ContextMenuController::ContextMenuController):
     43        (WebCore::ContextMenuController::clearContextMenu):
     44        (WebCore::ContextMenuController::handleContextMenuEvent):
     45        (WebCore::ContextMenuController::showContextMenu):
     46        (WebCore::ContextMenuController::createContextMenu):
     47        (WebCore::ContextMenuController::contextMenuItemSelected):
     48        * page/ContextMenuController.h:
     49        * page/ContextMenuSelectionHandler.h: Added.
     50        (WebCore::ContextMenuSelectionHandler::ContextMenuSelectionHandler):
     51        (WebCore::ContextMenuSelectionHandler::~ContextMenuSelectionHandler):
     52        * platform/ContextMenu.cpp:
     53        (WebCore::ContextMenu::checkOrEnableIfNeeded):
     54        * platform/ContextMenuItem.h:
     55
    1562009-12-08  Andras Becsi  <abecsi@inf.u-szeged.hu>
    257
  • trunk/WebCore/GNUmakefile.am

    r51813 r51839  
    13191319        WebCore/page/ContextMenuController.cpp \
    13201320        WebCore/page/ContextMenuController.h \
     1321        WebCore/page/ContextMenuSelectionHandler.h \
    13211322        WebCore/page/Coordinates.h \
    13221323        WebCore/page/DOMSelection.cpp \
  • trunk/WebCore/WebCore.gypi

    r51681 r51839  
    17551755            'page/ContextMenuController.cpp',
    17561756            'page/ContextMenuController.h',
     1757            'page/ContextMenuSelectionHandler.h',
    17571758            'page/DOMSelection.cpp',
    17581759            'page/DOMSelection.h',
     
    36403641            'inspector/front-end/ConsolePanel.js',
    36413642            'inspector/front-end/ConsoleView.js',
     3643            'inspector/front-end/ContextMenu.js',
    36423644            'inspector/front-end/CookieItemsView.js',
    36433645            'inspector/front-end/Database.js',
  • trunk/WebCore/WebCore.pro

    r51838 r51839  
    18361836    page/Console.h \
    18371837    page/ContextMenuController.h \
     1838    page/ContextMenuSelectionHandler.h \
    18381839    page/Coordinates.h \
    18391840    page/DOMSelection.h \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r51793 r51839  
    2052820528                        </File>
    2052920529                        <File
     20530                                RelativePath="..\page\ContextMenuSelectionHandler.h"
     20531                                >
     20532                        </File>
     20533                        <File
    2053020534                                RelativePath="..\page\Coordinates.h"
    2053120535                                >
     
    4243542439                                </File>
    4243642440                                <File
     42441                                        RelativePath="..\inspector\front-end\ContextMenu.js"
     42442                                        >
     42443                                </File>
     42444                                <File
    4243742445                                        RelativePath="..\inspector\front-end\Database.js"
    4243842446                                        >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r51793 r51839  
    12471247                7A74ECBB101839A600BF939E /* InspectorBackend.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A74ECB9101839A600BF939E /* InspectorBackend.h */; };
    12481248                7A74ECBD101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A74ECBC101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp */; };
     1249                7ADE722610CBBB9B006B3B3A /* ContextMenuSelectionHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 7ADE722510CBBB9B006B3B3A /* ContextMenuSelectionHandler.h */; };
    12491250                7AED3E050FBB1EAA00D2B03C /* InspectorFrontend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AED3E030FBB1EAA00D2B03C /* InspectorFrontend.cpp */; };
    12501251                7AED3E060FBB1EAA00D2B03C /* InspectorFrontend.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AED3E040FBB1EAA00D2B03C /* InspectorFrontend.h */; };
     
    65816582                7A74ECB9101839A600BF939E /* InspectorBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorBackend.h; sourceTree = "<group>"; };
    65826583                7A74ECBC101839DA00BF939E /* JSInspectorFrontendHostCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInspectorFrontendHostCustom.cpp; sourceTree = "<group>"; };
     6584                7ADE722510CBBB9B006B3B3A /* ContextMenuSelectionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextMenuSelectionHandler.h; sourceTree = "<group>"; };
    65836585                7AED3E030FBB1EAA00D2B03C /* InspectorFrontend.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorFrontend.cpp; sourceTree = "<group>"; };
    65846586                7AED3E040FBB1EAA00D2B03C /* InspectorFrontend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontend.h; sourceTree = "<group>"; };
     
    1122711229                                065AD4F30B0C2EDA005A2B1D /* ContextMenuController.cpp */,
    1122811230                                065AD4F40B0C2EDA005A2B1D /* ContextMenuController.h */,
     11231                                7ADE722510CBBB9B006B3B3A /* ContextMenuSelectionHandler.h */,
    1122911232                                FE6FD4850F676E5700092873 /* Coordinates.h */,
    1123011233                                FE6FD4860F676E5700092873 /* Coordinates.idl */,
     
    1822618229                                F4EAF4AF10C742B1009100D3 /* OpenTypeSanitizer.h in Headers */,
    1822718230                                599D1E3310C97D6E00E0EF12 /* jni_utility_private.h in Headers */,
     18231                                7ADE722610CBBB9B006B3B3A /* ContextMenuSelectionHandler.h in Headers */,
    1822818232                        );
    1822918233                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp

    r51631 r51839  
    3636#if ENABLE(INSPECTOR)
    3737
     38#include "ContextMenuItem.h"
    3839#include "ExceptionCode.h"
    3940#include "Frame.h"
    4041#include "InspectorController.h"
    4142#include "InspectorFrontendHost.h"
     43#include "JSEvent.h"
    4244#include "JSNode.h"
    4345#include "JSRange.h"
     46#include "MouseEvent.h"
    4447#include "Node.h"
    4548#include "Page.h"
     
    4851#include <runtime/JSArray.h>
    4952#include <runtime/JSLock.h>
     53#include <runtime/JSObject.h>
    5054#include <wtf/Vector.h>
    5155
     
    9094}
    9195
     96JSValue JSInspectorFrontendHost::showContextMenu(ExecState* execState, const ArgList& args)
     97{
     98    if (args.size() < 2)
     99        return jsUndefined();
     100
     101    Event* event = toEvent(args.at(0));
     102
     103    JSArray* array = asArray(args.at(1));
     104    Vector<ContextMenuItem> items;
     105
     106    for (size_t i = 0; i < array->length(); ++i) {
     107        JSObject* item = asObject(array->getIndex(i));
     108        JSValue label = item->get(execState, Identifier(execState, "label"));
     109        JSValue id = item->get(execState, Identifier(execState, "id"));
     110        if (label.isUndefined() || id.isUndefined())
     111            items.append(ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String()));
     112        else {
     113            ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(execState));
     114            items.append(ContextMenuItem(ActionType, typedId, label.toString(execState)));
     115        }
     116    }
     117
     118    impl()->showContextMenu(event, items);
     119    return jsUndefined();
     120}
     121
    92122} // namespace WebCore
    93123
  • trunk/WebCore/bindings/v8/custom/V8CustomBinding.h

    r51681 r51839  
    497497
    498498        DECLARE_CALLBACK(InspectorFrontendHostSearch);
    499         DECLARE_CALLBACK(InspectorFrontendHostSetting);
    500         DECLARE_CALLBACK(InspectorFrontendHostSetSetting);
     499        DECLARE_CALLBACK(InspectorFrontendHostShowContextMenu);
    501500
    502501        DECLARE_CALLBACK(ConsoleProfile);
  • trunk/WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp

    r51631 r51839  
    8585}
    8686
     87CALLBACK_FUNC_DECL(InspectorFrontendHostShowContextMenu)
     88{
     89    return v8::Undefined();
     90}
     91
    8792} // namespace WebCore
  • trunk/WebCore/inspector/InspectorFrontend.cpp

    r51621 r51839  
    531531}
    532532
     533void InspectorFrontend::contextMenuItemSelected(int itemId)
     534{
     535    ScriptFunctionCall function(m_scriptState, m_webInspector, "dispatch");
     536    function.appendArgument("contextMenuItemSelected");
     537    function.appendArgument(itemId);
     538    function.call();
     539}
     540
     541void InspectorFrontend::contextMenuCleared()
     542{
     543    callSimpleFunction("contextMenuCleared");
     544}
     545
    533546void InspectorFrontend::evaluateForTestInFrontend(int callId, const String& script)
    534547{
  • trunk/WebCore/inspector/InspectorFrontend.h

    r51621 r51839  
    133133        void addNodesToSearchResult(const String& nodeIds);
    134134
     135        void contextMenuItemSelected(int itemId);
     136        void contextMenuCleared();
     137
    135138        ScriptState* scriptState() const { return m_scriptState; }
    136139
  • trunk/WebCore/inspector/InspectorFrontendHost.cpp

    r51631 r51839  
    3333#if ENABLE(INSPECTOR)
    3434
     35#include "ContextMenu.h"
     36#include "ContextMenuItem.h"
     37#include "ContextMenuController.h"
     38#include "ContextMenuSelectionHandler.h"
    3539#include "Element.h"
    3640#include "Frame.h"
    3741#include "FrameLoader.h"
     42#include "HitTestResult.h"
    3843#include "HTMLFrameOwnerElement.h"
    3944#include "InspectorClient.h"
     45#include "InspectorFrontend.h"
    4046#include "InspectorResource.h"
     47#include "Page.h"
    4148
    4249#include <wtf/RefPtr.h>
     
    5057    : m_inspectorController(inspectorController)
    5158    , m_client(client)
     59    , m_menuSelectionHandler(MenuSelectionHandler::create(this))
    5260{
    5361}
     
    5563InspectorFrontendHost::~InspectorFrontendHost()
    5664{
     65    m_menuSelectionHandler->disconnect();
    5766}
    5867
     
    200209}
    201210
     211void InspectorFrontendHost::showContextMenu(Event* event, Vector<ContextMenuItem>& items)
     212{
     213    if (!m_inspectorController)
     214        return;
     215    if (!m_inspectorController->windowVisible())
     216        return;
     217
     218    ContextMenuController* menuController = m_inspectorController->m_page->contextMenuController();
     219    menuController->showContextMenu(event, items, m_menuSelectionHandler);
     220}
     221
     222void InspectorFrontendHost::contextMenuItemSelected(ContextMenuItem* item)
     223{
     224    if (m_inspectorController && m_inspectorController->windowVisible()) {
     225        int itemNumber = item->action() - ContextMenuItemBaseCustomTag;
     226        m_inspectorController->m_frontend->contextMenuItemSelected(itemNumber);
     227    }
     228}
     229
     230void InspectorFrontendHost::contextMenuCleared()
     231{
     232    if (m_inspectorController && m_inspectorController->windowVisible())
     233        m_inspectorController->m_frontend->contextMenuCleared();
     234}
     235
    202236} // namespace WebCore
    203237
  • trunk/WebCore/inspector/InspectorFrontendHost.h

    r51631 r51839  
    3131
    3232#include "Console.h"
     33#include "ContextMenuSelectionHandler.h"
    3334#include "InspectorController.h"
    3435#include "PlatformString.h"
    3536
    3637#include <wtf/RefCounted.h>
     38#include <wtf/Vector.h>
    3739
    3840namespace WebCore {
    3941
     42class ContextMenuItem;
     43class Event;
    4044class InspectorClient;
    4145class Node;
     
    5256
    5357    InspectorController* inspectorController() { return m_inspectorController; }
     58
    5459    void disconnectController() { m_inspectorController = 0; }
    5560
     
    7479    void setSetting(const String& key, const String& value);
    7580
     81    // Called from [Custom] implementations.
     82    void showContextMenu(Event*, Vector<ContextMenuItem>& items);
     83    void contextMenuItemSelected(ContextMenuItem*);
     84    void contextMenuCleared();
     85
    7686private:
     87    class MenuSelectionHandler : public ContextMenuSelectionHandler {
     88    public:
     89        static PassRefPtr<MenuSelectionHandler> create(InspectorFrontendHost* frontendHost)
     90        {
     91            return adoptRef(new MenuSelectionHandler(frontendHost));
     92        }
     93
     94        virtual ~MenuSelectionHandler() { }
     95
     96        void disconnect() { m_frontendHost = 0; }
     97
     98        virtual void contextMenuItemSelected(ContextMenuItem* item)
     99        {
     100            if (m_frontendHost)
     101                m_frontendHost->contextMenuItemSelected(item);
     102        }
     103
     104        virtual void contextMenuCleared()
     105        {
     106            if (m_frontendHost)
     107                m_frontendHost->contextMenuCleared();
     108        }
     109
     110    private:
     111        MenuSelectionHandler(InspectorFrontendHost* frontendHost)
     112            : m_frontendHost(frontendHost) { }
     113        InspectorFrontendHost* m_frontendHost;
     114    };
     115
    77116    InspectorFrontendHost(InspectorController* inspectorController, InspectorClient* client);
    78117
    79118    InspectorController* m_inspectorController;
    80119    InspectorClient* m_client;
     120    RefPtr<MenuSelectionHandler> m_menuSelectionHandler;
    81121};
    82122
  • trunk/WebCore/inspector/InspectorFrontendHost.idl

    r51631 r51839  
    5656
    5757        [Custom] void search(in Node node, in DOMString query);
     58        [Custom] void showContextMenu(in MouseEvent event, in DOMObject items);
    5859    };
    5960}
  • trunk/WebCore/inspector/front-end/ContextMenu.js

    r51838 r51839  
    11/*
    2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
    3  * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
    42 * Copyright (C) 2009 Google Inc. All rights reserved.
    53 *
     
    3129 */
    3230
    33 module core {
    34     interface [
    35         GenerateConstructor
    36     ] InspectorFrontendHost {
    37         void loaded();
    38         void attach();
    39         void detach();
    40         void closeWindow();
    41         void windowUnloading();
     31WebInspector.ContextMenu = function() {
     32    this._items = [];
     33    this._handlers = {};
     34    this._appendItem(WebInspector.UIString("Edit as HTML"), this._noop.bind(this));
     35    this._appendItem(WebInspector.UIString("Add attribute"), this._noop.bind(this));
     36    this._appendSeparator();
     37    this._appendItem(WebInspector.UIString("Copy"), this._copy.bind(this));
     38    this._appendItem(WebInspector.UIString("Delete"), this._delete.bind(this));
     39}
    4240
    43         void setAttachedWindowHeight(in unsigned long height);
    44         void moveWindowBy(in float x, in float y);
     41WebInspector.ContextMenu.prototype = {
     42    show: function(event)
     43    {
     44        // FIXME: Uncomment when popup menu has meaningful items.
     45        // InspectorFrontendHost.showContextMenu(event, this._items);
     46        // event.preventDefault();
     47    },
    4548
    46         DOMString localizedStringsURL();
    47         DOMString hiddenPanels();
    48         DOMString platform();
    49         DOMString port();
     49    _appendItem: function(label, handler)
     50    {
     51        var id = this._items.length;
     52        this._items.push({id: id, label: label});
     53        this._handlers[id] = handler;
     54    },
    5055
    51         void addResourceSourceToFrame(in long identifier, in Node frame);
    52         boolean addSourceToFrame(in DOMString mimeType, in DOMString sourceValue, in Node frame);
     56    _appendSeparator: function()
     57    {
     58        this._items.push({});
     59    },
    5360
    54         DOMString setting(in DOMString key);
    55         void setSetting(in DOMString key, in DOMString value);
     61    itemSelected: function(id)
     62    {
     63        if (this._handlers[id])
     64            this._handlers[id].call(this);
     65    },
    5666
    57         [Custom] void search(in Node node, in DOMString query);
    58     };
     67    _copy: function()
     68    {
     69        console.log("context menu: copy");
     70    },
     71
     72    _delete: function()
     73    {
     74        console.log("context menu: delete");
     75    },
     76
     77    _noop: function()
     78    {
     79        console.log("context menu: noop");
     80    }
    5981}
     82
     83
     84WebInspector.contextMenuItemSelected = function(id)
     85{
     86    if (WebInspector.contextMenu)
     87        WebInspector.contextMenu.itemSelected(id);
     88}
     89
     90WebInspector.contextMenuCleared = function()
     91{
     92    console.log("context menu: cleared");
     93}
  • trunk/WebCore/inspector/front-end/WebKit.qrc

    r51528 r51839  
    1212    <file>ConsolePanel.js</file>
    1313    <file>ConsoleView.js</file>
     14    <file>ContextMenu.js</file>
    1415    <file>CookieItemsView.js</file>
    1516    <file>Database.js</file>
  • trunk/WebCore/inspector/front-end/inspector.html

    r51528 r51839  
    3838    <script type="text/javascript" src="InspectorFrontendHostStub.js"></script>
    3939    <script type="text/javascript" src="Object.js"></script>
     40    <script type="text/javascript" src="ContextMenu.js"></script>
    4041    <script type="text/javascript" src="KeyboardShortcut.js"></script>
    4142    <script type="text/javascript" src="TextPrompt.js"></script>
  • trunk/WebCore/inspector/front-end/inspector.js

    r51553 r51839  
    472472    document.addEventListener("beforecopy", this.documentCanCopy.bind(this), true);
    473473    document.addEventListener("copy", this.documentCopy.bind(this), true);
    474     document.addEventListener("contextmenu", this.contextMenu.bind(this), true);
     474    document.addEventListener("contextmenu", this.contextMenuEventFired.bind(this), true);
    475475
    476476    var mainPanelsElement = document.getElementById("main-panels");
     
    749749}
    750750
    751 WebInspector.contextMenu = function(event)
     751WebInspector.contextMenuEventFired = function(event)
    752752{
    753753    if (event.handled || event.target.hasStyleClass("popup-glasspane"))
    754754        event.preventDefault();
     755
     756    if (!this.contextMenu)
     757        this.contextMenu = new WebInspector.ContextMenu();
     758    this.contextMenu.show(event);
    755759}
    756760
  • trunk/WebCore/page/ContextMenuController.cpp

    r49809 r51839  
    3232#include "ContextMenu.h"
    3333#include "ContextMenuClient.h"
     34#include "ContextMenuSelectionHandler.h"
    3435#include "Document.h"
    3536#include "DocumentFragment.h"
     
    6768    , m_client(client)
    6869    , m_contextMenu(0)
     70    , m_selectionHandler(0)
    6971{
    7072    ASSERT_ARG(page, page);
     
    8082{
    8183    m_contextMenu.set(0);
     84    if (m_selectionHandler)
     85        m_selectionHandler->contextMenuCleared();
     86    m_selectionHandler = 0;
    8287}
    8388
    8489void ContextMenuController::handleContextMenuEvent(Event* event)
    8590{
    86     ASSERT(event->type() == eventNames().contextmenuEvent);
    87     if (!event->isMouseEvent())
    88         return;
     91    m_contextMenu.set(createContextMenu(event));
     92    if (!m_contextMenu)
     93        return;
     94    m_contextMenu->populate();
     95    showContextMenu(event);
     96}
     97
     98void ContextMenuController::showContextMenu(Event* event, Vector<ContextMenuItem>& items, PassRefPtr<ContextMenuSelectionHandler> selectionHandler)
     99{
     100    m_selectionHandler = selectionHandler;
     101
     102    m_contextMenu.set(createContextMenu(event));
     103    if (!m_contextMenu) {
     104        clearContextMenu();
     105        return;
     106    }
     107    for (size_t i = 0; i < items.size(); ++i) {
     108        ContextMenuItem& item = items[i];
     109        m_contextMenu->appendItem(item);
     110    }
     111    showContextMenu(event);
     112}
     113
     114ContextMenu* ContextMenuController::createContextMenu(Event* event)
     115{
     116   if (!event->isMouseEvent())
     117        return 0;
    89118    MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
    90119    HitTestResult result(mouseEvent->absoluteLocation());
     
    94123
    95124    if (!result.innerNonSharedNode())
    96         return;
    97 
    98     m_contextMenu.set(new ContextMenu(result));
    99     m_contextMenu->populate();
     125        return 0;
     126    return new ContextMenu(result);
     127}
     128
     129void ContextMenuController::showContextMenu(Event* event)
     130{
    100131#if ENABLE(INSPECTOR)
    101132    if (m_page->inspectorController()->enabled())
    102133        m_contextMenu->addInspectElementItem();
    103134#endif
    104 
    105135    PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get());
    106136    m_contextMenu->setPlatformDescription(customMenu);
    107 
    108137    event->setDefaultHandled();
    109138}
     
    124153    if (item->action() >= ContextMenuItemBaseApplicationTag) {
    125154        m_client->contextMenuItemSelected(item, m_contextMenu.get());
     155        return;
     156    }
     157
     158    if (item->action() >= ContextMenuItemBaseCustomTag) {
     159        ASSERT(m_selectionHandler);
     160        m_selectionHandler->contextMenuItemSelected(item);
    126161        return;
    127162    }
  • trunk/WebCore/page/ContextMenuController.h

    r45891 r51839  
    2929#include <wtf/Noncopyable.h>
    3030#include <wtf/OwnPtr.h>
     31#include <wtf/PassRefPtr.h>
     32#include <wtf/RefPtr.h>
     33#include <wtf/Vector.h>
    3134
    3235namespace WebCore {
     
    3538    class ContextMenuClient;
    3639    class ContextMenuItem;
     40    class ContextMenuSelectionHandler;
    3741    class Event;
    3842    class Page;
     
    4953
    5054        void handleContextMenuEvent(Event*);
     55        void showContextMenu(Event*, Vector<ContextMenuItem>&, PassRefPtr<ContextMenuSelectionHandler>);
     56
    5157        void contextMenuItemSelected(ContextMenuItem*);
    5258
    5359    private:
     60        ContextMenu* createContextMenu(Event*);
     61        void showContextMenu(Event*);
     62
    5463        Page* m_page;
    5564        ContextMenuClient* m_client;
    5665        OwnPtr<ContextMenu> m_contextMenu;
     66        RefPtr<ContextMenuSelectionHandler> m_selectionHandler;
    5767    };
    5868
  • trunk/WebCore/page/ContextMenuSelectionHandler.h

    r51838 r51839  
    11/*
    2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
    3  * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
    42 * Copyright (C) 2009 Google Inc. All rights reserved.
    53 *
     
    3129 */
    3230
    33 module core {
    34     interface [
    35         GenerateConstructor
    36     ] InspectorFrontendHost {
    37         void loaded();
    38         void attach();
    39         void detach();
    40         void closeWindow();
    41         void windowUnloading();
     31#ifndef ContextMenuSelectionHandler_h
     32#define ContextMenuSelectionHandler_h
    4233
    43         void setAttachedWindowHeight(in unsigned long height);
    44         void moveWindowBy(in float x, in float y);
     34#include <wtf/RefCounted.h>
    4535
    46         DOMString localizedStringsURL();
    47         DOMString hiddenPanels();
    48         DOMString platform();
    49         DOMString port();
     36namespace WebCore {
    5037
    51         void addResourceSourceToFrame(in long identifier, in Node frame);
    52         boolean addSourceToFrame(in DOMString mimeType, in DOMString sourceValue, in Node frame);
     38    class ContextMenuItem;
    5339
    54         DOMString setting(in DOMString key);
    55         void setSetting(in DOMString key, in DOMString value);
     40    class ContextMenuSelectionHandler : public RefCounted<ContextMenuSelectionHandler> {
     41    public:
     42        ContextMenuSelectionHandler() { }
     43        virtual ~ContextMenuSelectionHandler() { };
    5644
    57         [Custom] void search(in Node node, in DOMString query);
     45        virtual void contextMenuItemSelected(ContextMenuItem*) = 0;
     46        virtual void contextMenuCleared() = 0;
    5847    };
     48
    5949}
     50
     51#endif // ContextMenuSelectionHandler_h
  • trunk/WebCore/platform/ContextMenu.cpp

    r49067 r51839  
    4141#include "Frame.h"
    4242#include "FrameLoader.h"
     43#include "InspectorController.h"
    4344#include "KURL.h"
    4445#include "LocalizedStrings.h"
     
    780781        case ContextMenuItemTagInspectElement:
    781782#endif
     783        case ContextMenuItemBaseCustomTag:
    782784        case ContextMenuItemBaseApplicationTag:
    783785            break;
  • trunk/WebCore/platform/ContextMenuItem.h

    r51149 r51839  
    144144        ContextMenuItemTagChangeBack,
    145145#endif
     146        ContextMenuItemBaseCustomTag = 5000,
    146147        ContextMenuItemBaseApplicationTag = 10000
    147148    };
Note: See TracChangeset for help on using the changeset viewer.