Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1106)

Unified Diff: third_party/WebKit/Source/core/css/StyleAutoColor.h

Issue 2520873002: [css-ui] Add support for caret-color property (Closed)
Patch Set: Patch for landing applying suggested changes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c3bb6ea7669aaa6f642716976c754c95514ba093
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/StyleAutoColor.h
@@ -0,0 +1,64 @@
+// 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(Color color)
+ : m_type(ValueType::SpecifiedColor), m_color(color) {}
+ static StyleAutoColor autoColor() { return StyleAutoColor(ValueType::Auto); }
+ 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

Powered by Google App Engine
This is Rietveld 408576698