Commit 9d45b94d authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez Committed by Commit Bot

[cssom] Make CSSOM APIs always append to the declaration block.

...instead of replacing if the property is already set.

This matches the spec[1] which was changed as a resolution from[2].

Intent thread: https://groups.google.com/a/chromium.org/d/msg/blink-dev/lzBoa1EAQpI/strfpNczAwAJ

[1]: https://drafts.csswg.org/cssom/#set-a-css-declaration
[2]: https://github.com/w3c/csswg-drafts/issues/1898

Bug: 782407
Change-Id: I4b72c0207a4cf734fc2e415bd62c7863103ec309
Reviewed-on: https://chromium-review.googlesource.com/1054867
Commit-Queue: Emilio Cobos Álvarez <emilio@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560180}
parent ec82e04d
...@@ -2934,7 +2934,6 @@ crbug.com/626703 external/wpt/mediacapture-streams/MediaStream-MediaElement-prel ...@@ -2934,7 +2934,6 @@ crbug.com/626703 external/wpt/mediacapture-streams/MediaStream-MediaElement-prel
crbug.com/626703 virtual/feature-policy-permissions/external/wpt/mediacapture-streams/MediaStream-MediaElement-preload-none-manual.https.html [ Skip ] crbug.com/626703 virtual/feature-policy-permissions/external/wpt/mediacapture-streams/MediaStream-MediaElement-preload-none-manual.https.html [ Skip ]
crbug.com/626703 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-flex-basis-content-003a.html [ Failure ] crbug.com/626703 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-flex-basis-content-003a.html [ Failure ]
crbug.com/626703 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-flex-basis-content-004a.html [ Failure ] crbug.com/626703 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-flex-basis-content-004a.html [ Failure ]
crbug.com/626703 external/wpt/css/cssom/cssstyledeclaration-mutationrecord-001.html [ Timeout ]
crbug.com/626703 external/wpt/css/css-shapes/shape-outside/shape-image/gradients/shape-outside-linear-gradient-008.html [ Failure ] crbug.com/626703 external/wpt/css/css-shapes/shape-outside/shape-image/gradients/shape-outside-linear-gradient-008.html [ Failure ]
crbug.com/626703 [ Mac10.11 ] virtual/webrtc-wpt-unified-plan/external/wpt/webrtc/RTCPeerConnection-track-stats.https.html [ Timeout ] crbug.com/626703 [ Mac10.11 ] virtual/webrtc-wpt-unified-plan/external/wpt/webrtc/RTCPeerConnection-track-stats.https.html [ Timeout ]
crbug.com/626703 external/wpt/css/css-shapes/shape-outside/shape-image/gradients/shape-outside-linear-gradient-006.html [ Failure ] crbug.com/626703 external/wpt/css/css-shapes/shape-outside/shape-image/gradients/shape-outside-linear-gradient-006.html [ Failure ]
...@@ -4386,9 +4385,6 @@ crbug.com/778745 http/tests/inspector-protocol/cachestorage/read-cached-response ...@@ -4386,9 +4385,6 @@ crbug.com/778745 http/tests/inspector-protocol/cachestorage/read-cached-response
# Sheriff failures 2017-10-24 # Sheriff failures 2017-10-24
crbug.com/773122 crbug.com/777813 [ Win ] fast/text/font-ascent-mac.html [ Failure Pass ] crbug.com/773122 crbug.com/777813 [ Win ] fast/text/font-ascent-mac.html [ Failure Pass ]
# Sheriff failures 2017-11-07
crbug.com/782067 [ Mac10.10 Mac10.11 ] fast/css/no-recalc-on-no-op-inline-style-changes.html [ Pass Failure ]
# Sheriff failures 2017-11-13 # Sheriff failures 2017-11-13
crbug.com/783800 imagecapture/MediaStreamTrack-applyConstraints.html [ Pass Failure ] crbug.com/783800 imagecapture/MediaStreamTrack-applyConstraints.html [ Pass Failure ]
crbug.com/783800 imagecapture/MediaStreamTrack-applyConstraints-getSettings.html [ Pass Failure ] crbug.com/783800 imagecapture/MediaStreamTrack-applyConstraints-getSettings.html [ Pass Failure ]
......
...@@ -9,7 +9,7 @@ Drag the link. Link ...@@ -9,7 +9,7 @@ Drag the link. Link
Test ID: selectionTest Test ID: selectionTest
text/plain: Select some text in this box and drag it. text/plain: Select some text in this box and drag it.
text/url: text/url:
text/html: <span style="color: rgb(0, 0, 0); font-family: serif; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">Select some text in this box and drag it.</span> text/html: <span style="color: rgb(0, 0, 0); font-family: serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; font-size: medium; display: inline !important; float: none;">Select some text in this box and drag it.</span>
Test ID: imageTest Test ID: imageTest
text/plain: text/plain:
text/url: text/url:
......
CONSOLE MESSAGE: line 21: text/plain: This test verifies that we can get text/html from the clipboard during an onpaste event. CONSOLE MESSAGE: line 21: text/plain: This test verifies that we can get text/html from the clipboard during an onpaste event.
CONSOLE MESSAGE: line 23: text/html: <span style="color: rgb(0, 0, 0); font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">This test verifies that we can get text/html from the clipboard during an onpaste event.<span> </span></span> CONSOLE MESSAGE: line 23: text/html: <span style="color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; font-size: medium; display: inline !important; float: none;">This test verifies that we can get text/html from the clipboard during an onpaste event.<span> </span></span>
This test verifies that we can get text/html from the clipboard during an onpaste event. This test requires DRT. This test verifies that we can get text/html from the clipboard during an onpaste event. This test requires DRT.
Paste content in this div.This test verifies that we can get text/html from the clipboard during an onpaste event.  Paste content in this div.This test verifies that we can get text/html from the clipboard during an onpaste event. 
PASS PASS
......
This is a testharness.js-based test.
FAIL setProperty with existing longhand should change order assert_array_equals: Property order should match after setting existing property property 0, expected "bottom" but got "top"
FAIL invoke property setter with existing longhand should change order assert_array_equals: Property order should match after setting existing property property 0, expected "bottom" but got "top"
FAIL setProperty with existing shorthand should change order assert_array_equals: Property order should match after setting an existing shorthand property 0, expected "top" but got "margin-top"
FAIL invoke property setter with existing shorthand should change order assert_array_equals: Property order should match after setting an existing shorthand property 0, expected "top" but got "margin-top"
Harness: the test ran to completion.
<!DOCTYPE html>
<div id="element"></div>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function () {
if (!window.internals)
assert_unreached('This test requires window.internals.');
assert_greater_than(internals.updateStyleAndReturnAffectedElementCount(), 1);
element.style.top = "0px";
assert_equals(internals.updateStyleAndReturnAffectedElementCount(), 1);
for (var i = 0; i < 100; i ++) {
element.style.top = "0px";
assert_equals(internals.updateStyleAndReturnAffectedElementCount(), 0);
}
}, "Check that a no-op inline style change doesn't result in a recalc");
</script>
...@@ -173,7 +173,7 @@ PASS mutations[0].attributeName is "style" ...@@ -173,7 +173,7 @@ PASS mutations[0].attributeName is "style"
PASS mutations[0].oldValue is "color: yellow; width: 100px;" PASS mutations[0].oldValue is "color: yellow; width: 100px;"
PASS mutations[1].type is "attributes" PASS mutations[1].type is "attributes"
PASS mutations[1].attributeName is "style" PASS mutations[1].attributeName is "style"
PASS mutations[1].oldValue is "color: red; width: 100px;" PASS mutations[1].oldValue is "width: 100px; color: red;"
PASS mutations[2].type is "attributes" PASS mutations[2].type is "attributes"
PASS mutations[2].attributeName is "style" PASS mutations[2].attributeName is "style"
PASS mutations[2].oldValue is "color: red; width: 200px;" PASS mutations[2].oldValue is "color: red; width: 200px;"
......
...@@ -715,7 +715,7 @@ function testStyleAttributePropertyAccessOldValue() { ...@@ -715,7 +715,7 @@ function testStyleAttributePropertyAccessOldValue() {
shouldBe('mutations[0].oldValue', '"color: yellow; width: 100px;"'); shouldBe('mutations[0].oldValue', '"color: yellow; width: 100px;"');
shouldBe('mutations[1].type', '"attributes"'); shouldBe('mutations[1].type', '"attributes"');
shouldBe('mutations[1].attributeName', '"style"'); shouldBe('mutations[1].attributeName', '"style"');
shouldBe('mutations[1].oldValue', '"color: red; width: 100px;"'); shouldBe('mutations[1].oldValue', '"width: 100px; color: red;"');
shouldBe('mutations[2].type', '"attributes"'); shouldBe('mutations[2].type', '"attributes"');
shouldBe('mutations[2].attributeName', '"style"'); shouldBe('mutations[2].attributeName', '"style"');
shouldBe('mutations[2].oldValue', '"color: red; width: 200px;"'); shouldBe('mutations[2].oldValue', '"color: red; width: 200px;"');
......
...@@ -6,11 +6,11 @@ It is OK if the order of properties changes from the expected results - IE 6 and ...@@ -6,11 +6,11 @@ It is OK if the order of properties changes from the expected results - IE 6 and
This is the test element. This is the test element.
Successfully set display to "block"; cssText is now: "top: 0px; display: block; bottom: 1px;". Successfully set display to "block"; cssText is now: "top: 0px; bottom: 1px; display: block;".
Successfully set display to "foobar"; cssText is now: "top: 0px; display: none; bottom: 1px;". Successfully set display to "foobar"; cssText is now: "top: 0px; display: none; bottom: 1px;".
Successfully set display to ""; cssText is now: "top: 0px; bottom: 1px;". Successfully set display to ""; cssText is now: "top: 0px; bottom: 1px;".
Successfully set display to null; cssText is now: "top: 0px; bottom: 1px;". Successfully set display to null; cssText is now: "top: 0px; bottom: 1px;".
Successfully set display to "block" with setProperty; cssText is now: "top: 0px; display: block; bottom: 1px;". Successfully set display to "block" with setProperty; cssText is now: "top: 0px; bottom: 1px; display: block;".
Successfully set display to "foobar" with setProperty; cssText is now: "top: 0px; display: none; bottom: 1px;". Successfully set display to "foobar" with setProperty; cssText is now: "top: 0px; display: none; bottom: 1px;".
Successfully set display to "" with setProperty; cssText is now: "top: 0px; bottom: 1px;". Successfully set display to "" with setProperty; cssText is now: "top: 0px; bottom: 1px;".
Successfully set display to null with setProperty; cssText is now: "top: 0px; bottom: 1px;". Successfully set display to null with setProperty; cssText is now: "top: 0px; bottom: 1px;".
CONSOLE MESSAGE: line 21: text/plain: This test verifies that we can get text/html from the drag object during an ondrop event. CONSOLE MESSAGE: line 21: text/plain: This test verifies that we can get text/html from the drag object during an ondrop event.
CONSOLE MESSAGE: line 23: text/html: <span style="color: rgb(0, 0, 0); font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">This test verifies that we can get text/html from the drag object during an ondrop event.<span> </span></span> CONSOLE MESSAGE: line 23: text/html: <span style="color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; font-size: medium; display: inline !important; float: none;">This test verifies that we can get text/html from the drag object during an ondrop event.<span> </span></span>
This test verifies that we can get text/html from the drag object during an ondrop event. This test requires DRT. This test verifies that we can get text/html from the drag object during an ondrop event. This test requires DRT.
PASS PASS
...@@ -360,10 +360,11 @@ MutableCSSPropertyValueSet::SetResult MutableCSSPropertyValueSet::SetProperty( ...@@ -360,10 +360,11 @@ MutableCSSPropertyValueSet::SetResult MutableCSSPropertyValueSet::SetProperty(
} }
// When replacing an existing property value, this moves the property to the // When replacing an existing property value, this moves the property to the
// end of the list. Firefox preserves the position, and MSIE moves the // end of the list.
// property to the beginning. bool parsed_and_changed =
return CSSParser::ParseValue(this, unresolved_property, value, important, CSSParser::ParseValue(this, unresolved_property, value, important,
secure_context_mode, context_style_sheet); secure_context_mode, context_style_sheet);
return SetResult{parsed_and_changed, parsed_and_changed};
} }
MutableCSSPropertyValueSet::SetResult MutableCSSPropertyValueSet::SetProperty( MutableCSSPropertyValueSet::SetResult MutableCSSPropertyValueSet::SetProperty(
...@@ -377,11 +378,12 @@ MutableCSSPropertyValueSet::SetResult MutableCSSPropertyValueSet::SetProperty( ...@@ -377,11 +378,12 @@ MutableCSSPropertyValueSet::SetResult MutableCSSPropertyValueSet::SetProperty(
if (value.IsEmpty()) { if (value.IsEmpty()) {
bool did_parse = true; bool did_parse = true;
bool did_change = RemoveProperty(custom_property_name); bool did_change = RemoveProperty(custom_property_name);
return MutableCSSPropertyValueSet::SetResult{did_parse, did_change}; return SetResult{did_parse, did_change};
} }
return CSSParser::ParseValueForCustomProperty( bool parsed_and_changed = CSSParser::ParseValueForCustomProperty(
this, custom_property_name, registry, value, important, this, custom_property_name, registry, value, important,
secure_context_mode, context_style_sheet, is_animation_tainted); secure_context_mode, context_style_sheet, is_animation_tainted);
return SetResult{parsed_and_changed, parsed_and_changed};
} }
void MutableCSSPropertyValueSet::SetProperty(CSSPropertyID property_id, void MutableCSSPropertyValueSet::SetProperty(CSSPropertyID property_id,
...@@ -402,31 +404,22 @@ void MutableCSSPropertyValueSet::SetProperty(CSSPropertyID property_id, ...@@ -402,31 +404,22 @@ void MutableCSSPropertyValueSet::SetProperty(CSSPropertyID property_id,
} }
} }
bool MutableCSSPropertyValueSet::SetProperty(const CSSPropertyValue& property, void MutableCSSPropertyValueSet::SetProperty(const CSSPropertyValue& property,
CSSPropertyValue* slot) { CSSPropertyValue* slot) {
const AtomicString& name = if (property.Id() == CSSPropertyVariable) {
(property.Id() == CSSPropertyVariable) RemoveProperty(ToCSSCustomPropertyDeclaration(property.Value())->GetName());
? ToCSSCustomPropertyDeclaration(property.Value())->GetName() } else {
: g_null_atom; RemoveProperty(property.Id());
CSSPropertyValue* to_replace =
slot ? slot : FindCSSPropertyWithID(property.Id(), name);
if (to_replace && *to_replace == property)
return false;
if (to_replace) {
*to_replace = property;
return true;
} }
property_vector_.push_back(property); property_vector_.push_back(property);
return true;
} }
bool MutableCSSPropertyValueSet::SetProperty(CSSPropertyID property_id, void MutableCSSPropertyValueSet::SetProperty(CSSPropertyID property_id,
CSSValueID identifier, CSSValueID identifier,
bool important) { bool important) {
SetProperty(CSSPropertyValue(CSSProperty::Get(property_id), SetProperty(CSSPropertyValue(CSSProperty::Get(property_id),
*CSSIdentifierValue::Create(identifier), *CSSIdentifierValue::Create(identifier),
important)); important));
return true;
} }
void MutableCSSPropertyValueSet::ParseDeclarationList( void MutableCSSPropertyValueSet::ParseDeclarationList(
...@@ -447,21 +440,20 @@ void MutableCSSPropertyValueSet::ParseDeclarationList( ...@@ -447,21 +440,20 @@ void MutableCSSPropertyValueSet::ParseDeclarationList(
CSSParser::ParseDeclarationList(context, this, style_declaration); CSSParser::ParseDeclarationList(context, this, style_declaration);
} }
bool MutableCSSPropertyValueSet::AddParsedProperties( void MutableCSSPropertyValueSet::AddParsedProperties(
const HeapVector<CSSPropertyValue, 256>& properties) { const HeapVector<CSSPropertyValue, 256>& properties) {
bool changed = false;
property_vector_.ReserveCapacity(property_vector_.size() + properties.size()); property_vector_.ReserveCapacity(property_vector_.size() + properties.size());
for (unsigned i = 0; i < properties.size(); ++i) for (unsigned i = 0; i < properties.size(); ++i)
changed |= SetProperty(properties[i]); SetProperty(properties[i]);
return changed;
} }
bool MutableCSSPropertyValueSet::AddRespectingCascade( bool MutableCSSPropertyValueSet::AddRespectingCascade(
const CSSPropertyValue& property) { const CSSPropertyValue& property) {
// Only add properties that have no !important counterpart present // Only add properties that have no !important counterpart present
if (!PropertyIsImportant(property.Id()) || property.IsImportant()) if (PropertyIsImportant(property.Id()) && !property.IsImportant())
return SetProperty(property); return false;
return false; SetProperty(property);
return true;
} }
String CSSPropertyValueSet::AsText() const { String CSSPropertyValueSet::AsText() const {
......
...@@ -227,7 +227,7 @@ class CORE_EXPORT MutableCSSPropertyValueSet : public CSSPropertyValueSet { ...@@ -227,7 +227,7 @@ class CORE_EXPORT MutableCSSPropertyValueSet : public CSSPropertyValueSet {
unsigned PropertyCount() const { return property_vector_.size(); } unsigned PropertyCount() const { return property_vector_.size(); }
// Returns whether this style set was changed. // Returns whether this style set was changed.
bool AddParsedProperties(const HeapVector<CSSPropertyValue, 256>&); void AddParsedProperties(const HeapVector<CSSPropertyValue, 256>&);
bool AddRespectingCascade(const CSSPropertyValue&); bool AddRespectingCascade(const CSSPropertyValue&);
struct SetResult { struct SetResult {
...@@ -250,10 +250,10 @@ class CORE_EXPORT MutableCSSPropertyValueSet : public CSSPropertyValueSet { ...@@ -250,10 +250,10 @@ class CORE_EXPORT MutableCSSPropertyValueSet : public CSSPropertyValueSet {
void SetProperty(CSSPropertyID, const CSSValue&, bool important = false); void SetProperty(CSSPropertyID, const CSSValue&, bool important = false);
// These do not. FIXME: This is too messy, we can do better. // These do not. FIXME: This is too messy, we can do better.
bool SetProperty(CSSPropertyID, void SetProperty(CSSPropertyID,
CSSValueID identifier, CSSValueID identifier,
bool important = false); bool important = false);
bool SetProperty(const CSSPropertyValue&, CSSPropertyValue* slot = nullptr); void SetProperty(const CSSPropertyValue&, CSSPropertyValue* slot = nullptr);
template <typename T> // CSSPropertyID or AtomicString template <typename T> // CSSPropertyID or AtomicString
bool RemoveProperty(T property, String* return_text = nullptr); bool RemoveProperty(T property, String* return_text = nullptr);
......
...@@ -50,10 +50,9 @@ bool DOMWindowCSS::supports(const ExecutionContext* execution_context, ...@@ -50,10 +50,9 @@ bool DOMWindowCSS::supports(const ExecutionContext* execution_context,
MutableCSSPropertyValueSet::Create(kHTMLStandardMode); MutableCSSPropertyValueSet::Create(kHTMLStandardMode);
bool is_animation_tainted = false; bool is_animation_tainted = false;
return CSSParser::ParseValueForCustomProperty( return CSSParser::ParseValueForCustomProperty(
dummy_style, "--valid", nullptr, value, false, dummy_style, "--valid", nullptr, value, false,
execution_context->GetSecureContextMode(), nullptr, execution_context->GetSecureContextMode(), nullptr,
is_animation_tainted) is_animation_tainted);
.did_parse;
} }
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
...@@ -65,8 +64,7 @@ bool DOMWindowCSS::supports(const ExecutionContext* execution_context, ...@@ -65,8 +64,7 @@ bool DOMWindowCSS::supports(const ExecutionContext* execution_context,
MutableCSSPropertyValueSet* dummy_style = MutableCSSPropertyValueSet* dummy_style =
MutableCSSPropertyValueSet::Create(kHTMLStandardMode); MutableCSSPropertyValueSet::Create(kHTMLStandardMode);
return CSSParser::ParseValue(dummy_style, unresolved_property, value, false, return CSSParser::ParseValue(dummy_style, unresolved_property, value, false,
execution_context->GetSecureContextMode()) execution_context->GetSecureContextMode());
.did_parse;
} }
bool DOMWindowCSS::supports(const ExecutionContext* execution_context, bool DOMWindowCSS::supports(const ExecutionContext* execution_context,
......
...@@ -81,28 +81,24 @@ void CSSParser::ParseSheetForInspector(const CSSParserContext* context, ...@@ -81,28 +81,24 @@ void CSSParser::ParseSheetForInspector(const CSSParserContext* context,
observer); observer);
} }
MutableCSSPropertyValueSet::SetResult CSSParser::ParseValue( bool CSSParser::ParseValue(MutableCSSPropertyValueSet* declaration,
MutableCSSPropertyValueSet* declaration, CSSPropertyID unresolved_property,
CSSPropertyID unresolved_property, const String& string,
const String& string, bool important,
bool important, SecureContextMode secure_context_mode) {
SecureContextMode secure_context_mode) {
return ParseValue(declaration, unresolved_property, string, important, return ParseValue(declaration, unresolved_property, string, important,
secure_context_mode, secure_context_mode,
static_cast<StyleSheetContents*>(nullptr)); static_cast<StyleSheetContents*>(nullptr));
} }
MutableCSSPropertyValueSet::SetResult CSSParser::ParseValue( bool CSSParser::ParseValue(MutableCSSPropertyValueSet* declaration,
MutableCSSPropertyValueSet* declaration, CSSPropertyID unresolved_property,
CSSPropertyID unresolved_property, const String& string,
const String& string, bool important,
bool important, SecureContextMode secure_context_mode,
SecureContextMode secure_context_mode, StyleSheetContents* style_sheet) {
StyleSheetContents* style_sheet) {
if (string.IsEmpty()) { if (string.IsEmpty()) {
bool did_parse = false; return false;
bool did_change = false;
return MutableCSSPropertyValueSet::SetResult{did_parse, did_change};
} }
CSSPropertyID resolved_property = resolveCSSPropertyID(unresolved_property); CSSPropertyID resolved_property = resolveCSSPropertyID(unresolved_property);
...@@ -110,10 +106,9 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValue( ...@@ -110,10 +106,9 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValue(
CSSValue* value = CSSParserFastPaths::MaybeParseValue(resolved_property, CSSValue* value = CSSParserFastPaths::MaybeParseValue(resolved_property,
string, parser_mode); string, parser_mode);
if (value) { if (value) {
bool did_parse = true; declaration->SetProperty(CSSPropertyValue(
bool did_change = declaration->SetProperty(CSSPropertyValue(
CSSProperty::Get(resolved_property), *value, important)); CSSProperty::Get(resolved_property), *value, important));
return MutableCSSPropertyValueSet::SetResult{did_parse, did_change}; return true;
} }
CSSParserContext* context; CSSParserContext* context;
if (style_sheet) { if (style_sheet) {
...@@ -126,7 +121,7 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValue( ...@@ -126,7 +121,7 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValue(
context); context);
} }
MutableCSSPropertyValueSet::SetResult CSSParser::ParseValueForCustomProperty( bool CSSParser::ParseValueForCustomProperty(
MutableCSSPropertyValueSet* declaration, MutableCSSPropertyValueSet* declaration,
const AtomicString& property_name, const AtomicString& property_name,
const PropertyRegistry* registry, const PropertyRegistry* registry,
...@@ -137,9 +132,7 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValueForCustomProperty( ...@@ -137,9 +132,7 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValueForCustomProperty(
bool is_animation_tainted) { bool is_animation_tainted) {
DCHECK(CSSVariableParser::IsValidVariableName(property_name)); DCHECK(CSSVariableParser::IsValidVariableName(property_name));
if (value.IsEmpty()) { if (value.IsEmpty()) {
bool did_parse = false; return false;
bool did_change = false;
return MutableCSSPropertyValueSet::SetResult{did_parse, did_change};
} }
CSSParserMode parser_mode = declaration->CssParserMode(); CSSParserMode parser_mode = declaration->CssParserMode();
CSSParserContext* context; CSSParserContext* context;
...@@ -154,12 +147,11 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValueForCustomProperty( ...@@ -154,12 +147,11 @@ MutableCSSPropertyValueSet::SetResult CSSParser::ParseValueForCustomProperty(
is_animation_tainted); is_animation_tainted);
} }
MutableCSSPropertyValueSet::SetResult CSSParser::ParseValue( bool CSSParser::ParseValue(MutableCSSPropertyValueSet* declaration,
MutableCSSPropertyValueSet* declaration, CSSPropertyID unresolved_property,
CSSPropertyID unresolved_property, const String& string,
const String& string, bool important,
bool important, const CSSParserContext* context) {
const CSSParserContext* context) {
return CSSParserImpl::ParseValue(declaration, unresolved_property, string, return CSSParserImpl::ParseValue(declaration, unresolved_property, string,
important, context); important, context);
} }
......
...@@ -47,29 +47,26 @@ class CORE_EXPORT CSSParser { ...@@ -47,29 +47,26 @@ class CORE_EXPORT CSSParser {
MutableCSSPropertyValueSet*, MutableCSSPropertyValueSet*,
const String&); const String&);
static MutableCSSPropertyValueSet::SetResult ParseValue( static bool ParseValue(MutableCSSPropertyValueSet*,
MutableCSSPropertyValueSet*, CSSPropertyID unresolved_property,
CSSPropertyID unresolved_property, const String&,
const String&, bool important,
bool important, SecureContextMode);
SecureContextMode); static bool ParseValue(MutableCSSPropertyValueSet*,
static MutableCSSPropertyValueSet::SetResult ParseValue( CSSPropertyID unresolved_property,
MutableCSSPropertyValueSet*, const String&,
CSSPropertyID unresolved_property, bool important,
const String&, SecureContextMode,
bool important, StyleSheetContents*);
SecureContextMode,
StyleSheetContents*); static bool ParseValueForCustomProperty(MutableCSSPropertyValueSet*,
const AtomicString& property_name,
static MutableCSSPropertyValueSet::SetResult ParseValueForCustomProperty( const PropertyRegistry*,
MutableCSSPropertyValueSet*, const String& value,
const AtomicString& property_name, bool important,
const PropertyRegistry*, SecureContextMode,
const String& value, StyleSheetContents*,
bool important, bool is_animation_tainted);
SecureContextMode,
StyleSheetContents*,
bool is_animation_tainted);
// This is for non-shorthands only // This is for non-shorthands only
static const CSSValue* ParseSingleValue(CSSPropertyID, static const CSSValue* ParseSingleValue(CSSPropertyID,
...@@ -104,12 +101,11 @@ class CORE_EXPORT CSSParser { ...@@ -104,12 +101,11 @@ class CORE_EXPORT CSSParser {
CSSParserObserver&); CSSParserObserver&);
private: private:
static MutableCSSPropertyValueSet::SetResult ParseValue( static bool ParseValue(MutableCSSPropertyValueSet*,
MutableCSSPropertyValueSet*, CSSPropertyID unresolved_property,
CSSPropertyID unresolved_property, const String&,
const String&, bool important,
bool important, const CSSParserContext*);
const CSSParserContext*);
}; };
} // namespace blink } // namespace blink
......
...@@ -65,12 +65,11 @@ CSSParserImpl::CSSParserImpl(const CSSParserContext* context, ...@@ -65,12 +65,11 @@ CSSParserImpl::CSSParserImpl(const CSSParserContext* context,
StyleSheetContents* style_sheet) StyleSheetContents* style_sheet)
: context_(context), style_sheet_(style_sheet), observer_(nullptr) {} : context_(context), style_sheet_(style_sheet), observer_(nullptr) {}
MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseValue( bool CSSParserImpl::ParseValue(MutableCSSPropertyValueSet* declaration,
MutableCSSPropertyValueSet* declaration, CSSPropertyID unresolved_property,
CSSPropertyID unresolved_property, const String& string,
const String& string, bool important,
bool important, const CSSParserContext* context) {
const CSSParserContext* context) {
CSSParserImpl parser(context); CSSParserImpl parser(context);
StyleRule::RuleType rule_type = StyleRule::kStyle; StyleRule::RuleType rule_type = StyleRule::kStyle;
if (declaration->CssParserMode() == kCSSViewportRuleMode) if (declaration->CssParserMode() == kCSSViewportRuleMode)
...@@ -81,23 +80,20 @@ MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseValue( ...@@ -81,23 +80,20 @@ MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseValue(
// TODO(crbug.com/661854): Use streams instead of ranges // TODO(crbug.com/661854): Use streams instead of ranges
parser.ConsumeDeclarationValue(CSSParserTokenRange(tokenizer.TokenizeToEOF()), parser.ConsumeDeclarationValue(CSSParserTokenRange(tokenizer.TokenizeToEOF()),
unresolved_property, important, rule_type); unresolved_property, important, rule_type);
bool did_parse = false; if (parser.parsed_properties_.IsEmpty()) {
bool did_change = false; return false;
if (!parser.parsed_properties_.IsEmpty()) {
did_parse = true;
did_change = declaration->AddParsedProperties(parser.parsed_properties_);
} }
return MutableCSSPropertyValueSet::SetResult{did_parse, did_change}; declaration->AddParsedProperties(parser.parsed_properties_);
return true;
} }
MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseVariableValue( bool CSSParserImpl::ParseVariableValue(MutableCSSPropertyValueSet* declaration,
MutableCSSPropertyValueSet* declaration, const AtomicString& property_name,
const AtomicString& property_name, const PropertyRegistry* registry,
const PropertyRegistry* registry, const String& value,
const String& value, bool important,
bool important, const CSSParserContext* context,
const CSSParserContext* context, bool is_animation_tainted) {
bool is_animation_tainted) {
CSSParserImpl parser(context); CSSParserImpl parser(context);
CSSTokenizer tokenizer(value); CSSTokenizer tokenizer(value);
// TODO(crbug.com/661854): Use streams instead of ranges // TODO(crbug.com/661854): Use streams instead of ranges
...@@ -105,25 +101,23 @@ MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseVariableValue( ...@@ -105,25 +101,23 @@ MutableCSSPropertyValueSet::SetResult CSSParserImpl::ParseVariableValue(
const CSSParserTokenRange range(tokens); const CSSParserTokenRange range(tokens);
parser.ConsumeVariableValue(range, property_name, important, parser.ConsumeVariableValue(range, property_name, important,
is_animation_tainted); is_animation_tainted);
bool did_parse = false; if (parser.parsed_properties_.IsEmpty())
bool did_change = false; return false;
if (!parser.parsed_properties_.IsEmpty()) {
const CSSCustomPropertyDeclaration* parsed_declaration = const CSSCustomPropertyDeclaration* parsed_declaration =
ToCSSCustomPropertyDeclaration(parser.parsed_properties_[0].Value()); ToCSSCustomPropertyDeclaration(parser.parsed_properties_[0].Value());
if (parsed_declaration->Value() && registry) { if (parsed_declaration->Value() && registry) {
const PropertyRegistration* registration = const PropertyRegistration* registration =
registry->Registration(property_name); registry->Registration(property_name);
// TODO(timloh): This is a bit wasteful, we parse the registered property // TODO(timloh): This is a bit wasteful, we parse the registered property
// to validate but throw away the result. // to validate but throw away the result.
if (registration && if (registration &&
!registration->Syntax().Parse(range, context, is_animation_tainted)) { !registration->Syntax().Parse(range, context, is_animation_tainted)) {
return MutableCSSPropertyValueSet::SetResult{did_parse, did_change}; return false;
}
} }
did_parse = true;
did_change = declaration->AddParsedProperties(parser.parsed_properties_);
} }
return MutableCSSPropertyValueSet::SetResult{did_parse, did_change}; declaration->AddParsedProperties(parser.parsed_properties_);
return true;
} }
static inline void FilterProperties( static inline void FilterProperties(
...@@ -216,7 +210,8 @@ bool CSSParserImpl::ParseDeclarationList( ...@@ -216,7 +210,8 @@ bool CSSParserImpl::ParseDeclarationList(
seen_properties, seen_custom_properties); seen_properties, seen_custom_properties);
if (unused_entries) if (unused_entries)
results.EraseAt(0, unused_entries); results.EraseAt(0, unused_entries);
return declaration->AddParsedProperties(results); declaration->AddParsedProperties(results);
return true;
} }
StyleRuleBase* CSSParserImpl::ParseRule(const String& string, StyleRuleBase* CSSParserImpl::ParseRule(const String& string,
......
...@@ -71,20 +71,18 @@ class CSSParserImpl { ...@@ -71,20 +71,18 @@ class CSSParserImpl {
static RangeOffset Ignore() { return {0, 0}; } static RangeOffset Ignore() { return {0, 0}; }
}; };
static MutableCSSPropertyValueSet::SetResult ParseValue( static bool ParseValue(MutableCSSPropertyValueSet*,
MutableCSSPropertyValueSet*, CSSPropertyID,
CSSPropertyID, const String&,
const String&, bool important,
bool important, const CSSParserContext*);
const CSSParserContext*); static bool ParseVariableValue(MutableCSSPropertyValueSet*,
static MutableCSSPropertyValueSet::SetResult ParseVariableValue( const AtomicString& property_name,
MutableCSSPropertyValueSet*, const PropertyRegistry*,
const AtomicString& property_name, const String&,
const PropertyRegistry*, bool important,
const String&, const CSSParserContext*,
bool important, bool is_animation_tainted);
const CSSParserContext*,
bool is_animation_tainted);
static ImmutableCSSPropertyValueSet* ParseInlineStyleDeclaration( static ImmutableCSSPropertyValueSet* ParseInlineStyleDeclaration(
const String&, const String&,
Element*); Element*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment