Title: [219870] trunk
Revision
219870
Author
drou...@apple.com
Date
2017-07-25 10:07:22 -0700 (Tue, 25 Jul 2017)

Log Message

Web Inspector: add context menu item for taking a screenshot of a node
https://bugs.webkit.org/show_bug.cgi?id=174754

Reviewed by Brian Burg.

Source/WebInspectorUI:

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Views/ContextMenuUtilities.js:
(WebInspector.appendContextMenuItemsForDOMNode):
Add "Capture Element Screenshot " context menu item that opens a save dialog with a picture of the node.

* UserInterface/Base/Main.js:
(WebInspector.saveDataToFile):
Allow the saveData to specify whether the contained content is base64Encoded, instead of
having to go through a Blob to save base64 data.

* UserInterface/Base/Utilities.js:
Add Number.pad to add leading zeros up to a certain width.

Drive-by: fix failing test for Number.constrain.

* UserInterface/Models/DOMNode.js:
(WebInspector.DOMNode.prototype.scrollIntoView.resolvedNode.scrollIntoView): Added.
(WebInspector.DOMNode.prototype.scrollIntoView.resolvedNode): Added.
(WebInspector.DOMNode.prototype.scrollIntoView): Added.
* UserInterface/Views/DOMTreeElement.js:
(WebInspector.DOMTreeElement.prototype._populateNodeContextMenu):
(WebInspector.DOMTreeElement.prototype._scrollIntoView.resolvedNode.scrollIntoView): Deleted.
(WebInspector.DOMTreeElement.prototype._scrollIntoView.resolvedNode): Deleted.
(WebInspector.DOMTreeElement.prototype._scrollIntoView): Deleted.
* UserInterface/Views/DOMTreeOutline.js:
(WebInspector.DOMTreeOutline.prototype.populateContextMenu):
Drive-by: move "Scroll Into View" context menu command to WebInspector.appendContextMenuItemsForDOMNode
so that it can be triggered from more places than just the DOM tree.

LayoutTests:

* inspector/unit-tests/number-utilities-expected.txt:
* inspector/unit-tests/number-utilities.html:
Add test for Number.zeroPad.

Drive-by: Change tests to use expectEqual for better output on failure.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219869 => 219870)


--- trunk/LayoutTests/ChangeLog	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/LayoutTests/ChangeLog	2017-07-25 17:07:22 UTC (rev 219870)
@@ -1,3 +1,15 @@
+2017-07-25  Devin Rousso  <drou...@apple.com>
+        Web Inspector: add context menu item for taking a screenshot of a node
+        https://bugs.webkit.org/show_bug.cgi?id=174754
+
+        Reviewed by Brian Burg.
+
+        * inspector/unit-tests/number-utilities-expected.txt:
+        * inspector/unit-tests/number-utilities.html:
+        Add test for Number.zeroPad.
+
+        Drive-by: Change tests to use expectEqual for better output on failure.
+
 2017-07-25  Claudio Saavedra  <csaave...@igalia.com>
 
         REGRESSION (r143068): fast/events/clientXY-in-zoom-and-scroll.html failing on GTK, Qt

Modified: trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt (219869 => 219870)


--- trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/LayoutTests/inspector/unit-tests/number-utilities-expected.txt	2017-07-25 17:07:22 UTC (rev 219870)
@@ -11,9 +11,7 @@
 PASS: constrain of a value above max becomes max
 PASS: constrain of a value above max becomes max
 PASS: constrain of a value above max becomes max
-FAIL: constrain of NaN becomes min
-    Expected: truthy
-    Actual: false
+PASS: constrain of NaN becomes min
 
 -- Running test case: Number.secondsToString
 PASS: normal resolution of 0ms should be ms with no decimals
@@ -53,3 +51,15 @@
 -- Running test case: Number.percentageString
 PASS: precision should default to 1 if unspecified
 
