Title: [93034] trunk/Source/WebCore
Revision
93034
Author
pfeld...@chromium.org
Date
2011-08-15 01:13:33 -0700 (Mon, 15 Aug 2011)

Log Message

Web Inspector: showContextMenu missing in Remote DevTools
https://bugs.webkit.org/show_bug.cgi?id=63725

Reviewed by Yury Semikhatsky.

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/front-end/ConsoleView.js:
* inspector/front-end/SoftContextMenu.js: Added.
(.WebInspector.SoftContextMenu):
(.WebInspector.SoftContextMenu.prototype.show):
(.WebInspector.SoftContextMenu.prototype._createMenuItem):
(.WebInspector.SoftContextMenu.prototype._createSeparator):
(.WebInspector.SoftContextMenu.prototype._menuItemMouseDown):
(.WebInspector.SoftContextMenu.prototype._menuItemMouseUp):
(.WebInspector.SoftContextMenu.prototype._triggerAction):
(.WebInspector.SoftContextMenu.prototype._menuItemMouseOver):
(.WebInspector.SoftContextMenu.prototype._menuItemMouseOut):
(.WebInspector.SoftContextMenu.prototype._highlightMenuItem):
(.WebInspector.SoftContextMenu.prototype._highlightPrevious):
(.WebInspector.SoftContextMenu.prototype._highlightNext):
(.WebInspector.SoftContextMenu.prototype._menuKeyDown):
(.WebInspector.SoftContextMenu.prototype._glassPaneMouseUp):
(.WebInspector.SoftContextMenu.prototype._discardMenu):
(.InspectorFrontendHost.showContextMenu):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.css:
(.soft-context-menu-glass-pane):
(.soft-context-menu):
(.soft-context-menu-item):
(.soft-context-menu-separator):
(.soft-context-menu-item-mouse-over):
* inspector/front-end/inspector.html:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (93033 => 93034)


--- trunk/Source/WebCore/ChangeLog	2011-08-15 06:57:27 UTC (rev 93033)
+++ trunk/Source/WebCore/ChangeLog	2011-08-15 08:13:33 UTC (rev 93034)
@@ -1,3 +1,39 @@
+2011-08-14  Pavel Feldman  <pfeld...@chromium.org>
+
+        Web Inspector: showContextMenu missing in Remote DevTools
+        https://bugs.webkit.org/show_bug.cgi?id=63725
+
+        Reviewed by Yury Semikhatsky.
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/front-end/ConsoleView.js:
+        * inspector/front-end/SoftContextMenu.js: Added.
+        (.WebInspector.SoftContextMenu):
+        (.WebInspector.SoftContextMenu.prototype.show):
+        (.WebInspector.SoftContextMenu.prototype._createMenuItem):
+        (.WebInspector.SoftContextMenu.prototype._createSeparator):
+        (.WebInspector.SoftContextMenu.prototype._menuItemMouseDown):
+        (.WebInspector.SoftContextMenu.prototype._menuItemMouseUp):
+        (.WebInspector.SoftContextMenu.prototype._triggerAction):
+        (.WebInspector.SoftContextMenu.prototype._menuItemMouseOver):
+        (.WebInspector.SoftContextMenu.prototype._menuItemMouseOut):
+        (.WebInspector.SoftContextMenu.prototype._highlightMenuItem):
+        (.WebInspector.SoftContextMenu.prototype._highlightPrevious):
+        (.WebInspector.SoftContextMenu.prototype._highlightNext):
+        (.WebInspector.SoftContextMenu.prototype._menuKeyDown):
+        (.WebInspector.SoftContextMenu.prototype._glassPaneMouseUp):
+        (.WebInspector.SoftContextMenu.prototype._discardMenu):
+        (.InspectorFrontendHost.showContextMenu):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/inspector.css:
+        (.soft-context-menu-glass-pane):
+        (.soft-context-menu):
+        (.soft-context-menu-item):
+        (.soft-context-menu-separator):
+        (.soft-context-menu-item-mouse-over):
+        * inspector/front-end/inspector.html:
+
 2011-08-13  Abhishek Arya  <infe...@chromium.org>
 
         Crash in HTMLTreeBuilder::processAnyOtherEndTagForInBody

Modified: trunk/Source/WebCore/WebCore.gypi (93033 => 93034)


