Web Inspector: Styles: missing contextmenu items for links
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 23:57:30 +0000 (23:57 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 23:57:30 +0000 (23:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191021

Reviewed by Joseph Pecoraro.

* UserInterface/Views/SpreadsheetStyleProperty.js:
(WI.SpreadsheetStyleProperty.prototype._renderValue):
(WI.SpreadsheetStyleProperty.prototype._handleLinkContextMenu): Added.
If the token is subtype of "link", add contextmenu items to the wrapper element.

* UserInterface/Views/ContextMenuUtilities.js:
(WI.appendContextMenuItemsForURL.showResourceWithOptions):
(WI.appendContextMenuItemsForURL):
Drive-by: don't assume that `options` will be provided.
* Localizations/en.lproj/localizedStrings.js:

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js
Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js

index e3dad33..f01c2de 100644 (file)
@@ -1,3 +1,22 @@
+2018-10-31  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Styles: missing contextmenu items for links
+        https://bugs.webkit.org/show_bug.cgi?id=191021
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Views/SpreadsheetStyleProperty.js:
+        (WI.SpreadsheetStyleProperty.prototype._renderValue):
+        (WI.SpreadsheetStyleProperty.prototype._handleLinkContextMenu): Added.
+        If the token is subtype of "link", add contextmenu items to the wrapper element.
+
+        * UserInterface/Views/ContextMenuUtilities.js:
+        (WI.appendContextMenuItemsForURL.showResourceWithOptions):
+        (WI.appendContextMenuItemsForURL):
+        Drive-by: don't assume that `options` will be provided.
+
+        * Localizations/en.lproj/localizedStrings.js:
+
 2018-10-31  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: Styles: implement copying and deletion of multiple properties
index d7df51a..8bd0720 100644 (file)
@@ -240,7 +240,7 @@ localizedStrings["Controls"] = "Controls";
 localizedStrings["Cookies"] = "Cookies";
 localizedStrings["Copy"] = "Copy";
 localizedStrings["Copy Action"] = "Copy Action";
-localizedStrings["Copy Link Address"] = "Copy Link Address";
+localizedStrings["Copy Link"] = "Copy Link";
 localizedStrings["Copy Path to Property"] = "Copy Path to Property";
 localizedStrings["Copy Row"] = "Copy Row";
 localizedStrings["Copy Selected"] = "Copy Selected";
index 096a65a..0500f51 100644 (file)
@@ -80,25 +80,26 @@ WI.appendContextMenuItemsForSourceCode = function(contextMenu, sourceCodeOrLocat
     }
 };
 
-WI.appendContextMenuItemsForURL = function(contextMenu, url, options)
+WI.appendContextMenuItemsForURL = function(contextMenu, url, options = {})
 {
     if (!url)
         return;
 
-    let {sourceCode, location, frame} = options;
     function showResourceWithOptions(options) {
-        if (location)
-            WI.showSourceCodeLocation(location, options);
-        else if (sourceCode)
-            WI.showSourceCode(sourceCode, options);
+        if (options.location)
+            WI.showSourceCodeLocation(options.location, options);
+        else if (options.sourceCode)
+            WI.showSourceCode(options.sourceCode, options);
         else
-            WI.openURL(url, frame, options);
+            WI.openURL(url, options.frame, options);
     }
 
-    contextMenu.appendItem(WI.UIString("Open in New Tab"), () => {
-        const frame = null;
-        WI.openURL(url, frame, {alwaysOpenExternally: true});
-    });
+    if (!url.startsWith("javascript:") && !url.startsWith("data:")) {
+        contextMenu.appendItem(WI.UIString("Open in New Tab"), () => {
+            const frame = null;
+            WI.openURL(url, frame, {alwaysOpenExternally: true});
+        });
+    }
 
     if (WI.networkManager.resourceForURL(url)) {
         if (!WI.isShowingResourcesTab()) {
@@ -113,7 +114,9 @@ WI.appendContextMenuItemsForURL = function(contextMenu, url, options)
         }
     }
 
-    contextMenu.appendItem(WI.UIString("Copy Link Address"), () => {
+    contextMenu.appendSeparator();
+
+    contextMenu.appendItem(WI.UIString("Copy Link"), () => {
         InspectorFrontendHost.copyText(url);
     });
 };
index a76aa7e..1fd4667 100644 (file)
@@ -420,6 +420,10 @@ WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object
                 let span = document.createElement("span");
                 span.classList.add(className);
                 span.textContent = token.value.truncateMiddle(maxValueLength);
+
+                if (token.type && token.type.includes("link"))
+                    span.addEventListener("contextmenu", this._handleLinkContextMenu.bind(this, token));
+
                 return span;
             }
 
@@ -738,6 +742,53 @@ WI.SpreadsheetStyleProperty = class SpreadsheetStyleProperty extends WI.Object
             WI.showSourceCodeLocation(sourceCode.createSourceCodeLocation(range.startLine, range.startColumn), options);
         });
     }
+
+    _handleLinkContextMenu(token, event)
+    {
+        let contextMenu = WI.ContextMenu.createFromEvent(event);
+
+        let resolveURL = (url) => {
+            let ownerStyle = this._property.ownerStyle;
+            if (!ownerStyle)
+                return url;
+
+            let ownerStyleSheet = ownerStyle.ownerStyleSheet;
+            if (!ownerStyleSheet) {
+                let ownerRule = ownerStyle.ownerRule;
+                if (ownerRule)
+                    ownerStyleSheet = ownerRule.ownerStyleSheet;
+            }
+            if (ownerStyleSheet) {
+                if (ownerStyleSheet.url)
+                    return absoluteURL(url, ownerStyleSheet.url);
+
+                let parentFrame = ownerStyleSheet.parentFrame;
+                if (parentFrame)
+                    return absoluteURL(url, parentFrame.url);
+            }
+
+            let node = ownerStyle.node;
+            if (!node) {
+                let nodeStyles = ownerStyle.nodeStyles;
+                if (!nodeStyles) {
+                    let ownerRule = ownerStyle.ownerRule;
+                    if (ownerRule)
+                        nodeStyles = ownerRule.nodeStyles;
+                }
+                if (nodeStyles)
+                    node = nodeStyles.node;
+            }
+            if (node) {
+                let ownerDocument = node.ownerDocument;
+                if (ownerDocument)
+                    return absoluteURL(url, node.ownerDocument.documentURL);
+            }
+
+            return url;
+        };
+
+        WI.appendContextMenuItemsForURL(contextMenu, resolveURL(token.value));
+    }
 };
 
 WI.SpreadsheetStyleProperty.StyleClassName = "property";