+-- Running test case: Number.zeroPad
+PASS: padding of 0 should add no zeros
+PASS: padding of 1 with one digit should add no zeros
+PASS: padding of 2 with one digit should add one zero
+PASS: padding of 1 with two digits should add no zeros
+PASS: padding of 2 with two digits should add no zeros
+PASS: padding of 3 with two digits should add one zero
+PASS: padding of 4 with two digits should add two zeros
+PASS: padding of 2 with one decimal should add no zeros
+PASS: padding of 3 with one decimal should add no zeros
+PASS: padding of 4 with one decimal should add one zero
+

Modified: trunk/LayoutTests/inspector/unit-tests/number-utilities.html (219869 => 219870)


--- trunk/LayoutTests/inspector/unit-tests/number-utilities.html	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/LayoutTests/inspector/unit-tests/number-utilities.html	2017-07-25 17:07:22 UTC (rev 219870)
@@ -10,20 +10,20 @@
     suite.addTestCase({
         name: "Number.constrain",
         test() {
-            InspectorTest.expectThat(Number.constrain(0, -1, 1) === 0, "constrain of a value between min and max does not change");
-            InspectorTest.expectThat(Number.constrain(0.5, -1, 1) === 0.5, "constrain of a value between min and max does not change");
-            InspectorTest.expectThat(Number.constrain(1, -1, 1) === 1, "constrain of a value between min and max does not change");
-            InspectorTest.expectThat(Number.constrain(-1, -1, 1) === -1, "constrain of a value between min and max does not change");
+            InspectorTest.expectEqual(Number.constrain(0, -1, 1), 0, "constrain of a value between min and max does not change");
+            InspectorTest.expectEqual(Number.constrain(0.5, -1, 1), 0.5, "constrain of a value between min and max does not change");
+            InspectorTest.expectEqual(Number.constrain(1, -1, 1), 1, "constrain of a value between min and max does not change");
+            InspectorTest.expectEqual(Number.constrain(-1, -1, 1), -1, "constrain of a value between min and max does not change");
             
-            InspectorTest.expectThat(Number.constrain(-1.01, -1, 1) === -1, "constrain of a value below min becomes min");
-            InspectorTest.expectThat(Number.constrain(-2, -1, 1) === -1, "constrain of a value below min becomes min");
-            InspectorTest.expectThat(Number.constrain(-Infinity, -1, 1) === -1, "constrain of a value below min becomes min");
+            InspectorTest.expectEqual(Number.constrain(-1.01, -1, 1), -1, "constrain of a value below min becomes min");
+            InspectorTest.expectEqual(Number.constrain(-2, -1, 1), -1, "constrain of a value below min becomes min");
+            InspectorTest.expectEqual(Number.constrain(-Infinity, -1, 1), -1, "constrain of a value below min becomes min");
 
-            InspectorTest.expectThat(Number.constrain(1.01, -1, 1) === 1, "constrain of a value above max becomes max");
-            InspectorTest.expectThat(Number.constrain(2, -1, 1) === 1, "constrain of a value above max becomes max");
-            InspectorTest.expectThat(Number.constrain(Infinity, -1, 1) === 1, "constrain of a value above max becomes max");
+            InspectorTest.expectEqual(Number.constrain(1.01, -1, 1), 1, "constrain of a value above max becomes max");
+            InspectorTest.expectEqual(Number.constrain(2, -1, 1), 1, "constrain of a value above max becomes max");
+            InspectorTest.expectEqual(Number.constrain(Infinity, -1, 1), 1, "constrain of a value above max becomes max");
             
-            InspectorTest.expectThat(Number.constrain(NaN, -1, 1) === -1, "constrain of NaN becomes min");
+            InspectorTest.expectEqual(Number.constrain(NaN, -1, 1), -1, "constrain of NaN becomes min");
             return true;
         }
     });
