Changeset 217258 in webkit


Ignore:
Timestamp:
May 22, 2017 4:44:49 PM (7 years ago)
Author:
Devin Rousso
Message:

Web Inspector: New CSS Rules should go into a new Stylesheet Resource that can be viewed/edited/saved
https://bugs.webkit.org/show_bug.cgi?id=138810

Reviewed by Joseph Pecoraro.

  • Localizations/en.lproj/localizedStrings.js:
  • UserInterface/Controllers/CSSStyleManager.js:

(WebInspector.CSSStyleManager):
(WebInspector.CSSStyleManager.prototype.preferredInspectorStyleSheetForFrame):
(WebInspector.CSSStyleManager.prototype._updateResourceContent.fetchedStyleSheetContent):
Manually dispatch a change event for modifications to CSSStyleSheet objects since they are
not covered by the listener for Resource changes.

  • UserInterface/Main.html:

Include WebInspector.CSSStyleSheetTreeElement.

  • UserInterface/Models/Collection.js:

(WebInspector.Collection.TypeVerifier):

  • UserInterface/Models/ResourceCollection.js:

(WebInspector.ResourceCollection.TypeVerifier.Stylesheet):
Add TypeVerifier for CSSStyleSheet.

  • UserInterface/Models/DOMNodeStyles.js:

(WebInspector.DOMNodeStyles.prototype._parseRulePayload):
Manually create a SourceCodeLocation object for Inspector Style Sheets.

  • UserInterface/Views/CSSStyleSheetTreeElement.js: Added.

(WebInspector.CSSStyleSheetTreeElement):

  • UserInterface/Views/ResourceIcons.css:

(:matches(.resource-icon.resource-type-stylesheet, .stylessheet-icon) .icon):

  • UserInterface/Views/FrameTreeElement.js:

(WebInspector.FrameTreeElement.forwardingConstructor):
(WebInspector.FrameTreeElement):
(WebInspector.FrameTreeElement.prototype.onattach):
(WebInspector.FrameTreeElement.prototype.ondetach):
(WebInspector.FrameTreeElement.prototype.onpopulate):
(WebInspector.FrameTreeElement.prototype._styleSheetAdded):

  • UserInterface/Views/ResourceSidebarPanel.js:

(WebInspector.ResourceSidebarPanel):
(WebInspector.ResourceSidebarPanel.prototype._styleSheetAdded):
(WebInspector.ResourceSidebarPanel.prototype._treeSelectionDidChange):
Listen for the creation of CSSStyleSheet objects and add them to the sidebar if they are an
Inspector Style Sheet. Regular style sheets are added via their respective resources.

  • UserInterface/Views/NavigationSidebarPanel.js:

(WebInspector.NavigationSidebarPanel.prototype._isTreeElementWithoutRepresentedObject):
Prevent CSSStyleSheetTreeElement instances from attempting to save state to a cookie.

  • UserInterface/Base/Main.js:

(WebInspector.tabContentViewClassForRepresentedObject):
(WebInspector.createSourceCodeLocationLink):

  • UserInterface/Views/ContentView.js:

(WebInspector.ContentView.createFromRepresentedObject):
(WebInspector.ContentView.isViewable):

  • UserInterface/Views/CSSStyleDeclarationSection.js:

(WebInspector.CSSStyleDeclarationSection.prototype.refresh):

  • UserInterface/Views/ResourcesTabContentView.js:

(WebInspector.ResourcesTabContentView.prototype.canShowRepresentedObject):

  • UserInterface/Views/ResourceContentView.js:

(WebInspector.ResourceContentView):

  • UserInterface/Views/SourceCodeTextEditor.js:

(WebInspector.SourceCodeTextEditor.prototype._prepareEditorForInitialContent):
(WebInspector.SourceCodeTextEditor.prototype._looselyMatchesSourceCodeLocation):
(WebInspector.SourceCodeTextEditor.prototype._matchesSourceCodeLocation):

  • UserInterface/Views/TextResourceContentView.js:

(WebInspector.TextResourceContentView):
(WebInspector.TextResourceContentView.prototype.get supportsSave):
(WebInspector.TextResourceContentView.prototype.get saveData):
(WebInspector.TextResourceContentView.prototype._contentWillPopulate):
(WebInspector.TextResourceContentView.prototype._shouldBeEditable):
Support editing and saving an Inspector Style Sheet via its CSSStyleSheet object.

