Title: [184977] trunk/Source/WebInspectorUI
Revision
184977
Author
commit-qu...@webkit.org
Date
2015-05-28 21:47:39 -0700 (Thu, 28 May 2015)

Log Message

Web Inspector: Jump from a computed style to the rule it came from
https://bugs.webkit.org/show_bug.cgi?id=120640

Patch by Devin Rousso <drou...@apple.com> on 2015-05-28
Reviewed by Timothy Hatcher.

* UserInterface/Views/CSSStyleDeclarationTextEditor.js:
(WebInspector.CSSStyleDeclarationTextEditor.prototype._createTextMarkerForPropertyIfNeeded):
If the delegate of CSSStyleDeclarationTextEditor has cssStyleDeclarationTextEditorShouldAddPropertyGoToArrows set to true, add a goToArrow to all CSS property entries.
(WebInspector.CSSStyleDeclarationTextEditor.prototype.highlightProperty.propertiesMatch):
(WebInspector.CSSStyleDeclarationTextEditor.prototype.highlightProperty.hasMatchingLonghandProperty):
(WebInspector.CSSStyleDeclarationTextEditor.prototype.highlightProperty):
Determines if a given CSS property is in the CSS style section and if so, select that CSS property, focus on the section containing that CSS property, and return true.
* UserInterface/Views/CSSStyleDeclarationSection.js:
(WebInspector.CSSStyleDeclarationSection.prototype.highlightProperty):
Searches through the properties of the section for a given property and scrolls to it if found.
* UserInterface/Views/CSSStyleDetailsSidebarPanel.js:
(WebInspector.CSSStyleDetailsSidebarPanel.prototype.computedStyleDetailsPanelShowProperty):
Switches to the rulesStyleDetailsPanel and scrolls to and hightlights a given property in that panel.
(WebInspector.CSSStyleDetailsSidebarPanel.prototype._navigationItemSelected):
(WebInspector.CSSStyleDetailsSidebarPanel.prototype._switchPanels):
Moved this function out of _navigationItemSelected for better reusablity.
* UserInterface/Views/ComputedStyleDetailsPanel.js:
(WebInspector.ComputedStyleDetailsPanel.prototype.cssStyleDeclarationTextEditorShowProperty):
Function that calls the delegate (which should be CSSStyleDetailsSidebarPanel) function computedStyleDetailsPanelShowProperty.
* UserInterface/Views/RulesStyleDetailsPanel.js:
(WebInspector.RulesStyleDetailsPanel):
(WebInspector.RulesStyleDetailsPanel.prototype.refresh):
(WebInspector.RulesStyleDetailsPanel.prototype.scrollToSectionAndHighlightProperty):
Searches through all the sections of the RulesStyleDetailsPanel for a given CSS property.
(WebInspector.RulesStyleDetailsPanel.prototype.shown):
(WebInspector.RulesStyleDetailsPanel.prototype.hidden):
(WebInspector.RulesStyleDetailsPanel.prototype.nodeStylesRefreshed):
Added a flag to this function that will highlight and scroll to a given property (_propertyToSelectAndHighlight) if set on load.
* UserInterface/Views/StyleDetailsPanel.js:
(WebInspector.StyleDetailsPanel.prototype.markAsNeedsRefresh):
(WebInspector.StyleDetailsPanel.prototype.nodeStylesRefreshed):
Made into protected function to allow it to be overridden.
(WebInspector.StyleDetailsPanel.prototype._nodeStylesRefreshed): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (184976 => 184977)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-05-29 04:47:39 UTC (rev 184977)
@@ -1,3 +1,44 @@
+2015-05-28  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: Jump from a computed style to the rule it came from
+        https://bugs.webkit.org/show_bug.cgi?id=120640
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/CSSStyleDeclarationTextEditor.js:
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._createTextMarkerForPropertyIfNeeded):
+        If the delegate of CSSStyleDeclarationTextEditor has cssStyleDeclarationTextEditorShouldAddPropertyGoToArrows set to true, add a goToArrow to all CSS property entries.
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype.highlightProperty.propertiesMatch):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype.highlightProperty.hasMatchingLonghandProperty):
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype.highlightProperty):
+        Determines if a given CSS property is in the CSS style section and if so, select that CSS property, focus on the section containing that CSS property, and return true.
+        * UserInterface/Views/CSSStyleDeclarationSection.js:
+        (WebInspector.CSSStyleDeclarationSection.prototype.highlightProperty):
+        Searches through the properties of the section for a given property and scrolls to it if found.
+        * UserInterface/Views/CSSStyleDetailsSidebarPanel.js:
+        (WebInspector.CSSStyleDetailsSidebarPanel.prototype.computedStyleDetailsPanelShowProperty):
+        Switches to the rulesStyleDetailsPanel and scrolls to and hightlights a given property in that panel.
+        (WebInspector.CSSStyleDetailsSidebarPanel.prototype._navigationItemSelected):
+        (WebInspector.CSSStyleDetailsSidebarPanel.prototype._switchPanels):
+        Moved this function out of _navigationItemSelected for better reusablity.
+        * UserInterface/Views/ComputedStyleDetailsPanel.js:
+        (WebInspector.ComputedStyleDetailsPanel.prototype.cssStyleDeclarationTextEditorShowProperty):
+        Function that calls the delegate (which should be CSSStyleDetailsSidebarPanel) function computedStyleDetailsPanelShowProperty.
+        * UserInterface/Views/RulesStyleDetailsPanel.js:
+        (WebInspector.RulesStyleDetailsPanel):
+        (WebInspector.RulesStyleDetailsPanel.prototype.refresh):
+        (WebInspector.RulesStyleDetailsPanel.prototype.scrollToSectionAndHighlightProperty):
+        Searches through all the sections of the RulesStyleDetailsPanel for a given CSS property.
+        (WebInspector.RulesStyleDetailsPanel.prototype.shown):
+        (WebInspector.RulesStyleDetailsPanel.prototype.hidden):
+        (WebInspector.RulesStyleDetailsPanel.prototype.nodeStylesRefreshed):
+        Added a flag to this function that will highlight and scroll to a given property (_propertyToSelectAndHighlight) if set on load.
+        * UserInterface/Views/StyleDetailsPanel.js:
+        (WebInspector.StyleDetailsPanel.prototype.markAsNeedsRefresh):
+        (WebInspector.StyleDetailsPanel.prototype.nodeStylesRefreshed):
+        Made into protected function to allow it to be overridden.
+        (WebInspector.StyleDetailsPanel.prototype._nodeStylesRefreshed): Deleted.
+
 2015-05-28  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Should have a keyboard shortcut to switch between inspector tabs

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js (184976 => 184977)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2015-05-29 04:47:39 UTC (rev 184977)
@@ -260,6 +260,16 @@
         }
     },
 
