Commit 2656da04 authored by meade's avatar meade Committed by Commit bot

Make CSSKeywordValue's value attribute mutable

Also update the attribute name to "value" to match the spec, and
change the type to a plain String, to avoid interning random
developer strings inside AtomicString when we don't need to.

In the original spec for Typed OM, every StyleValue subclass was
immutable, so you'd need to create new ones if you wanted to udpate
something. It turns out that this can be expensive due to garbage
collection churn, and it's now been changed so that StyleValue
subclasses are mutable.

CSSKeywordValue spec (note no "readonly" keyword on value now)
https://drafts.css-houdini.org/css-typed-om/#csskeywordvalue

BUG=545318

Review-Url: https://codereview.chromium.org/2893823002
Cr-Commit-Position: refs/heads/master@{#474962}
parent c378166d
...@@ -10,6 +10,6 @@ ...@@ -10,6 +10,6 @@
<script> <script>
test(function() { test(function() {
element.styleMap.set('width', new CSSKeywordValue('inherit')); element.styleMap.set('width', new CSSKeywordValue('inherit'));
assert_equals(element.styleMap.get('width').keywordValue, 'inherit', 'inherit should be a valid value for styleMap properties'); assert_equals(element.styleMap.get('width').value, 'inherit', 'inherit should be a valid value for styleMap properties');
}); });
</script> </script>
...@@ -7,8 +7,9 @@ CONSOLE MESSAGE: line 147: getter intrinsicRatio ...@@ -7,8 +7,9 @@ CONSOLE MESSAGE: line 147: getter intrinsicRatio
CONSOLE MESSAGE: line 147: getter intrinsicWidth CONSOLE MESSAGE: line 147: getter intrinsicWidth
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: interface CSSKeywordValue : CSSStyleValue CONSOLE MESSAGE: line 147: interface CSSKeywordValue : CSSStyleValue
CONSOLE MESSAGE: line 147: getter keywordValue CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSMatrixComponent : CSSTransformComponent CONSOLE MESSAGE: line 147: interface CSSMatrixComponent : CSSTransformComponent
CONSOLE MESSAGE: line 147: getter matrix CONSOLE MESSAGE: line 147: getter matrix
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
......
...@@ -17,12 +17,20 @@ test(function() { ...@@ -17,12 +17,20 @@ test(function() {
'implies that toCSSValue supports all keywords including custom identifiers'); 'implies that toCSSValue supports all keywords including custom identifiers');
test(function() { test(function() {
assert_equals(new CSSKeywordValue('initial').keywordValue, 'initial'); assert_equals(new CSSKeywordValue('initial').value, 'initial');
assert_equals(new CSSKeywordValue('center').keywordValue, 'center'); assert_equals(new CSSKeywordValue('center').value, 'center');
assert_equals(new CSSKeywordValue('customLemon').keywordValue, 'customLemon'); assert_equals(new CSSKeywordValue('customLemon').value, 'customLemon');
assert_equals(new CSSKeywordValue(' Hello World').keywordValue, ' Hello World'); assert_equals(new CSSKeywordValue(' Hello World').value, ' Hello World');
assert_equals(new CSSKeywordValue('3').keywordValue, '3'); assert_equals(new CSSKeywordValue('3').value, '3');
}, 'keywordValue returns a string equal to the string used in the constructor'); }, 'value returns a string equal to the string used in the constructor');
test(function() {
let keywordValue = new CSSKeywordValue('foo');
assert_equals(keywordValue.value, 'foo');
keywordValue.value = 'bar';
assert_equals(keywordValue.value, 'bar');
}, 'The keyword used in KeywordValue can be updated');
</script> </script>
<body> <body>
......
...@@ -620,8 +620,9 @@ interface CSSKeyframesRule : CSSRule ...@@ -620,8 +620,9 @@ interface CSSKeyframesRule : CSSRule
setter name setter name
interface CSSKeywordValue : CSSStyleValue interface CSSKeywordValue : CSSStyleValue
attribute @@toStringTag attribute @@toStringTag
getter keywordValue getter value
method constructor method constructor
setter value
interface CSSMatrixComponent : CSSTransformComponent interface CSSMatrixComponent : CSSTransformComponent
attribute @@toStringTag attribute @@toStringTag
getter matrix getter matrix
......
...@@ -620,8 +620,9 @@ interface CSSKeyframesRule : CSSRule ...@@ -620,8 +620,9 @@ interface CSSKeyframesRule : CSSRule
setter name setter name
interface CSSKeywordValue : CSSStyleValue interface CSSKeywordValue : CSSStyleValue
attribute @@toStringTag attribute @@toStringTag
getter keywordValue getter value
method constructor method constructor
setter value
interface CSSMatrixComponent : CSSTransformComponent interface CSSMatrixComponent : CSSTransformComponent
attribute @@toStringTag attribute @@toStringTag
getter matrix getter matrix
......
...@@ -11,10 +11,11 @@ ...@@ -11,10 +11,11 @@
#include "core/css/CSSInitialValue.h" #include "core/css/CSSInitialValue.h"
#include "core/css/CSSUnsetValue.h" #include "core/css/CSSUnsetValue.h"
#include "core/css/parser/CSSPropertyParser.h" #include "core/css/parser/CSSPropertyParser.h"
#include "platform/wtf/text/AtomicString.h"
namespace blink { namespace blink {
CSSKeywordValue* CSSKeywordValue::Create(const AtomicString& keyword, CSSKeywordValue* CSSKeywordValue::Create(const String& keyword,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (keyword.IsEmpty()) { if (keyword.IsEmpty()) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
...@@ -48,12 +49,12 @@ CSSKeywordValue* CSSKeywordValue::FromCSSValue(const CSSValue& value) { ...@@ -48,12 +49,12 @@ CSSKeywordValue* CSSKeywordValue::FromCSSValue(const CSSValue& value) {
return nullptr; return nullptr;
} }
CSSKeywordValue* CSSKeywordValue::Create(const AtomicString& keyword) { CSSKeywordValue* CSSKeywordValue::Create(const String& keyword) {
DCHECK(!keyword.IsEmpty()); DCHECK(!keyword.IsEmpty());
return new CSSKeywordValue(keyword); return new CSSKeywordValue(keyword);
} }
const AtomicString& CSSKeywordValue::keywordValue() const { const String& CSSKeywordValue::value() const {
return keyword_value_; return keyword_value_;
} }
...@@ -71,7 +72,7 @@ CSSValue* CSSKeywordValue::ToCSSValue() const { ...@@ -71,7 +72,7 @@ CSSValue* CSSKeywordValue::ToCSSValue() const {
case (CSSValueUnset): case (CSSValueUnset):
return CSSUnsetValue::Create(); return CSSUnsetValue::Create();
case (CSSValueInvalid): case (CSSValueInvalid):
return CSSCustomIdentValue::Create(keyword_value_); return CSSCustomIdentValue::Create(AtomicString(keyword_value_));
default: default:
return CSSIdentifierValue::Create(keyword_id); return CSSIdentifierValue::Create(keyword_id);
} }
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "core/CSSValueKeywords.h" #include "core/CSSValueKeywords.h"
#include "core/CoreExport.h" #include "core/CoreExport.h"
#include "core/css/cssom/CSSStyleValue.h" #include "core/css/cssom/CSSStyleValue.h"
#include "platform/wtf/text/AtomicString.h"
namespace blink { namespace blink {
...@@ -19,22 +18,22 @@ class CORE_EXPORT CSSKeywordValue final : public CSSStyleValue { ...@@ -19,22 +18,22 @@ class CORE_EXPORT CSSKeywordValue final : public CSSStyleValue {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static CSSKeywordValue* Create(const AtomicString& keyword); static CSSKeywordValue* Create(const String& keyword);
static CSSKeywordValue* Create(const AtomicString& keyword, ExceptionState&); static CSSKeywordValue* Create(const String& keyword, ExceptionState&);
static CSSKeywordValue* FromCSSValue(const CSSValue&); static CSSKeywordValue* FromCSSValue(const CSSValue&);
StyleValueType GetType() const override { return kKeywordType; } StyleValueType GetType() const override { return kKeywordType; }
const AtomicString& keywordValue() const; const String& value() const;
void setValue(const String& keyword) { keyword_value_ = keyword; }
CSSValueID KeywordValueID() const; CSSValueID KeywordValueID() const;
CSSValue* ToCSSValue() const override; CSSValue* ToCSSValue() const override;
private: private:
explicit CSSKeywordValue(const AtomicString& keyword) explicit CSSKeywordValue(const String& keyword) : keyword_value_(keyword) {}
: keyword_value_(keyword) {}
AtomicString keyword_value_; String keyword_value_;
}; };
DEFINE_TYPE_CASTS(CSSKeywordValue, DEFINE_TYPE_CASTS(CSSKeywordValue,
......
...@@ -11,5 +11,5 @@ ...@@ -11,5 +11,5 @@
RuntimeEnabled=CSSTypedOM, RuntimeEnabled=CSSTypedOM,
RaisesException=Constructor RaisesException=Constructor
] interface CSSKeywordValue : CSSStyleValue { ] interface CSSKeywordValue : CSSStyleValue {
readonly attribute DOMString keywordValue; attribute DOMString value;
}; };
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