--- trunk/Source/WebCore/WebCore.gypi	2011-08-15 06:57:27 UTC (rev 93033)
+++ trunk/Source/WebCore/WebCore.gypi	2011-08-15 08:13:33 UTC (rev 93034)
@@ -6421,6 +6421,7 @@
             'inspector/front-end/Settings.js',
             'inspector/front-end/SidebarPane.js',
             'inspector/front-end/SidebarTreeElement.js',
+            'inspector/front-end/SoftContextMenu.js',
             'inspector/front-end/SourceCSSTokenizer.js',
             'inspector/front-end/SourceFile.js',
             'inspector/front-end/SourceFrame.js',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (93033 => 93034)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-15 06:57:27 UTC (rev 93033)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2011-08-15 08:13:33 UTC (rev 93034)
@@ -69109,6 +69109,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\inspector\front-end\SoftContextMenu.js"
+					>
+				</File>
+				<File
 					RelativePath="..\inspector\front-end\SourceCSSTokenizer.js"
 					>
 				</File>

Modified: trunk/Source/WebCore/inspector/front-end/ConsoleView.js (93033 => 93034)


--- trunk/Source/WebCore/inspector/front-end/ConsoleView.js	2011-08-15 06:57:27 UTC (rev 93033)
+++ trunk/Source/WebCore/inspector/front-end/ConsoleView.js	2011-08-15 08:13:33 UTC (rev 93034)
@@ -542,6 +542,7 @@
         }
         contextMenu.appendCheckboxItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Preserve log upon navigation" : "Preserve Log upon Navigation"), preserveLogItemAction.bind(this), WebInspector.settings.preserveConsoleLog.get());
 
+        contextMenu.appendSeparator();
         contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear console" : "Clear Console"), this.requestClearMessages.bind(this));
         contextMenu.show(event);
     },

Added: trunk/Source/WebCore/inspector/front-end/SoftContextMenu.js (0 => 93034)


