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(Color color) |
| 19 : m_type(ValueType::SpecifiedColor), m_color(color) {} |
| 20 static StyleAutoColor autoColor() { return StyleAutoColor(ValueType::Auto); } |
| 21 static StyleAutoColor currentColor() { |
| 22 return StyleAutoColor(ValueType::CurrentColor); |
| 23 } |
| 24 |
| 25 bool isAutoColor() const { return m_type == ValueType::Auto; } |
| 26 bool isCurrentColor() const { return m_type == ValueType::CurrentColor; } |
| 27 Color color() const { |
| 28 DCHECK(m_type == ValueType::SpecifiedColor); |
| 29 return m_color; |
| 30 } |
| 31 |
| 32 Color resolve(Color currentColor) const { |
| 33 return m_type == ValueType::SpecifiedColor ? m_color : currentColor; |
| 34 } |
| 35 |
| 36 StyleColor toStyleColor() const { |
| 37 if (m_type == ValueType::SpecifiedColor) |
| 38 return StyleColor(m_color); |
| 39 return StyleColor::currentColor(); |
| 40 } |
| 41 |
| 42 private: |
| 43 enum class ValueType { Auto, CurrentColor, SpecifiedColor }; |
| 44 StyleAutoColor(ValueType type) : m_type(type) {} |
| 45 |
| 46 ValueType m_type; |
| 47 Color m_color; |
| 48 }; |
| 49 |
| 50 inline bool operator==(const StyleAutoColor& a, const StyleAutoColor& b) { |
| 51 if (a.isAutoColor() || b.isAutoColor()) |
| 52 return a.isAutoColor() && b.isAutoColor(); |
| 53 if (a.isCurrentColor() || b.isCurrentColor()) |
| 54 return a.isCurrentColor() && b.isCurrentColor(); |
| 55 return a.color() == b.color(); |
| 56 } |
| 57 |
| 58 inline bool operator!=(const StyleAutoColor& a, const StyleAutoColor& b) { |
| 59 return !(a == b); |
| 60 } |
| 61 |
| 62 } // namespace blink |
| 63 |
| 64 #endif // StyleAutoColor_h |
OLD | NEW |