Title: [132197] trunk/Source/WebCore
Revision
132197
Author
apav...@chromium.org
Date
2012-10-23 03:05:33 -0700 (Tue, 23 Oct 2012)

Log Message

Web Inspector: Sass can only resolve same folder paths
https://bugs.webkit.org/show_bug.cgi?id=99259

Reviewed by Vsevolod Vlasov.

The actual reason is that the rule source location linkifier tries to linkify a resource (*.scss), which does not exist,
and falls back to just stripping the main page URL prefix from the rule location URL. This change introduces LiveLocations
for CSSRule locations and makes sure they are linkified using uiSourceCode's parsedURL.displayName.

* inspector/front-end/CSSStyleModel.js:
(WebInspector.CSSStyleModel): Introduced LiveLocation management for CSSRules.
(WebInspector.CSSStyleModel.prototype.setSourceMapping):
(WebInspector.CSSStyleModel.prototype._updateLocations):
(WebInspector.CSSStyleModel.prototype.createLiveLocation):
(WebInspector.CSSStyleModel.prototype.updateLocations):
(WebInspector.CSSStyleModel.LiveLocation): A LiveLocation for the CSS domain.
(WebInspector.CSSStyleModel.LiveLocation.prototype.uiLocation):
(WebInspector.CSSStyleModel.LiveLocation.prototype.dispose):
* inspector/front-end/Linkifier.js:
(WebInspector.Linkifier.prototype.linkifyCSSRuleLocation): CSSRule LiveLocation-based link builder.
(WebInspector.Linkifier.DefaultFormatter.prototype.formatLiveAnchor): Add a title for anchors.
(WebInspector.Linkifier.DefaultCSSFormatter): Formatter for CSS location links.
(WebInspector.Linkifier.DefaultCSSFormatter.prototype.formatLiveAnchor):
* inspector/front-end/ResourceUtils.js:
(WebInspector.displayNameForURL): Use parsedURL.displayName if uiSourceCode is present for the specified URL.
* inspector/front-end/SASSSourceMapping.js:
* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylesSidebarPane):
(WebInspector.StylesSidebarPane.prototype._innerRebuildUpdate):
* inspector/front-end/inspector.html:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (132196 => 132197)


--- trunk/Source/WebCore/ChangeLog	2012-10-23 09:58:16 UTC (rev 132196)
+++ trunk/Source/WebCore/ChangeLog	2012-10-23 10:05:33 UTC (rev 132197)
@@ -1,3 +1,36 @@
+2012-10-23  Alexander Pavlov  <apav...@chromium.org>
+
+        Web Inspector: Sass can only resolve same folder paths
+        https://bugs.webkit.org/show_bug.cgi?id=99259
+
+        Reviewed by Vsevolod Vlasov.
+
+        The actual reason is that the rule source location linkifier tries to linkify a resource (*.scss), which does not exist,
+        and falls back to just stripping the main page URL prefix from the rule location URL. This change introduces LiveLocations
+        for CSSRule locations and makes sure they are linkified using uiSourceCode's parsedURL.displayName.
+
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSStyleModel): Introduced LiveLocation management for CSSRules.
+        (WebInspector.CSSStyleModel.prototype.setSourceMapping):
+        (WebInspector.CSSStyleModel.prototype._updateLocations):
+        (WebInspector.CSSStyleModel.prototype.createLiveLocation):
+        (WebInspector.CSSStyleModel.prototype.updateLocations):
+        (WebInspector.CSSStyleModel.LiveLocation): A LiveLocation for the CSS domain.
+        (WebInspector.CSSStyleModel.LiveLocation.prototype.uiLocation):
+        (WebInspector.CSSStyleModel.LiveLocation.prototype.dispose):
+        * inspector/front-end/Linkifier.js:
+        (WebInspector.Linkifier.prototype.linkifyCSSRuleLocation): CSSRule LiveLocation-based link builder.
+        (WebInspector.Linkifier.DefaultFormatter.prototype.formatLiveAnchor): Add a title for anchors.
+        (WebInspector.Linkifier.DefaultCSSFormatter): Formatter for CSS location links.
+        (WebInspector.Linkifier.DefaultCSSFormatter.prototype.formatLiveAnchor):
+        * inspector/front-end/ResourceUtils.js:
+        (WebInspector.displayNameForURL): Use parsedURL.displayName if uiSourceCode is present for the specified URL.
+        * inspector/front-end/SASSSourceMapping.js:
+        * inspector/front-end/StylesSidebarPane.js:
+        (WebInspector.StylesSidebarPane):
+        (WebInspector.StylesSidebarPane.prototype._innerRebuildUpdate):
+        * inspector/front-end/inspector.html:
+
 2012-10-23  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r132149.

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


--- trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2012-10-23 09:58:16 UTC (rev 132196)
+++ trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2012-10-23 10:05:33 UTC (rev 132197)
@@ -35,6 +35,8 @@
 WebInspector.CSSStyleModel = function()
 {
     this._pendingCommandsMajorState = [];
+    /** @type {Array.<WebInspector.CSSStyleModel.LiveLocation>} */
+    this._locations = [];
     this._sourceMappings = {};
     WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedoRequested, this._undoRedoRequested, this);
     WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedoCompleted, this._undoRedoCompleted, this);
@@ -481,6 +483,7 @@
     setSourceMapping: function(url, sourceMapping)
     {
         this._sourceMappings[url] = sourceMapping;
+        this._updateLocations();
     },
 
     resetSourceMappings: function()
@@ -493,7 +496,29 @@
         this._namedFlowCollections = {};
     },
 
+    _updateLocations: function()
+    {
+        for (var i = 0; i < this._locations.length; ++i)
+            this._locations[i].update();
+    },
+
     /**
+     * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate
+     * @return {?WebInspector.LiveLocation}
+     */
+    createLiveLocation: function(cssRule, updateDelegate)
+    {
+        if (!cssRule._rawLocation)
+            return null;
+        var location = new WebInspector.CSSStyleModel.LiveLocation(cssRule._rawLocation, updateDelegate);
+        if (!location.uiLocation())
+            return null;
+        this._locations.push(location);
+        location.update();
+        return location;
+    },
+
+    /**
      * @param {WebInspector.CSSLocation} rawLocation
      * @return {?WebInspector.UILocation}
      */
@@ -508,6 +533,38 @@
 
 /**
  * @constructor
+ * @extends {WebInspector.LiveLocation}
+ * @param {WebInspector.CSSLocation} rawLocation
+ * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate
+ */
+WebInspector.CSSStyleModel.LiveLocation = function(rawLocation, updateDelegate)
+{
+    WebInspector.LiveLocation.call(this, rawLocation, updateDelegate);
+}
+
+WebInspector.CSSStyleModel.LiveLocation.prototype = {
+    /**
+     * @return {WebInspector.UILocation}
+     */
+    uiLocation: function()
+    {
+        var cssLocation = /** @type WebInspector.CSSLocation */ this.rawLocation();
+        return WebInspector.cssModel._rawLocationToUILocation(cssLocation);
+    },
+
+    dispose: function()
+    {
+        WebInspector.LiveLocation.prototype.dispose.call(this);
+        var locations = WebInspector.cssModel._locations;
+        if (locations)
+            locations.remove(this);
+    },
+
+    __proto__: WebInspector.LiveLocation.prototype
+}
+
+/**
+ * @constructor
  * @implements {WebInspector.RawLocation}
  * @param {string} url
  * @param {number} lineNumber
@@ -785,16 +842,6 @@
     get isRegular()
     {
         return this.origin === "regular";
-    },
-
-    /**
-     * @return {?WebInspector.UILocation}
-     */
-    uiLocation: function()
-    {
-        if (!this._rawLocation)
-            return null;
-        return WebInspector.cssModel._rawLocationToUILocation(this._rawLocation);
     }
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/Linkifier.js (132196 => 132197)


--- trunk/Source/WebCore/inspector/front-end/Linkifier.js	2012-10-23 09:58:16 UTC (rev 132196)
+++ trunk/Source/WebCore/inspector/front-end/Linkifier.js	2012-10-23 10:05:33 UTC (rev 132197)
@@ -59,6 +59,7 @@
      * @param {number} lineNumber
      * @param {number=} columnNumber
      * @param {string=} classes
