Bug 32200 - Web Inspector: provide custom context menu in the front-end window.
Summary: Web Inspector: provide custom context menu in the front-end window.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Pavel Feldman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-06 12:38 PST by Pavel Feldman
Modified: 2009-12-08 02:20 PST (History)
4 users (show)

See Also:


Attachments
[IMAGE] Screenshot while running with patch. (76.23 KB, image/png)
2009-12-06 12:38 PST, Pavel Feldman
no flags Details
[PATCH] Proposed change (30.92 KB, patch)
2009-12-06 12:48 PST, Pavel Feldman
timothy: review+
pfeldman: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Feldman 2009-12-06 12:38:58 PST
Created attachment 44365 [details]
[IMAGE] Screenshot while running with patch.

This patch extends ContextMenuController in order to allow custom context menus on pages. So far, inspector is the only client of the new API, but this might change once HTML5's contextmenu is implemented.
Comment 1 Pavel Feldman 2009-12-06 12:48:45 PST
Created attachment 44366 [details]
[PATCH] Proposed change
Comment 2 Timothy Hatcher 2009-12-07 10:48:40 PST
Comment on attachment 44366 [details]
[PATCH] Proposed change


> +    class MenuSelectionHandler : public ContextMenuSelectionHandler
> +    {

Brace should be on the same line.


> +        virtual ~MenuSelectionHandler() {}

I think we informally like a space between the braces. { } vs {}.


> +        MenuSelectionHandler(InspectorFrontendHost* frontendHost)
> +            : m_frontendHost(frontendHost)
> +        {
> +        }

We informally like to put empty constructors on one line.


> +    this._appendItem(WebInspector.UIString("Edit as HTML"), this._noop.bind(this));
> +    this._appendItem(WebInspector.UIString("Add attribute"), this._noop.bind(this));
> +    this._appendSeparator();
> +    this._appendItem(WebInspector.UIString("Copy"), this._copy.bind(this));
> +    this._appendItem(WebInspector.UIString("Delete"), this._delete.bind(this));

This confused me, since those file is generic. We should land this file mostly empty until it is ready to work.


> +    _appendItem: function(label, handler)
> +    {
> +        var id = this._items.length;
> +        this._items.push({id: id, label: label});
> +        this._handlers[id] = handler;
> +    },
> +
> +    _appendSeparator: function()
> +    {
> +        this._items.push({});
> +    },

I think in the end these functions will be publicly used and should drop the underscore. But maybe I don't understand how the final design will work.


> +WebInspector.documentContextMenu = function(event)

Maybe contextMenuEventFired is a more descriptive name.


> +    if (item->action() >= ContextMenuItemBaseCustomTag) {
> +        ASSERT(m_selectionHandler);
> +        m_selectionHandler->contextMenuItemSelected(item);
> +        return;
> +    }

Does ContextMenuItemBaseApplicationTag get handled before this block? What prevents another tag higher that isn't a "ContextMenuItemBaseCustomTag" from hitting this?


> +    class ContextMenuSelectionHandler : public RefCounted<ContextMenuSelectionHandler>
> +    {

Brace should be on the same line.


> +        ContextMenuSelectionHandler() {}
> +        virtual ~ContextMenuSelectionHandler() {};

Put a space in the braces.
Comment 3 Pavel Feldman 2009-12-07 12:12:03 PST
(In reply to comment #2)
> (From update of attachment 44366 [details])
> 
> > +    class MenuSelectionHandler : public ContextMenuSelectionHandler
> > +    {
> 
> Brace should be on the same line.
> 

Done.

> 
> > +        virtual ~MenuSelectionHandler() {}
> 
> I think we informally like a space between the braces. { } vs {}.
>

Done.
 
> 
> > +        MenuSelectionHandler(InspectorFrontendHost* frontendHost)
> > +            : m_frontendHost(frontendHost)
> > +        {
> > +        }
> 
> We informally like to put empty constructors on one line.
> 

Done.

> 
> > +    this._appendItem(WebInspector.UIString("Edit as HTML"), this._noop.bind(this));
> > +    this._appendItem(WebInspector.UIString("Add attribute"), this._noop.bind(this));
> > +    this._appendSeparator();
> > +    this._appendItem(WebInspector.UIString("Copy"), this._copy.bind(this));
> > +    this._appendItem(WebInspector.UIString("Delete"), this._delete.bind(this));
> 
> This confused me, since those file is generic. We should land this file mostly
> empty until it is ready to work.
> 

I'll migrate to a context-per view schema in subsequent change. So far this context menu triggering is  anyway commented out.
> 
> > +    _appendItem: function(label, handler)
> > +    {
> > +        var id = this._items.length;
> > +        this._items.push({id: id, label: label});
> > +        this._handlers[id] = handler;
> > +    },
> > +
> > +    _appendSeparator: function()
> > +    {
> > +        this._items.push({});
> > +    },
> 
> I think in the end these functions will be publicly used and should drop the
> underscore. But maybe I don't understand how the final design will work.
> 

They will be public, yes.

> 
> > +WebInspector.documentContextMenu = function(event)
> 
> Maybe contextMenuEventFired is a more descriptive name.
> 
> 

Done.

> > +    if (item->action() >= ContextMenuItemBaseCustomTag) {
> > +        ASSERT(m_selectionHandler);
> > +        m_selectionHandler->contextMenuItemSelected(item);
> > +        return;
> > +    }
> 
> Does ContextMenuItemBaseApplicationTag get handled before this block? What
> prevents another tag higher that isn't a "ContextMenuItemBaseCustomTag" from
> hitting this?
> 

There is a following check above:
  if (item->action() >= ContextMenuItemBaseApplicationTag) {
        m_client->contextMenuItemSelected(item, m_contextMenu.get());
        return;
    }

> 
> > +    class ContextMenuSelectionHandler : public RefCounted<ContextMenuSelectionHandler>
> > +    {
> 
> Brace should be on the same line.
> 
> 

Done.

> > +        ContextMenuSelectionHandler() {}
> > +        virtual ~ContextMenuSelectionHandler() {};
> 
> Put a space in the braces.

Done.
Comment 4 Pavel Feldman 2009-12-07 12:16:32 PST
Comment on attachment 44366 [details]
[PATCH] Proposed change

I'll land manually with v8's [Custom] stub for showContextMenu.
Comment 5 Pavel Feldman 2009-12-08 02:20:09 PST
Committing to http://svn.webkit.org/repository/webkit/trunk ...
	C	WebCore/inspector/InspectorFrontendHost.idl => WebCore/inspector/front-end/ContextMenu.js
	C	WebCore/inspector/InspectorFrontendHost.idl => WebCore/page/ContextMenuSelectionHandler.h
	M	WebCore/ChangeLog
	M	WebCore/English.lproj/localizedStrings.js
	M	WebCore/GNUmakefile.am
	M	WebCore/WebCore.gypi
	M	WebCore/WebCore.pro
	M	WebCore/WebCore.vcproj/WebCore.vcproj
	M	WebCore/WebCore.xcodeproj/project.pbxproj
	M	WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp
	M	WebCore/bindings/v8/custom/V8CustomBinding.h
	M	WebCore/bindings/v8/custom/V8InspectorFrontendHostCustom.cpp
	M	WebCore/inspector/InspectorFrontend.cpp
	M	WebCore/inspector/InspectorFrontend.h
	M	WebCore/inspector/InspectorFrontendHost.cpp
	M	WebCore/inspector/InspectorFrontendHost.h
	M	WebCore/inspector/InspectorFrontendHost.idl
	M	WebCore/inspector/front-end/WebKit.qrc
	M	WebCore/inspector/front-end/inspector.html
	M	WebCore/inspector/front-end/inspector.js
	M	WebCore/page/ContextMenuController.cpp
	M	WebCore/page/ContextMenuController.h
	M	WebCore/platform/ContextMenu.cpp
	M	WebCore/platform/ContextMenuItem.h
Committed r51839