@@ -32,29 +32,29 @@
         name: "Number.secondsToString",
         test() {
             // Normal resolution.
-            InspectorTest.expectThat(Number.secondsToString(0, false) === "0ms", "normal resolution of 0ms should be ms with no decimals");
-            InspectorTest.expectThat(Number.secondsToString(0.000123456, false) === "0.12ms", "normal resolution of sub 1ms should be ms");
-            InspectorTest.expectThat(Number.secondsToString(0.00123456, false) === "1.23ms", "normal resolution of sub 10ms should be ms");
-            InspectorTest.expectThat(Number.secondsToString(0.0123456, false) === "12.3ms", "normal resolution of sub 100ms should be ms");
-            InspectorTest.expectThat(Number.secondsToString(0.123456, false) === "123ms", "normal resolution of greater than 100ms but sub 1s should be ms");
-            InspectorTest.expectThat(Number.secondsToString(1.123456, false) === "1.12s", "normal resolution of greater than 1s but sub 1min should be seconds");
-            InspectorTest.expectThat(Number.secondsToString(30.123456, false) === "30.12s", "normal resolution of greater than 1s but sub 1min should be seconds");
-            InspectorTest.expectThat(Number.secondsToString(60.123456, false) === "1.0min", "normal resolution of greater than 1min but sub 1hr should be minutes");
-            InspectorTest.expectThat(Number.secondsToString(100.123456, false) === "1.7min", "normal resolution of greater than 1min but sub 1hr should be minutes");
-            InspectorTest.expectThat(Number.secondsToString(12345, false) === "3.4hrs", "normal resolution of greater than 1hr but sub 1 day should be hrs");
-            InspectorTest.expectThat(Number.secondsToString(123456, false) === "1.4 days", "normal resolution of greater than 1 day should be days");
-            InspectorTest.expectThat(Number.secondsToString(1234567, false) === "14.3 days", "normal resolution of greater than 1 day should be days");
+            InspectorTest.expectEqual(Number.secondsToString(0, false), "0ms", "normal resolution of 0ms should be ms with no decimals");
+            InspectorTest.expectEqual(Number.secondsToString(0.000123456, false), "0.12ms", "normal resolution of sub 1ms should be ms");
+            InspectorTest.expectEqual(Number.secondsToString(0.00123456, false), "1.23ms", "normal resolution of sub 10ms should be ms");
+            InspectorTest.expectEqual(Number.secondsToString(0.0123456, false), "12.3ms", "normal resolution of sub 100ms should be ms");
+            InspectorTest.expectEqual(Number.secondsToString(0.123456, false), "123ms", "normal resolution of greater than 100ms but sub 1s should be ms");
+            InspectorTest.expectEqual(Number.secondsToString(1.123456, false), "1.12s", "normal resolution of greater than 1s but sub 1min should be seconds");
+            InspectorTest.expectEqual(Number.secondsToString(30.123456, false), "30.12s", "normal resolution of greater than 1s but sub 1min should be seconds");
+            InspectorTest.expectEqual(Number.secondsToString(60.123456, false), "1.0min", "normal resolution of greater than 1min but sub 1hr should be minutes");
+            InspectorTest.expectEqual(Number.secondsToString(100.123456, false), "1.7min", "normal resolution of greater than 1min but sub 1hr should be minutes");
+            InspectorTest.expectEqual(Number.secondsToString(12345, false), "3.4hrs", "normal resolution of greater than 1hr but sub 1 day should be hrs");
+            InspectorTest.expectEqual(Number.secondsToString(123456, false), "1.4 days", "normal resolution of greater than 1 day should be days");
+            InspectorTest.expectEqual(Number.secondsToString(1234567, false), "14.3 days", "normal resolution of greater than 1 day should be days");
 
             // High resolution.
-            InspectorTest.expectThat(Number.secondsToString(0, true) === "0ms", "high resolution of 0ms should be ms with no decimals");
-            InspectorTest.expectThat(Number.secondsToString(0.000123456, true) === "0.123ms", "high resolution of sub 1ms should be ms with decimals");
-            InspectorTest.expectThat(Number.secondsToString(0.00123456, true) === "1.235ms", "high resolution of sub 10ms should be ms with decimals");
-            InspectorTest.expectThat(Number.secondsToString(0.0123456, true) === "12.35ms", "high resolution of sub 100ms should be ms with decimals");
-            InspectorTest.expectThat(Number.secondsToString(0.123456, true) === "123.5ms", "high resolution of greater than 100ms but sub 1s should be ms with decimals");
-            InspectorTest.expectThat(Number.secondsToString(1.123456, true) === "1.12s", "high resolution of greater than 1s should be seconds with decimals");
-            InspectorTest.expectThat(Number.secondsToString(30.123456, true) === "30.12s", "high resolution of greater than 1s should be seconds with decimals");
-            InspectorTest.expectThat(Number.secondsToString(60.123456, true) === "60.12s", "high resolution of greater than 1s should be seconds with decimals");
-            InspectorTest.expectThat(Number.secondsToString(100.123456, true) === "100.12s", "high resolution greater than 1s should be seconds with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(0, true), "0ms", "high resolution of 0ms should be ms with no decimals");
+            InspectorTest.expectEqual(Number.secondsToString(0.000123456, true), "0.123ms", "high resolution of sub 1ms should be ms with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(0.00123456, true), "1.235ms", "high resolution of sub 10ms should be ms with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(0.0123456, true), "12.35ms", "high resolution of sub 100ms should be ms with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(0.123456, true), "123.5ms", "high resolution of greater than 100ms but sub 1s should be ms with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(1.123456, true), "1.12s", "high resolution of greater than 1s should be seconds with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(30.123456, true), "30.12s", "high resolution of greater than 1s should be seconds with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(60.123456, true), "60.12s", "high resolution of greater than 1s should be seconds with decimals");
+            InspectorTest.expectEqual(Number.secondsToString(100.123456, true), "100.12s", "high resolution greater than 1s should be seconds with decimals");
 
             return true;
         }
@@ -67,18 +67,18 @@
             const mb = kb * 1024;
 
             // Normal resolution.
-            InspectorTest.expectThat(Number.bytesToString(123, false) === "123 B", "normal resolution of sub 1k should be bytes");
-            InspectorTest.expectThat(Number.bytesToString(1.23 * kb, false) === "1.23 KB", "normal resolution of sub 10k should be kilobytes");
-            InspectorTest.expectThat(Number.bytesToString(10.123 * kb, false) === "10.1 KB", "normal resolution of sub 10k should be kilobytes");
-            InspectorTest.expectThat(Number.bytesToString(1.123 * mb, false) === "1.12 MB", "normal resolution of sub 10mb should be megabytes");
-            InspectorTest.expectThat(Number.bytesToString(10.123 * mb, false) === "10.1 MB", "normal resolution of greater than 10mb should be megabytes");
+            InspectorTest.expectEqual(Number.bytesToString(123, false), "123 B", "normal resolution of sub 1k should be bytes");
+            InspectorTest.expectEqual(Number.bytesToString(1.23 * kb, false), "1.23 KB", "normal resolution of sub 10k should be kilobytes");
+            InspectorTest.expectEqual(Number.bytesToString(10.123 * kb, false), "10.1 KB", "normal resolution of sub 10k should be kilobytes");
+            InspectorTest.expectEqual(Number.bytesToString(1.123 * mb, false), "1.12 MB", "normal resolution of sub 10mb should be megabytes");
+            InspectorTest.expectEqual(Number.bytesToString(10.123 * mb, false), "10.1 MB", "normal resolution of greater than 10mb should be megabytes");
 
             // High resolution.
-            InspectorTest.expectThat(Number.bytesToString(123, true) === "123 B", "high resolution of sub 1k should be bytes");
-            InspectorTest.expectThat(Number.bytesToString(1.23 * kb, true) === "1.23 KB", "high resolution of sub 10k should be kilobytes");
-            InspectorTest.expectThat(Number.bytesToString(10.123 * kb, true) === "10.12 KB", "high resolution of sub 10k should be kilobytes");
-            InspectorTest.expectThat(Number.bytesToString(1.123 * mb, true) === "1.12 MB", "high resolution of sub 10mb should be megabytes");
-            InspectorTest.expectThat(Number.bytesToString(10.123 * mb, true) === "10.12 MB", "high resolution of greater than 10mb should be megabytes");
+            InspectorTest.expectEqual(Number.bytesToString(123, true), "123 B", "high resolution of sub 1k should be bytes");
+            InspectorTest.expectEqual(Number.bytesToString(1.23 * kb, true), "1.23 KB", "high resolution of sub 10k should be kilobytes");
+            InspectorTest.expectEqual(Number.bytesToString(10.123 * kb, true), "10.12 KB", "high resolution of sub 10k should be kilobytes");
+            InspectorTest.expectEqual(Number.bytesToString(1.123 * mb, true), "1.12 MB", "high resolution of sub 10mb should be megabytes");
+            InspectorTest.expectEqual(Number.bytesToString(10.123 * mb, true), "10.12 MB", "high resolution of greater than 10mb should be megabytes");
 
             return true;
         }
