Changeset 132321 in webkit


Ignore:
Timestamp:
Oct 24, 2012, 12:34:24 AM (12 years ago)
Author:
[email protected]
Message:

Web Inspector: Implement CSS reload upon related SASS resource saving
https://bugs.webkit.org/show_bug.cgi?id=98024

Reviewed by Vsevolod Vlasov.

SASS-generated debug info in CSS is parsed to find out which SASS files contributed to this stylesheet.
Upon SASS file save in the Sources panel, all affected external CSS stylesheets are reloaded to update
the page styles (presuming that SASS is running in the "watch" mode during the development cycle).

  • English.lproj/localizedStrings.js:
  • inspector/front-end/SASSSourceMapping.js:

(WebInspector.SASSSourceMapping):
(WebInspector.SASSSourceMapping.prototype._fileSaveFinished.callback):
(WebInspector.SASSSourceMapping.prototype._reloadCSS):
(_bindUISourceCode):
(_addCSSURLforSASSURL):

  • inspector/front-end/Settings.js:
  • inspector/front-end/SettingsScreen.js:

(WebInspector.GenericSettingsTab):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r132315 r132321  
     12012-10-24  Alexander Pavlov  <[email protected]>
     2
     3        Web Inspector: Implement CSS reload upon related SASS resource saving
     4        https://bugs.webkit.org/show_bug.cgi?id=98024
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        SASS-generated debug info in CSS is parsed to find out which SASS files contributed to this stylesheet.
     9        Upon SASS file save in the Sources panel, all affected external CSS stylesheets are reloaded to update
     10        the page styles (presuming that SASS is running in the "watch" mode during the development cycle).
     11
     12        * English.lproj/localizedStrings.js:
     13        * inspector/front-end/SASSSourceMapping.js:
     14        (WebInspector.SASSSourceMapping):
     15        (WebInspector.SASSSourceMapping.prototype._fileSaveFinished.callback):
     16        (WebInspector.SASSSourceMapping.prototype._reloadCSS):
     17        (_bindUISourceCode):
     18        (_addCSSURLforSASSURL):
     19        * inspector/front-end/Settings.js:
     20        * inspector/front-end/SettingsScreen.js:
     21        (WebInspector.GenericSettingsTab):
     22
    1232012-10-23  Yury Semikhatsky  <[email protected]>
    224
  • trunk/Source/WebCore/English.lproj/localizedStrings.js

    r132199 r132321  
    7979localizedStrings["Audit Present State"] = "Audit Present State";
    8080localizedStrings["Audits"] = "Audits";
     81localizedStrings["Auto-reload CSS upon SASS save"] = "Auto-reload CSS upon SASS save";
    8182localizedStrings["Average"] = "Average";
    8283localizedStrings["Blocking"] = "Blocking";
     
    412413localizedStrings["Timeline"] = "Timeline";
    413414localizedStrings["Timeout"] = "Timeout";
     415localizedStrings["Timeout (ms)"] = "Timeout (ms)";
    414416localizedStrings["Timer Fired"] = "Timer Fired";
    415417localizedStrings["Timer ID"] = "Timer ID";
  • trunk/Source/WebCore/inspector/front-end/SASSSourceMapping.js

    r132234 r132321  
    3838    this._workspace = workspace;
    3939    this._uiLocations = {};
     40    this._cssURLsForSASSURL = {};
     41    this._timeoutForURL = {};
    4042    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
     43    WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._fileSaveFinished, this);
    4144    this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
    4245}
     
    5659
    5760        populateFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
     61    },
     62
     63    /**
     64     * @param {WebInspector.Event} event
     65     */
     66    _fileSaveFinished: function(event)
     67    {
     68        var sassURL = /** @type {string} */ event.data;
     69        function callback()
     70        {
     71            delete this._timeoutForURL[sassURL];
     72            var cssURLs = this._cssURLsForSASSURL[sassURL];
     73            if (!cssURLs)
     74                return;
     75            for (var i = 0; i < cssURLs.length; ++i)
     76                this._reloadCSS(cssURLs[i]);
     77        }
     78
     79        var timer = this._timeoutForURL[sassURL];
     80        if (timer) {
     81            clearTimeout(timer);
     82            delete this._timeoutForURL[sassURL];
     83        }
     84        if (!WebInspector.settings.cssReloadEnabled.get() || !this._cssURLsForSASSURL[sassURL])
     85            return;
     86        var timeout = WebInspector.settings.cssReloadTimeout.get();
     87        if (timeout && isFinite(timeout))
     88            this._timeoutForURL[sassURL] = setTimeout(callback.bind(this), Number(timeout));
     89    },
     90
     91    _reloadCSS: function(url)
     92    {
     93        var uiSourceCode = this._workspace.uiSourceCodeForURL(url);
     94        if (!uiSourceCode)
     95            return;
     96        var newContent = InspectorFrontendHost.loadResourceSynchronously(url);
     97        uiSourceCode.addRevision(newContent);
    5898    },
    5999
     
    122162        var rawLocationString = rawURL + ":" + (rawLine + 1);  // Next line after mapping metainfo
    123163        this._uiLocations[rawLocationString] = new WebInspector.UILocation(uiSourceCode, line - 1, 0);
     164        this._addCSSURLforSASSURL(rawURL, url);
     165    },
     166
     167    /**
     168     * @param {string} cssURL
     169     * @param {string} sassURL
     170     */
     171    _addCSSURLforSASSURL: function(cssURL, sassURL)
     172    {
     173        var cssURLs;
     174        if (this._cssURLsForSASSURL.hasOwnProperty(sassURL))
     175            cssURLs = this._cssURLsForSASSURL[sassURL];
     176        else {
     177            cssURLs = [];
     178            this._cssURLsForSASSURL[sassURL] = cssURLs;
     179        }
     180        if (cssURLs.indexOf(cssURL) === -1)
     181            cssURLs.push(cssURL);
    124182    },
    125183
  • trunk/Source/WebCore/inspector/front-end/Settings.js

    r131176 r132321  
    106106    this.textEditorIndent = this.createSetting("textEditorIndent", "    ");
    107107    this.lastDockState = this.createSetting("lastDockState", "");
     108    this.cssReloadEnabled = this.createSetting("cssReloadEnabled", false);
     109    this.cssReloadTimeout = this.createSetting("cssReloadTimeout", 1000);
    108110
    109111    // If there are too many breakpoints in a storage, it is likely due to a recent bug that caused
  • trunk/Source/WebCore/inspector/front-end/SettingsScreen.js

    r131870 r132321  
    277277    p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Search in content scripts"), WebInspector.settings.searchInContentScripts));
    278278    p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Enable source maps"), WebInspector.settings.sourceMapsEnabled));
     279    if (WebInspector.experimentsSettings.isEnabled("sass"))
     280        p.appendChild(this._createCSSAutoReloadControls());
    279281    p.appendChild(this._createSelectSetting(WebInspector.UIString("Indentation"), [
    280282            [ WebInspector.UIString("2 spaces"), WebInspector.TextEditorModel.Indent.TwoSpaces ],
     
    332334        // We need to manually update the checkbox state, since enabling JavaScript in the page can actually uncover the "forbidden" state.
    333335        PageAgent.setScriptExecutionDisabled(WebInspector.settings.javaScriptDisabled.get(), this._updateScriptDisabledCheckbox.bind(this));
     336    },
     337
     338    _createCSSAutoReloadControls: function()
     339    {
     340        var fragment = document.createDocumentFragment();
     341        var labelElement = fragment.createChild("label");
     342        var checkboxElement = labelElement.createChild("input");
     343        checkboxElement.type = "checkbox";
     344        checkboxElement.checked = WebInspector.settings.cssReloadEnabled.get();
     345        checkboxElement.addEventListener("click", checkboxClicked, false);
     346        labelElement.appendChild(document.createTextNode(WebInspector.UIString("Auto-reload CSS upon SASS save")));
     347
     348        var fieldsetElement = fragment.createChild("fieldset");
     349        fieldsetElement.disabled = !checkboxElement.checked;
     350        var p = fieldsetElement.createChild("p");
     351        p.appendChild(document.createTextNode(WebInspector.UIString("Timeout (ms)")));
     352        p.appendChild(document.createTextNode(" "));
     353        var timeoutInput = p.createChild("input");
     354        timeoutInput.value = WebInspector.settings.cssReloadTimeout.get();
     355        timeoutInput.style.width = "60px";
     356        timeoutInput.maxLength = 8;
     357        timeoutInput.addEventListener("blur", blurListener, false);
     358        return fragment;
     359
     360        function checkboxClicked()
     361        {
     362            var reloadEnabled = checkboxElement.checked;
     363            WebInspector.settings.cssReloadEnabled.set(reloadEnabled);
     364            fieldsetElement.disabled = !reloadEnabled;
     365        }
     366
     367        function blurListener()
     368        {
     369            var value = timeoutInput.value;
     370            if (!isFinite(value) || value <= 0) {
     371                timeoutInput.value = WebInspector.settings.cssReloadTimeout.get();
     372                return;
     373            }
     374            WebInspector.settings.cssReloadTimeout.set(Number(value));
     375        }
    334376    },
    335377
Note: See TracChangeset for help on using the changeset viewer.