Changeset 107561 in webkit


Ignore:
Timestamp:
Feb 13, 2012 5:12:15 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: wrap settings selector text and adding a rule with undoable actions.
https://bugs.webkit.org/show_bug.cgi?id=78482

Reviewed by Yury Semikhatsky.

Source/WebCore:

Tests: inspector/styles/undo-add-new-rule.html

inspector/styles/undo-set-selector-text.html

  • inspector/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::StyleSheetAction::StyleSheetAction):
(InspectorCSSAgent::StyleSheetAction):
(WebCore::InspectorCSSAgent::SetStyleSheetTextAction::SetStyleSheetTextAction):
(WebCore::InspectorCSSAgent::SetStyleSheetTextAction::perform):
(WebCore::InspectorCSSAgent::SetStyleSheetTextAction::undo):
(WebCore::InspectorCSSAgent::SetPropertyTextAction::SetPropertyTextAction):
(WebCore::InspectorCSSAgent::SetPropertyTextAction::perform):
(WebCore::InspectorCSSAgent::SetPropertyTextAction::undo):
(WebCore::InspectorCSSAgent::SetPropertyTextAction::mergeId):
(WebCore::InspectorCSSAgent::TogglePropertyAction::TogglePropertyAction):
(WebCore::InspectorCSSAgent::TogglePropertyAction::perform):
(WebCore::InspectorCSSAgent::TogglePropertyAction::undo):
(InspectorCSSAgent::SetRuleSelectorAction):
(WebCore::InspectorCSSAgent::SetRuleSelectorAction::SetRuleSelectorAction):
(WebCore::InspectorCSSAgent::SetRuleSelectorAction::perform):
(WebCore::InspectorCSSAgent::SetRuleSelectorAction::undo):
(WebCore):
(InspectorCSSAgent::AddRuleAction):
(WebCore::InspectorCSSAgent::AddRuleAction::AddRuleAction):
(WebCore::InspectorCSSAgent::AddRuleAction::perform):
(WebCore::InspectorCSSAgent::AddRuleAction::undo):
(WebCore::InspectorCSSAgent::AddRuleAction::newRuleId):
(WebCore::InspectorCSSAgent::setStyleSheetText):
(WebCore::InspectorCSSAgent::setPropertyText):
(WebCore::InspectorCSSAgent::toggleProperty):
(WebCore::InspectorCSSAgent::setRuleSelector):
(WebCore::InspectorCSSAgent::addRule):
(WebCore::InspectorCSSAgent::asInspectorStyleSheet):
(WebCore::InspectorCSSAgent::bindStyleSheet):
(WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
(WebCore::InspectorCSSAgent::styleSheetChanged):

  • inspector/InspectorCSSAgent.h:

(InspectorCSSAgent):

  • inspector/InspectorStyleSheet.cpp:

(WebCore::InspectorStyleSheet::create):
(WebCore::InspectorStyleSheet::InspectorStyleSheet):
(WebCore::InspectorStyleSheet::reparseStyleSheet):
(WebCore::InspectorStyleSheet::ruleSelector):
(WebCore):
(WebCore::InspectorStyleSheet::setRuleSelector):
(WebCore::InspectorStyleSheet::addRule):
(WebCore::InspectorStyleSheet::deleteRule):
(WebCore::InspectorStyleSheet::setPropertyText):
(WebCore::InspectorStyleSheet::toggleProperty):
(WebCore::InspectorStyleSheet::fireStyleSheetChanged):
(WebCore::InspectorStyleSheetForInlineStyle::create):
(WebCore::InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle):

  • inspector/InspectorStyleSheet.h:

(InspectorStyleSheet):
(WebCore::InspectorStyleSheet::styleId):
(InspectorStyleSheetForInlineStyle):

LayoutTests:

  • inspector/styles/undo-add-new-rule-expected.txt: Added.
  • inspector/styles/undo-add-new-rule.html: Added.
  • inspector/styles/undo-set-selector-text-expected.txt: Added.
  • inspector/styles/undo-set-selector-text.html: Added.
Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r107560 r107561  
     12012-02-13  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: wrap settings selector text and adding a rule with undoable actions.
     4        https://bugs.webkit.org/show_bug.cgi?id=78482
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/styles/undo-add-new-rule-expected.txt: Added.
     9        * inspector/styles/undo-add-new-rule.html: Added.
     10        * inspector/styles/undo-set-selector-text-expected.txt: Added.
     11        * inspector/styles/undo-set-selector-text.html: Added.
     12
    1132012-02-13  Csaba Osztrogonác  <ossy@webkit.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r107558 r107561  
     12012-02-13  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: wrap settings selector text and adding a rule with undoable actions.
     4        https://bugs.webkit.org/show_bug.cgi?id=78482
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        Tests: inspector/styles/undo-add-new-rule.html
     9               inspector/styles/undo-set-selector-text.html
     10
     11        * inspector/InspectorCSSAgent.cpp:
     12        (WebCore::InspectorCSSAgent::StyleSheetAction::StyleSheetAction):
     13        (InspectorCSSAgent::StyleSheetAction):
     14        (WebCore::InspectorCSSAgent::SetStyleSheetTextAction::SetStyleSheetTextAction):
     15        (WebCore::InspectorCSSAgent::SetStyleSheetTextAction::perform):
     16        (WebCore::InspectorCSSAgent::SetStyleSheetTextAction::undo):
     17        (WebCore::InspectorCSSAgent::SetPropertyTextAction::SetPropertyTextAction):
     18        (WebCore::InspectorCSSAgent::SetPropertyTextAction::perform):
     19        (WebCore::InspectorCSSAgent::SetPropertyTextAction::undo):
     20        (WebCore::InspectorCSSAgent::SetPropertyTextAction::mergeId):
     21        (WebCore::InspectorCSSAgent::TogglePropertyAction::TogglePropertyAction):
     22        (WebCore::InspectorCSSAgent::TogglePropertyAction::perform):
     23        (WebCore::InspectorCSSAgent::TogglePropertyAction::undo):
     24        (InspectorCSSAgent::SetRuleSelectorAction):
     25        (WebCore::InspectorCSSAgent::SetRuleSelectorAction::SetRuleSelectorAction):
     26        (WebCore::InspectorCSSAgent::SetRuleSelectorAction::perform):
     27        (WebCore::InspectorCSSAgent::SetRuleSelectorAction::undo):
     28        (WebCore):
     29        (InspectorCSSAgent::AddRuleAction):
     30        (WebCore::InspectorCSSAgent::AddRuleAction::AddRuleAction):
     31        (WebCore::InspectorCSSAgent::AddRuleAction::perform):
     32        (WebCore::InspectorCSSAgent::AddRuleAction::undo):
     33        (WebCore::InspectorCSSAgent::AddRuleAction::newRuleId):
     34        (WebCore::InspectorCSSAgent::setStyleSheetText):
     35        (WebCore::InspectorCSSAgent::setPropertyText):
     36        (WebCore::InspectorCSSAgent::toggleProperty):
     37        (WebCore::InspectorCSSAgent::setRuleSelector):
     38        (WebCore::InspectorCSSAgent::addRule):
     39        (WebCore::InspectorCSSAgent::asInspectorStyleSheet):
     40        (WebCore::InspectorCSSAgent::bindStyleSheet):
     41        (WebCore::InspectorCSSAgent::viaInspectorStyleSheet):
     42        (WebCore::InspectorCSSAgent::styleSheetChanged):
     43        * inspector/InspectorCSSAgent.h:
     44        (InspectorCSSAgent):
     45        * inspector/InspectorStyleSheet.cpp:
     46        (WebCore::InspectorStyleSheet::create):
     47        (WebCore::InspectorStyleSheet::InspectorStyleSheet):
     48        (WebCore::InspectorStyleSheet::reparseStyleSheet):
     49        (WebCore::InspectorStyleSheet::ruleSelector):
     50        (WebCore):
     51        (WebCore::InspectorStyleSheet::setRuleSelector):
     52        (WebCore::InspectorStyleSheet::addRule):
     53        (WebCore::InspectorStyleSheet::deleteRule):
     54        (WebCore::InspectorStyleSheet::setPropertyText):
     55        (WebCore::InspectorStyleSheet::toggleProperty):
     56        (WebCore::InspectorStyleSheet::fireStyleSheetChanged):
     57        (WebCore::InspectorStyleSheetForInlineStyle::create):
     58        (WebCore::InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle):
     59        * inspector/InspectorStyleSheet.h:
     60        (InspectorStyleSheet):
     61        (WebCore::InspectorStyleSheet::styleId):
     62        (InspectorStyleSheetForInlineStyle):
     63
    1642012-02-13  Hayato Ito  <hayato@chromium.org>
    265
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp

    r107407 r107561  
    222222    WTF_MAKE_NONCOPYABLE(StyleSheetAction);
    223223public:
    224     StyleSheetAction(const String& name, InspectorCSSAgent* cssAgent, const String& styleSheetId)
     224    StyleSheetAction(const String& name, InspectorStyleSheet* styleSheet)
    225225        : InspectorHistory::Action(name)
    226         , m_cssAgent(cssAgent)
    227         , m_styleSheetId(styleSheetId)
    228     {
    229     }
    230 
    231     virtual bool perform(ExceptionCode& ec)
    232     {
    233         ErrorString errorString;
    234         InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId(&errorString, m_styleSheetId);
    235         if (!styleSheet)
    236             return false;
    237         return perform(styleSheet, ec);
    238     }
    239 
    240     virtual bool undo(ExceptionCode& ec)
    241     {
    242         InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId(0, m_styleSheetId);
    243         if (!styleSheet)
    244             return false;
    245         return undo(styleSheet, ec);
    246     }
    247 
    248     virtual bool perform(InspectorStyleSheet*, ExceptionCode&) = 0;
    249 
    250     virtual bool undo(InspectorStyleSheet*, ExceptionCode&) = 0;
     226        , m_styleSheet(styleSheet)
     227    {
     228    }
    251229
    252230protected:
    253     InspectorCSSAgent* m_cssAgent;
    254     String m_styleSheetId;
     231    RefPtr<InspectorStyleSheet> m_styleSheet;
    255232};
    256233
     
    258235    WTF_MAKE_NONCOPYABLE(SetStyleSheetTextAction);
    259236public:
    260     SetStyleSheetTextAction(InspectorCSSAgent* cssAgent, const String& styleSheetId, const String& text)
    261         : InspectorCSSAgent::StyleSheetAction("SetStyleSheetText", cssAgent, styleSheetId)
     237    SetStyleSheetTextAction(InspectorStyleSheet* styleSheet, const String& text)
     238        : InspectorCSSAgent::StyleSheetAction("SetStyleSheetText", styleSheet)
    262239        , m_text(text)
    263240    {
    264241    }
    265242
    266     virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&)
    267     {
    268         if (!inspectorStyleSheet->getText(&m_oldText))
     243    virtual bool perform(ExceptionCode&)
     244    {
     245        if (!m_styleSheet->getText(&m_oldText))
    269246            return false;
    270247
    271         if (inspectorStyleSheet->setText(m_text)) {
    272             inspectorStyleSheet->reparseStyleSheet(m_text);
     248        if (m_styleSheet->setText(m_text)) {
     249            m_styleSheet->reparseStyleSheet(m_text);
    273250            return true;
    274251        }
     
    276253    }
    277254
    278     virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&)
    279     {
    280         if (inspectorStyleSheet->setText(m_oldText)) {
    281             inspectorStyleSheet->reparseStyleSheet(m_oldText);
     255    virtual bool undo(ExceptionCode&)
     256    {
     257        if (m_styleSheet->setText(m_oldText)) {
     258            m_styleSheet->reparseStyleSheet(m_oldText);
    282259            return true;
    283260        }
     
    293270    WTF_MAKE_NONCOPYABLE(SetPropertyTextAction);
    294271public:
    295     SetPropertyTextAction(InspectorCSSAgent* cssAgent, const String& styleSheetId, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite)
    296         : InspectorCSSAgent::StyleSheetAction("SetPropertyText", cssAgent, styleSheetId)
     272    SetPropertyTextAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite)
     273        : InspectorCSSAgent::StyleSheetAction("SetPropertyText", styleSheet)
    297274        , m_cssId(cssId)
    298275        , m_propertyIndex(propertyIndex)
     
    307284    }
    308285
    309     virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
     286    virtual bool perform(ExceptionCode& ec)
    310287    {
    311288        String oldText;
    312         bool result = inspectorStyleSheet->setPropertyText(m_cssId, m_propertyIndex, m_text, m_overwrite, &oldText, ec);
     289        bool result = m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_text, m_overwrite, &oldText, ec);
    313290        m_oldText = oldText.stripWhiteSpace();
    314291        // FIXME: remove this once the model handles this case.
     
    318295    }
    319296
    320     virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
     297    virtual bool undo(ExceptionCode& ec)
    321298    {
    322299        String placeholder;
    323         return inspectorStyleSheet->setPropertyText(m_cssId, m_propertyIndex, m_overwrite ? m_oldText : "", true, &placeholder, ec);
     300        return m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_overwrite ? m_oldText : "", true, &placeholder, ec);
    324301    }
    325302
    326303    virtual String mergeId()
    327304    {
    328         return String::format("SetPropertyText %s:%u:%s", m_styleSheetId.utf8().data(), m_propertyIndex, m_overwrite ? "true" : "false");
     305        return String::format("SetPropertyText %s:%u:%s", m_styleSheet->id().utf8().data(), m_propertyIndex, m_overwrite ? "true" : "false");
    329306    }
    330307
     
    348325    WTF_MAKE_NONCOPYABLE(TogglePropertyAction);
    349326public:
    350     TogglePropertyAction(InspectorCSSAgent* cssAgent, const String& styleSheetId, const InspectorCSSId& cssId, unsigned propertyIndex, bool disable)
    351         : InspectorCSSAgent::StyleSheetAction("ToggleProperty", cssAgent, styleSheetId)
     327    TogglePropertyAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, bool disable)
     328        : InspectorCSSAgent::StyleSheetAction("ToggleProperty", styleSheet)
    352329        , m_cssId(cssId)
    353330        , m_propertyIndex(propertyIndex)
     
    356333    }
    357334
    358     virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
    359     {
    360         return inspectorStyleSheet->toggleProperty(m_cssId, m_propertyIndex, m_disable, ec);
    361     }
    362 
    363     virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
    364     {
    365         return inspectorStyleSheet->toggleProperty(m_cssId, m_propertyIndex, !m_disable, ec);
     335    virtual bool perform(ExceptionCode& ec)
     336    {
     337        return m_styleSheet->toggleProperty(m_cssId, m_propertyIndex, m_disable, ec);
     338    }
     339
     340    virtual bool undo(ExceptionCode& ec)
     341    {
     342        return m_styleSheet->toggleProperty(m_cssId, m_propertyIndex, !m_disable, ec);
    366343    }
    367344
     
    370347    unsigned m_propertyIndex;
    371348    bool m_disable;
     349};
     350
     351class InspectorCSSAgent::SetRuleSelectorAction : public InspectorCSSAgent::StyleSheetAction {
     352    WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction);
     353public:
     354    SetRuleSelectorAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& selector)
     355        : InspectorCSSAgent::StyleSheetAction("SetRuleSelector", styleSheet)
     356        , m_cssId(cssId)
     357        , m_selector(selector)
     358    {
     359    }
     360
     361    virtual bool perform(ExceptionCode& ec)
     362    {
     363        m_oldSelector = m_styleSheet->ruleSelector(m_cssId, ec);
     364        if (ec)
     365            return false;
     366        return m_styleSheet->setRuleSelector(m_cssId, m_selector, ec);
     367    }
     368
     369    virtual bool undo(ExceptionCode& ec)
     370    {
     371        return m_styleSheet->setRuleSelector(m_cssId, m_oldSelector, ec);
     372    }
     373
     374private:
     375    InspectorCSSId m_cssId;
     376    String m_selector;
     377    String m_oldSelector;
     378};
     379
     380class InspectorCSSAgent::AddRuleAction : public InspectorCSSAgent::StyleSheetAction {
     381    WTF_MAKE_NONCOPYABLE(AddRuleAction);
     382public:
     383    AddRuleAction(InspectorStyleSheet* styleSheet, const String& selector)
     384        : InspectorCSSAgent::StyleSheetAction("AddRule", styleSheet)
     385        , m_selector(selector)
     386    {
     387    }
     388
     389    virtual bool perform(ExceptionCode& ec)
     390    {
     391        CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_selector, ec);
     392        if (ec)
     393            return false;
     394        m_newId = m_styleSheet->ruleId(cssStyleRule);
     395        return true;
     396    }
     397
     398    virtual bool undo(ExceptionCode& ec)
     399    {
     400        return m_styleSheet->deleteRule(m_newId, ec);
     401    }
     402
     403    InspectorCSSId newRuleId() { return m_newId; }
     404
     405private:
     406    InspectorCSSId m_newId;
     407    String m_selector;
     408    String m_oldSelector;
    372409};
    373410
     
    599636void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text)
    600637{
     638    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
     639    if (!inspectorStyleSheet)
     640        return;
     641
    601642    ExceptionCode ec = 0;
    602     m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(this, styleSheetId, text)), ec);
     643    m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspectorStyleSheet, text)), ec);
    603644    *errorString = InspectorDOMAgent::toErrorString(ec);
    604645    m_domAgent->history()->markUndoableState();
     
    615656
    616657    ExceptionCode ec = 0;
    617     bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, text, overwrite)), ec);
     658    bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAction(inspectorStyleSheet, compoundId, propertyIndex, text, overwrite)), ec);
    618659    if (success)
    619660        result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
     
    631672
    632673    ExceptionCode ec = 0;
    633     bool success = m_domAgent->history()->perform(adoptPtr(new TogglePropertyAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, disable)), ec);
     674    bool success = m_domAgent->history()->perform(adoptPtr(new TogglePropertyAction(inspectorStyleSheet, compoundId, propertyIndex, disable)), ec);
    634675    if (success)
    635676        result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
     
    647688        return;
    648689
    649     bool success = inspectorStyleSheet->setRuleSelector(compoundId, selector);
    650     if (!success)
    651         return;
    652 
    653     result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ruleForId(compoundId));
    654 }
    655 
    656 void InspectorCSSAgent::addRule(ErrorString*, const int contextNodeId, const String& selector, RefPtr<InspectorObject>& result)
    657 {
    658     Node* node = m_domAgent->nodeForId(contextNodeId);
     690    ExceptionCode ec = 0;
     691    bool success = m_domAgent->history()->perform(adoptPtr(new SetRuleSelectorAction(inspectorStyleSheet, compoundId, selector)), ec);
     692    if (success)
     693        result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
     694    *errorString = InspectorDOMAgent::toErrorString(ec);
     695
     696    if (success)
     697        result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ruleForId(compoundId));
     698    m_domAgent->history()->markUndoableState();
     699}
     700
     701void InspectorCSSAgent::addRule(ErrorString* errorString, const int contextNodeId, const String& selector, RefPtr<InspectorObject>& result)
     702{
     703    Node* node = m_domAgent->assertNode(errorString, contextNodeId);
    659704    if (!node)
    660705        return;
    661706
    662707    InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(node->document(), true);
    663     if (!inspectorStyleSheet)
    664         return;
    665     CSSStyleRule* newRule = inspectorStyleSheet->addRule(selector);
    666     if (!newRule)
    667         return;
    668 
    669     result = inspectorStyleSheet->buildObjectForRule(newRule);
     708    if (!inspectorStyleSheet) {
     709        *errorString = "No target stylesheet found";
     710        return;
     711    }
     712
     713    ExceptionCode ec = 0;
     714    OwnPtr<AddRuleAction> action = adoptPtr(new AddRuleAction(inspectorStyleSheet, selector));
     715    AddRuleAction* rawAction = action.get();
     716    bool success = m_domAgent->history()->perform(action.release(), ec);
     717    if (!success) {
     718        *errorString = InspectorDOMAgent::toErrorString(ec);
     719        return;
     720    }
     721
     722    InspectorCSSId ruleId = rawAction->newRuleId();
     723    CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId);
     724    result = inspectorStyleSheet->buildObjectForRule(rule);
     725    m_domAgent->history()->markUndoableState();
    670726}
    671727
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.h

    r107220 r107561  
    103103    class SetPropertyTextAction;
    104104    class TogglePropertyAction;
     105    class SetRuleSelectorAction;
     106    class AddRuleAction;
    105107
    106108    InspectorCSSAgent(InstrumentingAgents*, InspectorState*, InspectorDOMAgent*);
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r107399 r107561  
    708708}
    709709
    710 bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String& selector)
     710String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionCode& ec)
    711711{
    712712    CSSStyleRule* rule = ruleForId(id);
    713     if (!rule)
    714         return false;
     713    if (!rule) {
     714        ec = NOT_FOUND_ERR;
     715        return "";
     716    }
     717    return rule->selectorText();
     718}
     719
     720bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String& selector, ExceptionCode& ec)
     721{
     722    CSSStyleRule* rule = ruleForId(id);
     723    if (!rule) {
     724        ec = NOT_FOUND_ERR;
     725        return false;
     726    }
    715727    CSSStyleSheet* styleSheet = rule->parentStyleSheet();
    716     if (!styleSheet || !ensureParsedDataReady())
    717         return false;
     728    if (!styleSheet || !ensureParsedDataReady()) {
     729        ec = NOT_FOUND_ERR;
     730        return false;
     731    }
    718732
    719733    rule->setSelectorText(selector);
    720734    RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style());
    721     if (!sourceData)
    722         return false;
     735    if (!sourceData) {
     736        ec = NOT_FOUND_ERR;
     737        return false;
     738    }
    723739
    724740    String sheetText = m_parsedStyleSheet->text();
     
    728744}
    729745
    730 CSSStyleRule* InspectorStyleSheet::addRule(const String& selector)
     746CSSStyleRule* InspectorStyleSheet::addRule(const String& selector, ExceptionCode& ec)
    731747{
    732748    String styleSheetText;
    733749    bool success = getText(&styleSheetText);
    734     if (!success)
     750    if (!success) {
     751        ec = NOT_FOUND_ERR;
    735752        return 0;
    736 
    737     ExceptionCode ec = 0;
     753    }
     754
    738755    m_pageStyleSheet->addRule(selector, "", ec);
    739756    if (ec)
     
    753770
    754771    return rule;
     772}
     773
     774bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionCode& ec)
     775{
     776    CSSStyleRule* rule = ruleForId(id);
     777    if (!rule) {
     778        ec = NOT_FOUND_ERR;
     779        return false;
     780    }
     781    CSSStyleSheet* styleSheet = rule->parentStyleSheet();
     782    if (!styleSheet || !ensureParsedDataReady()) {
     783        ec = NOT_FOUND_ERR;
     784        return false;
     785    }
     786
     787    styleSheet->deleteRule(id.ordinal(), ec);
     788    if (ec)
     789        return false;
     790
     791    RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style());
     792    if (!sourceData) {
     793        ec = NOT_FOUND_ERR;
     794        return false;
     795    }
     796
     797    String sheetText = m_parsedStyleSheet->text();
     798    sheetText.remove(sourceData->selectorListRange.start, sourceData->styleSourceData->styleBodyRange.end - sourceData->selectorListRange.start + 1);
     799    m_parsedStyleSheet->setText(sheetText);
     800    return true;
    755801}
    756802
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.h

    r107399 r107561  
    169169    void reparseStyleSheet(const String&);
    170170    bool setText(const String&);
    171     bool setRuleSelector(const InspectorCSSId&, const String& selector);
    172     CSSStyleRule* addRule(const String& selector);
     171    String ruleSelector(const InspectorCSSId&, ExceptionCode&);
     172    bool setRuleSelector(const InspectorCSSId&, const String& selector, ExceptionCode&);
     173    CSSStyleRule* addRule(const String& selector, ExceptionCode&);
     174    bool deleteRule(const InspectorCSSId&, ExceptionCode&);
    173175    CSSStyleRule* ruleForId(const InspectorCSSId&) const;
    174176    PassRefPtr<InspectorObject> buildObjectForStyleSheet();
     
    181183    virtual bool getText(String* result) const;
    182184    virtual CSSStyleDeclaration* styleForId(const InspectorCSSId&) const;
     185
     186    InspectorCSSId ruleId(CSSStyleRule*) const;
     187    InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyleId(style); }
    183188
    184189protected:
     
    199204
    200205private:
     206    friend class InspectorStyle;
     207
    201208    static void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText);
    202209    static void collectFlatRules(PassRefPtr<CSSRuleList>, Vector<CSSStyleRule*>* result);
     
    205212    void ensureFlatRules() const;
    206213    bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newStyleText, String* result);
    207     InspectorCSSId ruleId(CSSStyleRule* rule) const;
    208     InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyleId(style); }
    209214    void revalidateStyle(CSSStyleDeclaration*);
    210215    bool originalStyleSheetText(String* result) const;
     
    221226    InspectorStyleMap m_inspectorStyles;
    222227    mutable Vector<CSSStyleRule*> m_flatRules;
    223 
    224     friend class InspectorStyle;
    225228};
    226229
    227230class InspectorStyleSheetForInlineStyle : public InspectorStyleSheet {
    228231public:
    229     static PassRefPtr<InspectorStyleSheetForInlineStyle> create(const String& id, PassRefPtr<Element> element, const String& origin);
     232    static PassRefPtr<InspectorStyleSheetForInlineStyle> create(const String& id, PassRefPtr<Element>, const String& origin);
    230233
    231234    void didModifyElementAttribute();
     
    234237
    235238protected:
    236     InspectorStyleSheetForInlineStyle(const String& id, PassRefPtr<Element> element, const String& origin);
     239    InspectorStyleSheetForInlineStyle(const String& id, PassRefPtr<Element>, const String& origin);
    237240
    238241    virtual Document* ownerDocument() const;
Note: See TracChangeset for help on using the changeset viewer.