@@ -87,12 +87,32 @@
     suite.addTestCase({
         name: "Number.percentageString",
         test() {
-            InspectorTest.expectThat(Number.percentageString(1 / 3) === "33.3%", "precision should default to 1 if unspecified");
+            InspectorTest.expectEqual(Number.percentageString(1 / 3), "33.3%", "precision should default to 1 if unspecified");
 
             return true;
         }
     });
 
+    suite.addTestCase({
+        name: "Number.zeroPad",
+        test() {
+            InspectorTest.expectEqual(Number.zeroPad(1, 0), "1", "padding of 0 should add no zeros");
+            InspectorTest.expectEqual(Number.zeroPad(1, 1), "1", "padding of 1 with one digit should add no zeros");
+            InspectorTest.expectEqual(Number.zeroPad(1, 2), "01", "padding of 2 with one digit should add one zero");
+            
+            InspectorTest.expectEqual(Number.zeroPad(10, 1), "10", "padding of 1 with two digits should add no zeros");
+            InspectorTest.expectEqual(Number.zeroPad(10, 2), "10", "padding of 2 with two digits should add no zeros");
+            InspectorTest.expectEqual(Number.zeroPad(10, 3), "010", "padding of 3 with two digits should add one zero");
+            InspectorTest.expectEqual(Number.zeroPad(10, 4), "0010", "padding of 4 with two digits should add two zeros");
+
+            InspectorTest.expectEqual(Number.zeroPad(1.1, 2), "1.1", "padding of 2 with one decimal should add no zeros");
+            InspectorTest.expectEqual(Number.zeroPad(1.1, 3), "1.1", "padding of 3 with one decimal should add no zeros");
+            InspectorTest.expectEqual(Number.zeroPad(1.1, 4), "01.1", "padding of 4 with one decimal should add one zero");
+
+            return true;
+        }
+    });
+
     suite.runTestCasesAndFinish();
 }
 </script>

