Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/StyleAutoColor.h |
| diff --git a/third_party/WebKit/Source/core/css/StyleAutoColor.h b/third_party/WebKit/Source/core/css/StyleAutoColor.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..40045fbd0167e63a91cbe0622f8cebbda3de7c57 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/css/StyleAutoColor.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef StyleAutoColor_h |
| +#define StyleAutoColor_h |
| + |
| +#include "core/css/StyleColor.h" |
| +#include "platform/graphics/Color.h" |
| +#include "wtf/Allocator.h" |
| + |
| +namespace blink { |
| + |
| +class StyleAutoColor { |
| + DISALLOW_NEW(); |
| + |
| + public: |
| + 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.
|
| + StyleAutoColor(Color color) |
| + : m_type(ValueType::SpecifiedColor), m_color(color) {} |
| + static StyleAutoColor autoColor() { return StyleAutoColor(); } |
| + static StyleAutoColor currentColor() { |
| + return StyleAutoColor(ValueType::CurrentColor); |
| + } |
| + |
| + bool isAutoColor() const { return m_type == ValueType::Auto; } |
| + bool isCurrentColor() const { return m_type == ValueType::CurrentColor; } |
| + Color color() const { |
| + DCHECK(m_type == ValueType::SpecifiedColor); |
| + return m_color; |
| + } |
| + |
| + Color resolve(Color currentColor) const { |
| + return m_type == ValueType::SpecifiedColor ? m_color : currentColor; |
| + } |
| + |
| + StyleColor toStyleColor() const { |
| + if (m_type == ValueType::SpecifiedColor) |
| + return StyleColor(m_color); |
| + return StyleColor::currentColor(); |
| + } |
| + |
| + private: |
| + enum class ValueType { Auto, CurrentColor, SpecifiedColor }; |
| + StyleAutoColor(ValueType type) : m_type(type) {} |
| + |
| + ValueType m_type; |
| + Color m_color; |
| +}; |
| + |
| +inline bool operator==(const StyleAutoColor& a, const StyleAutoColor& b) { |
| + if (a.isAutoColor() || b.isAutoColor()) |
| + return a.isAutoColor() && b.isAutoColor(); |
| + if (a.isCurrentColor() || b.isCurrentColor()) |
| + return a.isCurrentColor() && b.isCurrentColor(); |
| + return a.color() == b.color(); |
| +} |
| + |
| +inline bool operator!=(const StyleAutoColor& a, const StyleAutoColor& b) { |
| + return !(a == b); |
| +} |
| + |
| +} // namespace blink |
| + |
| +#endif // StyleAutoColor_h |