+    highlightProperty: function(property)
+    {
+        if (this._propertiesTextEditor.highlightProperty(property)) {
+            this._element.scrollIntoView();
+            return true;
+        }
+
+        return false;
+    },
+
     updateLayout: function()
     {
         this._propertiesTextEditor.updateLayout();

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js (184976 => 184977)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js	2015-05-29 04:47:39 UTC (rev 184977)
@@ -181,6 +181,46 @@
         this._codeMirror.refresh();
     }
 
+    highlightProperty(property)
+    {
+        function propertiesMatch(cssProperty)
+        {
+            if (cssProperty.enabled && !cssProperty.overridden) {
+                if (cssProperty.canonicalName === property.canonicalName || hasMatchingLonghandProperty(cssProperty))
+                    return true;
+            }
+
+            return false;
+        }
+
+        function hasMatchingLonghandProperty(cssProperty)
+        {
+            var cssProperties = cssProperty.relatedLonghandProperties;
+
+            if (!cssProperties.length)
+                return false;
+
+            for (var property of cssProperties) {
+                if (propertiesMatch(property))
+                    return true;
+            }
+
+            return false;
+        }
+
+        for (var cssProperty of this.style.properties) {
+            if (propertiesMatch(cssProperty)) {
+                var selection = cssProperty.__propertyTextMarker.find();
+                this._codeMirror.setSelection(selection.from, selection.to);
+                this.focus();
+
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     // Protected
 
     didDismissPopover(popover)
@@ -437,6 +477,17 @@
 
             var checkboxMarker = this._codeMirror.setUniqueBookmark(from, checkboxElement);
             checkboxMarker.__propertyCheckbox = true;
+        } else if (this._delegate.cssStyleDeclarationTextEditorShouldAddPropertyGoToArrows
+                && !property.implicit && typeof this._delegate.cssStyleDeclarationTextEditorShowProperty === "function") {
+
+            var arrowElement = WebInspector.createGoToArrowButton();
+
+            var delegate = this._delegate;
+            arrowElement.addEventListener("click", function() {
+                delegate.cssStyleDeclarationTextEditorShowProperty(property);
+            });
+
+            this._codeMirror.setUniqueBookmark(to, arrowElement);
         }
 
         var classNames = ["css-style-declaration-property"];

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDetailsSidebarPanel.js (184976 => 184977)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDetailsSidebarPanel.js	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDetailsSidebarPanel.js	2015-05-29 04:47:39 UTC (rev 184977)
@@ -70,7 +70,7 @@
             this.contentElement.appendChild(this._forcedPseudoClassContainer);
         }
 
-        this._computedStyleDetailsPanel = new WebInspector.ComputedStyleDetailsPanel;
+        this._computedStyleDetailsPanel = new WebInspector.ComputedStyleDetailsPanel(this);
         this._rulesStyleDetailsPanel = new WebInspector.RulesStyleDetailsPanel;
         this._metricsStyleDetailsPanel = new WebInspector.MetricsStyleDetailsPanel;
 
@@ -137,6 +137,14 @@
             this._selectedPanel.widthDidChange();
     }
 
