OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 StyleAutoColor_h | |
6 #define StyleAutoColor_h | |
7 | |
8 #include "core/css/StyleColor.h" | |
9 #include "platform/graphics/Color.h" | |
10 #include "wtf/Allocator.h" | |
11 | |
12 namespace blink { | |
13 | |
14 class StyleAutoColor { | |
15 DISALLOW_NEW(); | |
16 | |
17 public: | |
18 StyleAutoColor() : m_type(ValueType::Auto) {} | |
Timothy Loh
2016/11/30 14:51:10
Might be nicer to omit this constructor so users o
Manuel Rego
2016/11/30 15:41:53
Ok.
| |
19 StyleAutoColor(Color color) | |
20 : m_type(ValueType::SpecifiedColor), m_color(color) {} | |
21 static StyleAutoColor autoColor() { return StyleAutoColor(); } | |
22 static StyleAutoColor currentColor() { | |
23 return StyleAutoColor(ValueType::CurrentColor); | |
24 } | |
25 | |
26 bool isAutoColor() const { return m_type == ValueType::Auto; } | |
27 bool isCurrentColor() const { return m_type == ValueType::CurrentColor; } | |
28 Color color() const { | |
29 DCHECK(m_type == ValueType::SpecifiedColor); | |
30 return m_color; | |
31 } | |
32 | |
33 Color resolve(Color currentColor) const { | |
34 return m_type == ValueType::SpecifiedColor ? m_color : currentColor; | |
35 } | |
36 | |
37 StyleColor toStyleColor() const { | |
38 if (m_type == ValueType::SpecifiedColor) | |
39 return StyleColor(m_color); | |
40 return StyleColor::currentColor(); | |
41 } | |
42 | |
43 private: | |
44 enum class ValueType { Auto, CurrentColor, SpecifiedColor }; | |
45 StyleAutoColor(ValueType type) : m_type(type) {} | |
46 | |
47 ValueType m_type; | |
48 Color m_color; | |
49 }; | |
50 | |
51 inline bool operator==(const StyleAutoColor& a, const StyleAutoColor& b) { | |
52 if (a.isAutoColor() || b.isAutoColor()) | |
53 return a.isAutoColor() && b.isAutoColor(); | |
54 if (a.isCurrentColor() || b.isCurrentColor()) | |
55 return a.isCurrentColor() && b.isCurrentColor(); | |
56 return a.color() == b.color(); | |
57 } | |
58 | |
59 inline bool operator!=(const StyleAutoColor& a, const StyleAutoColor& b) { | |
60 return !(a == b); | |
61 } | |
62 | |
63 } // namespace blink | |
64 | |
65 #endif // StyleAutoColor_h | |
OLD | NEW |