Changeset 51946 in webkit


Ignore:
Timestamp:
Dec 10, 2009 4:53:42 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

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

Reviewed by Timothy Hatcher.

Web Inspector: Add context menu actions for DOM tree.

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

  • English.lproj/localizedStrings.js:
  • inspector/front-end/ContextMenu.js: (WebInspector.ContextMenu): (WebInspector.ContextMenu.prototype.show): (WebInspector.ContextMenu.prototype.appendItem): (WebInspector.ContextMenu.prototype.appendSeparator): (WebInspector.ContextMenu.prototype._itemSelected): (WebInspector.contextMenuItemSelected): (WebInspector.contextMenuCleared):
  • inspector/front-end/ElementsTreeOutline.js: (WebInspector.ElementsTreeOutline.prototype._onmouseout): (WebInspector.ElementsTreeOutline.prototype.populateContextMenu): (WebInspector.ElementsTreeElement.prototype.ondblclick): (WebInspector.ElementsTreeElement.prototype._startEditingFromEvent): (WebInspector.ElementsTreeElement.prototype._populateTagContextMenu): (WebInspector.ElementsTreeElement.prototype._populateTextContextMenu): (WebInspector.ElementsTreeElement.prototype._startEditing): (WebInspector.ElementsTreeElement.prototype._addNewAttribute):
  • inspector/front-end/ObjectPropertiesSection.js: (WebInspector.ObjectPropertyTreeElement.prototype.ondblclick):
  • inspector/front-end/ResourceView.js: (WebInspector.ResourceView.prototype._toggleURLdecoding):
  • inspector/front-end/ResourcesPanel.js: (WebInspector.ResourceSidebarTreeElement.prototype.ondblclick):
  • inspector/front-end/StylesSidebarPane.js: (WebInspector.StylePropertyTreeElement.prototype):
  • inspector/front-end/inspector.js: (WebInspector.contextMenuEventFired):
  • inspector/front-end/treeoutline.js: (TreeElement.treeElementDoubleClicked):