+    computedStyleDetailsPanelShowProperty(property)
+    {
+        this._rulesStyleDetailsPanel.scrollToSectionAndHighlightProperty(property);
+        this._switchPanels(this._rulesStyleDetailsPanel);
+
+        this._navigationBar.selectedNavigationItem = this._lastSelectedSectionSetting.value;
+    }
+
     // Protected
 
     addEventListeners()
@@ -180,6 +188,11 @@
             break;
         }
 
+        this._switchPanels(selectedPanel);
+    }
+
+    _switchPanels(selectedPanel)
+    {
         console.assert(selectedPanel);
 
         if (this._selectedPanel) {
@@ -201,7 +214,7 @@
             this._selectedPanel.shown();
         }
 
-        this._lastSelectedSectionSetting.value = selectedNavigationItem.identifier;
+        this._lastSelectedSectionSetting.value = selectedPanel.navigationItem.identifier;
     }
 
     _forcedPseudoClassCheckboxChanged(pseudoClass, event)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ComputedStyleDetailsPanel.css (184976 => 184977)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ComputedStyleDetailsPanel.css	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ComputedStyleDetailsPanel.css	2015-05-29 04:47:39 UTC (rev 184977)
@@ -35,3 +35,15 @@
 {
     vertical-align: top;
 }
+
+.details-section > .content > .group > .row .CodeMirror-code pre .go-to-arrow {
+    display: none;
+    position: absolute;
+    width: 12px;
+    height: 10px;
+    vertical-align: text-bottom;
+}
+
+.details-section > .content > .group > .row .CodeMirror-code pre:hover .go-to-arrow {
+    display: initial;
+}

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ComputedStyleDetailsPanel.js (184976 => 184977)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ComputedStyleDetailsPanel.js	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ComputedStyleDetailsPanel.js	2015-05-29 04:47:39 UTC (rev 184977)
@@ -25,10 +25,12 @@
 
 WebInspector.ComputedStyleDetailsPanel = class ComputedStyleDetailsPanel extends WebInspector.StyleDetailsPanel
 {
-    constructor()
+    constructor(delegate)
     {
         super(WebInspector.ComputedStyleDetailsPanel.StyleClassName, "computed", WebInspector.UIString("Computed"));
 
+        this._delegate = delegate || null;
+
         this._computedStyleShowAllSetting = new WebInspector.Setting("computed-style-show-all", false);
 
         var computedStyleShowAllLabel = document.createElement("label");
@@ -88,6 +90,8 @@
         this.element.appendChild(this._containerRegionsFlowSection.element);
 
         this._resetFlowDetails();
+        
+        this.cssStyleDeclarationTextEditorShouldAddPropertyGoToArrows = true;
     }
 
     // Public
@@ -139,6 +143,12 @@
         this._containerRegionsFlowSection.element.classList.remove("hidden");
     }
 
