Log 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.
Modified Paths
- trunk/LayoutTests/ChangeLog
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp
- trunk/Source/WebCore/inspector/InspectorCSSAgent.h
- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp
- trunk/Source/WebCore/inspector/InspectorStyleSheet.h
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (107560 => 107561)
--- trunk/LayoutTests/ChangeLog 2012-02-13 12:45:51 UTC (rev 107560)
+++ trunk/LayoutTests/ChangeLog 2012-02-13 13:12:15 UTC (rev 107561)
@@ -1,3 +1,15 @@
+2012-02-13 Pavel Feldman <pfeld...@google.com>
+
+ 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.
+
+ * 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.
+
2012-02-13 Csaba Osztrogonác <o...@webkit.org>
[Qt] Unreviewed gardening, unskip now passing tests.
Added: trunk/LayoutTests/inspector/styles/undo-add-new-rule-expected.txt (0 => 107561)
--- trunk/LayoutTests/inspector/styles/undo-add-new-rule-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/styles/undo-add-new-rule-expected.txt 2012-02-13 13:12:15 UTC (rev 107561)
@@ -0,0 +1,43 @@
+Tests that adding a new rule can be undone.
+
+Text
+After adding new rule:
+[expanded]
+element.style { ()
+font-size: 12px;
+
+======== Matched CSS Rules ========
+[expanded]
+div.foo { (via inspector)
+
+[expanded]
+div.foo { (via inspector)
+
+[expanded]
+div { (user agent stylesheet)
+display: block;
+
+
+===== Style sheet text: =====
+div.foo {}
+div.foo {}
+=============================
+After undo:
+[expanded]
+element.style { ()
+color: red;
+
+======== Matched CSS Rules ========
+[expanded]
+div.foo { (via inspector)
+
+[expanded]
+div { (user agent stylesheet)
+display: block;
+
+
+===== Style sheet text: =====
+div.foo {}
+
+=============================
+
Property changes on: trunk/LayoutTests/inspector/styles/undo-add-new-rule-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/styles/undo-add-new-rule.html (0 => 107561)
--- trunk/LayoutTests/inspector/styles/undo-add-new-rule.html (rev 0)
+++ trunk/LayoutTests/inspector/styles/undo-add-new-rule.html 2012-02-13 13:12:15 UTC (rev 107561)
@@ -0,0 +1,86 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+function test()
+{
+ WebInspector.showPanel("elements");
+ InspectorTest.selectNodeAndWaitForStyles("inspected", step1);
+
+ var treeElement;
+
+ function step1()
+ {
+ addNewRuleAndSelectNode("other", step2);
+ }
+
+ function step2()
+ {
+ addNewRuleAndSelectNode("inspected", step3);
+ }
+
+ function step3()
+ {
+ InspectorTest.addResult("After adding new rule:");
+ InspectorTest.dumpSelectedElementStyles(true, false, true);
+ printStyleSheetAndCall(step4);
+ }
+
+ function step4()
+ {
+ DOMAgent.undo();
+ InspectorTest.selectNodeAndWaitForStyles("other", step5);
+ }
+
+ function step5()
+ {
+ InspectorTest.addResult("After undo:");
+ InspectorTest.dumpSelectedElementStyles(true, false, true);
+ printStyleSheetAndCall(step6);
+ }
+
+ function step6()
+ {
+ InspectorTest.completeTest();
+ }
+
+ function addNewRuleAndSelectNode(nodeId, next)
+ {
+ // Click "Add new rule".
+ document.getElementById("add-style-button-test-id").click();
+ var section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][2];
+ section._selectorElement.textContent = "div.foo";
+ section._selectorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
+ InspectorTest.selectNodeAndWaitForStyles(nodeId, next);
+ }
+
+ function printStyleSheetAndCall(next)
+ {
+ var section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][2];
+ var id = section.styleRule.style.id.styleSheetId;
+ CSSAgent.getStyleSheetText(id, callback);
+ function callback(result, styleSheetText)
+ {
+ InspectorTest.addResult("===== Style sheet text: =====");
+ InspectorTest.addResult(styleSheetText);
+ InspectorTest.addResult("=============================");
+ next();
+ }
+ }
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+Tests that adding a new rule can be undone.
+</p>
+
+<div class="foo" id="inspected" style="font-size: 12px">Text</div>
+<div class="foo" id="other" style="color:red"></div>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/styles/undo-add-new-rule.html
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/styles/undo-set-selector-text-expected.txt (0 => 107561)
--- trunk/LayoutTests/inspector/styles/undo-set-selector-text-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/styles/undo-set-selector-text-expected.txt 2012-02-13 13:12:15 UTC (rev 107561)
@@ -0,0 +1,45 @@
+Tests that setting selector text can be undone.
+
+=== Before selector modification ===
+[expanded]
+element.style { ()
+
+======== Matched CSS Rules ========
+[expanded]
+#inspected { (undo-set-selector-text.html:4)
+color: green;
+
+[expanded]
+div { (user agent stylesheet)
+display: block;
+
+
+=== After selector modification ===
+[expanded]
+element.style { ()
+
+======== Matched CSS Rules ========
+[expanded]
+#inspected, #other { (undo-set-selector-text.html:4)
+color: green;
+
+[expanded]
+div { (user agent stylesheet)
+display: block;
+
+
+=== After undo ===
+[expanded]
+element.style { ()
+
+======== Matched CSS Rules ========
+[expanded]
+#inspected { (undo-set-selector-text.html:4)
+color: green;
+
+[expanded]
+div { (user agent stylesheet)
+display: block;
+
+
+
Property changes on: trunk/LayoutTests/inspector/styles/undo-set-selector-text-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/styles/undo-set-selector-text.html (0 => 107561)
--- trunk/LayoutTests/inspector/styles/undo-set-selector-text.html (rev 0)
+++ trunk/LayoutTests/inspector/styles/undo-set-selector-text.html 2012-02-13 13:12:15 UTC (rev 107561)
@@ -0,0 +1,56 @@
+<html>
+<head>
+<style>
+#inspected {
+ color: green;
+}
+</style>
+<script src=""
+<script src=""
+<script>
+
+function test()
+{
+ WebInspector.showPanel("elements");
+ InspectorTest.selectNodeAndWaitForStyles("inspected", step1);
+
+ function step1()
+ {
+ InspectorTest.addResult("=== Before selector modification ===");
+ InspectorTest.dumpSelectedElementStyles(true);
+ var section = WebInspector.panels.elements.sidebarPanes.styles.sections[0][2];
+ section.startEditingSelector();
+ section._selectorElement.textContent = "#inspected, #other";
+ section._selectorElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
+ InspectorTest.selectNodeAndWaitForStyles("other", step2);
+ }
+
+ function step2()
+ {
+ InspectorTest.addResult("=== After selector modification ===");
+ InspectorTest.dumpSelectedElementStyles(true);
+ DOMAgent.undo();
+ InspectorTest.selectNodeAndWaitForStyles("inspected", step3);
+ }
+
+ function step3()
+ {
+ InspectorTest.addResult("=== After undo ===");
+ InspectorTest.dumpSelectedElementStyles(true);
+ InspectorTest.completeTest();
+ }
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+Tests that setting selector text can be undone.
+</p>
+
+<div id="inspected"></div>
+<div id="other"></div>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/styles/undo-set-selector-text.html
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (107560 => 107561)
--- trunk/Source/WebCore/ChangeLog 2012-02-13 12:45:51 UTC (rev 107560)
+++ trunk/Source/WebCore/ChangeLog 2012-02-13 13:12:15 UTC (rev 107561)
@@ -1,3 +1,66 @@
+2012-02-13 Pavel Feldman <pfeld...@google.com>
+
+ 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.
+
+ 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):
+
2012-02-13 Hayato Ito <hay...@chromium.org>
Rename names defined in ContentInclutionSelector to more intuitive names.
Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (107560 => 107561)
--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2012-02-13 12:45:51 UTC (rev 107560)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2012-02-13 13:12:15 UTC (rev 107561)
@@ -221,64 +221,41 @@
class InspectorCSSAgent::StyleSheetAction : public InspectorHistory::Action {
WTF_MAKE_NONCOPYABLE(StyleSheetAction);
public:
- StyleSheetAction(const String& name, InspectorCSSAgent* cssAgent, const String& styleSheetId)
+ StyleSheetAction(const String& name, InspectorStyleSheet* styleSheet)
: InspectorHistory::Action(name)
- , m_cssAgent(cssAgent)
- , m_styleSheetId(styleSheetId)
+ , m_styleSheet(styleSheet)
{
}
- virtual bool perform(ExceptionCode& ec)
- {
- ErrorString errorString;
- InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId(&errorString, m_styleSheetId);
- if (!styleSheet)
- return false;
- return perform(styleSheet, ec);
- }
-
- virtual bool undo(ExceptionCode& ec)
- {
- InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId(0, m_styleSheetId);
- if (!styleSheet)
- return false;
- return undo(styleSheet, ec);
- }
-
- virtual bool perform(InspectorStyleSheet*, ExceptionCode&) = 0;
-
- virtual bool undo(InspectorStyleSheet*, ExceptionCode&) = 0;
-
protected:
- InspectorCSSAgent* m_cssAgent;
- String m_styleSheetId;
+ RefPtr<InspectorStyleSheet> m_styleSheet;
};
class InspectorCSSAgent::SetStyleSheetTextAction : public InspectorCSSAgent::StyleSheetAction {
WTF_MAKE_NONCOPYABLE(SetStyleSheetTextAction);
public:
- SetStyleSheetTextAction(InspectorCSSAgent* cssAgent, const String& styleSheetId, const String& text)
- : InspectorCSSAgent::StyleSheetAction("SetStyleSheetText", cssAgent, styleSheetId)
+ SetStyleSheetTextAction(InspectorStyleSheet* styleSheet, const String& text)
+ : InspectorCSSAgent::StyleSheetAction("SetStyleSheetText", styleSheet)
, m_text(text)
{
}
- virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&)
+ virtual bool perform(ExceptionCode&)
{
- if (!inspectorStyleSheet->getText(&m_oldText))
+ if (!m_styleSheet->getText(&m_oldText))
return false;
- if (inspectorStyleSheet->setText(m_text)) {
- inspectorStyleSheet->reparseStyleSheet(m_text);
+ if (m_styleSheet->setText(m_text)) {
+ m_styleSheet->reparseStyleSheet(m_text);
return true;
}
return false;
}
- virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&)
+ virtual bool undo(ExceptionCode&)
{
- if (inspectorStyleSheet->setText(m_oldText)) {
- inspectorStyleSheet->reparseStyleSheet(m_oldText);
+ if (m_styleSheet->setText(m_oldText)) {
+ m_styleSheet->reparseStyleSheet(m_oldText);
return true;
}
return false;
@@ -292,8 +269,8 @@
class InspectorCSSAgent::SetPropertyTextAction : public InspectorCSSAgent::StyleSheetAction {
WTF_MAKE_NONCOPYABLE(SetPropertyTextAction);
public:
- SetPropertyTextAction(InspectorCSSAgent* cssAgent, const String& styleSheetId, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite)
- : InspectorCSSAgent::StyleSheetAction("SetPropertyText", cssAgent, styleSheetId)
+ SetPropertyTextAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite)
+ : InspectorCSSAgent::StyleSheetAction("SetPropertyText", styleSheet)
, m_cssId(cssId)
, m_propertyIndex(propertyIndex)
, m_text(text)
@@ -306,10 +283,10 @@
return mergeId() + ": " + m_oldText + " -> " + m_text;
}
- virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
+ virtual bool perform(ExceptionCode& ec)
{
String oldText;
- bool result = inspectorStyleSheet->setPropertyText(m_cssId, m_propertyIndex, m_text, m_overwrite, &oldText, ec);
+ bool result = m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_text, m_overwrite, &oldText, ec);
m_oldText = oldText.stripWhiteSpace();
// FIXME: remove this once the model handles this case.
if (!m_oldText.endsWith(";"))
@@ -317,15 +294,15 @@
return result;
}
- virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
+ virtual bool undo(ExceptionCode& ec)
{
String placeholder;
- return inspectorStyleSheet->setPropertyText(m_cssId, m_propertyIndex, m_overwrite ? m_oldText : "", true, &placeholder, ec);
+ return m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_overwrite ? m_oldText : "", true, &placeholder, ec);
}
virtual String mergeId()
{
- return String::format("SetPropertyText %s:%u:%s", m_styleSheetId.utf8().data(), m_propertyIndex, m_overwrite ? "true" : "false");
+ return String::format("SetPropertyText %s:%u:%s", m_styleSheet->id().utf8().data(), m_propertyIndex, m_overwrite ? "true" : "false");
}
virtual void merge(PassOwnPtr<Action> action)
@@ -347,22 +324,22 @@
class InspectorCSSAgent::TogglePropertyAction : public InspectorCSSAgent::StyleSheetAction {
WTF_MAKE_NONCOPYABLE(TogglePropertyAction);
public:
- TogglePropertyAction(InspectorCSSAgent* cssAgent, const String& styleSheetId, const InspectorCSSId& cssId, unsigned propertyIndex, bool disable)
- : InspectorCSSAgent::StyleSheetAction("ToggleProperty", cssAgent, styleSheetId)
+ TogglePropertyAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, bool disable)
+ : InspectorCSSAgent::StyleSheetAction("ToggleProperty", styleSheet)
, m_cssId(cssId)
, m_propertyIndex(propertyIndex)
, m_disable(disable)
{
}
- virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
+ virtual bool perform(ExceptionCode& ec)
{
- return inspectorStyleSheet->toggleProperty(m_cssId, m_propertyIndex, m_disable, ec);
+ return m_styleSheet->toggleProperty(m_cssId, m_propertyIndex, m_disable, ec);
}
- virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
+ virtual bool undo(ExceptionCode& ec)
{
- return inspectorStyleSheet->toggleProperty(m_cssId, m_propertyIndex, !m_disable, ec);
+ return m_styleSheet->toggleProperty(m_cssId, m_propertyIndex, !m_disable, ec);
}
private:
@@ -371,6 +348,66 @@
bool m_disable;
};
+class InspectorCSSAgent::SetRuleSelectorAction : public InspectorCSSAgent::StyleSheetAction {
+ WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction);
+public:
+ SetRuleSelectorAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& selector)
+ : InspectorCSSAgent::StyleSheetAction("SetRuleSelector", styleSheet)
+ , m_cssId(cssId)
+ , m_selector(selector)
+ {
+ }
+
+ virtual bool perform(ExceptionCode& ec)
+ {
+ m_oldSelector = m_styleSheet->ruleSelector(m_cssId, ec);
+ if (ec)
+ return false;
+ return m_styleSheet->setRuleSelector(m_cssId, m_selector, ec);
+ }
+
+ virtual bool undo(ExceptionCode& ec)
+ {
+ return m_styleSheet->setRuleSelector(m_cssId, m_oldSelector, ec);
+ }
+
+private:
+ InspectorCSSId m_cssId;
+ String m_selector;
+ String m_oldSelector;
+};
+
+class InspectorCSSAgent::AddRuleAction : public InspectorCSSAgent::StyleSheetAction {
+ WTF_MAKE_NONCOPYABLE(AddRuleAction);
+public:
+ AddRuleAction(InspectorStyleSheet* styleSheet, const String& selector)
+ : InspectorCSSAgent::StyleSheetAction("AddRule", styleSheet)
+ , m_selector(selector)
+ {
+ }
+
+ virtual bool perform(ExceptionCode& ec)
+ {
+ CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_selector, ec);
+ if (ec)
+ return false;
+ m_newId = m_styleSheet->ruleId(cssStyleRule);
+ return true;
+ }
+
+ virtual bool undo(ExceptionCode& ec)
+ {
+ return m_styleSheet->deleteRule(m_newId, ec);
+ }
+
+ InspectorCSSId newRuleId() { return m_newId; }
+
+private:
+ InspectorCSSId m_newId;
+ String m_selector;
+ String m_oldSelector;
+};
+
// static
CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule)
{
@@ -598,8 +635,12 @@
void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text)
{
+ InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
+ if (!inspectorStyleSheet)
+ return;
+
ExceptionCode ec = 0;
- m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(this, styleSheetId, text)), ec);
+ m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspectorStyleSheet, text)), ec);
*errorString = InspectorDOMAgent::toErrorString(ec);
m_domAgent->history()->markUndoableState();
}
@@ -614,7 +655,7 @@
return;
ExceptionCode ec = 0;
- bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, text, overwrite)), ec);
+ bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAction(inspectorStyleSheet, compoundId, propertyIndex, text, overwrite)), ec);
if (success)
result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
*errorString = InspectorDOMAgent::toErrorString(ec);
@@ -630,7 +671,7 @@
return;
ExceptionCode ec = 0;
- bool success = m_domAgent->history()->perform(adoptPtr(new TogglePropertyAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, disable)), ec);
+ bool success = m_domAgent->history()->perform(adoptPtr(new TogglePropertyAction(inspectorStyleSheet, compoundId, propertyIndex, disable)), ec);
if (success)
result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
*errorString = InspectorDOMAgent::toErrorString(ec);
@@ -646,27 +687,42 @@
if (!inspectorStyleSheet)
return;
- bool success = inspectorStyleSheet->setRuleSelector(compoundId, selector);
- if (!success)
- return;
+ ExceptionCode ec = 0;
+ bool success = m_domAgent->history()->perform(adoptPtr(new SetRuleSelectorAction(inspectorStyleSheet, compoundId, selector)), ec);
+ if (success)
+ result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
+ *errorString = InspectorDOMAgent::toErrorString(ec);
- result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ruleForId(compoundId));
+ if (success)
+ result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ruleForId(compoundId));
+ m_domAgent->history()->markUndoableState();
}
-void InspectorCSSAgent::addRule(ErrorString*, const int contextNodeId, const String& selector, RefPtr<InspectorObject>& result)
+void InspectorCSSAgent::addRule(ErrorString* errorString, const int contextNodeId, const String& selector, RefPtr<InspectorObject>& result)
{
- Node* node = m_domAgent->nodeForId(contextNodeId);
+ Node* node = m_domAgent->assertNode(errorString, contextNodeId);
if (!node)
return;
InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(node->document(), true);
- if (!inspectorStyleSheet)
+ if (!inspectorStyleSheet) {
+ *errorString = "No target stylesheet found";
return;
- CSSStyleRule* newRule = inspectorStyleSheet->addRule(selector);
- if (!newRule)
+ }
+
+ ExceptionCode ec = 0;
+ OwnPtr<AddRuleAction> action = "" AddRuleAction(inspectorStyleSheet, selector));
+ AddRuleAction* rawAction = action.get();
+ bool success = m_domAgent->history()->perform(action.release(), ec);
+ if (!success) {
+ *errorString = InspectorDOMAgent::toErrorString(ec);
return;
+ }
- result = inspectorStyleSheet->buildObjectForRule(newRule);
+ InspectorCSSId ruleId = rawAction->newRuleId();
+ CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId);
+ result = inspectorStyleSheet->buildObjectForRule(rule);
+ m_domAgent->history()->markUndoableState();
}
void InspectorCSSAgent::getSupportedCSSProperties(ErrorString*, RefPtr<InspectorArray>& cssProperties)
Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.h (107560 => 107561)
--- trunk/Source/WebCore/inspector/InspectorCSSAgent.h 2012-02-13 12:45:51 UTC (rev 107560)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.h 2012-02-13 13:12:15 UTC (rev 107561)
@@ -102,6 +102,8 @@
class SetStyleSheetTextAction;
class SetPropertyTextAction;
class TogglePropertyAction;
+ class SetRuleSelectorAction;
+ class AddRuleAction;
InspectorCSSAgent(InstrumentingAgents*, InspectorState*, InspectorDOMAgent*);
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (107560 => 107561)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2012-02-13 12:45:51 UTC (rev 107560)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2012-02-13 13:12:15 UTC (rev 107561)
@@ -707,19 +707,35 @@
return true;
}
-bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String& selector)
+String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionCode& ec)
{
CSSStyleRule* rule = ruleForId(id);
- if (!rule)
+ if (!rule) {
+ ec = NOT_FOUND_ERR;
+ return "";
+ }
+ return rule->selectorText();
+}
+
+bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String& selector, ExceptionCode& ec)
+{
+ CSSStyleRule* rule = ruleForId(id);
+ if (!rule) {
+ ec = NOT_FOUND_ERR;
return false;
+ }
CSSStyleSheet* styleSheet = rule->parentStyleSheet();
- if (!styleSheet || !ensureParsedDataReady())
+ if (!styleSheet || !ensureParsedDataReady()) {
+ ec = NOT_FOUND_ERR;
return false;
+ }
rule->setSelectorText(selector);
RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style());
- if (!sourceData)
+ if (!sourceData) {
+ ec = NOT_FOUND_ERR;
return false;
+ }
String sheetText = m_parsedStyleSheet->text();
sheetText.replace(sourceData->selectorListRange.start, sourceData->selectorListRange.end - sourceData->selectorListRange.start, selector);
@@ -727,14 +743,15 @@
return true;
}
-CSSStyleRule* InspectorStyleSheet::addRule(const String& selector)
+CSSStyleRule* InspectorStyleSheet::addRule(const String& selector, ExceptionCode& ec)
{
String styleSheetText;
bool success = getText(&styleSheetText);
- if (!success)
+ if (!success) {
+ ec = NOT_FOUND_ERR;
return 0;
+ }
- ExceptionCode ec = 0;
m_pageStyleSheet->addRule(selector, "", ec);
if (ec)
return 0;
@@ -754,6 +771,35 @@
return rule;
}
+bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, ExceptionCode& ec)
+{
+ CSSStyleRule* rule = ruleForId(id);
+ if (!rule) {
+ ec = NOT_FOUND_ERR;
+ return false;
+ }
+ CSSStyleSheet* styleSheet = rule->parentStyleSheet();
+ if (!styleSheet || !ensureParsedDataReady()) {
+ ec = NOT_FOUND_ERR;
+ return false;
+ }
+
+ styleSheet->deleteRule(id.ordinal(), ec);
+ if (ec)
+ return false;
+
+ RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(rule->style());
+ if (!sourceData) {
+ ec = NOT_FOUND_ERR;
+ return false;
+ }
+
+ String sheetText = m_parsedStyleSheet->text();
+ sheetText.remove(sourceData->selectorListRange.start, sourceData->styleSourceData->styleBodyRange.end - sourceData->selectorListRange.start + 1);
+ m_parsedStyleSheet->setText(sheetText);
+ return true;
+}
+
CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const
{
if (!m_pageStyleSheet)
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.h (107560 => 107561)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2012-02-13 12:45:51 UTC (rev 107560)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2012-02-13 13:12:15 UTC (rev 107561)
@@ -168,8 +168,10 @@
CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet.get(); }
void reparseStyleSheet(const String&);
bool setText(const String&);
- bool setRuleSelector(const InspectorCSSId&, const String& selector);
- CSSStyleRule* addRule(const String& selector);
+ String ruleSelector(const InspectorCSSId&, ExceptionCode&);
+ bool setRuleSelector(const InspectorCSSId&, const String& selector, ExceptionCode&);
+ CSSStyleRule* addRule(const String& selector, ExceptionCode&);
+ bool deleteRule(const InspectorCSSId&, ExceptionCode&);
CSSStyleRule* ruleForId(const InspectorCSSId&) const;
PassRefPtr<InspectorObject> buildObjectForStyleSheet();
PassRefPtr<InspectorObject> buildObjectForStyleSheetInfo();
@@ -181,6 +183,9 @@
virtual bool getText(String* result) const;
virtual CSSStyleDeclaration* styleForId(const InspectorCSSId&) const;
+ InspectorCSSId ruleId(CSSStyleRule*) const;
+ InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyleId(style); }
+
protected:
InspectorStyleSheet(const String& id, PassRefPtr<CSSStyleSheet> pageStyleSheet, const String& origin, const String& documentURL);
@@ -198,14 +203,14 @@
virtual bool setStyleText(CSSStyleDeclaration*, const String&);
private:
+ friend class InspectorStyle;
+
static void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const String& styleSheetText);
static void collectFlatRules(PassRefPtr<CSSRuleList>, Vector<CSSStyleRule*>* result);
bool ensureText() const;
bool ensureSourceData();
void ensureFlatRules() const;
bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newStyleText, String* result);
- InspectorCSSId ruleId(CSSStyleRule* rule) const;
- InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyleId(style); }
void revalidateStyle(CSSStyleDeclaration*);
bool originalStyleSheetText(String* result) const;
bool resourceStyleSheetText(String* result) const;
@@ -220,20 +225,18 @@
ParsedStyleSheet* m_parsedStyleSheet;
InspectorStyleMap m_inspectorStyles;
mutable Vector<CSSStyleRule*> m_flatRules;
-
- friend class InspectorStyle;
};
class InspectorStyleSheetForInlineStyle : public InspectorStyleSheet {
public:
- static PassRefPtr<InspectorStyleSheetForInlineStyle> create(const String& id, PassRefPtr<Element> element, const String& origin);
+ static PassRefPtr<InspectorStyleSheetForInlineStyle> create(const String& id, PassRefPtr<Element>, const String& origin);
void didModifyElementAttribute();
virtual bool getText(String* result) const;
virtual CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const { ASSERT_UNUSED(id, !id.ordinal()); return inlineStyle(); }
protected:
- InspectorStyleSheetForInlineStyle(const String& id, PassRefPtr<Element> element, const String& origin);
+ InspectorStyleSheetForInlineStyle(const String& id, PassRefPtr<Element>, const String& origin);
virtual Document* ownerDocument() const;
virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* style) const { ASSERT_UNUSED(style, style == inlineStyle()); return m_ruleSourceData; }
_______________________________________________ webkit-changes mailing list webkit-changes@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes