OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Antti Koivisto (koivisto@kde.org) | 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) | 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 23 matching lines...) Expand all Loading... |
34 namespace blink { | 34 namespace blink { |
35 | 35 |
36 class BorderValue { | 36 class BorderValue { |
37 DISALLOW_NEW(); | 37 DISALLOW_NEW(); |
38 friend class ComputedStyle; | 38 friend class ComputedStyle; |
39 | 39 |
40 public: | 40 public: |
41 BorderValue() | 41 BorderValue() |
42 : color_(0), | 42 : color_(0), |
43 color_is_current_color_(true), | 43 color_is_current_color_(true), |
44 style_(kBorderStyleNone), | 44 style_(static_cast<unsigned>(EBorderStyle::kNone)), |
45 is_auto_(kOutlineIsAutoOff) { | 45 is_auto_(kOutlineIsAutoOff) { |
46 SetWidth(3); | 46 SetWidth(3); |
47 } | 47 } |
48 | 48 |
49 BorderValue(const BorderStyle& data, const StyleColor& color, float width) { | 49 BorderValue(const BorderStyle& data, const StyleColor& color, float width) { |
50 SetColor(color.Resolve(Color())); | 50 SetColor(color.Resolve(Color())); |
51 SetStyle(data.Style()); | 51 SetStyle(data.Style()); |
52 SetIsAuto(data.IsAuto()); | 52 SetIsAuto(data.IsAuto()); |
53 SetWidth(width); | 53 SetWidth(width); |
54 } | 54 } |
55 | 55 |
56 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); } | 56 bool NonZero() const { |
| 57 return Width() && (style_ != static_cast<unsigned>(EBorderStyle::kNone)); |
| 58 } |
57 | 59 |
58 bool IsTransparent() const { | 60 bool IsTransparent() const { |
59 return !color_is_current_color_ && !color_.Alpha(); | 61 return !color_is_current_color_ && !color_.Alpha(); |
60 } | 62 } |
61 | 63 |
62 bool operator==(const BorderValue& o) const { | 64 bool operator==(const BorderValue& o) const { |
63 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && | 65 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && |
64 color_is_current_color_ == o.color_is_current_color_; | 66 color_is_current_color_ == o.color_is_current_color_; |
65 } | 67 } |
66 | 68 |
67 // The default width is 3px, but if the style is none we compute a value of 0 | 69 // The default width is 3px, but if the style is none we compute a value of 0 |
68 // (in ComputedStyle itself) | 70 // (in ComputedStyle itself) |
69 bool VisuallyEqual(const BorderValue& o) const { | 71 bool VisuallyEqual(const BorderValue& o) const { |
70 if (style_ == kBorderStyleNone && o.style_ == kBorderStyleNone) | 72 if (style_ == static_cast<unsigned>(EBorderStyle::kNone) && |
| 73 o.style_ == static_cast<unsigned>(EBorderStyle::kNone)) |
71 return true; | 74 return true; |
72 if (style_ == kBorderStyleHidden && o.style_ == kBorderStyleHidden) | 75 if (style_ == static_cast<unsigned>(EBorderStyle::kHidden) && |
| 76 o.style_ == static_cast<unsigned>(EBorderStyle::kHidden)) |
73 return true; | 77 return true; |
74 return *this == o; | 78 return *this == o; |
75 } | 79 } |
76 | 80 |
77 bool operator!=(const BorderValue& o) const { return !(*this == o); } | 81 bool operator!=(const BorderValue& o) const { return !(*this == o); } |
78 | 82 |
79 void SetColor(const StyleColor& color) { | 83 void SetColor(const StyleColor& color) { |
80 color_ = color.Resolve(Color()); | 84 color_ = color.Resolve(Color()); |
81 color_is_current_color_ = color.IsCurrentColor(); | 85 color_is_current_color_ = color.IsCurrentColor(); |
82 } | 86 } |
83 | 87 |
84 StyleColor GetColor() const { | 88 StyleColor GetColor() const { |
85 return color_is_current_color_ ? StyleColor::CurrentColor() | 89 return color_is_current_color_ ? StyleColor::CurrentColor() |
86 : StyleColor(color_); | 90 : StyleColor(color_); |
87 } | 91 } |
88 | 92 |
89 float Width() const { | 93 float Width() const { |
90 return static_cast<float>(width_) / kBorderWidthDenominator; | 94 return static_cast<float>(width_) / kBorderWidthDenominator; |
91 } | 95 } |
92 void SetWidth(float width) { width_ = WidthToFixedPoint(width); } | 96 void SetWidth(float width) { width_ = WidthToFixedPoint(width); } |
93 | 97 |
94 // Since precision is lost with fixed point, comparisons also have | 98 // Since precision is lost with fixed point, comparisons also have |
95 // to be done in fixed point. | 99 // to be done in fixed point. |
96 bool WidthEquals(float width) const { | 100 bool WidthEquals(float width) const { |
97 return WidthToFixedPoint(width) == width_; | 101 return WidthToFixedPoint(width) == width_; |
98 } | 102 } |
99 | 103 |
100 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } | 104 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } |
101 void SetStyle(EBorderStyle style) { style_ = style; } | 105 void SetStyle(EBorderStyle style) { style_ = static_cast<unsigned>(style); } |
102 | 106 |
103 OutlineIsAuto IsAuto() const { return static_cast<OutlineIsAuto>(is_auto_); } | 107 OutlineIsAuto IsAuto() const { return static_cast<OutlineIsAuto>(is_auto_); } |
104 void SetIsAuto(OutlineIsAuto is_auto) { is_auto_ = is_auto; } | 108 void SetIsAuto(OutlineIsAuto is_auto) { is_auto_ = is_auto; } |
105 | 109 |
106 bool ColorIsCurrentColor() const { return color_is_current_color_; } | 110 bool ColorIsCurrentColor() const { return color_is_current_color_; } |
107 void SetColorIsCurrentColor(bool color_is_current_color) { | 111 void SetColorIsCurrentColor(bool color_is_current_color) { |
108 color_is_current_color_ = static_cast<unsigned>(color_is_current_color); | 112 color_is_current_color_ = static_cast<unsigned>(color_is_current_color); |
109 } | 113 } |
110 | 114 |
111 protected: | 115 protected: |
112 static unsigned WidthToFixedPoint(float width) { | 116 static unsigned WidthToFixedPoint(float width) { |
113 DCHECK_GE(width, 0); | 117 DCHECK_GE(width, 0); |
114 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * | 118 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * |
115 kBorderWidthDenominator); | 119 kBorderWidthDenominator); |
116 } | 120 } |
117 | 121 |
118 Color color_; | 122 Color color_; |
119 unsigned color_is_current_color_ : 1; | 123 unsigned color_is_current_color_ : 1; |
120 | 124 |
121 unsigned width_ : 26; // Fixed point width | 125 unsigned width_ : 26; // Fixed point width |
122 unsigned style_ : 4; // EBorderStyle | 126 unsigned style_ : 4; // EBorderStyle |
123 | 127 |
124 // This is only used by OutlineValue but moved here to keep the bits packed. | 128 // This is only used by OutlineValue but moved here to keep the bits packed. |
125 unsigned is_auto_ : 1; // OutlineIsAuto | 129 unsigned is_auto_ : 1; // OutlineIsAuto |
126 }; | 130 }; |
127 | 131 |
128 } // namespace blink | 132 } // namespace blink |
129 | 133 |
130 #endif // BorderValue_h | 134 #endif // BorderValue_h |
OLD | NEW |