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 14 matching lines...) Expand all Loading... |
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/ComputedStyleConstants.h" | 29 #include "core/style/ComputedStyleConstants.h" |
30 #include "platform/graphics/Color.h" | 30 #include "platform/graphics/Color.h" |
31 #include "wtf/Allocator.h" | 31 #include "wtf/Allocator.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
| 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 |
35 class BorderValue { | 45 class BorderValue { |
36 DISALLOW_NEW(); | 46 DISALLOW_NEW(); |
37 friend class ComputedStyle; | 47 friend class ComputedStyle; |
38 | 48 |
39 public: | 49 public: |
40 BorderValue() | 50 BorderValue() |
41 : m_color(0), | 51 : m_color(0), |
42 m_colorIsCurrentColor(true), | 52 m_colorIsCurrentColor(true), |
43 m_width(3), | |
44 m_style(BorderStyleNone), | 53 m_style(BorderStyleNone), |
45 m_isAuto(OutlineIsAutoOff) {} | 54 m_isAuto(OutlineIsAutoOff) { |
| 55 setWidth(3); |
| 56 } |
46 | 57 |
47 bool nonZero() const { return width() && (m_style != BorderStyleNone); } | 58 bool nonZero() const { return width() && (m_style != BorderStyleNone); } |
48 | 59 |
49 bool isTransparent() const { | 60 bool isTransparent() const { |
50 return !m_colorIsCurrentColor && !m_color.alpha(); | 61 return !m_colorIsCurrentColor && !m_color.alpha(); |
51 } | 62 } |
52 | 63 |
53 bool operator==(const BorderValue& o) const { | 64 bool operator==(const BorderValue& o) const { |
54 return m_width == o.m_width && m_style == o.m_style && | 65 return m_width == o.m_width && m_style == o.m_style && |
55 m_color == o.m_color && | 66 m_color == o.m_color && |
(...skipping 15 matching lines...) Expand all Loading... |
71 void setColor(const StyleColor& color) { | 82 void setColor(const StyleColor& color) { |
72 m_color = color.resolve(Color()); | 83 m_color = color.resolve(Color()); |
73 m_colorIsCurrentColor = color.isCurrentColor(); | 84 m_colorIsCurrentColor = color.isCurrentColor(); |
74 } | 85 } |
75 | 86 |
76 StyleColor color() const { | 87 StyleColor color() const { |
77 return m_colorIsCurrentColor ? StyleColor::currentColor() | 88 return m_colorIsCurrentColor ? StyleColor::currentColor() |
78 : StyleColor(m_color); | 89 : StyleColor(m_color); |
79 } | 90 } |
80 | 91 |
81 int width() const { return m_width; } | 92 float width() const { |
| 93 return static_cast<float>(m_width) / kBorderWidthDenominator; |
| 94 } |
| 95 void setWidth(float width) { m_width = widthToFixedPoint(width); } |
| 96 |
| 97 // Since precision is lost with fixed point, comparisons also have |
| 98 // to be done in fixed point. |
| 99 bool widthEquals(float width) const { |
| 100 return widthToFixedPoint(width) == m_width; |
| 101 } |
82 | 102 |
83 EBorderStyle style() const { return static_cast<EBorderStyle>(m_style); } | 103 EBorderStyle style() const { return static_cast<EBorderStyle>(m_style); } |
84 void setStyle(EBorderStyle style) { m_style = style; } | 104 void setStyle(EBorderStyle style) { m_style = style; } |
85 | 105 |
86 protected: | 106 protected: |
| 107 static unsigned widthToFixedPoint(float width) { |
| 108 DCHECK_GE(width, 0); |
| 109 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * |
| 110 kBorderWidthDenominator); |
| 111 } |
| 112 |
87 Color m_color; | 113 Color m_color; |
88 unsigned m_colorIsCurrentColor : 1; | 114 unsigned m_colorIsCurrentColor : 1; |
89 | 115 |
90 unsigned m_width : 26; | 116 unsigned m_width : 26; // Fixed point width |
91 unsigned m_style : 4; // EBorderStyle | 117 unsigned m_style : 4; // EBorderStyle |
92 | 118 |
93 // This is only used by OutlineValue but moved here to keep the bits packed. | 119 // This is only used by OutlineValue but moved here to keep the bits packed. |
94 unsigned m_isAuto : 1; // OutlineIsAuto | 120 unsigned m_isAuto : 1; // OutlineIsAuto |
95 }; | 121 }; |
96 | 122 |
97 } // namespace blink | 123 } // namespace blink |
98 | 124 |
99 #endif // BorderValue_h | 125 #endif // BorderValue_h |
OLD | NEW |