Changeset 82252 in webkit


Ignore:
Timestamp:
Mar 29, 2011 8:09:55 AM (13 years ago)
Author:
apavlov@chromium.org
Message:

2011-03-29 Alexander Pavlov <apavlov@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: Fix handling of the CSSAgent.setStyleSheetText() results in CSSStyleModel.js
https://bugs.webkit.org/show_bug.cgi?id=56310

Instead of stylesheet ids, CSSAgent.getAllStyleSheets() now returns metainfo objects containing
"styleSheetId", "sourceURL", "disabled", and "title" fields. The latter three are not returned
by CSSAgent.getStyleSheet() anymore.

Test: inspector/styles/get-set-stylesheet-text.html

WebCore:

  • inspector/Inspector.json:
  • inspector/InspectorCSSAgent.cpp: (WebCore::InspectorCSSAgent::getAllStyleSheets):
  • inspector/InspectorCSSAgent.h:
  • inspector/InspectorStyleSheet.cpp: (WebCore::InspectorStyleSheet::buildObjectForStyleSheet): (WebCore::InspectorStyleSheet::buildObjectForStyleSheetInfo):
  • inspector/InspectorStyleSheet.h:
  • inspector/front-end/AuditRules.js: (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.styleSheetCallback): (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.allStylesCallback): (WebInspector.AuditRules.UnusedCssRule.prototype.doRun):
  • inspector/front-end/CSSStyleModel.js: (WebInspector.CSSStyleModel.prototype._styleSheetChanged.callback): (WebInspector.CSSStyleModel.prototype._styleSheetChanged): (WebInspector.CSSStyleModel.prototype._onRevert): (WebInspector.CSSStyleSheet): (WebInspector.CSSStyleSheet.prototype.setText):

LayoutTests:

  • inspector/styles/get-set-stylesheet-text-expected.txt: Added.
  • inspector/styles/get-set-stylesheet-text.html: Added.
  • inspector/styles/resources/get-set-stylesheet-text.css: Added. (body): (/* comment before selector */body.main1/* comment after selector */): (body.main2):
  • inspector/styles/styles-add-blank-property.html: Tentatively fix flakiness by waiting for pending dispatches to finish
  • inspector/styles/styles-new-API.html:
