Title: [144405] trunk
Revision
144405
Author
[email protected]
Date
2013-02-28 17:58:44 -0800 (Thu, 28 Feb 2013)

Log Message

WebInspector: Switch hide element shortcut in ElementsPanel to use a selector
https://bugs.webkit.org/show_bug.cgi?id=110641

Patch by Eberhard Graether <[email protected]> on 2013-02-28
Reviewed by Pavel Feldman.

This change switches the shortcut for adding visibility:hidden to an element's style
to toggling a class name on the element and injecting a style rule into the element's
document instead. This way it is possible to change the visibility of all child
elements as well.

Test: inspector/elements/hide-shortcut.html

Source/WebCore:

* inspector/front-end/CSSStyleModel.js:
* inspector/front-end/ElementsTreeOutline.js:
(WebInspector.ElementsTreeOutline.prototype._onkeydown):
(WebInspector.ElementsTreeOutline.prototype.resolvedNode.toggleClassAndInjectStyleRule):
(WebInspector.ElementsTreeOutline.prototype.):
(WebInspector.ElementsTreeOutline.prototype._toggleHideShortcut):

LayoutTests:

* inspector/elements/hide-shortcut-expected.txt: Added.
* inspector/elements/hide-shortcut.html: Added.
* inspector/elements/resources/hide-shortcut-iframe.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (144404 => 144405)


--- trunk/LayoutTests/ChangeLog	2013-03-01 01:53:51 UTC (rev 144404)
+++ trunk/LayoutTests/ChangeLog	2013-03-01 01:58:44 UTC (rev 144405)
@@ -1,3 +1,21 @@
+2013-02-28  Eberhard Graether  <[email protected]>
+
+        WebInspector: Switch hide element shortcut in ElementsPanel to use a selector
+        https://bugs.webkit.org/show_bug.cgi?id=110641
+
+        Reviewed by Pavel Feldman.
+
+        This change switches the shortcut for adding visibility:hidden to an element's style
+        to toggling a class name on the element and injecting a style rule into the element's
+        document instead. This way it is possible to change the visibility of all child
+        elements as well.
+
+        Test: inspector/elements/hide-shortcut.html
+
+        * inspector/elements/hide-shortcut-expected.txt: Added.
+        * inspector/elements/hide-shortcut.html: Added.
+        * inspector/elements/resources/hide-shortcut-iframe.html: Added.
+
 2013-02-28  Seokju Kwon  <[email protected]>
 
         [EFL] Focus problem in inspector/extensions/extensions-panel.html

Added: trunk/LayoutTests/inspector/elements/hide-shortcut-expected.txt (0 => 144405)


--- trunk/LayoutTests/inspector/elements/hide-shortcut-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/elements/hide-shortcut-expected.txt	2013-03-01 01:58:44 UTC (rev 144405)
@@ -0,0 +1,27 @@
+Tests the hide shortcut, which toggles visibility:hidden on the node and it's ancestors. Bug 110641
+
+parent
+child
+
+
+Running: testSetUp
+
+Running: testToggleHideShortcutOn
+=== Added hide shortcut ===
+=== Parent node is hidden ===
+visibility: hidden;
+=== Child node is hidden ===
+visibility: hidden;
+
+Running: testToggleHideShortcutOff
+=== Removed hide shortcut ===
+=== Parent node is visible ===
+visibility: visible;
+=== Child node is visible ===
+visibility: visible;
+
+Running: testToggleHideShortcutOnInFrame
+=== Added hide shortcut in frame ===
+=== Frame node is hidden ===
+visibility: hidden;
+

Added: trunk/LayoutTests/inspector/elements/hide-shortcut.html (0 => 144405)


