Diff
Modified: trunk/LayoutTests/ChangeLog (148722 => 148723)
--- trunk/LayoutTests/ChangeLog 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/LayoutTests/ChangeLog 2013-04-19 05:59:02 UTC (rev 148723)
@@ -1,3 +1,17 @@
+2013-04-18 Timothy Hatcher <timo...@apple.com>
+
+ Add CSS.setStyleText to the Web Inspector protocol.
+
+ This provides a direct path for the Safari Web Inspector to live edit whole style rules.
+
+ https://webkit.org/b/109340
+ rdar://problem/13337211
+
+ Reviewed by Joseph Pecoraro.
+
+ * inspector/styles/styles-new-API-expected.txt: Updated.
+ * inspector/styles/styles-new-API.html: Test CSSAgent.setStyleText.
+
2013-04-18 Jessie Berlin <jber...@apple.com>
More cleaning up of skipped tests.
Modified: trunk/LayoutTests/inspector/styles/styles-new-API-expected.txt (148722 => 148723)
--- trunk/LayoutTests/inspector/styles/styles-new-API-expected.txt 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/LayoutTests/inspector/styles/styles-new-API-expected.txt 2013-04-19 05:59:02 UTC (rev 148723)
@@ -353,7 +353,7 @@
['text-align':'justify'] @[0:99-0:119] active
}
-=== After style text set ===
+=== After property text set ===
StyleSheet: 'html *, body[foo="bar"] {
color: white; background: black;
@@ -376,6 +376,38 @@
['text-align':'justify'] @[2:11-2:31] active
}
+=== After first style text set ===
+
+StyleSheet: 'html *, body[foo="bar"] {}body { text-align: justify;}'
+html *, body[foo="bar"]: [regular, 0:0-0:23] {
+}
+body: [regular, 0:26-0:30] {
+ ['text-align':'justify'] @[0:36-0:56] active
+}
+
+=== After second style text set ===
+
+StyleSheet: 'html *, body[foo="bar"] {color: green; background: red; foo: bar; *baz: bar; /* Comment */ font-weight: bold !important}body { text-align: justify;}'
+html *, body[foo="bar"]: [regular, 0:0-0:23] {
+ ['color':'green'] @[0:25-0:38] active
+ ['background':'red'] @[0:39-0:55] active
+ ['foo':'bar' non-parsed] @[0:56-0:65] active
+ ['font-weight':'bold !important' is-important] @[0:91-0:119] active
+ ['background-image':'initial'] @[undefined-undefined] style
+ ['background-repeat-x':'initial'] @[undefined-undefined] style
+ ['background-repeat-y':'initial'] @[undefined-undefined] style
+ ['background-attachment':'initial'] @[undefined-undefined] style
+ ['background-position-x':'initial'] @[undefined-undefined] style
+ ['background-position-y':'initial'] @[undefined-undefined] style
+ ['background-origin':'initial'] @[undefined-undefined] style
+ ['background-clip':'initial'] @[undefined-undefined] style
+ ['background-color':'red'] @[undefined-undefined] style
+ ['background-size':'initial'] @[undefined-undefined] style
+}
+body: [regular, 0:120-0:124] {
+ ['text-align':'justify'] @[0:130-0:150] active
+}
+
=== Matched rules after rule added ===
body: [user-agent] {
['display':'block'] @[undefined-undefined] style
@@ -402,8 +434,10 @@
['color':'"badcolor" ! important /* good property with strange value */' is-important non-parsed] @[18:4-18:73] active
}
html *, body[foo="bar"]: [regular, 0:0-0:23] {
- ['color':'white'] @[1:4-1:17] active
- ['background':'black'] @[1:18-1:36] active
+ ['color':'green'] @[0:25-0:38] active
+ ['background':'red'] @[0:39-0:55] active
+ ['foo':'bar' non-parsed] @[0:56-0:65] active
+ ['font-weight':'bold !important' is-important] @[0:91-0:119] active
['background-image':'initial'] @[undefined-undefined] style
['background-repeat-x':'initial'] @[undefined-undefined] style
['background-repeat-y':'initial'] @[undefined-undefined] style
@@ -412,11 +446,11 @@
['background-position-y':'initial'] @[undefined-undefined] style
['background-origin':'initial'] @[undefined-undefined] style
['background-clip':'initial'] @[undefined-undefined] style
- ['background-color':'black'] @[undefined-undefined] style
+ ['background-color':'red'] @[undefined-undefined] style
['background-size':'initial'] @[undefined-undefined] style
}
-body: [regular, 2:1-2:5] {
- ['text-align':'justify'] @[2:11-2:31] active
+body: [regular, 0:120-0:124] {
+ ['text-align':'justify'] @[0:130-0:150] active
}
body: [inspector, 0:0-0:4] {
['font-family':'serif'] @[1:4-1:23] active
Modified: trunk/LayoutTests/inspector/styles/styles-new-API.html (148722 => 148723)
--- trunk/LayoutTests/inspector/styles/styles-new-API.html 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/LayoutTests/inspector/styles/styles-new-API.html 2013-04-19 05:59:02 UTC (rev 148723)
@@ -192,23 +192,23 @@
}
InspectorTest.addResult("");
InspectorTest.addResult("=== After selector set ===");
- loadAndDumpStyleSheet(rule.ruleId.styleSheetId, test_setStyleText);
+ loadAndDumpStyleSheet(rule.ruleId.styleSheetId, test_setPropertyText);
}
CSSAgent.setRuleSelector(styleSheet.rules[0].ruleId, "html *, body[foo=\"bar\"]", didSetSelector);
}
- function test_setStyleText(styleSheet)
+ function test_setPropertyText(styleSheet)
{
- function didSetStyleText(error, style)
+ function didSetPropertyText(error, style)
{
if (error) {
InspectorTest.addResult("error: " + error);
return;
}
InspectorTest.addResult("");
- InspectorTest.addResult("=== After style text set ===");
- loadAndDumpStyleSheet(style.styleId.styleSheetId, test_addRule);
+ InspectorTest.addResult("=== After property text set ===");
+ loadAndDumpStyleSheet(style.styleId.styleSheetId, test_setStyleText1);
}
CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "", true);
@@ -216,9 +216,41 @@
// This operation should not update the style as the new property text is not parsable.
CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "zzz;", false);
- CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "color: white; background: black;", false, didSetStyleText);
+ CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "color: white; background: black;", false, didSetPropertyText);
}
+ function test_setStyleText1(styleSheet)
+ {
+ function didSetStyleText1(error, style)
+ {
+ if (error) {
+ InspectorTest.addResult("error: " + error);
+ return;
+ }
+ InspectorTest.addResult("");
+ InspectorTest.addResult("=== After first style text set ===");
+ loadAndDumpStyleSheet(style.styleId.styleSheetId, test_setStyleText2);
+ }
+
+ CSSAgent.setStyleText(styleSheet.rules[0].style.styleId, "", didSetStyleText1);
+ }
+
+ function test_setStyleText2(styleSheet)
+ {
+ function didSetStyleText2(error, style)
+ {
+ if (error) {
+ InspectorTest.addResult("error: " + error);
+ return;
+ }
+ InspectorTest.addResult("");
+ InspectorTest.addResult("=== After second style text set ===");
+ loadAndDumpStyleSheet(style.styleId.styleSheetId, test_addRule);
+ }
+
+ CSSAgent.setStyleText(styleSheet.rules[0].style.styleId, "color: green; background: red; foo: bar; *baz: bar; /* Comment */ font-weight: bold !important", didSetStyleText2);
+ }
+
function test_addRule()
{
function didGetStyles(error, matchedCSSRules)
Modified: trunk/Source/WebCore/ChangeLog (148722 => 148723)
--- trunk/Source/WebCore/ChangeLog 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/Source/WebCore/ChangeLog 2013-04-19 05:59:02 UTC (rev 148723)
@@ -1,3 +1,36 @@
+2013-04-18 Timothy Hatcher <timo...@apple.com>
+
+ Add CSS.setStyleText to the Web Inspector protocol.
+
+ This provides a direct path for the Safari Web Inspector to live edit whole style rules.
+
+ https://webkit.org/b/109340
+ rdar://problem/13337211
+
+ Reviewed by Joseph Pecoraro.
+
+ * inspector/Inspector.json:
+ (CSS.setStyleText): Added.
+ * inspector/InspectorCSSAgent.cpp:
+ (InspectorCSSAgent::SetStyleTextAction):
+ (WebCore::InspectorCSSAgent::SetStyleTextAction::SetStyleTextAction): Added.
+ (WebCore::InspectorCSSAgent::SetStyleTextAction::perform): Added.
+ (WebCore::InspectorCSSAgent::SetStyleTextAction::undo): Added.
+ (WebCore::InspectorCSSAgent::SetStyleTextAction::redo): Added.
+ (WebCore::InspectorCSSAgent::SetStyleTextAction::mergeId): Added.
+ (WebCore::InspectorCSSAgent::SetStyleTextAction::merge): Added.
+ (WebCore::InspectorCSSAgent::SetPropertyTextAction::redo):
+ (WebCore::InspectorCSSAgent::setStyleText): Added.
+ * inspector/InspectorCSSAgent.h:
+ * inspector/InspectorStyleSheet.cpp:
+ (WebCore::InspectorStyle::getText): Added.
+ (WebCore::InspectorStyle::setText): Added.
+ (WebCore::InspectorStyleSheet::setStyleText):
+ (WebCore::InspectorStyleSheetForInlineStyle::setStyleText):
+ * inspector/InspectorStyleSheet.h:
+ (WebCore::InspectorStyle::styleText): Added as an alias to getText.
+ (WebCore::InspectorStyle::applyStyleText): Added as an alias to setText.
+
2013-04-18 Jer Noble <jer.no...@apple.com>
Unreviewed gardening; fix bindings tests after r148700.
Modified: trunk/Source/WebCore/inspector/Inspector.json (148722 => 148723)
--- trunk/Source/WebCore/inspector/Inspector.json 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/Source/WebCore/inspector/Inspector.json 2013-04-19 05:59:02 UTC (rev 148723)
@@ -2516,6 +2516,17 @@
"description": "Sets the new stylesheet text, thereby invalidating all existing <code>CSSStyleId</code>'s and <code>CSSRuleId</code>'s contained by this stylesheet."
},
{
+ "name": "setStyleText",
+ "parameters": [
+ { "name": "styleId", "$ref": "CSSStyleId" },
+ { "name": "text", "type": "string" }
+ ],
+ "returns": [
+ { "name": "style", "$ref": "CSSStyle", "description": "The resulting style after the text modification." }
+ ],
+ "description": "Sets the new <code>text</code> for the respective style."
+ },
+ {
"name": "setPropertyText",
"parameters": [
{ "name": "styleId", "$ref": "CSSStyleId" },
Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (148722 => 148723)
--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp 2013-04-19 05:59:02 UTC (rev 148723)
@@ -356,6 +356,51 @@
String m_oldText;
};
+class InspectorCSSAgent::SetStyleTextAction : public InspectorCSSAgent::StyleSheetAction {
+ WTF_MAKE_NONCOPYABLE(SetStyleTextAction);
+public:
+ SetStyleTextAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& text)
+ : InspectorCSSAgent::StyleSheetAction(ASCIILiteral("SetStyleText"), styleSheet)
+ , m_cssId(cssId)
+ , m_text(text)
+ {
+ }
+
+ virtual bool perform(ExceptionCode& ec)
+ {
+ return redo(ec);
+ }
+
+ virtual bool undo(ExceptionCode& ec)
+ {
+ return m_styleSheet->setStyleText(m_cssId, m_oldText, 0, ec);
+ }
+
+ virtual bool redo(ExceptionCode& ec)
+ {
+ return m_styleSheet->setStyleText(m_cssId, m_text, &m_oldText, ec);
+ }
+
+ virtual String mergeId()
+ {
+ ASSERT(m_styleSheet->id() == m_cssId.styleSheetId());
+ return String::format("SetStyleText %s:%u", m_styleSheet->id().utf8().data(), m_cssId.ordinal());
+ }
+
+ virtual void merge(PassOwnPtr<Action> action)
+ {
+ ASSERT(action->mergeId() == mergeId());
+
+ SetStyleTextAction* other = static_cast<SetStyleTextAction*>(action.get());
+ m_text = other->m_text;
+ }
+
+private:
+ InspectorCSSId m_cssId;
+ String m_text;
+ String m_oldText;
+};
+
class InspectorCSSAgent::SetPropertyTextAction : public InspectorCSSAgent::StyleSheetAction {
WTF_MAKE_NONCOPYABLE(SetPropertyTextAction);
public:
@@ -392,6 +437,7 @@
// FIXME: remove this once the model handles this case.
if (!m_oldText.endsWith(';'))
m_oldText.append(';');
+
return result;
}
@@ -800,6 +846,22 @@
*errorString = InspectorDOMAgent::toErrorString(ec);
}
+void InspectorCSSAgent::setStyleText(ErrorString* errorString, const RefPtr<InspectorObject>& fullStyleId, const String& text, RefPtr<TypeBuilder::CSS::CSSStyle>& result)
+{
+ InspectorCSSId compoundId(fullStyleId);
+ ASSERT(!compoundId.isEmpty());
+
+ InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId());
+ if (!inspectorStyleSheet)
+ return;
+
+ ExceptionCode ec = 0;
+ bool success = m_domAgent->history()->perform(adoptPtr(new SetStyleTextAction(inspectorStyleSheet, compoundId, text)), ec);
+ if (success)
+ result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
+ *errorString = InspectorDOMAgent::toErrorString(ec);
+}
+
void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<InspectorObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result)
{
InspectorCSSId compoundId(fullStyleId);
Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.h (148722 => 148723)
--- trunk/Source/WebCore/inspector/InspectorCSSAgent.h 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.h 2013-04-19 05:59:02 UTC (rev 148723)
@@ -115,6 +115,7 @@
virtual void getStyleSheet(ErrorString*, const String& styleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& result);
virtual void getStyleSheetText(ErrorString*, const String& styleSheetId, String* result);
virtual void setStyleSheetText(ErrorString*, const String& styleSheetId, const String& text);
+ virtual void setStyleText(ErrorString*, const RefPtr<InspectorObject>& styleId, const String& text, RefPtr<TypeBuilder::CSS::CSSStyle>& result);
virtual void setPropertyText(ErrorString*, const RefPtr<InspectorObject>& styleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result);
virtual void toggleProperty(ErrorString*, const RefPtr<InspectorObject>& styleId, int propertyIndex, bool disable, RefPtr<TypeBuilder::CSS::CSSStyle>& result);
virtual void setRuleSelector(ErrorString*, const RefPtr<InspectorObject>& ruleId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result);
@@ -135,6 +136,7 @@
private:
class StyleSheetAction;
class SetStyleSheetTextAction;
+ class SetStyleTextAction;
class SetPropertyTextAction;
class TogglePropertyAction;
class SetRuleSelectorAction;
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (148722 => 148723)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2013-04-19 05:59:02 UTC (rev 148723)
@@ -460,7 +460,7 @@
return applyStyleText(editor.styleText());
}
-bool InspectorStyle::styleText(String* result) const
+bool InspectorStyle::getText(String* result) const
{
// Precondition: m_parentStyleSheet->ensureParsedDataReady() has been called successfully.
RefPtr<CSSRuleSourceData> sourceData = extractSourceData();
@@ -641,9 +641,9 @@
return m_parentStyleSheet->ruleSourceDataFor(m_style.get());
}
-bool InspectorStyle::applyStyleText(const String& text)
+bool InspectorStyle::setText(const String& text, ExceptionCode& ec)
{
- return m_parentStyleSheet->setStyleText(m_style.get(), text);
+ return m_parentStyleSheet->setStyleText(m_style.get(), text, ec);
}
String InspectorStyle::shorthandValue(const String& shorthandProperty) const
@@ -1109,6 +1109,23 @@
return result.release();
}
+bool InspectorStyleSheet::setStyleText(const InspectorCSSId& id, const String& text, String* oldText, ExceptionCode& ec)
+{
+ RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
+ if (!inspectorStyle) {
+ ec = NOT_FOUND_ERR;
+ return false;
+ }
+
+ if (oldText && !inspectorStyle->getText(oldText))
+ return false;
+
+ bool success = inspectorStyle->setText(text, ec);
+ if (success)
+ fireStyleSheetChanged();
+ return success;
+}
+
bool InspectorStyleSheet::setPropertyText(const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, String* oldText, ExceptionCode& ec)
{
RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
@@ -1279,7 +1296,7 @@
collectFlatRules(asCSSRuleList(pageStyleSheet()), &m_flatRules);
}
-bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String& text)
+bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String& text, ExceptionCode& ec)
{
if (!m_pageStyleSheet)
return false;
@@ -1295,7 +1312,6 @@
if (id.isEmpty())
return false;
- ExceptionCode ec = 0;
style->setCssText(text, ec);
if (!ec)
m_parsedStyleSheet->setText(patchedStyleSheetText);
@@ -1342,7 +1358,9 @@
if (parsedRule->styleRule()->properties()->asText() != pageStyle->cssText()) {
// Clear the disabled properties for the invalid style here.
m_inspectorStyles.remove(pageStyle);
- setStyleText(pageStyle, pageStyle->cssText());
+
+ ExceptionCode ec = 0;
+ setStyleText(pageStyle, pageStyle->cssText(), ec);
}
break;
}
@@ -1460,10 +1478,9 @@
return true;
}
-bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style, const String& text)
+bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style, const String& text, ExceptionCode& ec)
{
ASSERT_UNUSED(style, style == inlineStyle());
- ExceptionCode ec = 0;
{
InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->ownerDocument());
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.h (148722 => 148723)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2013-04-19 02:31:45 UTC (rev 148722)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2013-04-19 05:59:02 UTC (rev 148723)
@@ -146,14 +146,19 @@
bool setPropertyText(unsigned index, const String& text, bool overwrite, String* oldText, ExceptionCode&);
bool toggleProperty(unsigned index, bool disable, ExceptionCode&);
+ bool getText(String* result) const;
+ bool setText(const String&, ExceptionCode&);
+
private:
InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet);
- bool styleText(String* result) const;
+ // FIXME: Remove these aliases and update all the current call sites to use the new public methods.
+ bool styleText(String* result) const { return getText(result); }
+ bool applyStyleText(const String& text) { ExceptionCode ec = 0; return setText(text, ec); }
+
bool populateAllProperties(Vector<InspectorStyleProperty>* result) const;
PassRefPtr<TypeBuilder::CSS::CSSStyle> styleWithProperties() const;
PassRefPtr<CSSRuleSourceData> extractSourceData() const;
- bool applyStyleText(const String&);
String shorthandValue(const String& shorthandProperty) const;
String shorthandPriority(const String& shorthandProperty) const;
Vector<String> longhandProperties(const String& shorthandProperty) const;
@@ -196,6 +201,7 @@
PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> buildObjectForStyleSheetInfo();
PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*);
PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForStyle(CSSStyleDeclaration*);
+ bool setStyleText(const InspectorCSSId&, const String& text, String* oldText, ExceptionCode&);
bool setPropertyText(const InspectorCSSId&, unsigned propertyIndex, const String& text, bool overwrite, String* oldPropertyText, ExceptionCode&);
bool toggleProperty(const InspectorCSSId&, unsigned propertyIndex, bool disable, ExceptionCode&);
@@ -220,7 +226,7 @@
virtual void forgetInspectorStyle(CSSStyleDeclaration* style);
// Also accessed by friend class InspectorStyle.
- virtual bool setStyleText(CSSStyleDeclaration*, const String&);
+ virtual bool setStyleText(CSSStyleDeclaration*, const String&, ExceptionCode&);
virtual PassOwnPtr<Vector<size_t> > lineEndings() const;
private:
@@ -272,7 +278,7 @@
virtual void forgetInspectorStyle(CSSStyleDeclaration*) { }
// Also accessed by friend class InspectorStyle.
- virtual bool setStyleText(CSSStyleDeclaration*, const String&);
+ virtual bool setStyleText(CSSStyleDeclaration*, const String&, ExceptionCode&);
virtual PassOwnPtr<Vector<size_t> > lineEndings() const;
private: