Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/core/style/BorderValue.h

Issue 2880573002: Store border-*-style on SurroundData in ComputedStyle (Closed)
Patch Set: Store border-*-style on SurroundData in ComputedStyle not BorderStyle Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/BorderStyle.h"
30 #include "core/style/ComputedStyleConstants.h" 29 #include "core/style/ComputedStyleConstants.h"
31 #include "platform/graphics/Color.h" 30 #include "platform/graphics/Color.h"
32 #include "platform/wtf/Allocator.h" 31 #include "platform/wtf/Allocator.h"
33 32
34 namespace blink { 33 namespace blink {
35 34
36 class BorderValue { 35 class BorderValue {
37 DISALLOW_NEW(); 36 DISALLOW_NEW();
38 friend class ComputedStyle; 37 friend class ComputedStyle;
39 38
40 public: 39 public:
41 BorderValue() 40 BorderValue()
42 : color_(0), 41 : color_(0),
43 color_is_current_color_(true), 42 color_is_current_color_(true),
44 style_(kBorderStyleNone), 43 style_(static_cast<unsigned>(EBorderStyle::kNone)),
45 is_auto_(kOutlineIsAutoOff) { 44 is_auto_(kOutlineIsAutoOff) {
46 SetWidth(3); 45 SetWidth(3);
47 } 46 }
48 47
49 BorderValue(const BorderStyle& data, const StyleColor& color, float width) { 48 BorderValue(EBorderStyle style, const StyleColor& color, float width) {
50 SetColor(color.Resolve(Color())); 49 SetColor(color.Resolve(Color()));
51 SetStyle(data.Style()); 50 SetStyle(style);
52 SetIsAuto(data.IsAuto());
53 SetWidth(width); 51 SetWidth(width);
54 } 52 }
55 53
56 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); } 54 bool NonZero() const {
55 return Width() && (style_ != static_cast<unsigned>(EBorderStyle::kNone));
56 }
57 57
58 bool IsTransparent() const { 58 bool IsTransparent() const {
59 return !color_is_current_color_ && !color_.Alpha(); 59 return !color_is_current_color_ && !color_.Alpha();
60 } 60 }
61 61
62 bool operator==(const BorderValue& o) const { 62 bool operator==(const BorderValue& o) const {
63 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && 63 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ &&
64 color_is_current_color_ == o.color_is_current_color_; 64 color_is_current_color_ == o.color_is_current_color_;
65 } 65 }
66 66
67 // The default width is 3px, but if the style is none we compute a value of 0 67 // The default width is 3px, but if the style is none we compute a value of 0
68 // (in ComputedStyle itself) 68 // (in ComputedStyle itself)
69 bool VisuallyEqual(const BorderValue& o) const { 69 bool VisuallyEqual(const BorderValue& o) const {
70 if (style_ == kBorderStyleNone && o.style_ == kBorderStyleNone) 70 if (style_ == static_cast<unsigned>(EBorderStyle::kNone) &&
71 o.style_ == static_cast<unsigned>(EBorderStyle::kNone))
71 return true; 72 return true;
72 if (style_ == kBorderStyleHidden && o.style_ == kBorderStyleHidden) 73 if (style_ == static_cast<unsigned>(EBorderStyle::kHidden) &&
74 o.style_ == static_cast<unsigned>(EBorderStyle::kHidden))
73 return true; 75 return true;
74 return *this == o; 76 return *this == o;
75 } 77 }
76 78
77 bool operator!=(const BorderValue& o) const { return !(*this == o); } 79 bool operator!=(const BorderValue& o) const { return !(*this == o); }
78 80
79 void SetColor(const StyleColor& color) { 81 void SetColor(const StyleColor& color) {
80 color_ = color.Resolve(Color()); 82 color_ = color.Resolve(Color());
81 color_is_current_color_ = color.IsCurrentColor(); 83 color_is_current_color_ = color.IsCurrentColor();
82 } 84 }
83 85
84 StyleColor GetColor() const { 86 StyleColor GetColor() const {
85 return color_is_current_color_ ? StyleColor::CurrentColor() 87 return color_is_current_color_ ? StyleColor::CurrentColor()
86 : StyleColor(color_); 88 : StyleColor(color_);
87 } 89 }
88 90
89 float Width() const { 91 float Width() const {
90 return static_cast<float>(width_) / kBorderWidthDenominator; 92 return static_cast<float>(width_) / kBorderWidthDenominator;
91 } 93 }
92 void SetWidth(float width) { width_ = WidthToFixedPoint(width); } 94 void SetWidth(float width) { width_ = WidthToFixedPoint(width); }
93 95
94 // Since precision is lost with fixed point, comparisons also have 96 // Since precision is lost with fixed point, comparisons also have
95 // to be done in fixed point. 97 // to be done in fixed point.
96 bool WidthEquals(float width) const { 98 bool WidthEquals(float width) const {
97 return WidthToFixedPoint(width) == width_; 99 return WidthToFixedPoint(width) == width_;
98 } 100 }
99 101
100 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } 102 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); }
101 void SetStyle(EBorderStyle style) { style_ = style; } 103 void SetStyle(EBorderStyle style) { style_ = static_cast<unsigned>(style); }
102 104
103 OutlineIsAuto IsAuto() const { return static_cast<OutlineIsAuto>(is_auto_); } 105 OutlineIsAuto IsAuto() const { return static_cast<OutlineIsAuto>(is_auto_); }
104 void SetIsAuto(OutlineIsAuto is_auto) { is_auto_ = is_auto; } 106 void SetIsAuto(OutlineIsAuto is_auto) { is_auto_ = is_auto; }
105 107
106 bool ColorIsCurrentColor() const { return color_is_current_color_; } 108 bool ColorIsCurrentColor() const { return color_is_current_color_; }
107 void SetColorIsCurrentColor(bool color_is_current_color) { 109 void SetColorIsCurrentColor(bool color_is_current_color) {
108 color_is_current_color_ = static_cast<unsigned>(color_is_current_color); 110 color_is_current_color_ = static_cast<unsigned>(color_is_current_color);
109 } 111 }
110 112
111 protected: 113 protected:
112 static unsigned WidthToFixedPoint(float width) { 114 static unsigned WidthToFixedPoint(float width) {
113 DCHECK_GE(width, 0); 115 DCHECK_GE(width, 0);
114 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * 116 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) *
115 kBorderWidthDenominator); 117 kBorderWidthDenominator);
116 } 118 }
117 119
118 Color color_; 120 Color color_;
119 unsigned color_is_current_color_ : 1; 121 unsigned color_is_current_color_ : 1;
120 122
121 unsigned width_ : 26; // Fixed point width 123 unsigned width_ : 26; // Fixed point width
122 unsigned style_ : 4; // EBorderStyle 124 unsigned style_ : 4; // EBorderStyle
123 125
124 // This is only used by OutlineValue but moved here to keep the bits packed. 126 // This is only used by OutlineValue but moved here to keep the bits packed.
125 unsigned is_auto_ : 1; // OutlineIsAuto 127 unsigned is_auto_ : 1; // OutlineIsAuto
126 }; 128 };
127 129
128 } // namespace blink 130 } // namespace blink
129 131
130 #endif // BorderValue_h 132 #endif // BorderValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698