OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CSSVariableData_h | 5 #ifndef CSSVariableData_h |
6 #define CSSVariableData_h | 6 #define CSSVariableData_h |
7 | 7 |
8 #include "core/css/StylePropertySet.h" | 8 #include "core/css/StylePropertySet.h" |
9 #include "core/css/parser/CSSParserToken.h" | 9 #include "core/css/parser/CSSParserToken.h" |
10 #include "core/css/parser/CSSParserTokenRange.h" | 10 #include "core/css/parser/CSSParserTokenRange.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 public: | 24 public: |
25 static PassRefPtr<CSSVariableData> Create(const CSSParserTokenRange& range, | 25 static PassRefPtr<CSSVariableData> Create(const CSSParserTokenRange& range, |
26 bool is_animation_tainted, | 26 bool is_animation_tainted, |
27 bool needs_variable_resolution) { | 27 bool needs_variable_resolution) { |
28 return AdoptRef(new CSSVariableData(range, is_animation_tainted, | 28 return AdoptRef(new CSSVariableData(range, is_animation_tainted, |
29 needs_variable_resolution)); | 29 needs_variable_resolution)); |
30 } | 30 } |
31 | 31 |
32 static PassRefPtr<CSSVariableData> CreateResolved( | 32 static PassRefPtr<CSSVariableData> CreateResolved( |
33 const Vector<CSSParserToken>& resolved_tokens, | 33 const Vector<CSSParserToken>& resolved_tokens, |
34 const CSSVariableData& unresolved_data, | 34 Vector<String> backing_strings, |
35 bool is_animation_tainted) { | 35 bool is_animation_tainted) { |
36 return AdoptRef(new CSSVariableData(resolved_tokens, | 36 return AdoptRef(new CSSVariableData( |
37 unresolved_data.backing_string_, | 37 resolved_tokens, std::move(backing_strings), is_animation_tainted)); |
38 is_animation_tainted)); | |
39 } | 38 } |
40 | 39 |
41 CSSParserTokenRange TokenRange() const { return tokens_; } | 40 CSSParserTokenRange TokenRange() const { return tokens_; } |
42 | 41 |
43 const Vector<CSSParserToken>& Tokens() const { return tokens_; } | 42 const Vector<CSSParserToken>& Tokens() const { return tokens_; } |
| 43 const Vector<String>& BackingStrings() const { return backing_strings_; } |
44 | 44 |
45 bool operator==(const CSSVariableData& other) const; | 45 bool operator==(const CSSVariableData& other) const; |
46 | 46 |
47 bool IsAnimationTainted() const { return is_animation_tainted_; } | 47 bool IsAnimationTainted() const { return is_animation_tainted_; } |
48 | 48 |
49 bool NeedsVariableResolution() const { return needs_variable_resolution_; } | 49 bool NeedsVariableResolution() const { return needs_variable_resolution_; } |
50 | 50 |
51 const CSSValue* ParseForSyntax(const CSSSyntaxDescriptor&) const; | 51 const CSSValue* ParseForSyntax(const CSSSyntaxDescriptor&) const; |
52 | 52 |
53 StylePropertySet* PropertySet(); | 53 StylePropertySet* PropertySet(); |
54 | 54 |
55 private: | 55 private: |
56 CSSVariableData(const CSSParserTokenRange&, | 56 CSSVariableData(const CSSParserTokenRange&, |
57 bool is_animation_tainted, | 57 bool is_animation_tainted, |
58 bool needs_variable_resolution); | 58 bool needs_variable_resolution); |
59 | 59 |
60 // We can safely copy the tokens (which have raw pointers to substrings) | |
61 // because StylePropertySets contain references to | |
62 // CSSCustomPropertyDeclarations, which point to the unresolved | |
63 // CSSVariableData values that own the backing strings this will potentially | |
64 // reference. | |
65 CSSVariableData(const Vector<CSSParserToken>& resolved_tokens, | 60 CSSVariableData(const Vector<CSSParserToken>& resolved_tokens, |
66 String backing_string, | 61 Vector<String> backing_strings, |
67 bool is_animation_tainted) | 62 bool is_animation_tainted) |
68 : backing_string_(backing_string), | 63 : backing_strings_(std::move(backing_strings)), |
69 tokens_(resolved_tokens), | 64 tokens_(resolved_tokens), |
70 is_animation_tainted_(is_animation_tainted), | 65 is_animation_tainted_(is_animation_tainted), |
71 needs_variable_resolution_(false), | 66 needs_variable_resolution_(false), |
72 cached_property_set_(false) {} | 67 cached_property_set_(false) {} |
73 | 68 |
74 void ConsumeAndUpdateTokens(const CSSParserTokenRange&); | 69 void ConsumeAndUpdateTokens(const CSSParserTokenRange&); |
75 template <typename CharacterType> | |
76 void UpdateTokens(const CSSParserTokenRange&); | |
77 | 70 |
78 String backing_string_; | 71 // tokens_ may have raw pointers to string data, we store the String objects |
| 72 // owning that data in backing_strings_ to keep it alive alongside the |
| 73 // tokens_. |
| 74 Vector<String> backing_strings_; |
79 Vector<CSSParserToken> tokens_; | 75 Vector<CSSParserToken> tokens_; |
80 const bool is_animation_tainted_; | 76 const bool is_animation_tainted_; |
81 const bool needs_variable_resolution_; | 77 const bool needs_variable_resolution_; |
82 | 78 |
83 // Parsed representation for @apply | 79 // Parsed representation for @apply |
84 bool cached_property_set_; | 80 bool cached_property_set_; |
85 Persistent<StylePropertySet> property_set_; | 81 Persistent<StylePropertySet> property_set_; |
86 }; | 82 }; |
87 | 83 |
88 } // namespace blink | 84 } // namespace blink |
89 | 85 |
90 #endif // CSSVariableData_h | 86 #endif // CSSVariableData_h |
OLD | NEW |