Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CSSStringValue_h | |
| 6 #define CSSStringValue_h | |
| 7 | |
| 8 #include "core/CoreExport.h" | |
| 9 #include "core/css/CSSMarkup.h" | |
| 10 #include "core/css/CSSValue.h" | |
| 11 #include "wtf/PassRefPtr.h" | |
| 12 #include "wtf/RefCounted.h" | |
| 13 #include "wtf/text/WTFString.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 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
| |
| 18 SerializeAsString, | |
| 19 SerializeAsCustomIdentifier, | |
| 20 SerializeAsURI | |
| 21 }; | |
| 22 | |
| 23 template <int T> | |
| 24 class CORE_EXPORT CSSStringValueBase : public CSSValue { | |
| 25 public: | |
| 26 static PassRefPtrWillBeRawPtr<CSSStringValueBase> create(const String& str) | |
| 27 { | |
| 28 switch (T) { | |
| 29 case SerializeAsString: | |
| 30 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
| |
| 31 case SerializeAsCustomIdentifier: | |
| 32 return adoptRefWillBeNoop(new CSSStringValueBase(str, IdentClass)); | |
| 33 case SerializeAsURI: | |
| 34 return adoptRefWillBeNoop(new CSSStringValueBase(str, URIClass)); | |
| 35 } | |
| 36 ASSERT_NOT_REACHED(); | |
| 37 return nullptr; | |
| 38 } | |
| 39 | |
| 40 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.
| |
| 41 | |
| 42 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
| |
| 43 { | |
| 44 switch (T) { | |
| 45 case SerializeAsString: | |
| 46 return serializeString(m_string); | |
| 47 case SerializeAsCustomIdentifier: | |
| 48 return quoteCSSStringIfNeeded(m_string); | |
| 49 case SerializeAsURI: | |
| 50 return "url(" + quoteCSSURLIfNeeded(m_string) + ")"; | |
| 51 } | |
| 52 ASSERT_NOT_REACHED(); | |
| 53 return String(); | |
| 54 } | |
| 55 | |
| 56 bool equals(const CSSStringValueBase& other) const | |
| 57 { | |
| 58 return m_string == other.m_string; | |
| 59 } | |
| 60 | |
| 61 DEFINE_INLINE_TRACE_AFTER_DISPATCH() | |
| 62 { | |
| 63 CSSValue::traceAfterDispatch(visitor); | |
| 64 } | |
| 65 | |
| 66 private: | |
| 67 CSSStringValueBase(const String& str, ClassType type) | |
| 68 : CSSValue(type) | |
| 69 , m_string(str) { } | |
| 70 | |
| 71 String m_string; | |
| 72 }; | |
| 73 | |
| 74 using CSSStringValue = CSSStringValueBase<SerializeAsString>; | |
| 75 using CSSIdentValue = CSSStringValueBase<SerializeAsCustomIdentifier>; | |
| 76 using CSSURIValue = CSSStringValueBase<SerializeAsURI>; | |
| 77 | |
| 78 DEFINE_CSS_VALUE_TYPE_CASTS(CSSStringValue, isStringValue()); | |
| 79 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
| |
| 80 DEFINE_CSS_VALUE_TYPE_CASTS(CSSURIValue, isURIValue()); | |
| 81 | |
| 82 } // namespace | |
| 83 | |
| 84 #endif // CSSStringValue_h | |
| OLD | NEW |