OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "core/CSSValueKeywords.h" | 34 #include "core/CSSValueKeywords.h" |
35 #include "platform/graphics/Color.h" | 35 #include "platform/graphics/Color.h" |
36 #include "wtf/Allocator.h" | 36 #include "wtf/Allocator.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 class StyleColor { | 40 class StyleColor { |
41 DISALLOW_NEW(); | 41 DISALLOW_NEW(); |
42 | 42 |
43 public: | 43 public: |
44 StyleColor() : m_currentColor(true) {} | 44 StyleColor() : m_type(CurrentColor) {} |
45 StyleColor(Color color) : m_color(color), m_currentColor(false) {} | 45 StyleColor(Color color) : m_color(color), m_type(SpecifiedColor) {} |
46 static StyleColor currentColor() { return StyleColor(); } | 46 static StyleColor currentColor() { return StyleColor(); } |
47 static StyleColor autoColor() { return StyleColor(AutoColor); } | |
47 | 48 |
48 bool isCurrentColor() const { return m_currentColor; } | 49 bool isAutoColor() const { return m_type == AutoColor; } |
50 bool isCurrentColor() const { return m_type == CurrentColor; } | |
49 Color getColor() const { | 51 Color getColor() const { |
50 ASSERT(!isCurrentColor()); | 52 DCHECK(!isAutoColor()); |
53 DCHECK(!isCurrentColor()); | |
51 return m_color; | 54 return m_color; |
52 } | 55 } |
53 | 56 |
54 Color resolve(Color currentColor) const { | 57 Color resolve(Color currentColor) const { |
55 return m_currentColor ? currentColor : m_color; | 58 return m_type == SpecifiedColor ? m_color : currentColor; |
56 } | 59 } |
57 | 60 |
58 static Color colorFromKeyword(CSSValueID); | 61 static Color colorFromKeyword(CSSValueID); |
59 static bool isColorKeyword(CSSValueID); | 62 static bool isColorKeyword(CSSValueID); |
60 static bool isSystemColor(CSSValueID); | 63 static bool isSystemColor(CSSValueID); |
61 | 64 |
62 private: | 65 private: |
66 enum ColorType { AutoColor, CurrentColor, SpecifiedColor }; | |
Timothy Loh
2016/11/22 02:17:35
I'd prefer if we didn't add Auto to StyleColor. Th
yosin_UTC9
2016/11/22 02:25:10
nit: Let's use |enum class|.
|ColorType| is ambig
Manuel Rego
2016/11/22 09:36:01
I can create a different class, but I don't see ho
Manuel Rego
2016/11/22 09:36:01
Good suggestion, anyway as @timloh suggested I can
| |
67 StyleColor(ColorType type) : m_type(type) {} | |
63 Color m_color; | 68 Color m_color; |
64 bool m_currentColor; | 69 ColorType m_type; |
65 }; | 70 }; |
66 | 71 |
67 inline bool operator==(const StyleColor& a, const StyleColor& b) { | 72 inline bool operator==(const StyleColor& a, const StyleColor& b) { |
68 if (a.isCurrentColor() || b.isCurrentColor()) | 73 if (a.isCurrentColor() || b.isCurrentColor()) |
69 return a.isCurrentColor() && b.isCurrentColor(); | 74 return a.isCurrentColor() && b.isCurrentColor(); |
75 if (a.isAutoColor() || b.isAutoColor()) | |
76 return a.isAutoColor() && b.isAutoColor(); | |
70 return a.getColor() == b.getColor(); | 77 return a.getColor() == b.getColor(); |
71 } | 78 } |
72 | 79 |
73 inline bool operator!=(const StyleColor& a, const StyleColor& b) { | 80 inline bool operator!=(const StyleColor& a, const StyleColor& b) { |
74 return !(a == b); | 81 return !(a == b); |
75 } | 82 } |
76 | 83 |
77 } // namespace blink | 84 } // namespace blink |
78 | 85 |
79 #endif // StyleColor_h | 86 #endif // StyleColor_h |
OLD | NEW |