1 // Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_INITIAL_DATA_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_INITIAL_DATA_H_ 7 8 #include "base/memory/ptr_util.h" 9 #include "third_party/blink/renderer/core/css/css_value.h" 10 #include "third_party/blink/renderer/core/style/style_variables.h" 11 #include "third_party/blink/renderer/platform/heap/persistent.h" 12 #include "third_party/blink/renderer/platform/wtf/forward.h" 13 #include "third_party/blink/renderer/platform/wtf/hash_map.h" 14 #include "third_party/blink/renderer/platform/wtf/text/atomic_string_hash.h" 15 16 namespace blink { 17 18 class PropertyRegistry; 19 20 // Holds data stored on the initial ComputedStyle only. 21 // 22 // An instance of this class is created once, and then shared between all the 23 // ComputedStyles that inherit (directly or indirectly) from the initial style. 24 class CORE_EXPORT StyleInitialData : public RefCounted<StyleInitialData> { 25 public: Create(const PropertyRegistry & registry)26 static scoped_refptr<StyleInitialData> Create( 27 const PropertyRegistry& registry) { 28 return base::AdoptRef(new StyleInitialData(registry)); 29 } 30 31 bool operator==(const StyleInitialData& other) const; 32 bool operator!=(const StyleInitialData& other) const { 33 return !(*this == other); 34 } 35 HasInitialVariables()36 bool HasInitialVariables() const { return !variables_.IsEmpty(); } 37 CollectVariableNames(HashSet<AtomicString> & names)38 void CollectVariableNames(HashSet<AtomicString>& names) const { 39 return variables_.CollectNames(names); 40 } 41 GetVariableData(const AtomicString & name)42 CSSVariableData* GetVariableData(const AtomicString& name) const { 43 return variables_.GetData(name).value_or(nullptr); 44 } 45 GetVariableValue(const AtomicString & name)46 const CSSValue* GetVariableValue(const AtomicString& name) const { 47 return variables_.GetValue(name).value_or(nullptr); 48 } 49 50 private: 51 StyleInitialData(const PropertyRegistry&); 52 53 // Initial values for all registered properties. This is set on 54 // the initial style, and then shared with all other styles that directly or 55 // indirectly inherit from that. 56 StyleVariables variables_; 57 }; 58 59 } // namespace blink 60 61 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_INITIAL_DATA_H_ 62