--- trunk/Source/WebCore/inspector/front-end/SoftContextMenu.js	                        (rev 0)
+++ trunk/Source/WebCore/inspector/front-end/SoftContextMenu.js	2011-08-15 08:13:33 UTC (rev 93034)
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2011 Google Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+if (!InspectorFrontendHost.showContextMenu) {
+
+WebInspector.SoftContextMenu = function(items)
+{
+    this._items = items;
+}
+
+WebInspector.SoftContextMenu.prototype = {
+    show: function(event)
+    {
+        this._x = event.x;
+        this._y = event.y;
+        this._time = new Date().getTime();
+
+        // Absolutely position menu for iframes.
+        var absoluteX = event.pageX;
+        var absoluteY = event.pageY;
+        var targetElement = event.target;
+        while (targetElement && window !== targetElement.ownerDocument.defaultView) {
+            var frameElement = targetElement.ownerDocument.defaultView.frameElement;
+            absoluteY += frameElement.totalOffsetTop;
+            absoluteX += frameElement.totalOffsetLeft;
+            targetElement = frameElement;
+        }
+
+        // Install glass pane capturing events.
+        this._glassPaneElement = document.createElement("div");
+        this._glassPaneElement.className = "soft-context-menu-glass-pane";
+        this._glassPaneElement.tabIndex = 0;
+        this._glassPaneElement.addEventListener("mouseup", this._glassPaneMouseUp.bind(this), false);
+
+        // Create context menu.
+        this._contextMenuElement = document.createElement("div");
+        this._contextMenuElement.className = "soft-context-menu";
+        this._contextMenuElement.tabIndex = 0;
+        this._contextMenuElement.style.top = absoluteY + "px";
+        this._contextMenuElement.style.left = absoluteX + "px";
+
+        this._contextMenuElement.addEventListener("mousedown", this._discardMenu.bind(this), false);
+        this._contextMenuElement.addEventListener("keydown", this._menuKeyDown.bind(this), false);
+        this._contextMenuElement.addEventListener("blur", this._discardMenu.bind(this), false);
+
+        for (var i = 0; i < this._items.length; ++i)
+            this._contextMenuElement.appendChild(this._createMenuItem(this._items[i]));
+
+        this._glassPaneElement.appendChild(this._contextMenuElement);
+        document.body.appendChild(this._glassPaneElement);
+        this._contextMenuElement.focus();
+
+        // Re-position menu in case it does not fit.
+        if (document.body.offsetWidth <  this._contextMenuElement.offsetLeft + this._contextMenuElement.offsetWidth)
+            this._contextMenuElement.style.left = (absoluteX - this._contextMenuElement.offsetWidth) + "px";
+        if (document.body.offsetHeight < this._contextMenuElement.offsetTop + this._contextMenuElement.offsetHeight)
+            this._contextMenuElement.style.top = (document.body.offsetHeight - this._contextMenuElement.offsetHeight) + "px";
+
+        event.stopPropagation();
+        event.preventDefault();
+    },
+
+    _createMenuItem: function(item)
+    {
+        if (item.type === "separator")
+            return this._createSeparator();
+
+        var menuItemElement = document.createElement("div");
+        menuItemElement.className = "soft-context-menu-item";
+
+        var checkMarkElement = document.createElement("span");
+        checkMarkElement.textContent = "\u2713 "; // Checkmark Unicode symbol
+        checkMarkElement.style.pointerEvents = "none";
+        if (!item.checked)
+            checkMarkElement.style.opacity = "0";
+
+        menuItemElement.appendChild(checkMarkElement);
+        menuItemElement.appendChild(document.createTextNode(item.label));
+
+        menuItemElement.addEventListener("mousedown", this._menuItemMouseDown.bind(this), false);
+        menuItemElement.addEventListener("mouseup", this._menuItemMouseUp.bind(this), false);
+
+        // Manually manage hover highlight since :hover does not work in case of click-and-hold menu invocation.
+        menuItemElement.addEventListener("mouseover", this._menuItemMouseOver.bind(this), false);
+        menuItemElement.addEventListener("mouseout", this._menuItemMouseOut.bind(this), false);
+
+        menuItemElement._actionId = item.id;
+        return menuItemElement;
+    },
+
+    _createSeparator: function()
+    {
+        var separatorElement = document.createElement("div");
+        separatorElement.className = "soft-context-menu-separator";
+        separatorElement._isSeparator = true;
+        return separatorElement;
+    },
+
+    _menuItemMouseDown: function(event)
+    {
+        // Do not let separator's mouse down hit menu's handler - we need to receive mouse up!
+        event.stopPropagation();
+        event.preventDefault();
+    },
+
+    _menuItemMouseUp: function(event)
+    {
+        this._triggerAction(event.target);
+    },
+
+    _triggerAction: function(menuItemElement)
+    {
+        this._discardMenu(event);
+        if (typeof menuItemElement._actionId !== "undefined") {
+            WebInspector.contextMenuItemSelected(menuItemElement._actionId);
+            delete menuItemElement._actionId;
+        }
+    },
+
+    _menuItemMouseOver: function(event)
+    {
+        this._highlightMenuItem(event.target);
+    },
+
+    _menuItemMouseOut: function(event)
+    {
+        this._highlightMenuItem(null);
+    },
+
+    _highlightMenuItem: function(menuItemElement)
+    {
+        if (this._highlightedMenuItemElement)
+            this._highlightedMenuItemElement.removeStyleClass("soft-context-menu-item-mouse-over");
+        this._highlightedMenuItemElement = menuItemElement;
+        if (this._highlightedMenuItemElement)
+            this._highlightedMenuItemElement.addStyleClass("soft-context-menu-item-mouse-over");
+    },
+
+    _highlightPrevious: function()
+    {
+        var menuItemElement = this._highlightedMenuItemElement ? this._highlightedMenuItemElement.previousSibling : this._contextMenuElement.lastChild;
+        while (menuItemElement && menuItemElement._isSeparator)
+            menuItemElement = menuItemElement.previousSibling;
+        if (menuItemElement)
+            this._highlightMenuItem(menuItemElement);
+    },
+
+    _highlightNext: function()
+    {
+        var menuItemElement = this._highlightedMenuItemElement ? this._highlightedMenuItemElement.nextSibling : this._contextMenuElement.firstChild;
+        while (menuItemElement && menuItemElement._isSeparator)
+            menuItemElement = menuItemElement.nextSibling;
+        if (menuItemElement)
+            this._highlightMenuItem(menuItemElement);
+    },
+
+    _menuKeyDown: function(event)
+    {
+        switch (event.keyIdentifier) {
+        case "Up":
+            this._highlightPrevious(); break;
+        case "Down":
+            this._highlightNext(); break;
+        case "U+001B": // Escape
+            this._discardMenu(event); break;
+        case "Enter":
+            if (!isEnterKey(event))
+                break;
+            // Fall through
+        case "U+0020": // Space
+            if (this._highlightedMenuItemElement)
+                this._triggerAction(this._highlightedMenuItemElement);
+            break;
+        }
+        event.stopPropagation();
+        event.preventDefault();
+    },
+
+    _glassPaneMouseUp: function(event)
+    {
+        // Return if this is simple 'click', since dispatched on glass pane, can't use 'click' event.
+        if (event.x === this._x && event.y === this._y && new Date().getTime() - this._time < 300)
+            return;
+        this._discardMenu(event);
+    },
+
+    _discardMenu: function(event)
+    {
+        if (this._glassPaneElement) {
+            var glassPane = this._glassPaneElement;
+            delete this._glassPaneElement;
+            // This can re-enter discardMenu due to blur.
+            document.body.removeChild(glassPane);
+
+            event.stopPropagation();
+            event.preventDefault();
+        }
+    }
+}
+
+InspectorFrontendHost.showContextMenu = function(event, items)
+{
+    new WebInspector.SoftContextMenu(items).show(event);
+}
+
+}
Property changes on: trunk/Source/WebCore/inspector/front-end/SoftContextMenu.js
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/inspector/front-end/WebKit.qrc (93033 => 93034)


--- trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-08-15 06:57:27 UTC (rev 93033)
+++ trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2011-08-15 08:13:33 UTC (rev 93034)
@@ -16,7 +16,6 @@
     <file>Color.js</file>
     <file>ConsolePanel.js</file>
     <file>ConsoleView.js</file>
-    <file>_javascript_ContextManager.js</file>
     <file>ContextMenu.js</file>
     <file>CookieItemsView.js</file>
     <file>CookieParser.js</file>
@@ -62,6 +61,7 @@
     <file>InjectedFakeWorker.js</file>
     <file>inspector.js</file>
     <file>InspectorFrontendHostStub.js</file>
+    <file>_javascript_ContextManager.js</file>
     <file>_javascript_Formatter.js</file>
     <file>KeyboardShortcut.js</file>
     <file>MetricsSidebarPane.js</file>
@@ -105,6 +105,7 @@
     <file>ShowMoreDataGridNode.js</file>
     <file>SidebarPane.js</file>
     <file>SidebarTreeElement.js</file>
+    <file>SoftContextMenu.js</file>
     <file>SourceCSSTokenizer.js</file>
     <file>SourceFrame.js</file>
     <file>SourceHTMLTokenizer.js</file>

Modified: trunk/Source/WebCore/inspector/front-end/inspector.css (93033 => 93034)


--- trunk/Source/WebCore/inspector/front-end/inspector.css	2011-08-15 06:57:27 UTC (rev 93033)
+++ trunk/Source/WebCore/inspector/front-end/inspector.css	2011-08-15 08:13:33 UTC (rev 93034)
@@ -4068,3 +4068,40 @@
     height: 100%;
     position: absolute;
 }
+
+.soft-context-menu-glass-pane {
+    position: absolute;
+    top: 0;
+    bottom: 0;
+    left: 0;
+    right: 0;
+    z-index: 20000;
+}
+
+.soft-context-menu {
+    position: absolute;
+    border: 1px solid rgb(180, 180, 180);
+    border-radius: 5px;
+    background-color: rgba(255, 255, 255, 0.95);
+    -webkit-box-shadow: rgba(0, 0, 0, 0.5) 0 3px 10px;
+}
+
+.soft-context-menu-item {
+    width: 100%;
+    line-height: 13px;
+    font-size: 13px;
+    padding: 4px 7px;
+    margin: 3px 0;
+    white-space: nowrap;
+}
+
+.soft-context-menu-separator {
+    margin-top: 6px;
+    margin-bottom: 6px;
+    border-bottom: 1px solid rgb(180, 180, 180);
+}
+
+.soft-context-menu-item-mouse-over {
+    background-color: rgb(56, 121, 217);
+    color: white;
+}

Modified: trunk/Source/WebCore/inspector/front-end/inspector.html (93033 => 93034)


--- trunk/Source/WebCore/inspector/front-end/inspector.html	2011-08-15 06:57:27 UTC (rev 93033)
+++ trunk/Source/WebCore/inspector/front-end/inspector.html	2011-08-15 08:13:33 UTC (rev 93034)
@@ -51,6 +51,7 @@
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
+    <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to