Title: [144451] trunk/Source/WebCore
Revision
144451
Author
[email protected]
Date
2013-03-01 06:47:02 -0800 (Fri, 01 Mar 2013)

Log Message

Web Inspector: [Styles] Implement navigation to UI locations of property names/values in the source code
Relanding fixed r144449.
https://bugs.webkit.org/show_bug.cgi?id=105285

Reviewed by Vsevolod Vlasov.

Users can now Ctrl/Cmd-click CSS property names/values whose UI locations are found in
an external stylesheet/sass/other file. Inline stylesheets are not navigable,
since their start position is not detectable inside the surrounding HTML as of yet.

No new tests, a UI change.

* inspector/front-end/CSSStyleModel.js:
(WebInspector.CSSRule.prototype.isSourceNavigable): Whether the rule contains reliable source code information.
(WebInspector.CSSProperty.prototype.uiLocation): Returns a UILocation for the property name of value.
* inspector/front-end/StylesSidebarPane.js: Add navigation code.
(WebInspector.StylesSidebarPane.prototype._innerRebuildUpdate):
(WebInspector.StylePropertiesSection):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (144450 => 144451)


--- trunk/Source/WebCore/ChangeLog	2013-03-01 14:34:09 UTC (rev 144450)
+++ trunk/Source/WebCore/ChangeLog	2013-03-01 14:47:02 UTC (rev 144451)
@@ -1,3 +1,24 @@
+2013-03-01  Alexander Pavlov  <[email protected]>
+
+        Web Inspector: [Styles] Implement navigation to UI locations of property names/values in the source code
+        Relanding fixed r144449.
+        https://bugs.webkit.org/show_bug.cgi?id=105285
+
+        Reviewed by Vsevolod Vlasov.
+
+        Users can now Ctrl/Cmd-click CSS property names/values whose UI locations are found in
+        an external stylesheet/sass/other file. Inline stylesheets are not navigable,
+        since their start position is not detectable inside the surrounding HTML as of yet.
+
+        No new tests, a UI change.
+
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSRule.prototype.isSourceNavigable): Whether the rule contains reliable source code information.
+        (WebInspector.CSSProperty.prototype.uiLocation): Returns a UILocation for the property name of value.
+        * inspector/front-end/StylesSidebarPane.js: Add navigation code.
+        (WebInspector.StylesSidebarPane.prototype._innerRebuildUpdate):
+        (WebInspector.StylePropertiesSection):
+
 2013-03-01  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r144449.

Modified: trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js (144450 => 144451)


--- trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2013-03-01 14:34:09 UTC (rev 144450)
+++ trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2013-03-01 14:47:02 UTC (rev 144451)
@@ -882,6 +882,17 @@
     get isRegular()
     {
         return this.origin === "regular";
+    },
+
+    /**
+     * @return {boolean}
+     */
+    isSourceNavigable: function()
+    {
+        if (!this.sourceURL)
+            return false;
+        var resource = WebInspector.resourceTreeModel.resourceForURL(this.sourceURL);
+        return !!resource && resource.contentType() === WebInspector.resourceTypes.Stylesheet;
     }
 }
 
@@ -1070,6 +1081,23 @@
 
         WebInspector.cssModel._pendingCommandsMajorState.push(false);
         CSSAgent.toggleProperty(this.ownerStyle.id, this.index, disabled, callback.bind(this));
+    },
+
+    /**
+     * @param {boolean} forName
+     * @return {WebInspector.UILocation}
+     */
+    uiLocation: function(forName)
+    {
+        if (!this.range || !this.ownerStyle || !this.ownerStyle.parentRule || !this.ownerStyle.parentRule.sourceURL)
+            return null;
+
+        var range = this.range;
+        var line = forName ? range.startLine : range.endLine;
+        // End of range is exclusive, so subtract 1 from the end offset.
+        var column = forName ? range.startColumn : range.endColumn - 1;
+        var rawLocation = new WebInspector.CSSLocation(this.ownerStyle.parentRule.sourceURL, line, column);
+        return WebInspector.cssModel.rawLocationToUILocation(rawLocation);
     }
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js (144450 => 144451)


--- trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2013-03-01 14:34:09 UTC (rev 144450)
+++ trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2013-03-01 14:47:02 UTC (rev 144451)
@@ -376,7 +376,7 @@
         this.sections[0] = this._rebuildSectionsForStyleRules(styleRules, usedProperties, 0, null);
         var anchorElement = this.sections[0].inheritedPropertiesSeparatorElement;
 
-        if (styles.computedStyle)        
+        if (styles.computedStyle)
             this.sections[0][0].rebuildComputedTrace(this.sections[0]);
 
         for (var i = 0; i < styles.pseudoElements.length; ++i) {
@@ -894,6 +894,11 @@
         // Prevent editing the user agent and user rules.
         if (this.rule.isUserAgent || this.rule.isUser)
             this.editable = false;
+        else {
+            // Check this is a real CSSRule, not a bogus object coming from WebInspector.BlankStylePropertiesSection.
+            if (this.rule.id)
+                this.navigable = this.rule.isSourceNavigable();
+        }
         this.titleElement.addStyleClass("styles-selector");
     }
 
@@ -909,6 +914,9 @@
     if (isInherited)
         this.element.addStyleClass("show-inherited"); // This one is related to inherited rules, not computed style.
 
+    if (this.navigable)
+        this.element.addStyleClass("navigable");
+
     if (!this.editable)
         this.element.addStyleClass("read-only");
 }
@@ -2045,6 +2053,7 @@
             if (!newStyle)
                 return;
 
+            newStyle.parentRule = this.style.parentRule;
             this.style = newStyle;
             this._styleRule.style = newStyle;
 
@@ -2158,9 +2167,27 @@
             return;
         }
 
+        if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && this.section().navigable) {
+            this._navigateToSource(event.target);
+            return;
+        }
+
         this.startEditing(event.target);
     },
 
+    /**
+     * @param {Element} element
+     */
+    _navigateToSource: function(element)
+    {
+        console.assert(this.section().navigable);
+        var propertyNameClicked = element === this.nameElement;
+        var uiLocation = this.property.uiLocation(propertyNameClicked);
+        if (!uiLocation)
+            return;
+        WebInspector.showPanel("scripts").showUISourceCode(uiLocation.uiSourceCode, uiLocation.lineNumber);
+    },
+
     _isNameElement: function(element)
     {
         return element.enclosingNodeOrSelfWithClass("webkit-css-property") === this.nameElement;
@@ -2580,6 +2607,7 @@
 
             if (this._newProperty)
                 this._newPropertyInStyle = true;
+            newStyle.parentRule = this.style.parentRule;
             this.style = newStyle;
             this.property = newStyle.propertyAt(this.property.index);
             this._styleRule.style = this.style;
@@ -2673,7 +2701,7 @@
             // Synthesize property text disregarding any comments, custom whitespace etc.
             this._sidebarPane.applyStyleText(this._sidebarPane.nameElement.textContent + ": " + this._sidebarPane.valueElement.textContent, false, false, false);
         }
-    
+
         // Handle numeric value increment/decrement only at this point.
         if (!this._isEditingName && WebInspector.handleElementValueModifications(event, this._sidebarPane.valueElement, finishHandler.bind(this), this._isValueSuggestion.bind(this)))
             return true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to