Chromium Code Reviews| Index: Source/core/css/CSSStringValue.h |
| diff --git a/Source/core/css/CSSStringValue.h b/Source/core/css/CSSStringValue.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6581fdf7ca8abcf2d9a738f8e66a8374f8c0ce5 |
| --- /dev/null |
| +++ b/Source/core/css/CSSStringValue.h |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CSSStringValue_h |
| +#define CSSStringValue_h |
| + |
| +#include "core/CoreExport.h" |
| +#include "core/css/CSSMarkup.h" |
| +#include "core/css/CSSValue.h" |
| +#include "wtf/PassRefPtr.h" |
| +#include "wtf/RefCounted.h" |
| +#include "wtf/text/WTFString.h" |
| + |
| +namespace blink { |
| + |
| +enum StringSerializationType { |
|
Timothy Loh
2015/09/10 07:36:51
This.. isn't really a serialization type, <string>
sashab
2015/09/17 04:19:49
Used CSSValue's types, but had to make CSSValue::c
|
| + SerializeAsString, |
| + SerializeAsCustomIdentifier, |
| + SerializeAsURI |
| +}; |
| + |
| +template <int T> |
| +class CORE_EXPORT CSSStringValueBase : public CSSValue { |
| +public: |
| + static PassRefPtrWillBeRawPtr<CSSStringValueBase> create(const String& str) |
| + { |
| + switch (T) { |
| + case SerializeAsString: |
| + return adoptRefWillBeNoop(new CSSStringValueBase(str, StringClass)); |
|
Timothy Loh
2015/09/10 07:36:51
This logic would be better in the ctor
sashab
2015/09/17 04:19:49
Just used CSSValue's types and got rid of this
|
| + case SerializeAsCustomIdentifier: |
| + return adoptRefWillBeNoop(new CSSStringValueBase(str, IdentClass)); |
| + case SerializeAsURI: |
| + return adoptRefWillBeNoop(new CSSStringValueBase(str, URIClass)); |
| + } |
| + ASSERT_NOT_REACHED(); |
| + return nullptr; |
| + } |
| + |
| + String getStringValue() const { return m_string; } |
|
Timothy Loh
2015/09/10 07:36:51
value() maybe?
sashab
2015/09/17 04:19:49
Oh yeah, I meant to do this. Done.
|
| + |
| + String customCSSText() const |
|
Timothy Loh
2015/09/10 07:36:51
This should be in a .cpp file
sashab
2015/09/17 04:19:49
Used specializations instead of the switch stateme
|
| + { |
| + switch (T) { |
| + case SerializeAsString: |
| + return serializeString(m_string); |
| + case SerializeAsCustomIdentifier: |
| + return quoteCSSStringIfNeeded(m_string); |
| + case SerializeAsURI: |
| + return "url(" + quoteCSSURLIfNeeded(m_string) + ")"; |
| + } |
| + ASSERT_NOT_REACHED(); |
| + return String(); |
| + } |
| + |
| + bool equals(const CSSStringValueBase& other) const |
| + { |
| + return m_string == other.m_string; |
| + } |
| + |
| + DEFINE_INLINE_TRACE_AFTER_DISPATCH() |
| + { |
| + CSSValue::traceAfterDispatch(visitor); |
| + } |
| + |
| +private: |
| + CSSStringValueBase(const String& str, ClassType type) |
| + : CSSValue(type) |
| + , m_string(str) { } |
| + |
| + String m_string; |
| +}; |
| + |
| +using CSSStringValue = CSSStringValueBase<SerializeAsString>; |
| +using CSSIdentValue = CSSStringValueBase<SerializeAsCustomIdentifier>; |
| +using CSSURIValue = CSSStringValueBase<SerializeAsURI>; |
| + |
| +DEFINE_CSS_VALUE_TYPE_CASTS(CSSStringValue, isStringValue()); |
| +DEFINE_CSS_VALUE_TYPE_CASTS(CSSIdentValue, isIdentValue()); |
|
Timothy Loh
2015/09/10 07:36:51
CSSCustomIdentValue and similar elsewhere
sashab
2015/09/17 04:19:49
Done. Also renamed this file to CSSStringValueBase
|
| +DEFINE_CSS_VALUE_TYPE_CASTS(CSSURIValue, isURIValue()); |
| + |
| +} // namespace |
| + |
| +#endif // CSSStringValue_h |