Title: [237660] trunk/Source/WebInspectorUI
Revision
237660
Author
drou...@apple.com
Date
2018-10-31 16:57:30 -0700 (Wed, 31 Oct 2018)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (237659 => 237660)


--- trunk/Source/WebInspectorUI/ChangeLog	2018-10-31 22:52:11 UTC (rev 237659)
+++ trunk/Source/WebInspectorUI/ChangeLog	2018-10-31 23:57:30 UTC (rev 237660)
@@ -1,3 +1,22 @@
+2018-10-31  Devin Rousso  <drou...@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  <nvasil...@apple.com>
 
         Web Inspector: Styles: implement copying and deletion of multiple properties

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


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2018-10-31 22:52:11 UTC (rev 237659)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2018-10-31 23:57:30 UTC (rev 237660)
@@ -240,7 +240,7 @@
 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";

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js (237659 => 237660)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js	2018-10-31 22:52:11 UTC (rev 237659)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js	2018-10-31 23:57:30 UTC (rev 237660)
@@ -80,25 +80,26 @@
     }
 };
 
-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 @@
         }
     }
 
-    contextMenu.appendItem(WI.UIString("Copy Link Address"), () => {
+    contextMenu.appendSeparator();
+
+    contextMenu.appendItem(WI.UIString("Copy Link"), () => {
         InspectorFrontendHost.copyText(url);
     });
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js (237659 => 237660)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2018-10-31 22:52:11 UTC (rev 237659)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js	2018-10-31 23:57:30 UTC (rev 237660)
@@ -420,6 +420,10 @@
                 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.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";
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to