+     * @return {Element}
      */
     linkifyLocation: function(sourceURL, lineNumber, columnNumber, classes)
     {
@@ -71,6 +72,7 @@
     /**
      * @param {WebInspector.DebuggerModel.Location} rawLocation
      * @param {string=} classes
+     * @return {Element}
      */
     linkifyRawLocation: function(rawLocation, classes)
     {
@@ -83,6 +85,20 @@
         return anchor;
     },
 
+    /**
+     * @param {WebInspector.CSSRule} rule
+     * @return {?Element}
+     */
+    linkifyCSSRuleLocation: function(rule)
+    {
+        var anchor = WebInspector.linkifyURLAsNode("", "", "", false);
+        var liveLocation = WebInspector.cssModel.createLiveLocation(rule, this._updateAnchor.bind(this, anchor));
+        if (!liveLocation)
+            return null;
+        this._liveLocations.push(liveLocation);
+        return anchor;
+    },
+
     reset: function()
     {
         for (var i = 0; i < this._liveLocations.length; ++i)
@@ -125,7 +141,36 @@
         if (this._maxLength)
             text = text.trimMiddle(this._maxLength);
         anchor.textContent = text;
+
+        var titleText = uiLocation.uiSourceCode.url;
+        if (typeof uiLocation.lineNumber === "number")
+            titleText += ":" + (uiLocation.lineNumber + 1);
+        anchor.title = titleText;
     },
 
     __proto__: WebInspector.LinkifierFormatter.prototype
 }
+
+/**
+ * @constructor
+ * @extends {WebInspector.Linkifier.DefaultFormatter}
+ */
+WebInspector.Linkifier.DefaultCSSFormatter = function()
+{
+    WebInspector.Linkifier.DefaultFormatter.call(this);
+}
+
+WebInspector.Linkifier.DefaultCSSFormatter.prototype = {
+    /**
+     * @param {Element} anchor
+     * @param {WebInspector.UILocation} uiLocation
+     */
+    formatLiveAnchor: function(anchor, uiLocation)
+    {
+        WebInspector.Linkifier.DefaultFormatter.prototype.formatLiveAnchor.call(this, anchor, uiLocation);
+        anchor.classList.add("webkit-html-resource-link");
+        anchor.setAttribute("data-uncopyable", anchor.textContent);
+        anchor.textContent = "";
+    },
+    __proto__: WebInspector.Linkifier.DefaultFormatter.prototype
+}
\ No newline at end of file

Modified: trunk/Source/WebCore/inspector/front-end/ResourceUtils.js (132196 => 132197)


--- trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	2012-10-23 09:58:16 UTC (rev 132196)
+++ trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	2012-10-23 10:05:33 UTC (rev 132197)
@@ -58,6 +58,10 @@
     if (resource)
         return resource.displayName;
 
+    var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
+    if (uiSourceCode)
+        return uiSourceCode.parsedURL.displayName;
+
     if (!WebInspector.inspectedPageURL)
         return url.trimURL("");
 

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


--- trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2012-10-23 09:58:16 UTC (rev 132196)
+++ trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2012-10-23 10:05:33 UTC (rev 132197)
@@ -94,6 +94,7 @@
     this.bodyElement.appendChild(this._sectionsContainer);
 
     this._spectrum = new WebInspector.Spectrum();
+    this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.DefaultCSSFormatter());
 
     WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
     WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this);
@@ -353,6 +354,7 @@
     {
         this._sectionsContainer.removeChildren();
         this._computedStylePane.bodyElement.removeChildren();
+        this._linkifier.reset();
 
         var styleRules = this._rebuildStyleRules(node, styles);
         var usedProperties = {};
@@ -1191,13 +1193,8 @@
             return link;
         }
 
-        if (this.styleRule.sourceURL) {
-            var uiLocation = this.rule.uiLocation();
-            if (uiLocation)
-                return linkifyUncopyable(uiLocation.url(), uiLocation.lineNumber);
-            else
-                return linkifyUncopyable(this.styleRule.sourceURL, this.rule.sourceLine);
-        }
+        if (this.styleRule.sourceURL)
+            return this._parentPane._linkifier.linkifyCSSRuleLocation(this.rule) || linkifyUncopyable(this.styleRule.sourceURL, this.rule.sourceLine);
 
         if (!this.rule)
             return document.createTextNode("");

Modified: trunk/Source/WebCore/inspector/front-end/inspector.html (132196 => 132197)


--- trunk/Source/WebCore/inspector/front-end/inspector.html	2012-10-23 09:58:16 UTC (rev 132196)
+++ trunk/Source/WebCore/inspector/front-end/inspector.html	2012-10-23 10:05:33 UTC (rev 132197)
@@ -71,6 +71,7 @@
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
+    <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
@@ -131,7 +132,6 @@
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
-    <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to