Location:
trunk/Source/WebInspectorUI
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r217248 r217258  
     12017-05-22  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: New CSS Rules should go into a new Stylesheet Resource that can be viewed/edited/saved
     4        https://bugs.webkit.org/show_bug.cgi?id=138810
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * Localizations/en.lproj/localizedStrings.js:
     9
     10        * UserInterface/Controllers/CSSStyleManager.js:
     11        (WebInspector.CSSStyleManager):
     12        (WebInspector.CSSStyleManager.prototype.preferredInspectorStyleSheetForFrame):
     13        (WebInspector.CSSStyleManager.prototype._updateResourceContent.fetchedStyleSheetContent):
     14        Manually dispatch a change event for modifications to CSSStyleSheet objects since they are
     15        not covered by the listener for Resource changes.
     16
     17        * UserInterface/Main.html:
     18        Include WebInspector.CSSStyleSheetTreeElement.
     19
     20        * UserInterface/Models/Collection.js:
     21        (WebInspector.Collection.TypeVerifier):
     22        * UserInterface/Models/ResourceCollection.js:
     23        (WebInspector.ResourceCollection.TypeVerifier.Stylesheet):
     24        Add TypeVerifier for CSSStyleSheet.
     25
     26        * UserInterface/Models/DOMNodeStyles.js:
     27        (WebInspector.DOMNodeStyles.prototype._parseRulePayload):
     28        Manually create a SourceCodeLocation object for Inspector Style Sheets.
     29
     30        * UserInterface/Views/CSSStyleSheetTreeElement.js: Added.
     31        (WebInspector.CSSStyleSheetTreeElement):
     32
     33        * UserInterface/Views/ResourceIcons.css:
     34        (:matches(.resource-icon.resource-type-stylesheet, .stylessheet-icon) .icon):
     35
     36        * UserInterface/Views/FrameTreeElement.js:
     37        (WebInspector.FrameTreeElement.forwardingConstructor):
     38        (WebInspector.FrameTreeElement):
     39        (WebInspector.FrameTreeElement.prototype.onattach):
     40        (WebInspector.FrameTreeElement.prototype.ondetach):
     41        (WebInspector.FrameTreeElement.prototype.onpopulate):
     42        (WebInspector.FrameTreeElement.prototype._styleSheetAdded):
     43        * UserInterface/Views/ResourceSidebarPanel.js:
     44        (WebInspector.ResourceSidebarPanel):
     45        (WebInspector.ResourceSidebarPanel.prototype._styleSheetAdded):
     46        (WebInspector.ResourceSidebarPanel.prototype._treeSelectionDidChange):
     47        Listen for the creation of CSSStyleSheet objects and add them to the sidebar if they are an
     48        Inspector Style Sheet.  Regular style sheets are added via their respective resources.
     49
     50        * UserInterface/Views/NavigationSidebarPanel.js:
     51        (WebInspector.NavigationSidebarPanel.prototype._isTreeElementWithoutRepresentedObject):
     52        Prevent CSSStyleSheetTreeElement instances from attempting to save state to a cookie.
     53
     54        * UserInterface/Base/Main.js:
     55        (WebInspector.tabContentViewClassForRepresentedObject):
     56        (WebInspector.createSourceCodeLocationLink):
     57        * UserInterface/Views/ContentView.js:
     58        (WebInspector.ContentView.createFromRepresentedObject):
     59        (WebInspector.ContentView.isViewable):
     60        * UserInterface/Views/CSSStyleDeclarationSection.js:
     61        (WebInspector.CSSStyleDeclarationSection.prototype.refresh):
     62        * UserInterface/Views/ResourcesTabContentView.js:
     63        (WebInspector.ResourcesTabContentView.prototype.canShowRepresentedObject):
     64        * UserInterface/Views/ResourceContentView.js:
     65        (WebInspector.ResourceContentView):
     66        * UserInterface/Views/SourceCodeTextEditor.js:
     67        (WebInspector.SourceCodeTextEditor.prototype._prepareEditorForInitialContent):
     68        (WebInspector.SourceCodeTextEditor.prototype._looselyMatchesSourceCodeLocation):
     69        (WebInspector.SourceCodeTextEditor.prototype._matchesSourceCodeLocation):
     70        * UserInterface/Views/TextResourceContentView.js:
     71        (WebInspector.TextResourceContentView):
     72        (WebInspector.TextResourceContentView.prototype.get supportsSave):
     73        (WebInspector.TextResourceContentView.prototype.get saveData):
     74        (WebInspector.TextResourceContentView.prototype._contentWillPopulate):
     75        (WebInspector.TextResourceContentView.prototype._shouldBeEditable):
     76        Support editing and saving an Inspector Style Sheet via its CSSStyleSheet object.
     77
    1782017-05-22  Brian Burg  <bburg@apple.com>
    279
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r216629 r217258  
    461461localizedStrings["Input: "] = "Input: ";
    462462localizedStrings["Inset"] = "Inset";
     463localizedStrings["Inspector Style Sheet"] = "Inspector Style Sheet";
    463464localizedStrings["Instances"] = "Instances";
    464465localizedStrings["Invalid"] = "Invalid";
  • trunk/Source/WebInspectorUI/UserInterface/Base/Main.js

    r217248 r217258  
    11261126    }
    11271127
    1128     if (representedObject instanceof WebInspector.Frame || representedObject instanceof WebInspector.Resource || representedObject instanceof WebInspector.Script)
     1128    if (representedObject instanceof WebInspector.Frame
     1129        || representedObject instanceof WebInspector.Resource
     1130        || representedObject instanceof WebInspector.Script
     1131        || representedObject instanceof WebInspector.StyleSheet)
    11291132        return WebInspector.ResourcesTabContentView;
    11301133
     
    23142317        linkElement.appendChild(WebInspector.createGoToArrowButton());
    23152318    else
    2316         sourceCodeLocation.populateLiveDisplayLocationString(linkElement, "textContent");
     2319        sourceCodeLocation.populateLiveDisplayLocationString(linkElement, "textContent", options.columnStyle, options.nameStyle, options.prefix);
    23172320
    23182321    if (options.dontFloat)
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js

    r208779 r217258  
    168168    }
    169169
    170     preferredInspectorStyleSheetForFrame(frame, callback)
     170    preferredInspectorStyleSheetForFrame(frame, callback, doNotCreateIfMissing)
    171171    {
    172172        var inspectorStyleSheets = this._inspectorStyleSheetsForFrame(frame);
     
    177177            }
    178178        }
     179
     180        if (doNotCreateIfMissing)
     181            return;
    179182
    180183        if (CSSAgent.createStyleSheet) {
     
    495498        function fetchedStyleSheetContent(parameters)
    496499        {
    497             var styleSheet = parameters.sourceCode;
    498             var content = parameters.content;
    499 
    500             styleSheet.__pendingChangeTimeout = undefined;
    501 
    502             console.assert(styleSheet.url);
    503             if (!styleSheet.url)
    504                 return;
    505 
    506             var resource = styleSheet.parentFrame.resourceForURL(styleSheet.url);
    507             if (!resource)
    508                 return;
    509 
    510             // Only try to update stylesheet resources. Other resources, like documents, can contain
    511             // multiple stylesheets and we don't have the source ranges to update those.
    512             if (resource.type !== WebInspector.Resource.Type.Stylesheet)
    513                 return;
    514 
    515             if (resource.__ignoreNextUpdateResourceContent) {
    516                 resource.__ignoreNextUpdateResourceContent = false;
    517                 return;
    518             }
    519 
    520             this._ignoreResourceContentDidChangeEventForResource = resource;
    521             WebInspector.branchManager.currentBranch.revisionForRepresentedObject(resource).content = content;
     500            let representedObject = parameters.sourceCode;
     501            representedObject.__pendingChangeTimeout = undefined;
     502
     503            console.assert(representedObject.url);
     504            if (!representedObject.url)
     505                return;
     506
     507            if (!styleSheet.isInspectorStyleSheet()) {
     508                representedObject = representedObject.parentFrame.resourceForURL(representedObject.url);
     509                if (!representedObject)
     510                    return;
     511
     512                // Only try to update stylesheet resources. Other resources, like documents, can contain
     513                // multiple stylesheets and we don't have the source ranges to update those.
     514                if (representedObject.type !== WebInspector.Resource.Type.Stylesheet)
     515                    return;
     516            }
     517
     518            if (representedObject.__ignoreNextUpdateResourceContent) {
     519                representedObject.__ignoreNextUpdateResourceContent = false;
     520                return;
     521            }
     522
     523            this._ignoreResourceContentDidChangeEventForResource = representedObject;
     524
     525            let revision = WebInspector.branchManager.currentBranch.revisionForRepresentedObject(representedObject);
     526            if (styleSheet.isInspectorStyleSheet()) {
     527                revision.content = representedObject.content;
     528                styleSheet.dispatchEventToListeners(WebInspector.SourceCode.Event.ContentDidChange);
     529            } else
     530                revision.content = parameters.content;
     531
    522532            this._ignoreResourceContentDidChangeEventForResource = null;
    523533        }
  • trunk/Source/WebInspectorUI/UserInterface/Main.html

    r216147 r217258  
    507507    <script src="Views/CSSStyleDeclarationTextEditor.js"></script>
    508508    <script src="Views/CSSStyleDetailsSidebarPanel.js"></script>
     509    <script src="Views/CSSStyleSheetTreeElement.js"></script>
    509510    <script src="Views/CallFrameTreeElement.js"></script>
    510511    <script src="Views/CallFrameView.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/Models/Collection.js

    r208246 r217258  
    117117    Resource: (object) => object instanceof WebInspector.Resource,
    118118    Script: (object) => object instanceof WebInspector.Script,
     119    CSSStyleSheet: (object) => object instanceof WebInspector.CSSStyleSheet,
    119120};
  • trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js

    r213961 r217258  
    766766        }
    767767
    768         if (styleSheet)
     768        if (styleSheet) {
     769            if (!sourceCodeLocation && styleSheet.isInspectorStyleSheet())
     770                sourceCodeLocation = styleSheet.createSourceCodeLocation(sourceRange.startLine, sourceRange.startColumn)
     771
    769772            sourceCodeLocation = styleSheet.offsetSourceCodeLocation(sourceCodeLocation);
     773        }
    770774
    771775        var mediaList = [];
  • trunk/Source/WebInspectorUI/UserInterface/Models/ResourceCollection.js

    r209629 r217258  
    189189WebInspector.ResourceCollection.TypeVerifier = {
    190190    Document: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Document,
    191     Stylesheet: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Stylesheet,
     191    Stylesheet: (object) => {
     192        if (WebInspector.Collection.TypeVerifier.CSSStyleSheet(object))
     193            return true;
     194        return WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Stylesheet
     195    },
    192196    Image: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Image,
    193197    Font: (object) => WebInspector.Collection.TypeVerifier.Resource(object) && object.type === WebInspector.Resource.Type.Font,
  • trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js

    r216692 r217258  
    249249
    250250            if (this._style.ownerRule.sourceCodeLocation) {
    251                 const options = {
     251                let options = {
    252252                    dontFloat: true,
    253253                    ignoreNetworkTab: true,
    254254                    ignoreSearchTab: true,
    255255                };
     256                if (this._style.ownerStyleSheet.isInspectorStyleSheet()) {
     257                    options.nameStyle = WebInspector.SourceCodeLocation.NameStyle.None;
     258                    options.prefix = WebInspector.UIString("Inspector Style Sheet") + ":";
     259                }
     260
    256261                let sourceCodeLink = WebInspector.createSourceCodeLocationLink(this._style.ownerRule.sourceCodeLocation, options);
    257262                this._originElement.appendChild(sourceCodeLink);
  • trunk/Source/WebInspectorUI/UserInterface/Views/ContentView.js

    r216147 r217258  
    5555            return new WebInspector.ScriptContentView(representedObject, extraArguments);
    5656
     57        if (representedObject instanceof WebInspector.CSSStyleSheet)
     58            return new WebInspector.TextResourceContentView(representedObject, extraArguments);
     59
    5760        if (representedObject instanceof WebInspector.TimelineRecording)
    5861            return new WebInspector.TimelineRecordingContentView(representedObject, extraArguments);
     
    235238        if (representedObject instanceof WebInspector.Script)
    236239            return true;
     240        if (representedObject instanceof WebInspector.CSSStyleSheet)
     241            return true;
    237242        if (representedObject instanceof WebInspector.TimelineRecording)
    238243            return true;
  • trunk/Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js

    r214354 r217258  
    5454        this.registerFolderizeSettings("extra-scripts", WebInspector.UIString("Extra Scripts"), this._frame.extraScriptCollection, WebInspector.ScriptTreeElement);
    5555
     56        function forwardingConstructor(representedObject, ...extraArguments) {
     57            if (representedObject instanceof WebInspector.CSSStyleSheet)
     58                return new WebInspector.CSSStyleSheetTreeElement(representedObject, ...extraArguments);
     59            return new WebInspector.ResourceTreeElement(representedObject, ...extraArguments);
     60        }
     61
    5662        for (let [key, value] of Object.entries(WebInspector.Resource.Type)) {
    5763            let folderName = WebInspector.Resource.displayNameForType(value, true);
    5864
    59             let treeElementConstructor = WebInspector.ResourceTreeElement;
     65            let treeElementConstructor = forwardingConstructor;
    6066            if (value === WebInspector.Resource.Type.WebSocket)
    6167                treeElementConstructor = WebInspector.WebSocketResourceTreeElement;
    6268
    63             this.registerFolderizeSettings(key, folderName, this._frame.resourceCollectionForType(value), treeElementConstructor);
     69            this.registerFolderizeSettings(key, folderName, this._frame.resourceCollectionForType(value), forwardingConstructor);
    6470        }
    6571
     
    114120        // Immediate superclasses are skipped, since Frames handle their own SourceMapResources.
    115121        WebInspector.GeneralTreeElement.prototype.onattach.call(this);
     122
     123        WebInspector.cssStyleManager.addEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, this._styleSheetAdded, this);
     124    }
     125
     126    ondetach()
     127    {
     128        WebInspector.cssStyleManager.removeEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, this._styleSheetAdded, this);
     129
     130        super.ondetach();
    116131    }
    117132
     
    171186                this.addChildForRepresentedObject(extraScript);
    172187        }
     188
     189        const doNotCreateIfMissing = true;
     190        WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(this._frame, this.addRepresentedObjectToNewChildQueue.bind(this), doNotCreateIfMissing);
    173191    }
    174192
     
    254272            this._frame.domTree.requestContentFlowList();
    255273    }
     274
     275    _styleSheetAdded(event)
     276    {
     277        if (!event.data.styleSheet.isInspectorStyleSheet())
     278            return;
     279
     280        this.addRepresentedObjectToNewChildQueue(event.data.styleSheet);
     281    }
    256282};
  • trunk/Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js

    r215113 r217258  
    646646            || treeElement instanceof WebInspector.DOMBreakpointTreeElement
    647647            || treeElement instanceof WebInspector.XHRBreakpointTreeElement
     648            || treeElement instanceof WebInspector.CSSStyleSheetTreeElement
    648649            || typeof treeElement.representedObject === "string"
    649650            || treeElement.representedObject instanceof String;
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js

    r216138 r217258  
    2828    constructor(resource, styleClassName)
    2929    {
    30         console.assert(resource instanceof WebInspector.Resource, resource);
     30        console.assert(resource instanceof WebInspector.Resource || resource instanceof WebInspector.CSSStyleSheet, resource);
    3131        console.assert(typeof styleClassName === "string");
    3232
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourceIcons.css

    r217067 r217258  
    4040}
    4141
    42 .resource-icon.resource-type-stylesheet .icon {
     42:matches(.resource-icon.resource-type-stylesheet, .stylesheet-icon) .icon {
    4343    content: image-set(url(../Images/DocumentCSS.png) 1x, url(../Images/DocumentCSS@2x.png) 2x);
    4444}
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js

    r215630 r217258  
    6464        WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptsCleared, this._scriptsCleared, this);
    6565
     66        WebInspector.cssStyleManager.addEventListener(WebInspector.CSSStyleManager.Event.StyleSheetAdded, this._styleSheetAdded, this);
     67
    6668        WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event.TargetRemoved, this._targetRemoved, this);
    6769
     
    393395    }
    394396
     397    _styleSheetAdded(event)
     398    {
     399        let styleSheet = event.data.styleSheet;
     400        if (!styleSheet.isInspectorStyleSheet())
     401            return;
     402
     403        let frameTreeElement = this.treeElementForRepresentedObject(styleSheet.parentFrame);
     404        if (!frameTreeElement)
     405            return;
     406
     407        frameTreeElement.addRepresentedObjectToNewChildQueue(styleSheet);
     408    }
     409
    395410    _addTargetWithMainResource(target)
    396411    {
     
    422437            || treeElement instanceof WebInspector.ResourceTreeElement
    423438            || treeElement instanceof WebInspector.ScriptTreeElement
     439            || treeElement instanceof WebInspector.CSSStyleSheetTreeElement
    424440            || treeElement instanceof WebInspector.ContentFlowTreeElement) {
    425441            const cookie = null;
  • trunk/Source/WebInspectorUI/UserInterface/Views/ResourcesTabContentView.js

    r212400 r217258  
    6565            || representedObject instanceof WebInspector.Resource
    6666            || representedObject instanceof WebInspector.Script
     67            || representedObject instanceof WebInspector.CSSStyleSheet
    6768            || representedObject instanceof WebInspector.ContentFlow
    6869            || representedObject instanceof WebInspector.Collection;
  • trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js

    r215630 r217258  
    517517        else if (this._sourceCode instanceof WebInspector.Script)
    518518            this.mimeType = "text/javascript";
     519        else if (this._sourceCode instanceof WebInspector.CSSStyleSheet)
     520            this.mimeType = "text/css";
    519521
    520522        // Decide to automatically format the content if it looks minified and it can be formatted.
     
    970972        if (this._sourceCode instanceof WebInspector.SourceMapResource)
    971973            return sourceCodeLocation.displaySourceCode === this._sourceCode;
    972         if (this._sourceCode instanceof WebInspector.Resource || this._sourceCode instanceof WebInspector.Script)
     974        if (this._sourceCode instanceof WebInspector.Resource || this._sourceCode instanceof WebInspector.Script || this._sourceCode instanceof WebInspector.CSSStyleSheet)
    973975            return sourceCodeLocation.sourceCode.url === this._sourceCode.url;
    974976        return false;
     
    979981        if (this._sourceCode instanceof WebInspector.SourceMapResource)
    980982            return sourceCodeLocation.displaySourceCode === this._sourceCode;
    981         if (this._sourceCode instanceof WebInspector.Resource)
     983        if (this._sourceCode instanceof WebInspector.Resource || this._sourceCode instanceof WebInspector.CSSStyleSheet)
    982984            return sourceCodeLocation.sourceCode.url === this._sourceCode.url;
    983985        if (this._sourceCode instanceof WebInspector.Script)
  • trunk/Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js

    r214133 r217258  
    3939        this._textEditor.addEventListener(WebInspector.SourceCodeTextEditor.Event.ContentWillPopulate, this._contentWillPopulate, this);
    4040        this._textEditor.addEventListener(WebInspector.SourceCodeTextEditor.Event.ContentDidPopulate, this._contentDidPopulate, this);
     41        this._textEditor.readOnly = !this._shouldBeEditable();
    4142
    4243        WebInspector.probeManager.addEventListener(WebInspector.ProbeManager.Event.ProbeSetAdded, this._probeSetsChanged, this);
     
    127128    }
    128129
     130    get supportsSave()
     131    {
     132        return super.supportsSave || this.resource instanceof WebInspector.CSSStyleSheet;
     133    }
     134
    129135    get saveData()
    130136    {
     137        if (this.resource instanceof WebInspector.CSSStyleSheet)
     138            return {url: "web-inspector:///InspectorStyleSheet.css", content: this._textEditor.string, forceSaveAs: true};
    131139        return {url: this.resource.url, content: this._textEditor.string};
    132140    }
     
    183191        if (this._textEditor.parentView === this)
    184192            return;
    185 
    186         // Check the MIME-type for CSS since Resource.Type.Stylesheet also includes XSL, which we can't edit yet.
    187         if (this.resource.type === WebInspector.Resource.Type.Stylesheet && this.resource.syntheticMIMEType === "text/css")
    188             this._textEditor.readOnly = false;
    189 
    190         // Allow editing any local file since edits can be saved and reloaded right from the Inspector.
    191         if (this.resource.urlComponents.scheme === "file")
    192             this._textEditor.readOnly = false;
    193193
    194194        this.element.removeChildren();
     
    275275            this.dispatchEventToListeners(WebInspector.ContentView.Event.SupplementalRepresentedObjectsDidChange);
    276276    }
     277
     278    _shouldBeEditable()
     279    {
     280        if (this.resource instanceof WebInspector.CSSStyleSheet)
     281            return true;
     282
     283        // Check the MIME-type for CSS since Resource.Type.Stylesheet also includes XSL, which we can't edit yet.
     284        if (this.resource.type === WebInspector.Resource.Type.Stylesheet && this.resource.syntheticMIMEType === "text/css")
     285            return true;
     286
     287        // Allow editing any local file since edits can be saved and reloaded right from the Inspector.
     288        if (this.resource.urlComponents.scheme === "file")
     289            return true;
     290
     291        return false;
     292    }
    277293};
Note: See TracChangeset for help on using the changeset viewer.