--- trunk/LayoutTests/inspector/elements/hide-shortcut.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/elements/hide-shortcut.html	2013-03-01 01:58:44 UTC (rev 144405)
@@ -0,0 +1,128 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+function test()
+{
+    var treeOutline;
+    var parentNode;
+    var childNode;
+    var frameNode;
+
+    WebInspector.showPanel("elements");
+    InspectorTest.runTestSuite([
+        function testSetUp(next)
+        {
+            treeOutline = WebInspector.panels.elements.treeOutline;
+
+            InspectorTest.nodeWithId("parent-node", callback);
+
+            function callback(node)
+            {
+                parentNode = node
+                InspectorTest.nodeWithId("child-node", callback2);
+            }
+
+            function callback2(node)
+            {
+                childNode = node;
+                InspectorTest.nodeWithId("frame-node", callback3);
+            }
+
+            function callback3(node)
+            {
+                frameNode = node;
+                next();
+            }
+        },
+
+        function testToggleHideShortcutOn(next)
+        {
+            treeOutline._toggleHideShortcut(parentNode, callback);
+
+            function callback()
+            {
+                InspectorTest.addResult("=== Added hide shortcut ===");
+                WebInspector.cssModel.getComputedStyleAsync(parentNode.id, callback2);
+            }
+
+            function callback2(style)
+            {
+                InspectorTest.addResult("=== Parent node is hidden ===");
+                InspectorTest.addResult(style.getLiveProperty("visibility").propertyText);
+                WebInspector.cssModel.getComputedStyleAsync(childNode.id, callback3);
+            }
+
+            function callback3(style)
+            {
+                InspectorTest.addResult("=== Child node is hidden ===");
+                InspectorTest.addResult(style.getLiveProperty("visibility").propertyText);
+                next();
+            }
+        },
+
+        function testToggleHideShortcutOff(next)
+        {
+            treeOutline._toggleHideShortcut(parentNode, callback);
+
+            function callback()
+            {
+                InspectorTest.addResult("=== Removed hide shortcut ===");
+                WebInspector.cssModel.getComputedStyleAsync(parentNode.id, callback2);
+            }
+
+            function callback2(style)
+            {
+                InspectorTest.addResult("=== Parent node is visible ===");
+                InspectorTest.addResult(style.getLiveProperty("visibility").propertyText);
+                WebInspector.cssModel.getComputedStyleAsync(childNode.id, callback3);
+            }
+
+            function callback3(style)
+            {
+                InspectorTest.addResult("=== Child node is visible ===");
+                InspectorTest.addResult(style.getLiveProperty("visibility").propertyText);
+                next();
+            }
+        },
+
+        function testToggleHideShortcutOnInFrame(next)
+        {
+            treeOutline._toggleHideShortcut(frameNode, callback);
+
+            function callback()
+            {
+                InspectorTest.addResult("=== Added hide shortcut in frame ===");
+                WebInspector.cssModel.getComputedStyleAsync(frameNode.id, callback2);
+            }
+
+            function callback2(style)
+            {
+                InspectorTest.addResult("=== Frame node is hidden ===");
+                InspectorTest.addResult(style.getLiveProperty("visibility").propertyText);
+                next();
+            }
+        }
+    ]);
+}
+</script>
+</head>
+
+<body>
+<p>
+Tests the hide shortcut, which toggles visibility:hidden on the node and it's ancestors.
+<a href="" 110641</a>
+</p>
+
+<div id="parent-node">parent
+    <div style="visibility:hidden">hidden
+        <div id="child-node" style="visibility:visible">child</div>
+    </div>
+</div>
+
+<iframe src="" _onload_="runTest()">
+
+</body>
+</html>

Added: trunk/LayoutTests/inspector/elements/resources/hide-shortcut-iframe.html (0 => 144405)


--- trunk/LayoutTests/inspector/elements/resources/hide-shortcut-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/elements/resources/hide-shortcut-iframe.html	2013-03-01 01:58:44 UTC (rev 144405)
@@ -0,0 +1,7 @@
+<html>
+<head>
+</head>
+<body>
+<div id="frame-node">iframe</div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (144404 => 144405)