+    cssStyleDeclarationTextEditorShowProperty(property)
+    {
+        if (typeof this._delegate.computedStyleDetailsPanelShowProperty === "function")
+            this._delegate.computedStyleDetailsPanelShowProperty(property);
+    }
+
     refresh()
     {
         this._propertiesTextEditor.style = this.nodeStyles.computedStyle;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/RulesStyleDetailsPanel.js (184976 => 184977)


--- trunk/Source/WebInspectorUI/UserInterface/Views/RulesStyleDetailsPanel.js	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/RulesStyleDetailsPanel.js	2015-05-29 04:47:39 UTC (rev 184977)
@@ -30,6 +30,7 @@
         super("rules", "rules", WebInspector.UIString("Rules"));
 
         this._sections = [];
+        this._propertyToSelectAndHighlight = null;
     }
 
     // Public
@@ -241,11 +242,26 @@
             previousFocusedSection.focus();
     }
 
+    scrollToSectionAndHighlightProperty(property)
+    {
+        if (!this._visible) {
+            this._propertyToSelectAndHighlight = property;
+            return false;
+        }
+
+        for (var section of this._sections) {
+            if (section.highlightProperty(property))
+                return true;
+        }
+
+        return false;
+    }
+
     // Protected
 
     shown()
     {
-        WebInspector.StyleDetailsPanel.prototype.shown.call(this);
+        super.shown();
 
         // Associate the style and section objects so they can be reused.
         // Also update the layout in case we changed widths while hidden.
@@ -258,7 +274,7 @@
 
     hidden()
     {
-        WebInspector.StyleDetailsPanel.prototype.hidden.call(this);
+        super.hidden();
 
         // Disconnect the style and section objects so they have a chance
         // to release their objects when this panel is not visible.
@@ -272,6 +288,16 @@
             this._sections[i].updateLayout();
     }
 
+    nodeStylesRefreshed(event)
+    {
+        super.nodeStylesRefreshed(event);
+        
+        if (this._propertyToSelectAndHighlight) {
+            this.scrollToSectionAndHighlightProperty(this._propertyToSelectAndHighlight);
+            this._propertyToSelectAndHighlight = null;
+        }
+    }
+
     // Private
 
     _newRuleClicked(event)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/StyleDetailsPanel.js (184976 => 184977)


--- trunk/Source/WebInspectorUI/UserInterface/Views/StyleDetailsPanel.js	2015-05-29 04:30:09 UTC (rev 184976)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/StyleDetailsPanel.js	2015-05-29 04:47:39 UTC (rev 184977)
@@ -86,7 +86,7 @@
 
         if (!this._nodeStyles || this._nodeStyles.node !== domNode) {
             if (this._nodeStyles) {
-                this._nodeStyles.removeEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, this._nodeStylesRefreshed, this);
+                this._nodeStyles.removeEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, this.nodeStylesRefreshed, this);
                 this._nodeStyles.removeEventListener(WebInspector.DOMNodeStyles.Event.NeedsRefresh, this._nodeStylesNeedsRefreshed, this);
             }
 
@@ -96,7 +96,7 @@
             if (!this._nodeStyles)
                 return;
 
-            this._nodeStyles.addEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, this._nodeStylesRefreshed, this);
+            this._nodeStyles.addEventListener(WebInspector.DOMNodeStyles.Event.Refreshed, this.nodeStylesRefreshed, this);
             this._nodeStyles.addEventListener(WebInspector.DOMNodeStyles.Event.NeedsRefresh, this._nodeStylesNeedsRefreshed, this);
 
             this._forceSignificantChange = true;
@@ -111,6 +111,14 @@
         // Implemented by subclasses.
     }
 
+    // Protected
+
+    nodeStylesRefreshed(event)
+    {
+        if (this._visible)
+            this._refreshPreservingScrollPosition(event.data.significantChange);
+    }
+
     // Private
 
     get _initialScrollOffset()
@@ -146,12 +154,6 @@
             this.element.parentNode.scrollTop = previousScrollTop;
     }
 
-    _nodeStylesRefreshed(event)
-    {
-        if (this._visible)
-            this._refreshPreservingScrollPosition(event.data.significantChange);
-    }
-
     _nodeStylesNeedsRefreshed(event)
     {
         if (this._visible)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to