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

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

Issue 2861773004: Move border-*-width out of BorderValue and store on SurroundData in ComputedStyle instead (Closed)
Patch Set: shend@'s suggestions 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/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();
meade_UTC10 2017/05/09 03:25:06 Do you actually need to remove this? I couldn't fi
nainar 2017/05/09 05:48:11 This was an artefact from an old change. Removed t
47 friend class ComputedStyle; 37 friend class ComputedStyle;
48 38
49 public: 39 public:
50 BorderValue() 40 BorderValue()
51 : color_(0), 41 : color_(0),
52 color_is_current_color_(true), 42 color_is_current_color_(true),
53 style_(kBorderStyleNone), 43 style_(kBorderStyleNone),
54 is_auto_(kOutlineIsAutoOff) { 44 is_auto_(kOutlineIsAutoOff) {
55 SetWidth(3); 45 SetWidth(3);
56 } 46 }
57 47
48 BorderValue(const BorderColorAndStyle& data, float width) {
49 SetColor(data.GetColor());
50 SetColorIsCurrentColor(ColorIsCurrentColor());
51 SetStyle(data.Style());
52 SetIsAuto(data.IsAuto());
53 SetWidth(width);
54 }
55
58 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); } 56 bool NonZero() const { return Width() && (style_ != kBorderStyleNone); }
59 57
60 bool IsTransparent() const { 58 bool IsTransparent() const {
61 return !color_is_current_color_ && !color_.Alpha(); 59 return !color_is_current_color_ && !color_.Alpha();
62 } 60 }
63 61
64 bool operator==(const BorderValue& o) const { 62 bool operator==(const BorderValue& o) const {
65 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ && 63 return width_ == o.width_ && style_ == o.style_ && color_ == o.color_ &&
66 color_is_current_color_ == o.color_is_current_color_; 64 color_is_current_color_ == o.color_is_current_color_;
67 } 65 }
(...skipping 27 matching lines...) Expand all
95 93
96 // Since precision is lost with fixed point, comparisons also have 94 // Since precision is lost with fixed point, comparisons also have
97 // to be done in fixed point. 95 // to be done in fixed point.
98 bool WidthEquals(float width) const { 96 bool WidthEquals(float width) const {
99 return WidthToFixedPoint(width) == width_; 97 return WidthToFixedPoint(width) == width_;
100 } 98 }
101 99
102 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); } 100 EBorderStyle Style() const { return static_cast<EBorderStyle>(style_); }
103 void SetStyle(EBorderStyle style) { style_ = style; } 101 void SetStyle(EBorderStyle style) { style_ = style; }
104 102
103 OutlineIsAuto IsAuto() const { return static_cast<OutlineIsAuto>(is_auto_); }
104 void SetIsAuto(OutlineIsAuto is_auto) { is_auto_ = is_auto; }
105
106 bool ColorIsCurrentColor() const { return color_is_current_color_; }
107 void SetColorIsCurrentColor(bool color_is_current_color) {
108 color_is_current_color_ = static_cast<unsigned>(color_is_current_color);
109 }
110
105 protected: 111 protected:
106 static unsigned WidthToFixedPoint(float width) { 112 static unsigned WidthToFixedPoint(float width) {
107 DCHECK_GE(width, 0); 113 DCHECK_GE(width, 0);
108 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) * 114 return static_cast<unsigned>(std::min<float>(width, kMaxForBorderWidth) *
109 kBorderWidthDenominator); 115 kBorderWidthDenominator);
110 } 116 }
111 117
112 Color color_; 118 Color color_;
113 unsigned color_is_current_color_ : 1; 119 unsigned color_is_current_color_ : 1;
114 120
115 unsigned width_ : 26; // Fixed point width 121 unsigned width_ : 26; // Fixed point width
116 unsigned style_ : 4; // EBorderStyle 122 unsigned style_ : 4; // EBorderStyle
117 123
118 // This is only used by OutlineValue but moved here to keep the bits packed. 124 // This is only used by OutlineValue but moved here to keep the bits packed.
119 unsigned is_auto_ : 1; // OutlineIsAuto 125 unsigned is_auto_ : 1; // OutlineIsAuto
120 }; 126 };
121 127
122 } // namespace blink 128 } // namespace blink
123 129
124 #endif // BorderValue_h 130 #endif // BorderValue_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/BorderData.h ('k') | third_party/WebKit/Source/core/style/CachedUAStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698