Location:
trunk/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r51945 r51946  
     12009-12-10  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: Add context menu actions for DOM tree.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=32348
     8
     9        * English.lproj/localizedStrings.js:
     10        * inspector/front-end/ContextMenu.js:
     11        (WebInspector.ContextMenu):
     12        (WebInspector.ContextMenu.prototype.show):
     13        (WebInspector.ContextMenu.prototype.appendItem):
     14        (WebInspector.ContextMenu.prototype.appendSeparator):
     15        (WebInspector.ContextMenu.prototype._itemSelected):
     16        (WebInspector.contextMenuItemSelected):
     17        (WebInspector.contextMenuCleared):
     18        * inspector/front-end/ElementsTreeOutline.js:
     19        (WebInspector.ElementsTreeOutline.prototype._onmouseout):
     20        (WebInspector.ElementsTreeOutline.prototype.populateContextMenu):
     21        (WebInspector.ElementsTreeElement.prototype.ondblclick):
     22        (WebInspector.ElementsTreeElement.prototype._startEditingFromEvent):
     23        (WebInspector.ElementsTreeElement.prototype._populateTagContextMenu):
     24        (WebInspector.ElementsTreeElement.prototype._populateTextContextMenu):
     25        (WebInspector.ElementsTreeElement.prototype._startEditing):
     26        (WebInspector.ElementsTreeElement.prototype._addNewAttribute):
     27        * inspector/front-end/ObjectPropertiesSection.js:
     28        (WebInspector.ObjectPropertyTreeElement.prototype.ondblclick):
     29        * inspector/front-end/ResourceView.js:
     30        (WebInspector.ResourceView.prototype._toggleURLdecoding):
     31        * inspector/front-end/ResourcesPanel.js:
     32        (WebInspector.ResourceSidebarTreeElement.prototype.ondblclick):
     33        * inspector/front-end/StylesSidebarPane.js:
     34        (WebInspector.StylePropertyTreeElement.prototype):
     35        * inspector/front-end/inspector.js:
     36        (WebInspector.contextMenuEventFired):
     37        * inspector/front-end/treeoutline.js:
     38        (TreeElement.treeElementDoubleClicked):
     39
    1402009-12-09  Nikolas Zimmermann  <nzimmermann@rim.com>
    241
  • trunk/WebCore/inspector/front-end/ContextMenu.js

    r51839 r51946  
    3232    this._items = [];
    3333    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));
    3934}
    4035
     
    4237    show: function(event)
    4338    {
    44         // FIXME: Uncomment when popup menu has meaningful items.
    45         // InspectorFrontendHost.showContextMenu(event, this._items);
    46         // event.preventDefault();
     39        // Remove trailing separator.
     40        while (this._items.length > 0 && !("id" in this._items[this._items.length - 1]))
     41            this._items.splice(this._items.length - 1, 1);
     42
     43        if (this._items.length) {
     44            WebInspector._contextMenu = this;
     45            InspectorFrontendHost.showContextMenu(event, this._items);
     46        }
    4747    },
    4848
    49     _appendItem: function(label, handler)
     49    appendItem: function(label, handler)
    5050    {
    5151        var id = this._items.length;
     
    5454    },
    5555
    56     _appendSeparator: function()
     56    appendSeparator: function()
    5757    {
     58        // No separator dupes allowed.
     59        if (this._items.length === 0)
     60            return;
     61        if (!("id" in this._items[this._items.length - 1]))
     62            return;
    5863        this._items.push({});
    5964    },
    6065
    61     itemSelected: function(id)
     66    _itemSelected: function(id)
    6267    {
    6368        if (this._handlers[id])
    6469            this._handlers[id].call(this);
    65     },
    66 
    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");
    8070    }
    8171}
    8272
    83 
    8473WebInspector.contextMenuItemSelected = function(id)
    8574{
    86     if (WebInspector.contextMenu)
    87         WebInspector.contextMenu.itemSelected(id);
     75    if (WebInspector._contextMenu)
     76        WebInspector._contextMenu._itemSelected(id);
    8877}
    8978
    9079WebInspector.contextMenuCleared = function()
    9180{
    92     console.log("context menu: cleared");
     81    // FIXME: Unfortunately, contextMenuCleared is invoked between show and item selected
     82    // so we can't delete last menu object from WebInspector. Fix the contract.
    9383}
  • trunk/WebCore/inspector/front-end/ElementsTreeOutline.js

    r51559 r51946  
    4242    this.rootDOMNode = null;
    4343    this.focusedDOMNode = null;
     44
     45    this.element.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
    4446}
    4547
     
    260262
    261263        WebInspector.hoveredDOMNode = null;
     264    },
     265
     266    _contextMenuEventFired: function(event)
     267    {
     268        var listItem = event.target.enclosingNodeOrSelfWithNodeName("LI");
     269        if (!listItem || !listItem.treeElement)
     270            return;
     271
     272        var contextMenu = new WebInspector.ContextMenu();
     273
     274        var tag = event.target.enclosingNodeOrSelfWithClass("webkit-html-tag");
     275        var textNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-text-node");
     276        if (tag)
     277            listItem.treeElement._populateTagContextMenu(contextMenu, event);
     278        else if (textNode)
     279            listItem.treeElement._populateTextContextMenu(contextMenu, textNode);
     280        contextMenu.show(event);
    262281    }
    263282}
     
    550569    },
    551570
    552     ondblclick: function(treeElement, event)
     571    ondblclick: function(event)
    553572    {
    554573        if (this._editing)
    555574            return;
    556575
    557         if (this._startEditingFromEvent(event, treeElement))
     576        if (this._startEditingFromEvent(event))
    558577            return;
    559578
     
    577596    },
    578597
    579     _startEditingFromEvent: function(event, treeElement)
     598    _startEditingFromEvent: function(event)
    580599    {
    581600        if (this.treeOutline.focusedDOMNode != this.representedObject)
     
    595614        var newAttribute = event.target.enclosingNodeOrSelfWithClass("add-attribute");
    596615        if (newAttribute)
    597             return this._addNewAttribute(treeElement.listItemElement);
     616            return this._addNewAttribute();
    598617
    599618        return false;
     619    },
     620
     621    _populateTagContextMenu: function(contextMenu, event)
     622    {
     623        var attribute = event.target.enclosingNodeOrSelfWithClass("webkit-html-attribute");
     624        var newAttribute = event.target.enclosingNodeOrSelfWithClass("add-attribute");
     625
     626        // Add attribute-related actions.
     627        contextMenu.appendItem(WebInspector.UIString("Add Attribute"), this._addNewAttribute.bind(this));
     628        if (attribute && !newAttribute)
     629            contextMenu.appendItem(WebInspector.UIString("Edit Attribute"), this._startEditingAttribute.bind(this, attribute, event.target));
     630        contextMenu.appendSeparator();
     631
     632        // Add node-related actions.
     633        contextMenu.appendItem(WebInspector.UIString("Delete Node"), this.remove.bind(this));
     634    },
     635
     636    _populateTextContextMenu: function(contextMenu, textNode)
     637    {
     638        contextMenu.appendItem(WebInspector.UIString("Edit Text"), this._startEditingTextNode.bind(this, textNode));
    600639    },
    601640
     
    613652                return this._startEditingAttribute(attribute, attribute.getElementsByClassName("webkit-html-attribute-value")[0]);
    614653
    615             return this._addNewAttribute(listItem);
     654            return this._addNewAttribute();
    616655        }
    617656
     
    624663    },
    625664
    626     _addNewAttribute: function(listItemElement)
     665    _addNewAttribute: function()
    627666    {
    628667        var attr = document.createElement("span");
     
    638677        attr.appendChild(value);
    639678
    640         var tag = listItemElement.getElementsByClassName("webkit-html-tag")[0];
     679        var tag = this.listItemElement.getElementsByClassName("webkit-html-tag")[0];
    641680        this._insertInLastAttributePosition(tag, attr);
    642681        return this._startEditingAttribute(attr, attr);
  • trunk/WebCore/inspector/front-end/ObjectPropertiesSection.js

    r48431 r51946  
    151151    },
    152152
    153     ondblclick: function(element, event)
     153    ondblclick: function(event)
    154154    {
    155155        this.startEditing();
  • trunk/WebCore/inspector/front-end/ResourceView.js

    r49938 r51946  
    249249    },
    250250
    251     _toggleURLdecoding: function(treeElement, event)
     251    _toggleURLdecoding: function(event)
    252252    {
    253253        this._decodeRequestParameters = !this._decodeRequestParameters;
  • trunk/WebCore/inspector/front-end/ResourcesPanel.js

    r51528 r51946  
    968968    },
    969969   
    970     ondblclick: function(treeElement, event)
     970    ondblclick: function(event)
    971971    {
    972972        InjectedScriptAccess.openInInspectedWindow(this.resource.url, function() {});
  • trunk/WebCore/inspector/front-end/StylesSidebarPane.js

    r51528 r51946  
    10991099    },
    11001100
    1101     ondblclick: function(element, event)
     1101    ondblclick: function(event)
    11021102    {
    11031103        this.startEditing(event.target);
  • trunk/WebCore/inspector/front-end/inspector.js

    r51846 r51946  
    761761    if (event.handled || event.target.hasStyleClass("popup-glasspane"))
    762762        event.preventDefault();
    763 
    764     if (!this.contextMenu)
    765         this.contextMenu = new WebInspector.ContextMenu();
    766     this.contextMenu.show(event);
    767763}
    768764
  • trunk/WebCore/inspector/front-end/treeoutline.js

    r47725 r51946  
    625625
    626626    if (element.treeElement.ondblclick)
    627         element.treeElement.ondblclick(element.treeElement, event);
     627        element.treeElement.ondblclick.call(element.treeElement, event);
    628628    else if (element.treeElement.hasChildren && !element.treeElement.expanded)
    629629        element.treeElement.expand();
Note: See TracChangeset for help on using the changeset viewer.