--- trunk/Source/WebCore/ChangeLog	2013-03-01 01:53:51 UTC (rev 144404)
+++ trunk/Source/WebCore/ChangeLog	2013-03-01 01:58:44 UTC (rev 144405)
@@ -1,3 +1,24 @@
+2013-02-28  Eberhard Graether  <[email protected]>
+
+        WebInspector: Switch hide element shortcut in ElementsPanel to use a selector
+        https://bugs.webkit.org/show_bug.cgi?id=110641
+
+        Reviewed by Pavel Feldman.
+
+        This change switches the shortcut for adding visibility:hidden to an element's style
+        to toggling a class name on the element and injecting a style rule into the element's
+        document instead. This way it is possible to change the visibility of all child
+        elements as well.
+
+        Test: inspector/elements/hide-shortcut.html
+
+        * inspector/front-end/CSSStyleModel.js:
+        * inspector/front-end/ElementsTreeOutline.js:
+        (WebInspector.ElementsTreeOutline.prototype._onkeydown):
+        (WebInspector.ElementsTreeOutline.prototype.resolvedNode.toggleClassAndInjectStyleRule):
+        (WebInspector.ElementsTreeOutline.prototype.):
+        (WebInspector.ElementsTreeOutline.prototype._toggleHideShortcut):
+
 2013-02-28  Ryuan Choi  <[email protected]>
 
         [EFL] Build break with --no-web-audio and --no-video

Modified: trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js (144404 => 144405)


--- trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2013-03-01 01:53:51 UTC (rev 144404)
+++ trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2013-03-01 01:58:44 UTC (rev 144405)
@@ -554,29 +554,6 @@
         return new WebInspector.UILocation(uiSourceCode, rawLocation.lineNumber, rawLocation.columnNumber);
     },
 
-    /**
-     * @param {DOMAgent.NodeId} nodeId
-     */
-    toggleInlineVisibility: function(nodeId)
-    {
-        /**
-         * @param {WebInspector.CSSStyleDeclaration} inlineStyles
-         */
-        function callback(inlineStyles)
-        {
-            var visibility = inlineStyles.getLiveProperty("visibility");
-            if (visibility) {
-                if (visibility.value === "hidden")
-                    visibility.setText("", false, true);
-                else
-                    visibility.setValue("hidden", false, true);
-            } else
-                inlineStyles.appendProperty("visibility", "hidden");
-        }
-
-        this.getInlineStylesAsync(nodeId, callback.bind(this));
-    },
-
     __proto__: WebInspector.Object.prototype
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js (144404 => 144405)


--- trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js	2013-03-01 01:53:51 UTC (rev 144404)
+++ trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js	2013-03-01 01:58:44 UTC (rev 144405)
@@ -483,7 +483,7 @@
             return;
 
         if (!treeElement._editing && WebInspector.KeyboardShortcut.hasNoModifiers(keyboardEvent) && keyboardEvent.keyCode === WebInspector.KeyboardShortcut.Keys.H.code) {
-            WebInspector.cssModel.toggleInlineVisibility(node.id);
+            this._toggleHideShortcut(node);
             event.consume(true);
             return;
         }
@@ -610,6 +610,48 @@
         return newTreeItem;
     },
 
+    /**
+     * Runs a script on the node's remote object that toggles a class name on
+     * the node and injects a stylesheet into the head of the node's document
+     * containing a rule to set "visibility: hidden" on the class and all it's
+     * ancestors.
+     *
+     * @param {WebInspector.DOMNode} node
+     * @param {function(?WebInspector.RemoteObject)=} userCallback
+     */
+    _toggleHideShortcut: function(node, userCallback)
+    {
+        function resolvedNode(object)
+        {
+            if (!object)
+                return;
+
+            function toggleClassAndInjectStyleRule()
+            {
+                const className = "__web-inspector-hide-shortcut__";
+                const styleTagId = "__web-inspector-hide-shortcut-style__";
+                const styleRule = ".__web-inspector-hide-shortcut__, .__web-inspector-hide-shortcut__ * { visibility: hidden !important; }";
+
+                this.classList.toggle(className);
+
+                var style = document.head.querySelector("style#" + styleTagId);
+                if (style)
+                    return;
+
+                style = document.createElement("style");
+                style.id = styleTagId;
+                style.type = "text/css";
+                style.innerHTML = styleRule;
+                document.head.appendChild(style);
+            }
+
+            object.callFunction(toggleClassAndInjectStyleRule, undefined, userCallback);
+            object.release();
+        }
+
+        WebInspector.RemoteObject.resolveNode(node, "", resolvedNode);
+    },
+
     __proto__: TreeOutline.prototype
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to