| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 StyleAutoColor_h | 5 #ifndef StyleAutoColor_h |
| 6 #define StyleAutoColor_h | 6 #define StyleAutoColor_h |
| 7 | 7 |
| 8 #include "core/css/StyleColor.h" | 8 #include "core/css/StyleColor.h" |
| 9 #include "platform/graphics/Color.h" | 9 #include "platform/graphics/Color.h" |
| 10 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 Color color() const { | 27 Color color() const { |
| 28 DCHECK(m_type == ValueType::SpecifiedColor); | 28 DCHECK(m_type == ValueType::SpecifiedColor); |
| 29 return m_color; | 29 return m_color; |
| 30 } | 30 } |
| 31 | 31 |
| 32 Color resolve(Color currentColor) const { | 32 Color resolve(Color currentColor) const { |
| 33 return m_type == ValueType::SpecifiedColor ? m_color : currentColor; | 33 return m_type == ValueType::SpecifiedColor ? m_color : currentColor; |
| 34 } | 34 } |
| 35 | 35 |
| 36 StyleColor toStyleColor() const { | 36 StyleColor toStyleColor() const { |
| 37 DCHECK(m_type != ValueType::Auto); |
| 37 if (m_type == ValueType::SpecifiedColor) | 38 if (m_type == ValueType::SpecifiedColor) |
| 38 return StyleColor(m_color); | 39 return StyleColor(m_color); |
| 40 DCHECK(m_type == ValueType::CurrentColor); |
| 39 return StyleColor::currentColor(); | 41 return StyleColor::currentColor(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 private: | 44 private: |
| 43 enum class ValueType { Auto, CurrentColor, SpecifiedColor }; | 45 enum class ValueType { Auto, CurrentColor, SpecifiedColor }; |
| 44 StyleAutoColor(ValueType type) : m_type(type) {} | 46 StyleAutoColor(ValueType type) : m_type(type) {} |
| 45 | 47 |
| 46 ValueType m_type; | 48 ValueType m_type; |
| 47 Color m_color; | 49 Color m_color; |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 inline bool operator==(const StyleAutoColor& a, const StyleAutoColor& b) { | 52 inline bool operator==(const StyleAutoColor& a, const StyleAutoColor& b) { |
| 51 if (a.isAutoColor() || b.isAutoColor()) | 53 if (a.isAutoColor() || b.isAutoColor()) |
| 52 return a.isAutoColor() && b.isAutoColor(); | 54 return a.isAutoColor() && b.isAutoColor(); |
| 53 if (a.isCurrentColor() || b.isCurrentColor()) | 55 if (a.isCurrentColor() || b.isCurrentColor()) |
| 54 return a.isCurrentColor() && b.isCurrentColor(); | 56 return a.isCurrentColor() && b.isCurrentColor(); |
| 55 return a.color() == b.color(); | 57 return a.color() == b.color(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 inline bool operator!=(const StyleAutoColor& a, const StyleAutoColor& b) { | 60 inline bool operator!=(const StyleAutoColor& a, const StyleAutoColor& b) { |
| 59 return !(a == b); | 61 return !(a == b); |
| 60 } | 62 } |
| 61 | 63 |
| 62 } // namespace blink | 64 } // namespace blink |
| 63 | 65 |
| 64 #endif // StyleAutoColor_h | 66 #endif // StyleAutoColor_h |
| OLD | NEW |