Changeset 144449 in webkit


Ignore:
Timestamp:
Mar 1, 2013 6:12:38 AM (11 years ago)
Author:
apavlov@chromium.org
Message:

Web Inspector: [Styles] Implement navigation to UI locations of property names/values in the source code
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):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r144447 r144449  
     12013-03-01  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        Web Inspector: [Styles] Implement navigation to UI locations of property names/values in the source code
     4        https://bugs.webkit.org/show_bug.cgi?id=105285
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        Users can now Ctrl/Cmd-click CSS property names/values whose UI locations are found in
     9        an external stylesheet/sass/other file. Inline stylesheets are not navigable,
     10        since their start position is not detectable inside the surrounding HTML as of yet.
     11
     12        No new tests, a UI change.
     13
     14        * inspector/front-end/CSSStyleModel.js:
     15        (WebInspector.CSSRule.prototype.isSourceNavigable): Whether the rule contains reliable source code information.
     16        (WebInspector.CSSProperty.prototype.uiLocation): Returns a UILocation for the property name of value.
     17        * inspector/front-end/StylesSidebarPane.js: Add navigation code.
     18        (WebInspector.StylesSidebarPane.prototype._innerRebuildUpdate):
     19        (WebInspector.StylePropertiesSection):
     20
    1212013-03-01  Sheriff Bot  <webkit.review.bot@gmail.com>
    222
  • trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js

    r144434 r144449  
    883883    {
    884884        return this.origin === "regular";
     885    },
     886
     887    /**
     888     * @return {boolean}
     889     */
     890    isSourceNavigable: function()
     891    {
     892        if (!this.sourceURL)
     893            return false;
     894        var resource = WebInspector.resourceTreeModel.resourceForURL(this.sourceURL);
     895        return !!resource && resource.contentType() === WebInspector.resourceTypes.Stylesheet;
    885896    }
    886897}
     
    10711082        WebInspector.cssModel._pendingCommandsMajorState.push(false);
    10721083        CSSAgent.toggleProperty(this.ownerStyle.id, this.index, disabled, callback.bind(this));
     1084    },
     1085
     1086    /**
     1087     * @param {boolean} forName
     1088     * @return {WebInspector.UILocation}
     1089     */
     1090    uiLocation: function(forName)
     1091    {
     1092        if (!this.range || !this.ownerStyle || !this.ownerStyle.parentRule || !this.ownerStyle.parentRule.sourceURL)
     1093            return null;
     1094
     1095        var range = this.range;
     1096        var line = forName ? range.startLine : range.endLine;
     1097        // End of range is exclusive, so subtract 1 from the end offset.
     1098        var column = forName ? range.startColumn : range.endColumn - 1;
     1099        var rawLocation = new WebInspector.CSSLocation(this.ownerStyle.parentRule.sourceURL, line, column);
     1100        return WebInspector.cssModel.rawLocationToUILocation(rawLocation);
    10731101    }
    10741102}
  • trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js

    r143333 r144449  
    377377        var anchorElement = this.sections[0].inheritedPropertiesSeparatorElement;
    378378
    379         if (styles.computedStyle)       
     379        if (styles.computedStyle)
    380380            this.sections[0][0].rebuildComputedTrace(this.sections[0]);
    381381
     
    895895        if (this.rule.isUserAgent || this.rule.isUser)
    896896            this.editable = false;
     897        else
     898            this.navigable = this.rule.isSourceNavigable();
    897899        this.titleElement.addStyleClass("styles-selector");
    898900    }
     
    909911    if (isInherited)
    910912        this.element.addStyleClass("show-inherited"); // This one is related to inherited rules, not computed style.
     913
     914    if (this.navigable)
     915        this.element.addStyleClass("navigable");
    911916
    912917    if (!this.editable)
     
    20462051                return;
    20472052
     2053            newStyle.parentRule = this.style.parentRule;
    20482054            this.style = newStyle;
    20492055            this._styleRule.style = newStyle;
     
    21592165        }
    21602166
     2167        if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && this.section().navigable) {
     2168            this._navigateToSource(event.target);
     2169            return;
     2170        }
     2171
    21612172        this.startEditing(event.target);
     2173    },
     2174
     2175    /**
     2176     * @param {Element} element
     2177     */
     2178    _navigateToSource: function(element)
     2179    {
     2180        console.assert(this.section().navigable);
     2181        var propertyNameClicked = element === this.nameElement;
     2182        var uiLocation = this.property.uiLocation(propertyNameClicked);
     2183        if (!uiLocation)
     2184            return;
     2185        WebInspector.showPanel("scripts").showUISourceCode(uiLocation.uiSourceCode, uiLocation.lineNumber);
    21622186    },
    21632187
     
    25812605            if (this._newProperty)
    25822606                this._newPropertyInStyle = true;
     2607            newStyle.parentRule = this.style.parentRule;
    25832608            this.style = newStyle;
    25842609            this.property = newStyle.propertyAt(this.property.index);
     
    26742699            this._sidebarPane.applyStyleText(this._sidebarPane.nameElement.textContent + ": " + this._sidebarPane.valueElement.textContent, false, false, false);
    26752700        }
    2676    
     2701
    26772702        // Handle numeric value increment/decrement only at this point.
    26782703        if (!this._isEditingName && WebInspector.handleElementValueModifications(event, this._sidebarPane.valueElement, finishHandler.bind(this), this._isValueSuggestion.bind(this)))
Note: See TracChangeset for help on using the changeset viewer.