Modified: trunk/Source/WebInspectorUI/ChangeLog (219869 => 219870)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-07-25 17:07:22 UTC (rev 219870)
@@ -1,3 +1,39 @@
+2017-07-25  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: add context menu item for taking a screenshot of a node
+        https://bugs.webkit.org/show_bug.cgi?id=174754
+
+        Reviewed by Brian Burg.
+
+        * Localizations/en.lproj/localizedStrings.js:
+        * UserInterface/Views/ContextMenuUtilities.js:
+        (WebInspector.appendContextMenuItemsForDOMNode):
+        Add "Capture Element Screenshot " context menu item that opens a save dialog with a picture of the node.
+
+        * UserInterface/Base/Main.js:
+        (WebInspector.saveDataToFile):
+        Allow the saveData to specify whether the contained content is base64Encoded, instead of
+        having to go through a Blob to save base64 data.
+
+        * UserInterface/Base/Utilities.js:
+        Add Number.pad to add leading zeros up to a certain width.
+
+        Drive-by: fix failing test for Number.constrain.
+
+        * UserInterface/Models/DOMNode.js:
+        (WebInspector.DOMNode.prototype.scrollIntoView.resolvedNode.scrollIntoView): Added.
+        (WebInspector.DOMNode.prototype.scrollIntoView.resolvedNode): Added.
+        (WebInspector.DOMNode.prototype.scrollIntoView): Added.
+        * UserInterface/Views/DOMTreeElement.js:
+        (WebInspector.DOMTreeElement.prototype._populateNodeContextMenu):
+        (WebInspector.DOMTreeElement.prototype._scrollIntoView.resolvedNode.scrollIntoView): Deleted.
+        (WebInspector.DOMTreeElement.prototype._scrollIntoView.resolvedNode): Deleted.
+        (WebInspector.DOMTreeElement.prototype._scrollIntoView): Deleted.
+        * UserInterface/Views/DOMTreeOutline.js:
+        (WebInspector.DOMTreeOutline.prototype.populateContextMenu):
+        Drive-by: move "Scroll Into View" context menu command to WebInspector.appendContextMenuItemsForDOMNode
+        so that it can be triggered from more places than just the DOM tree.
+
 2017-07-24  Nikita Vasilyev  <m...@elv1s.ru>
 
         Web Inspector: Settings: Some controls overlay settings header

Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (219869 => 219870)


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2017-07-25 17:07:22 UTC (rev 219870)
@@ -156,6 +156,7 @@
 localizedStrings["Canvases"] = "Canvases";
 localizedStrings["Cap"] = "Cap";
 localizedStrings["Caps"] = "Caps";
