Changeset 217911 in webkit


Ignore:
Timestamp:
Jun 7, 2017 4:53:10 PM (7 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Allow user to choose stylesheet when creating new rules
https://bugs.webkit.org/show_bug.cgi?id=172487

Reviewed by Joseph Pecoraro.

Source/WebCore:

New test: inspector/css/add-rule.html

  • inspector/InspectorStyleSheet.cpp:

(WebCore::InspectorStyleSheet::addRule):
Reparse the content when a new rule is added to a non-inspector origin stylesheet.

Source/WebInspectorUI:

  • Localizations/en.lproj/localizedStrings.js:
  • UserInterface/Models/DOMNodeStyles.js:

(WebInspector.DOMNodeStyles.prototype.addRule.inspectorStyleSheetAvailable):
(WebInspector.DOMNodeStyles.prototype.addRule):

  • UserInterface/Views/CSSStyleDetailsSidebarPanel.js:

(WebInspector.CSSStyleDetailsSidebarPanel.prototype.initialLayout):
(WebInspector.CSSStyleDetailsSidebarPanel.prototype._newRuleButtonContextMenu):

  • UserInterface/Views/RulesStyleDetailsPanel.js:

(WebInspector.RulesStyleDetailsPanel.prototype.newRuleButtonClicked):
(WebInspector.RulesStyleDetailsPanel.prototype.newRuleButtonContextMenu):

  • UserInterface/Views/VisualStyleSelectorSection.js:

(WebInspector.VisualStyleSelectorSection):
(WebInspector.VisualStyleSelectorSection.prototype._addNewRuleContextMenu):
(WebInspector.VisualStyleSelectorSection.prototype._addNewRule): Renamed _addNewRuleClick.

LayoutTests:

  • inspector/css/add-rule-expected.html: Added.
  • inspector/css/add-rule.html: Added.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r217910 r217911  
     12017-06-07  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Allow user to choose stylesheet when creating new rules
     4        https://bugs.webkit.org/show_bug.cgi?id=172487
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * inspector/css/add-rule-expected.html: Added.
     9        * inspector/css/add-rule.html: Added.
     10
    1112017-06-07  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r217910 r217911  
     12017-06-07  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Allow user to choose stylesheet when creating new rules
     4        https://bugs.webkit.org/show_bug.cgi?id=172487
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        New test: inspector/css/add-rule.html
     9
     10        * inspector/InspectorStyleSheet.cpp:
     11        (WebCore::InspectorStyleSheet::addRule):
     12        Reparse the content when a new rule is added to a non-inspector origin stylesheet.
     13
    1142017-06-07  Youenn Fablet  <youenn@apple.com>
    215
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r216426 r217911  
    930930        return text.releaseException();
    931931
    932     StringBuilder styleSheetText;
    933     styleSheetText.append(text.releaseReturnValue());
    934 
    935932    auto addRuleResult = m_pageStyleSheet->addRule(selector, emptyString(), std::nullopt);
    936933    if (addRuleResult.hasException())
    937934        return addRuleResult.releaseException();
     935
     936    StringBuilder styleSheetText;
     937    styleSheetText.append(text.releaseReturnValue());
     938
     939    if (!styleSheetText.isEmpty())
     940        styleSheetText.append('\n');
     941
     942    styleSheetText.append(selector);
     943    styleSheetText.appendLiteral(" {}");
     944
     945    // Using setText() as this operation changes the stylesheet rule set.
     946    setText(styleSheetText.toString());
     947
     948    // Inspector Style Sheets are always treated as though their parsed data is ready.
     949    if (m_origin == Inspector::Protocol::CSS::StyleSheetOrigin::Inspector)
     950        fireStyleSheetChanged();
     951    else
     952        reparseStyleSheet(styleSheetText.toString());
     953
    938954    ASSERT(m_pageStyleSheet->length());
    939955    unsigned lastRuleIndex = m_pageStyleSheet->length() - 1;
     
    948964        return Exception { SYNTAX_ERR };
    949965    }
    950 
    951     if (!styleSheetText.isEmpty())
    952         styleSheetText.append('\n');
    953 
    954     styleSheetText.append(selector);
    955     styleSheetText.appendLiteral(" {}");
    956     // Using setText() as this operation changes the stylesheet rule set.
    957     setText(styleSheetText.toString());
    958 
    959     fireStyleSheetChanged();
    960966
    961967    return styleRule;
  • trunk/Source/WebInspectorUI/ChangeLog

    r217843 r217911  
     12017-06-07  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Allow user to choose stylesheet when creating new rules
     4        https://bugs.webkit.org/show_bug.cgi?id=172487
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * Localizations/en.lproj/localizedStrings.js:
     9        * UserInterface/Models/DOMNodeStyles.js:
     10        (WebInspector.DOMNodeStyles.prototype.addRule.inspectorStyleSheetAvailable):
     11        (WebInspector.DOMNodeStyles.prototype.addRule):
     12        * UserInterface/Views/CSSStyleDetailsSidebarPanel.js:
     13        (WebInspector.CSSStyleDetailsSidebarPanel.prototype.initialLayout):
     14        (WebInspector.CSSStyleDetailsSidebarPanel.prototype._newRuleButtonContextMenu):
     15        * UserInterface/Views/RulesStyleDetailsPanel.js:
     16        (WebInspector.RulesStyleDetailsPanel.prototype.newRuleButtonClicked):
     17        (WebInspector.RulesStyleDetailsPanel.prototype.newRuleButtonContextMenu):
     18        * UserInterface/Views/VisualStyleSelectorSection.js:
     19        (WebInspector.VisualStyleSelectorSection):
     20        (WebInspector.VisualStyleSelectorSection.prototype._addNewRuleContextMenu):
     21        (WebInspector.VisualStyleSelectorSection.prototype._addNewRule): Renamed _addNewRuleClick.
     22
    1232017-06-06  Joseph Pecoraro  <pecoraro@apple.com>
    224
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r217733 r217911  
    113113localizedStrings["Automatically continue after evaluating"] = "Automatically continue after evaluating";
    114114localizedStrings["Automatically insert newline"] = "Automatically insert newline";
     115localizedStrings["Available Style Sheets"] = "Available Style Sheets";
    115116localizedStrings["Average Time"] = "Average Time";
    116117localizedStrings["Back (%s)"] = "Back (%s)";
  • trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js

    r217258 r217911  
    264264    }
    265265
    266     addRule(selector, text)
     266    addRule(selector, text, styleSheetId)
    267267    {
    268268        selector = selector || this._node.appropriateSelectorFor(true);
     
    303303        function inspectorStyleSheetAvailable(styleSheet)
    304304        {
     305            if (!styleSheet)
     306                return;
     307
    305308            CSSAgent.addRule(styleSheet.id, selector, addedRule.bind(this));
    306309        }
    307310
    308         WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(this._node.frame, inspectorStyleSheetAvailable.bind(this));
     311        if (styleSheetId)
     312            inspectorStyleSheetAvailable.call(this, WebInspector.cssStyleManager.styleSheetForIdentifier(styleSheetId));
     313        else
     314            WebInspector.cssStyleManager.preferredInspectorStyleSheetForFrame(this._node.frame, inspectorStyleSheetAvailable.bind(this));
    309315    }
    310316
  • trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDetailsSidebarPanel.js

    r215192 r217911  
    171171        newRuleButton.title = WebInspector.UIString("Add new rule");
    172172        newRuleButton.addEventListener("click", this._newRuleButtonClicked.bind(this));
     173        newRuleButton.addEventListener("contextmenu", this._newRuleButtonContextMenu.bind(this));
    173174
    174175        this._filterBar = new WebInspector.FilterBar;
     
    321322        if (this._selectedPanel && typeof this._selectedPanel.newRuleButtonClicked === "function")
    322323            this._selectedPanel.newRuleButtonClicked();
     324    }
     325
     326    _newRuleButtonContextMenu(event)
     327    {
     328        if (this._selectedPanel && typeof this._selectedPanel.newRuleButtonContextMenu === "function")
     329            this._selectedPanel.newRuleButtonContextMenu(event);
    323330    }
    324331
  • trunk/Source/WebInspectorUI/UserInterface/Views/RulesStyleDetailsPanel.js

    r217266 r217911  
    398398    }
    399399
     400    newRuleButtonContextMenu(event)
     401    {
     402        if (this.nodeStyles.node.isInUserAgentShadowTree())
     403            return;
     404
     405        let styleSheets = WebInspector.cssStyleManager.styleSheets.filter(styleSheet => styleSheet.hasInfo() && !styleSheet.isInlineStyleTag() && !styleSheet.isInlineStyleAttributeStyleSheet());
     406        if (!styleSheets.length)
     407            return;
     408
     409        const justSelector = true;
     410        let selector = this.nodeStyles.node.appropriateSelectorFor(justSelector);
     411
     412        let contextMenu = WebInspector.ContextMenu.createFromEvent(event);
     413
     414        const handler = null;
     415        const disabled = true;
     416        contextMenu.appendItem(WebInspector.UIString("Available Style Sheets"), handler, disabled);
     417
     418        for (let styleSheet of styleSheets) {
     419            contextMenu.appendItem(styleSheet.displayName, () => {
     420                const text = "";
     421                this.nodeStyles.addRule(selector, text, styleSheet.id);
     422            });
     423        }
     424    }
     425
    400426    sectionForStyle(style)
    401427    {
  • trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleSelectorSection.js

    r211462 r217911  
    6161
    6262        let addGlyphElement = useSVGSymbol("Images/Plus13.svg", "visual-style-selector-section-add-rule", WebInspector.UIString("Add new rule"));
    63         addGlyphElement.addEventListener("click", this._addNewRule.bind(this));
     63        addGlyphElement.addEventListener("click", this._addNewRuleClick.bind(this));
     64        addGlyphElement.addEventListener("contextmenu", this._addNewRuleContextMenu.bind(this));
    6465        controlElement.appendChild(addGlyphElement);
    6566
     
    257258    }
    258259
    259     _addNewRule(event)
     260    _addNewRuleClick(event)
    260261    {
    261262        if (!this._nodeStyles || this._nodeStyles.node.isInUserAgentShadowTree())
     
    271272        this._newInspectorRuleSelector = selector;
    272273        this._nodeStyles.addRule(selector);
     274    }
     275
     276    _addNewRuleContextMenu(event)
     277    {
     278        if (!this._nodeStyles || this._nodeStyles.node.isInUserAgentShadowTree())
     279            return;
     280
     281        let styleSheets = WebInspector.cssStyleManager.styleSheets.filter(styleSheet => styleSheet.hasInfo() && !styleSheet.isInlineStyleTag() && !styleSheet.isInlineStyleAttributeStyleSheet());
     282        if (!styleSheets.length)
     283            return;
     284
     285        let contextMenu = WebInspector.ContextMenu.createFromEvent(event);
     286
     287        const handler = null;
     288        const disabled = true;
     289        contextMenu.appendItem(WebInspector.UIString("Available Style Sheets"), handler, disabled);
     290
     291        for (let styleSheet of styleSheets) {
     292            contextMenu.appendItem(styleSheet.displayName, () => {
     293                const text = "";
     294                this._nodeStyles.addRule(this.currentStyle().selectorText, text, styleSheet.id);
     295            });
     296        }
    273297    }
    274298
Note: See TracChangeset for help on using the changeset viewer.