| 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 // In order to conserve memory, the border width uses fixed point, |
| 36 // which can be bitpacked. This fixed point implementation is | 37 // which can be bitpacked. This fixed point implementation is |
| 37 // essentially the same as in LayoutUnit. Six bits are used for the | 38 // 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 // fraction, which leaves 20 bits for the integer part, making 1048575 |
| 39 // the largest number. | 40 // the largest number. |
| 40 | 41 |
| 41 static const int kBorderWidthFractionalBits = 6; | 42 static const int kBorderWidthFractionalBits = 6; |
| 42 static const int kBorderWidthDenominator = 1 << kBorderWidthFractionalBits; | 43 static const int kBorderWidthDenominator = 1 << kBorderWidthFractionalBits; |
| 43 static const int kMaxForBorderWidth = ((1 << 26) - 1) / kBorderWidthDenominator; | 44 static const int kMaxForBorderWidth = ((1 << 26) - 1) / kBorderWidthDenominator; |
| 44 | 45 |
| 45 class BorderValue { | 46 class BorderValue { |
| 46 DISALLOW_NEW(); | |
| 47 friend class ComputedStyle; | 47 friend class ComputedStyle; |
| 48 | 48 |
| 49 public: | 49 public: |
| 50 BorderValue() | 50 BorderValue() |
| 51 : color_(0), | 51 : color_(0), |
| 52 color_is_current_color_(true), | 52 color_is_current_color_(true), |
| 53 style_(kBorderStyleNone), | 53 style_(kBorderStyleNone), |
| 54 is_auto_(kOutlineIsAutoOff) { | 54 is_auto_(kOutlineIsAutoOff) { |
| 55 SetWidth(3); | 55 SetWidth(3); |
| 56 } | 56 } |
| 57 | 57 |
| 58 BorderValue(const BorderColorAndStyle& data, const float width) { |
| 59 SetColor(data.GetColor()); |
| 60 SetColorIsCurrentColor(ColorIsCurrentColor()); |
| 61 SetStyle(data.Style()); |
| 62 SetIsAuto(data.IsAuto()); |
| 63 SetWidth(width); |
| 64 } |
| 65 |
| 58 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); } | 66 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); } |
| 59 | 67 |
| 60 bool IsTransparent() const { | 68 bool IsTransparent() const { |
| 61 return !color_is_current_color_ && !color_.Alpha(); | 69 return !color_is_current_color_ && !color_.Alpha(); |
| 62 } | 70 } |
| 63 | 71 |
| 64 bool operator==(const BorderValue& o) const { | 72 bool operator==(const BorderValue& o) const { |
| 65 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && | 73 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && |
| 66 color_is_current_color_ == o.color_is_current_color_; | 74 color_is_current_color_ == o.color_is_current_color_; |
| 67 } | 75 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 95 | 103 |
| 96 // Since precision is lost with fixed point, comparisons also have | 104 // Since precision is lost with fixed point, comparisons also have |
| 97 // to be done in fixed point. | 105 // to be done in fixed point. |
| 98 bool WidthEquals(float width) const { | 106 bool WidthEquals(float width) const { |
| 99 return WidthToFixedPoint(width) == width_; | 107 return WidthToFixedPoint(width) == width_; |
| 100 } | 108 } |
| 101 | 109 |
| 102 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } | 110 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } |
| 103 void SetStyle(EBorderStyle style) { style_ = style; } | 111 void SetStyle(EBorderStyle style) { style_ = style; } |
| 104 | 112 |
| 113 OutlineIsAuto IsAuto() const { return static_cast<OutlineIsAuto>(is_auto_); } |
| 114 void SetIsAuto(OutlineIsAuto is_auto) { is_auto_ = is_auto; } |
| 115 |
| 116 bool ColorIsCurrentColor() const { return color_is_current_color_; } |
| 117 void SetColorIsCurrentColor(bool color_is_current_color) { |
| 118 color_is_current_color_ = static_cast<unsigned>(color_is_current_color); |
| 119 } |
| 120 |
| 105 protected: | 121 protected: |
| 106 static unsigned WidthToFixedPoint(float width) { | 122 static unsigned WidthToFixedPoint(float width) { |
| 107 DCHECK_GE(width, 0); | 123 DCHECK_GE(width, 0); |
| 108 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * | 124 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * |
| 109 kBorderWidthDenominator); | 125 kBorderWidthDenominator); |
| 110 } | 126 } |
| 111 | 127 |
| 112 Color color_; | 128 Color color_; |
| 113 unsigned color_is_current_color_ : 1; | 129 unsigned color_is_current_color_ : 1; |
| 114 | 130 |
| 115 unsigned width_ : 26; // Fixed point width | 131 unsigned width_ : 26; // Fixed point width |
| 116 unsigned style_ : 4; // EBorderStyle | 132 unsigned style_ : 4; // EBorderStyle |
| 117 | 133 |
| 118 // This is only used by OutlineValue but moved here to keep the bits packed. | 134 // This is only used by OutlineValue but moved here to keep the bits packed. |
| 119 unsigned is_auto_ : 1; // OutlineIsAuto | 135 unsigned is_auto_ : 1; // OutlineIsAuto |
| 120 }; | 136 }; |
| 121 | 137 |
| 122 } // namespace blink | 138 } // namespace blink |
| 123 | 139 |
| 124 #endif // BorderValue_h | 140 #endif // BorderValue_h |
| OLD | NEW |