+localizedStrings["Capture Element Screenshot"] = "Capture Element Screenshot";
 localizedStrings["Capturing"] = "Capturing";
 localizedStrings["Catch Variables"] = "Catch Variables";
 localizedStrings["Categories"] = "Categories";
@@ -724,6 +725,7 @@
 localizedStrings["Scheme"] = "Scheme";
 localizedStrings["Scope"] = "Scope";
 localizedStrings["Scope Chain"] = "Scope Chain";
+localizedStrings["Screen Shot %s-%s-%s at %s.%s.%s"] = "Screen Shot %s-%s-%s at %s.%s.%s";
 localizedStrings["Script"] = "Script";
 localizedStrings["Script Element %d"] = "Script Element %d";
 localizedStrings["Script Evaluated"] = "Script Evaluated";

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (219869 => 219870)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2017-07-25 17:07:22 UTC (rev 219870)
@@ -885,7 +885,7 @@
     }
 
     if (typeof saveData.content === "string") {
-        const base64Encoded = false;
+        const base64Encoded = saveData.base64Encoded || false;
         InspectorFrontendHost.save(suggestedName, saveData.content, base64Encoded, forceSaveAs || saveData.forceSaveAs);
         return;
     }

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (219869 => 219870)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2017-07-25 17:07:22 UTC (rev 219870)
@@ -997,7 +997,7 @@
 {
     value: function(num, min, max)
     {
-        if (max < min)
+        if (isNaN(num) || max < min)
             return min;
 
         if (num < min)
@@ -1119,6 +1119,15 @@
     }
 });
 
+Object.defineProperty(Number, "zeroPad",
+{
+    value(num, length)
+    {
+        let string = num.toLocaleString();
+        return string.padStart(length, "0");
+    },
+});
+
 Object.defineProperty(Number.prototype, "maxDecimals",
 {
     value(decimals)

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/DOMNode.js (219869 => 219870)


--- trunk/Source/WebInspectorUI/UserInterface/Models/DOMNode.js	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/DOMNode.js	2017-07-25 17:07:22 UTC (rev 219870)
@@ -458,6 +458,25 @@
         WebInspector.RemoteObject.resolveNode(this, "", resolvedNode);
     }
 
+    scrollIntoView()
+    {
+        function resolvedNode(object)
+        {
+            if (!object)
+                return;
+
+            function inspectedPage_node_scrollIntoView()
+            {
+                this.scrollIntoViewIfNeeded(true);
+            }
+
+            object.callFunction(inspectedPage_node_scrollIntoView);
+            object.release();
+        }
+
+        WebInspector.RemoteObject.resolveNode(this, "", resolvedNode);
+    }
+
     getChildNodes(callback)
     {
         if (this.children) {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js (219869 => 219870)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js	2017-07-25 17:07:22 UTC (rev 219870)
@@ -110,6 +110,11 @@
         return;
 
     let isElement = domNode.nodeType() === Node.ELEMENT_NODE;
+    if (isElement) {
+        contextMenu.appendItem(WebInspector.UIString("Scroll Into View"), () => {
+            domNode.scrollIntoView();
+        });
+    }
 
     contextMenu.appendSeparator();
 
@@ -194,4 +199,37 @@
             });
         });
     }
