Web Inspector: DOM: "Capture Screenshot" should only be shown if the node is attached
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 18:03:33 +0000 (18:03 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 18:03:33 +0000 (18:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195793
<rdar://problem/48916594>

Reviewed by Joseph Pecoraro.

* UserInterface/Models/DOMNode.js:
(WI.DOMNode.prototype.get attached): Added.

* UserInterface/Views/ContextMenuUtilities.js:
(WI.appendContextMenuItemsForDOMNode):
* UserInterface/Views/DOMTreeElement.js:
(WI.DOMTreeElement.prototype._populateTagContextMenu):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243152 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Models/DOMNode.js
Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js
Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js

index 1762732..164d022 100644 (file)
@@ -1,3 +1,19 @@
+2019-03-19  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: DOM: "Capture Screenshot" should only be shown if the node is attached
+        https://bugs.webkit.org/show_bug.cgi?id=195793
+        <rdar://problem/48916594>
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Models/DOMNode.js:
+        (WI.DOMNode.prototype.get attached): Added.
+
+        * UserInterface/Views/ContextMenuUtilities.js:
+        (WI.appendContextMenuItemsForDOMNode):
+        * UserInterface/Views/DOMTreeElement.js:
+        (WI.DOMTreeElement.prototype._populateTagContextMenu):
+
 2019-03-18  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: HAR Extension for `serverIPAddress` port number
index 5189d62..555c398 100644 (file)
@@ -193,6 +193,15 @@ WI.DOMNode = class DOMNode extends WI.Object
         return this._frame;
     }
 
+    get attached()
+    {
+        for (let node = this; node; node = node.parentNode) {
+            if (node.ownerDocument === node)
+                return true;
+        }
+        return false;
+    }
+
     get children()
     {
         if (!this._children)
index b290ce0..848edd1 100644 (file)
@@ -156,14 +156,16 @@ WI.appendContextMenuItemsForDOMNode = function(contextMenu, domNode, options = {
     let copySubMenu = options.copySubMenu || contextMenu.appendSubMenuItem(WI.UIString("Copy"));
 
     let isElement = domNode.nodeType() === Node.ELEMENT_NODE;
-    if (domNode.ownerDocument && isElement) {
+    let attached = domNode.attached;
+
+    if (isElement && attached) {
         copySubMenu.appendItem(WI.UIString("Selector Path"), () => {
             let cssPath = WI.cssPath(domNode);
             InspectorFrontendHost.copyText(cssPath);
         });
     }
 
-    if (domNode.ownerDocument && !domNode.isPseudoElement()) {
+    if (!domNode.isPseudoElement() && attached) {
         copySubMenu.appendItem(WI.UIString("XPath"), () => {
             let xpath = WI.xpath(domNode);
             InspectorFrontendHost.copyText(xpath);
@@ -205,7 +207,7 @@ WI.appendContextMenuItemsForDOMNode = function(contextMenu, domNode, options = {
         contextMenu.appendSeparator();
     }
 
-    if (WI.domDebuggerManager.supported && isElement && !domNode.isPseudoElement() && domNode.ownerDocument) {
+    if (WI.domDebuggerManager.supported && isElement && !domNode.isPseudoElement() && attached) {
         contextMenu.appendSeparator();
 
         WI.appendContextMenuItemsForDOMNodeBreakpoints(contextMenu, domNode);
@@ -224,19 +226,19 @@ WI.appendContextMenuItemsForDOMNode = function(contextMenu, domNode, options = {
         });
     }
 
-    if (!options.excludeRevealElement && window.DOMAgent && domNode.ownerDocument) {
+    if (!options.excludeRevealElement && window.DOMAgent && attached) {
         contextMenu.appendItem(WI.UIString("Reveal in DOM Tree"), () => {
             WI.domManager.inspectElement(domNode.id);
         });
     }
 
-    if (!options.excludeRevealLayer && window.LayerTreeAgent && domNode.parentNode) {
+    if (!options.excludeRevealLayer && window.LayerTreeAgent && attached) {
         contextMenu.appendItem(WI.UIString("Reveal in Layers Tab"), () => {
             WI.showLayersTab({nodeToSelect: domNode});
         });
     }
 
-    if (window.PageAgent) {
+    if (window.PageAgent && attached) {
         contextMenu.appendItem(WI.UIString("Capture Screenshot"), () => {
             PageAgent.snapshotNode(domNode.id, (error, dataURL) => {
                 if (error) {
@@ -259,7 +261,7 @@ WI.appendContextMenuItemsForDOMNode = function(contextMenu, domNode, options = {
         });
     }
 
-    if (isElement) {
+    if (isElement && attached) {
         contextMenu.appendItem(WI.UIString("Scroll Into View"), () => {
             domNode.scrollIntoView();
         });
index 6598502..724cc3e 100644 (file)
@@ -727,6 +727,7 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
     {
         let node = this.representedObject;
         let isNonShadowEditable = !node.isInUserAgentShadowTree() && this.editable;
+        let attached = node.attached;
 
         if (event.target && event.target.tagName === "A") {
             let url = event.target.href;
@@ -760,7 +761,7 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
                 attributeName = attributeNameElement.textContent.trim();
         }
 
-        let attributeValue = this.representedObject.getAttribute(attributeName);
+        let attributeValue = node.getAttribute(attributeName);
         subMenus.copy.appendItem(WI.UIString("Attribute"), () => {
             let text = attributeName;
             if (attributeValue)
@@ -769,7 +770,7 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
         }, !attribute || !isNonShadowEditable);
 
         subMenus.delete.appendItem(WI.UIString("Attribute"), () => {
-            this.representedObject.removeAttribute(attributeName);
+            node.removeAttribute(attributeName);
         }, !attribute || !isNonShadowEditable);
 
         subMenus.edit.appendItem(WI.UIString("Tag"), () => {
@@ -778,14 +779,14 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
 
         contextMenu.appendSeparator();
 
-        if (WI.cssManager.canForcePseudoClasses()) {
+        if (WI.cssManager.canForcePseudoClasses() && attached) {
             let pseudoSubMenu = contextMenu.appendSubMenuItem(WI.UIString("Forced Pseudo-Classes"));
 
-            let enabledPseudoClasses = this.representedObject.enabledPseudoClasses;
+            let enabledPseudoClasses = node.enabledPseudoClasses;
             WI.CSSManager.ForceablePseudoClasses.forEach((pseudoClass) => {
                 let enabled = enabledPseudoClasses.includes(pseudoClass);
                 pseudoSubMenu.appendCheckboxItem(pseudoClass.capitalize(), () => {
-                    this.representedObject.setPseudoClassEnabled(pseudoClass, !enabled);
+                    node.setPseudoClassEnabled(pseudoClass, !enabled);
                 }, enabled);
             });