1 // Copyright 2014 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_ANIMATION_CSS_CSS_TRANSITION_DATA_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_TRANSITION_DATA_H_
7 
8 #include <memory>
9 
10 #include "base/memory/ptr_util.h"
11 #include "third_party/blink/renderer/core/animation/css/css_timing_data.h"
12 #include "third_party/blink/renderer/core/css/css_property_names.h"
13 #include "third_party/blink/renderer/platform/wtf/vector.h"
14 
15 namespace blink {
16 
17 class CORE_EXPORT CSSTransitionData final : public CSSTimingData {
18  public:
19   enum TransitionPropertyType {
20     kTransitionNone,
21     kTransitionKnownProperty,
22     kTransitionUnknownProperty,
23   };
24 
25   // FIXME: We shouldn't allow 'none' to be used alongside other properties.
26   struct TransitionProperty {
27     DISALLOW_NEW();
TransitionPropertyTransitionProperty28     TransitionProperty(CSSPropertyID id)
29         : property_type(kTransitionKnownProperty), unresolved_property(id) {
30       DCHECK_NE(id, CSSPropertyID::kInvalid);
31     }
32 
TransitionPropertyTransitionProperty33     TransitionProperty(const AtomicString& string)
34         : property_type(kTransitionUnknownProperty),
35           unresolved_property(CSSPropertyID::kInvalid),
36           property_string(string) {}
37 
TransitionPropertyTransitionProperty38     TransitionProperty(TransitionPropertyType type)
39         : property_type(type), unresolved_property(CSSPropertyID::kInvalid) {
40       DCHECK_EQ(type, kTransitionNone);
41     }
42 
43     bool operator==(const TransitionProperty& other) const {
44       return property_type == other.property_type &&
45              unresolved_property == other.unresolved_property &&
46              property_string == other.property_string;
47     }
48 
49     TransitionPropertyType property_type;
50     CSSPropertyID unresolved_property;
51     AtomicString property_string;
52   };
53 
Clone()54   std::unique_ptr<CSSTransitionData> Clone() {
55     return base::WrapUnique(new CSSTransitionData(*this));
56   }
57 
58   CSSTransitionData();
59   explicit CSSTransitionData(const CSSTransitionData&);
60 
61   bool TransitionsMatchForStyleRecalc(const CSSTransitionData& other) const;
62   bool operator==(const CSSTransitionData& other) const {
63     return TransitionsMatchForStyleRecalc(other);
64   }
65 
66   Timing ConvertToTiming(size_t index) const;
67 
PropertyList()68   const Vector<TransitionProperty>& PropertyList() const {
69     return property_list_;
70   }
PropertyList()71   Vector<TransitionProperty>& PropertyList() { return property_list_; }
72 
InitialProperty()73   static TransitionProperty InitialProperty() {
74     return TransitionProperty(CSSPropertyID::kAll);
75   }
76 
77  private:
78   Vector<TransitionProperty> property_list_;
79 };
80 
81 }  // namespace blink
82 
83 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_CSS_TRANSITION_DATA_H_
84