+
+    if (window.PageAgent) {
+        contextMenu.appendItem(WebInspector.UIString("Capture Element Screenshot"), () => {
+            PageAgent.snapshotNode(domNode.id, (error, dataURL) => {
+                if (error) {
+                    const target = WebInspector.mainTarget;
+                    const source = WebInspector.ConsoleMessage.MessageSource.Other;
+                    const level = WebInspector.ConsoleMessage.MessageLevel.Error;
+                    let consoleMessage = new WebInspector.ConsoleMessage(target, source, level, error);
+                    consoleMessage.shouldRevealConsole = true;
+
+                    WebInspector.consoleLogViewController.appendConsoleMessage(consoleMessage);
+                    return;
+                }
+
+                let date = new Date;
+                let values = [
+                    date.getFullYear(),
+                    Number.zeroPad(date.getMonth() + 1, 2),
+                    Number.zeroPad(date.getDate(), 2),
+                    Number.zeroPad(date.getHours(), 2),
+                    Number.zeroPad(date.getMinutes(), 2),
+                    Number.zeroPad(date.getSeconds(), 2),
+                ];
+                let filename = WebInspector.UIString("Screen Shot %s-%s-%s at %s.%s.%s").format(...values);
+                WebInspector.saveDataToFile({
+                    url: encodeURI(`web-inspector:///${filename}.png`),
+                    content: parseDataURL(dataURL).data,
+                    base64Encoded: true,
+                });
+            });
+        });
+    }
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js (219869 => 219870)


--- trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js	2017-07-25 17:07:22 UTC (rev 219870)
@@ -787,8 +787,6 @@
             contextMenu.appendItem(WebInspector.UIString("Copy as HTML"), this._copyHTML.bind(this));
         if (this.editable)
             contextMenu.appendItem(WebInspector.UIString("Delete Node"), this.remove.bind(this));
-        if (node.nodeType() === Node.ELEMENT_NODE)
-            contextMenu.appendItem(WebInspector.UIString("Scroll Into View"), this._scrollIntoView.bind(this));
     }
 
     _startEditing()
@@ -1521,26 +1519,6 @@
         this.representedObject.removeNode(removeNodeCallback);
     }
 
-    _scrollIntoView()
-    {
-        function resolvedNode(object)
-        {
-            if (!object)
-                return;
-
-            function scrollIntoView()
-            {
-                this.scrollIntoViewIfNeeded(true);
-            }
-
-            object.callFunction(scrollIntoView, undefined, false, function() {});
-            object.release();
-        }
-
-        let node = this.representedObject;
-        WebInspector.RemoteObject.resolveNode(node, "", resolvedNode);
-    }
-
     _editAsHTML()
     {
         var treeOutline = this.treeOutline;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js (219869 => 219870)


--- trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js	2017-07-25 16:49:49 UTC (rev 219869)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js	2017-07-25 17:07:22 UTC (rev 219870)
@@ -243,19 +243,12 @@
         let commentNode = event.target.enclosingNodeOrSelfWithClass("html-comment");
         let pseudoElement = event.target.enclosingNodeOrSelfWithClass("html-pseudo-element");
 
-        if (tag && treeElement._populateTagContextMenu) {
-            contextMenu.appendSeparator();
-
+        if (tag && treeElement._populateTagContextMenu)
             treeElement._populateTagContextMenu(contextMenu, event);
-        } else if (textNode && treeElement._populateTextContextMenu) {
-            contextMenu.appendSeparator();
-
+        else if (textNode && treeElement._populateTextContextMenu)
             treeElement._populateTextContextMenu(contextMenu, textNode);
-        } else if ((commentNode || pseudoElement) && treeElement._populateNodeContextMenu) {
-            contextMenu.appendSeparator();
-
+        else if ((commentNode || pseudoElement) && treeElement._populateNodeContextMenu)
             treeElement._populateNodeContextMenu(contextMenu);
-        }
 
         const options = {excludeRevealElement: this._excludeRevealElementContextMenu};
         WebInspector.appendContextMenuItemsForDOMNode(contextMenu, treeElement.representedObject, options);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to