Location:
trunk
Files:
3 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r82250 r82252  
     12011-03-29  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: Fix handling of the CSSAgent.setStyleSheetText() results in CSSStyleModel.js
     6        https://bugs.webkit.org/show_bug.cgi?id=56310
     7
     8        * inspector/styles/get-set-stylesheet-text-expected.txt: Added.
     9        * inspector/styles/get-set-stylesheet-text.html: Added.
     10        * inspector/styles/resources/get-set-stylesheet-text.css: Added.
     11        (body):
     12        (/* comment before selector */body.main1/* comment after selector */):
     13        (body.main2):
     14        * inspector/styles/styles-add-blank-property.html: Tentatively fix flakiness by waiting for pending dispatches to finish
     15        * inspector/styles/styles-new-API.html:
     16
    1172011-03-29  Jeremy Moskovich  <jeremy@chromium.org>
    218
  • trunk/LayoutTests/inspector/styles/styles-add-blank-property.html

    r80416 r82252  
    88{
    99    WebInspector.showPanel("elements");
    10     InspectorTest.selectNodeWithId("inspected", step1);
     10    InspectorTest.selectNodeWithId("inspected", step0);
    1111
    1212    var treeElement;
     13    var section;
     14
     15    function step0()
     16    {
     17        InspectorTest.addResult("Before append:");
     18        InspectorTest.dumpSelectedElementStyles(true);
     19        section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][1];
     20        section.expand();
     21        InspectorTest.runAfterPendingDispatches(step1);
     22    }
    1323
    1424    function step1()
    1525    {
    16         InspectorTest.addResult("Before append:");
    17         InspectorTest.dumpSelectedElementStyles(true);
    18 
    19         var section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][1];
    20         section.expand();
    21 
    2226        // Create and increment.
    2327        treeElement = section.addNewBlankProperty();
  • trunk/LayoutTests/inspector/styles/styles-new-API.html

    r81957 r82252  
    103103        }
    104104
    105         function styleSheetIdsLoaded(error, ids)
     105        function styleSheetInfosLoaded(error, infos)
    106106        {
    107107            if (error) {
     
    111111            InspectorTest.addResult("");
    112112            InspectorTest.addResult("=== All stylesheets ===");
    113             for (var i = 0; i < ids.length; ++i)
    114                 loadAndDumpStyleSheet(ids[i], (i < ids.length - 1) ? null : patchStyleSheet);
    115         }
    116         CSSAgent.getAllStyles(styleSheetIdsLoaded);
     113            for (var i = 0; i < infos.length; ++i)
     114                loadAndDumpStyleSheet(infos[i].styleSheetId, (i < infos.length - 1) ? null : patchStyleSheet);
     115        }
     116        CSSAgent.getAllStyleSheets(styleSheetInfosLoaded);
    117117    }
    118118
     
    297297    {
    298298        if (error) {
    299             InspectorTest.addRecord("error: " + error);
     299            InspectorTest.addError("error: " + error);
    300300            return;
    301301        }
     302
    302303        function styleSheetLoaded(error, styleSheet)
    303304        {
    304305            if (error) {
    305                 InspectorTest.addRecord("error: " + error);
     306                InspectorTest.addError("error: " + error);
    306307                return;
    307308            }
     
    321322Covered API methods:
    322323 - getStylesForNode
    323  - getAllStyles
     324 - getAllStyleSheets
    324325 - getStyleSheet
    325326 - setStyleSheetText
  • trunk/Source/WebCore/ChangeLog

    r82250 r82252  
     12011-03-29  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: Fix handling of the CSSAgent.setStyleSheetText() results in CSSStyleModel.js
     6        https://bugs.webkit.org/show_bug.cgi?id=56310
     7
     8        Instead of stylesheet ids, CSSAgent.getAllStyleSheets() now returns metainfo objects containing
     9        "styleSheetId", "sourceURL", "disabled", and "title" fields. The latter three are not returned
     10        by CSSAgent.getStyleSheet() anymore.
     11
     12        Test: inspector/styles/get-set-stylesheet-text.html
     13
     14        * inspector/Inspector.json:
     15        * inspector/InspectorCSSAgent.cpp:
     16        (WebCore::InspectorCSSAgent::getAllStyleSheets):
     17        * inspector/InspectorCSSAgent.h:
     18        * inspector/InspectorStyleSheet.cpp:
     19        (WebCore::InspectorStyleSheet::buildObjectForStyleSheet):
     20        (WebCore::InspectorStyleSheet::buildObjectForStyleSheetInfo):
     21        * inspector/InspectorStyleSheet.h:
     22        * inspector/front-end/AuditRules.js:
     23        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.styleSheetCallback):
     24        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun.allStylesCallback):
     25        (WebInspector.AuditRules.UnusedCssRule.prototype.doRun):
     26        * inspector/front-end/CSSStyleModel.js:
     27        (WebInspector.CSSStyleModel.prototype._styleSheetChanged.callback):
     28        (WebInspector.CSSStyleModel.prototype._styleSheetChanged):
     29        (WebInspector.CSSStyleModel.prototype._onRevert):
     30        (WebInspector.CSSStyleSheet):
     31        (WebInspector.CSSStyleSheet.prototype.setText):
     32
    1332011-03-29  Jeremy Moskovich  <jeremy@chromium.org>
    234
  • trunk/Source/WebCore/inspector/Inspector.json

    r82239 r82252  
    938938            },
    939939            {
    940                 "name": "getAllStyles",
    941                 "returns": [
    942                     { "name": "styleSheetIds", "type": "array", "items": { "type": "string" } }
     940                "name": "getAllStyleSheets",
     941                "returns": [
     942                    { "name": "styleSheetInfos", "type": "array", "items": { "$ref": "CSSStyleSheetInfo" } }
    943943                ]
    944944            },
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp

    r81957 r82252  
    105105// }
    106106//
     107// cssStyleSheetInfo = {
     108//    styleSheetId : <number>
     109//    sourceURL    : <string>
     110//    title        : <string>
     111//    disabled     : <boolean>
     112// }
     113//
    107114// cssStyleSheet = {
    108 //    styleSheetId   : <number>
    109 //    sourceURL      : <string>
    110 //    title          : <string>
    111 //    disabled       : <boolean>
    112 //    rules          : [
    113 //                         #cssRule,
    114 //                         ...
    115 //                         #cssRule
    116 //                     ]
    117 //    text           : <string> // Optional - whenever the text is available for a text-based stylesheet
     115//    styleSheetId : <number>
     116//    rules        : [
     117//                       #cssRule,
     118//                       ...
     119//                       #cssRule
     120//                   ]
     121//    text         : <string> // Optional - whenever the text is available for a text-based stylesheet
    118122// }
    119123
     
    251255}
    252256
    253 void InspectorCSSAgent::getAllStyles(ErrorString*, RefPtr<InspectorArray>* styles)
     257void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<InspectorArray>* styleInfos)
    254258{
    255259    Vector<Document*> documents = m_domAgent->documents();
     
    260264            if (styleSheet->isCSSStyleSheet()) {
    261265                InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSStyleSheet*>(styleSheet));
    262                 (*styles)->pushString(inspectorStyleSheet->id());
     266                (*styleInfos)->pushObject(inspectorStyleSheet->buildObjectForStyleSheetInfo());
    263267            }
    264268        }
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.h

    r81957 r82252  
    6565    void getInlineStyleForNode(ErrorString*, int nodeId, RefPtr<InspectorObject>* style);
    6666    void getComputedStyleForNode(ErrorString*, int nodeId, RefPtr<InspectorObject>* style);
    67     void getAllStyles(ErrorString*, RefPtr<InspectorArray>* styles);
     67    void getAllStyleSheets(ErrorString*, RefPtr<InspectorArray>* styleSheetInfos);
    6868    void getStyleSheet(ErrorString*, const String& styleSheetId, RefPtr<InspectorObject>* result);
    6969    void getStyleSheetText(ErrorString*, const String& styleSheetId, String* url, String* result);
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r82106 r82252  
    709709
    710710    RefPtr<InspectorObject> result = InspectorObject::create();
    711     result->setBoolean("disabled", styleSheet->disabled());
    712     result->setString("sourceURL", finalURL());
    713     result->setString("title", styleSheet->title());
     711    result->setString("styleSheetId", id());
    714712    RefPtr<CSSRuleList> cssRuleList = CSSRuleList::create(styleSheet, true);
    715713    RefPtr<InspectorArray> cssRules = buildArrayForRuleList(cssRuleList.get());
     
    721719        result->setString("text", styleSheetText);
    722720
     721    return result.release();
     722}
     723
     724PassRefPtr<InspectorObject> InspectorStyleSheet::buildObjectForStyleSheetInfo()
     725{
     726    CSSStyleSheet* styleSheet = pageStyleSheet();
     727    if (!styleSheet)
     728        return 0;
     729
     730    RefPtr<InspectorObject> result = InspectorObject::create();
    723731    result->setString("styleSheetId", id());
    724 
     732    result->setBoolean("disabled", styleSheet->disabled());
     733    result->setString("sourceURL", finalURL());
     734    result->setString("title", styleSheet->title());
    725735    return result.release();
    726736}
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.h

    r81957 r82252  
    169169    CSSStyleRule* ruleForId(const InspectorCSSId&) const;
    170170    PassRefPtr<InspectorObject> buildObjectForStyleSheet();
     171    PassRefPtr<InspectorObject> buildObjectForStyleSheetInfo();
    171172    PassRefPtr<InspectorObject> buildObjectForRule(CSSStyleRule*);
    172173    PassRefPtr<InspectorObject> buildObjectForStyle(CSSStyleDeclaration*);
  • trunk/Source/WebCore/inspector/front-end/AuditRules.js

    r81957 r82252  
    378378        }
    379379
    380         function styleSheetCallback(styleSheets, continuation, styleSheet)
    381         {
    382             if (styleSheet)
     380        function styleSheetCallback(styleSheets, sourceURL, continuation, styleSheet)
     381        {
     382            if (styleSheet) {
     383                styleSheet.sourceURL = sourceURL;
    383384                styleSheets.push(styleSheet);
     385            }
    384386            if (continuation)
    385387                continuation(styleSheets);
    386388        }
    387389
    388         function allStylesCallback(error, styleSheetIds)
    389         {
    390             if (error || !styleSheetIds || !styleSheetIds.length)
     390        function allStylesCallback(error, styleSheetInfos)
     391        {
     392            if (error || !styleSheetInfos || !styleSheetInfos.length)
    391393                return evalCallback([]);
    392394            var styleSheets = [];
    393             for (var i = 0; i < styleSheetIds.length; ++i)
    394                 WebInspector.CSSStyleSheet.createForId(styleSheetIds[i], styleSheetCallback.bind(null, styleSheets, i == styleSheetIds.length - 1 ? evalCallback : null));
    395         }
    396 
    397         CSSAgent.getAllStyles(allStylesCallback);
     395            for (var i = 0; i < styleSheetInfos.length; ++i) {
     396                var info = styleSheetInfos[i];
     397                WebInspector.CSSStyleSheet.createForId(info.styleSheetId, styleSheetCallback.bind(null, styleSheets, info.sourceURL, i == styleSheetInfos.length - 1 ? evalCallback : null));
     398            }
     399        }
     400
     401        CSSAgent.getAllStyleSheets(allStylesCallback);
    398402    }
    399403}
  • trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js

    r81957 r82252  
    169169                return;
    170170            var resource = WebInspector.resourceForURL(href);
    171             if (resource && resource.type === WebInspector.Resource.Type.Stylesheet)
     171            if (resource && resource.type === WebInspector.Resource.Type.Stylesheet) {
    172172                resource.setContent(content, this._onRevert.bind(this, styleSheetId));
     173                this.dispatchEventToListeners("stylesheet changed");
     174            }
    173175        }
    174176        CSSAgent.getStyleSheetText(styleSheetId, callback.bind(this));
     
    182184                return;
    183185            this._styleSheetChanged(styleSheetId, true);
    184             this.dispatchEventToListeners("stylesheet changed");
    185186        }
    186187        CSSAgent.setStyleSheetText(styleSheetId, contentToRevertTo, callback.bind(this));
     
    538539{
    539540    this.id = payload.styleSheetId;
    540     this.sourceURL = payload.sourceURL;
    541     this.title = payload.title;
    542     this.disabled = payload.disabled;
    543541    this.rules = [];
    544542    this.styles = {};
     
    573571    setText: function(newText, userCallback)
    574572    {
    575         function callback(error, styleSheetPayload)
    576         {
    577             if (error)
    578                 userCallback(null);
    579             else {
    580                 userCallback(new WebInspector.CSSStyleSheet(styleSheetPayload));
    581                 WebInspector.cssModel._styleSheetChanged(this.id, true);
    582             }
     573        function callback(error, isChangeSuccessful)
     574        {
     575             if (userCallback)
     576                 userCallback(isChangeSuccessful);
     577             if (isChangeSuccessful)
     578                 WebInspector.cssModel._styleSheetChanged(this.id, true);
    583579        }
    584580
Note: See TracChangeset for help on using the changeset viewer.