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 |
11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
12 * | 12 * |
13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
17 * | 17 * |
18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #ifndef BorderValue_h | 25 #ifndef BorderValue_h |
26 #define BorderValue_h | 26 #define BorderValue_h |
27 | 27 |
28 #include "core/css/StyleColor.h" | 28 #include "core/css/StyleColor.h" |
| 29 #include "core/style/BorderColorAndStyle.h" |
29 #include "core/style/ComputedStyleConstants.h" | 30 #include "core/style/ComputedStyleConstants.h" |
30 #include "platform/graphics/Color.h" | 31 #include "platform/graphics/Color.h" |
31 #include "platform/wtf/Allocator.h" | 32 #include "platform/wtf/Allocator.h" |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
34 | 35 |
35 // In order to conserve memory, the border width uses fixed point, | |
36 // which can be bitpacked. This fixed point implementation is | |
37 // essentially the same as in LayoutUnit. Six bits are used for the | |
38 // fraction, which leaves 20 bits for the integer part, making 1048575 | |
39 // the largest number. | |
40 | |
41 static const int kBorderWidthFractionalBits = 6; | |
42 static const int kBorderWidthDenominator = 1 << kBorderWidthFractionalBits; | |
43 static const int kMaxForBorderWidth = ((1 << 26) - 1) / kBorderWidthDenominator; | |
44 | |
45 class BorderValue { | 36 class BorderValue { |
46 DISALLOW_NEW(); | 37 DISALLOW_NEW(); |
47 friend class ComputedStyle; | 38 friend class ComputedStyle; |
48 | 39 |
49 public: | 40 public: |
50 BorderValue() | 41 BorderValue() |
51 : color_(0), | 42 : color_(0), |
52 color_is_current_color_(true), | 43 color_is_current_color_(true), |
53 style_(kBorderStyleNone), | 44 style_(kBorderStyleNone), |
54 is_auto_(kOutlineIsAutoOff) { | 45 is_auto_(kOutlineIsAutoOff) { |
55 SetWidth(3); | 46 SetWidth(3); |
56 } | 47 } |
57 | 48 |
| 49 BorderValue(const BorderColorAndStyle& data, float width) { |
| 50 SetColor(data.GetColor()); |
| 51 SetColorIsCurrentColor(ColorIsCurrentColor()); |
| 52 SetStyle(data.Style()); |
| 53 SetIsAuto(data.IsAuto()); |
| 54 SetWidth(width); |
| 55 } |
| 56 |
58 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); } | 57 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); } |
59 | 58 |
60 bool IsTransparent() const { | 59 bool IsTransparent() const { |
61 return !color_is_current_color_ && !color_.Alpha(); | 60 return !color_is_current_color_ && !color_.Alpha(); |
62 } | 61 } |
63 | 62 |
64 bool operator==(const BorderValue& o) const { | 63 bool operator==(const BorderValue& o) const { |
65 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && | 64 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && |
66 color_is_current_color_ == o.color_is_current_color_; | 65 color_is_current_color_ == o.color_is_current_color_; |
67 } | 66 } |
(...skipping 27 matching lines...) Expand all Loading... |
95 | 94 |
96 // Since precision is lost with fixed point, comparisons also have | 95 // Since precision is lost with fixed point, comparisons also have |
97 // to be done in fixed point. | 96 // to be done in fixed point. |
98 bool WidthEquals(float width) const { | 97 bool WidthEquals(float width) const { |
99 return WidthToFixedPoint(width) == width_; | 98 return WidthToFixedPoint(width) == width_; |
100 } | 99 } |
101 | 100 |
102 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } | 101 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } |
103 void SetStyle(EBorderStyle style) { style_ = style; } | 102 void SetStyle(EBorderStyle style) { style_ = style; } |
104 | 103 |
| 104 OutlineIsAuto IsAuto() const { return static_cast<OutlineIsAuto>(is_auto_); } |
| 105 void SetIsAuto(OutlineIsAuto is_auto) { is_auto_ = is_auto; } |
| 106 |
| 107 bool ColorIsCurrentColor() const { return color_is_current_color_; } |
| 108 void SetColorIsCurrentColor(bool color_is_current_color) { |
| 109 color_is_current_color_ = static_cast<unsigned>(color_is_current_color); |
| 110 } |
| 111 |
105 protected: | 112 protected: |
106 static unsigned WidthToFixedPoint(float width) { | 113 static unsigned WidthToFixedPoint(float width) { |
107 DCHECK_GE(width, 0); | 114 DCHECK_GE(width, 0); |
108 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * | 115 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * |
109 kBorderWidthDenominator); | 116 kBorderWidthDenominator); |
110 } | 117 } |
111 | 118 |
112 Color color_; | 119 Color color_; |
113 unsigned color_is_current_color_ : 1; | 120 unsigned color_is_current_color_ : 1; |
114 | 121 |
115 unsigned width_ : 26; // Fixed point width | 122 unsigned width_ : 26; // Fixed point width |
116 unsigned style_ : 4; // EBorderStyle | 123 unsigned style_ : 4; // EBorderStyle |
117 | 124 |
118 // This is only used by OutlineValue but moved here to keep the bits packed. | 125 // This is only used by OutlineValue but moved here to keep the bits packed. |
119 unsigned is_auto_ : 1; // OutlineIsAuto | 126 unsigned is_auto_ : 1; // OutlineIsAuto |
120 }; | 127 }; |
121 | 128 |
122 } // namespace blink | 129 } // namespace blink |
123 | 130 |
124 #endif // BorderValue_h | 131 #endif // BorderValue_h |
OLD | NEW |