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 | |
10 namespace blink { | |
11 | |
12 class StyleAutoColor : public StyleColor { | |
Timothy Loh
2016/11/28 03:11:21
This is a weird use of inheritance because it brea
Manuel Rego
2016/11/28 10:47:55
Ok, yeah I had doubts about what to do. I'll creat
| |
13 DISALLOW_NEW(); | |
14 | |
15 public: | |
16 StyleAutoColor() : m_autoColor(true) { setCurrentColor(false); } | |
17 StyleAutoColor(Color color) : StyleColor(color), m_autoColor(false) {} | |
18 static StyleAutoColor autoColor() { return StyleAutoColor(); } | |
19 static StyleAutoColor currentColor() { | |
20 StyleAutoColor currentColor; | |
21 currentColor.m_autoColor = false; | |
22 currentColor.setCurrentColor(true); | |
23 return currentColor; | |
24 } | |
25 | |
26 bool isAutoColor() const { return m_autoColor; } | |
27 Color getColor() const { | |
28 DCHECK(!isAutoColor()); | |
29 DCHECK(!isCurrentColor()); | |
30 return color(); | |
31 } | |
32 | |
33 Color resolve(Color currentColor) const { | |
34 return isAutoColor() || isCurrentColor() ? currentColor : color(); | |
35 } | |
36 | |
37 private: | |
38 bool m_autoColor; | |
39 }; | |
40 | |
41 inline bool operator==(const StyleAutoColor& a, const StyleAutoColor& b) { | |
42 if (a.isAutoColor() || b.isAutoColor()) | |
43 return a.isAutoColor() && b.isAutoColor(); | |
44 if (a.isCurrentColor() || b.isCurrentColor()) | |
45 return a.isCurrentColor() && b.isCurrentColor(); | |
46 return a.getColor() == b.getColor(); | |
47 } | |
48 | |
49 inline bool operator!=(const StyleAutoColor& a, const StyleAutoColor& b) { | |
50 return !(a == b); | |
51 } | |
52 | |
53 } // namespace blink | |
54 | |
55 #endif // StyleAutoColor_h | |
OLD | NEW |