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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSGradientValue.h

Issue 2817523002: Cleanup CSSGradientValue (Closed)
Patch Set: moar cleanup Created 3 years, 8 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSGradientValue.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 17 matching lines...) Expand all
28 28
29 #include "core/css/CSSIdentifierValue.h" 29 #include "core/css/CSSIdentifierValue.h"
30 #include "core/css/CSSImageGeneratorValue.h" 30 #include "core/css/CSSImageGeneratorValue.h"
31 #include "core/css/CSSPrimitiveValue.h" 31 #include "core/css/CSSPrimitiveValue.h"
32 #include "wtf/RefPtr.h" 32 #include "wtf/RefPtr.h"
33 #include "wtf/Vector.h" 33 #include "wtf/Vector.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 class Color; 37 class Color;
38 class FloatPoint;
39 class Gradient; 38 class Gradient;
40 39
41 enum CSSGradientType { 40 enum CSSGradientType {
42 kCSSDeprecatedLinearGradient, 41 kCSSDeprecatedLinearGradient,
43 kCSSDeprecatedRadialGradient, 42 kCSSDeprecatedRadialGradient,
44 kCSSPrefixedLinearGradient, 43 kCSSPrefixedLinearGradient,
45 kCSSPrefixedRadialGradient, 44 kCSSPrefixedRadialGradient,
46 kCSSLinearGradient, 45 kCSSLinearGradient,
47 kCSSRadialGradient, 46 kCSSRadialGradient,
48 kCSSConicGradient 47 kCSSConicGradient
(...skipping 17 matching lines...) Expand all
66 65
67 bool IsHint() const { 66 bool IsHint() const {
68 DCHECK(color_ || offset_); 67 DCHECK(color_ || offset_);
69 return !color_; 68 return !color_;
70 } 69 }
71 70
72 bool IsCacheable() const; 71 bool IsCacheable() const;
73 72
74 DECLARE_TRACE(); 73 DECLARE_TRACE();
75 74
76 Member<CSSPrimitiveValue> offset_; // percentage | length | angle 75 Member<const CSSPrimitiveValue> offset_; // percentage | length | angle
77 Member<CSSValue> color_; 76 Member<const CSSValue> color_;
78 }; 77 };
79 78
80 } // namespace blink 79 } // namespace blink
81 80
82 // We have to declare the VectorTraits specialization before CSSGradientValue 81 // We have to declare the VectorTraits specialization before CSSGradientValue
83 // declares its inline capacity vector below. 82 // declares its inline capacity vector below.
84 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::CSSGradientColorStop); 83 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::CSSGradientColorStop);
85 84
86 namespace blink { 85 namespace blink {
87 86
88 class CSSGradientValue : public CSSImageGeneratorValue { 87 class CSSGradientValue : public CSSImageGeneratorValue {
89 public: 88 public:
90 PassRefPtr<Image> GetImage(const LayoutObject&, const IntSize&); 89 PassRefPtr<Image> GetImage(const LayoutObject&, const IntSize&);
91 90
92 void SetFirstX(CSSValue* val) { first_x_ = val; }
93 void SetFirstY(CSSValue* val) { first_y_ = val; }
94 void SetSecondX(CSSValue* val) { second_x_ = val; }
95 void SetSecondY(CSSValue* val) { second_y_ = val; }
96
97 void AddStop(const CSSGradientColorStop& stop) { 91 void AddStop(const CSSGradientColorStop& stop) {
98 stops_.push_back(stop); 92 stops_.push_back(stop);
99 is_cacheable_ = is_cacheable_ && stop.IsCacheable(); 93 is_cacheable_ = is_cacheable_ && stop.IsCacheable();
100 } 94 }
101 95
102 unsigned StopCount() const { return stops_.size(); } 96 size_t StopCount() const { return stops_.size(); }
103 97
104 bool IsRepeating() const { return repeating_; } 98 bool IsRepeating() const { return repeating_; }
105 99
106 CSSGradientType GradientType() const { return gradient_type_; } 100 CSSGradientType GradientType() const { return gradient_type_; }
107 101
108 bool IsFixedSize() const { return false; } 102 bool IsFixedSize() const { return false; }
109 IntSize FixedSize(const LayoutObject&) const { return IntSize(); } 103 IntSize FixedSize(const LayoutObject&) const { return IntSize(); }
110 104
111 bool IsPending() const { return false; } 105 bool IsPending() const { return false; }
112 bool KnownToBeOpaque(const LayoutObject&) const; 106 bool KnownToBeOpaque(const LayoutObject&) const;
(...skipping 14 matching lines...) Expand all
127 gradient_type_(gradient_type), 121 gradient_type_(gradient_type),
128 repeating_(repeat == kRepeating), 122 repeating_(repeat == kRepeating),
129 stops_sorted_(false), 123 stops_sorted_(false),
130 is_cacheable_(true) {} 124 is_cacheable_(true) {}
131 125
132 void AddStops(GradientDesc&, 126 void AddStops(GradientDesc&,
133 const CSSToLengthConversionData&, 127 const CSSToLengthConversionData&,
134 const LayoutObject&); 128 const LayoutObject&);
135 void AddDeprecatedStops(GradientDesc&, const LayoutObject&); 129 void AddDeprecatedStops(GradientDesc&, const LayoutObject&);
136 130
137 // Resolve points/radii to front end values.
138 FloatPoint ComputeEndPoint(CSSValue*,
139 CSSValue*,
140 const CSSToLengthConversionData&,
141 const IntSize&);
142
143 void AppendCSSTextForColorStops(StringBuilder&, 131 void AppendCSSTextForColorStops(StringBuilder&,
144 bool requires_separator) const; 132 bool requires_separator) const;
145 void AppendCSSTextForDeprecatedColorStops(StringBuilder&) const; 133 void AppendCSSTextForDeprecatedColorStops(StringBuilder&) const;
146 134
147 // Points. Some of these may be null.
148 Member<CSSValue> first_x_;
149 Member<CSSValue> first_y_;
150
151 // TODO(fmalita): relocate these to subclasses which need them.
152 Member<CSSValue> second_x_;
153 Member<CSSValue> second_y_;
154
155 // Stops 135 // Stops
156 HeapVector<CSSGradientColorStop, 2> stops_; 136 HeapVector<CSSGradientColorStop, 2> stops_;
157 CSSGradientType gradient_type_; 137 CSSGradientType gradient_type_;
158 bool repeating_ : 1; 138 bool repeating_ : 1;
159 bool stops_sorted_ : 1; 139 bool stops_sorted_ : 1;
160 bool is_cacheable_ : 1; 140 bool is_cacheable_ : 1;
161 }; 141 };
162 142
163 DEFINE_CSS_VALUE_TYPE_CASTS(CSSGradientValue, IsGradientValue()); 143 DEFINE_CSS_VALUE_TYPE_CASTS(CSSGradientValue, IsGradientValue());
164 144
165 class CSSLinearGradientValue final : public CSSGradientValue { 145 class CSSLinearGradientValue final : public CSSGradientValue {
166 public: 146 public:
167 static CSSLinearGradientValue* Create( 147 static CSSGradientValue* Create(
148 const CSSValue* first_x,
149 const CSSValue* first_y,
150 const CSSValue* second_x,
151 const CSSValue* second_y,
152 const CSSPrimitiveValue* angle,
168 CSSGradientRepeat repeat, 153 CSSGradientRepeat repeat,
169 CSSGradientType gradient_type = kCSSLinearGradient) { 154 CSSGradientType gradient_type = kCSSLinearGradient) {
170 return new CSSLinearGradientValue(repeat, gradient_type); 155 return new CSSLinearGradientValue(first_x, first_y, second_x, second_y,
156 angle, repeat, gradient_type);
171 } 157 }
172 158
173 void SetAngle(CSSPrimitiveValue* val) { angle_ = val; }
174
175 String CustomCSSText() const; 159 String CustomCSSText() const;
176 160
177 // Create the gradient for a given size. 161 // Create the gradient for a given size.
178 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&, 162 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&,
179 const IntSize&, 163 const IntSize&,
180 const LayoutObject&); 164 const LayoutObject&);
181 165
182 bool Equals(const CSSLinearGradientValue&) const; 166 bool Equals(const CSSLinearGradientValue&) const;
183 167
184 DECLARE_TRACE_AFTER_DISPATCH(); 168 DECLARE_TRACE_AFTER_DISPATCH();
185 169
186 private: 170 private:
187 CSSLinearGradientValue(CSSGradientRepeat repeat, 171 CSSLinearGradientValue(const CSSValue* first_x,
172 const CSSValue* first_y,
173 const CSSValue* second_x,
174 const CSSValue* second_y,
175 const CSSPrimitiveValue* angle,
176 CSSGradientRepeat repeat,
188 CSSGradientType gradient_type = kCSSLinearGradient) 177 CSSGradientType gradient_type = kCSSLinearGradient)
189 : CSSGradientValue(kLinearGradientClass, repeat, gradient_type) {} 178 : CSSGradientValue(kLinearGradientClass, repeat, gradient_type),
179 first_x_(first_x),
180 first_y_(first_y),
181 second_x_(second_x),
182 second_y_(second_y),
183 angle_(angle) {}
190 184
191 Member<CSSPrimitiveValue> angle_; // may be null. 185 Member<const CSSValue> first_x_;
186 Member<const CSSValue> first_y_;
187 Member<const CSSValue> second_x_;
188 Member<const CSSValue> second_y_;
189 Member<const CSSPrimitiveValue> angle_; // may be null.
fs 2017/04/12 13:28:15 Could we try to use const CSSValue& as (argument)
f(malita) 2017/04/12 13:59:05 Yeah - the problem is there's much implicit voodoo
fs 2017/04/12 14:01:26 Roger that.
192 }; 190 };
193 191
194 DEFINE_CSS_VALUE_TYPE_CASTS(CSSLinearGradientValue, IsLinearGradientValue()); 192 DEFINE_CSS_VALUE_TYPE_CASTS(CSSLinearGradientValue, IsLinearGradientValue());
195 193
196 class CSSRadialGradientValue final : public CSSGradientValue { 194 class CSSRadialGradientValue final : public CSSGradientValue {
197 public: 195 public:
198 static CSSRadialGradientValue* Create( 196 static CSSGradientValue* Create(
197 const CSSValue* first_x,
198 const CSSValue* first_y,
199 const CSSPrimitiveValue* first_radius,
200 const CSSValue* second_x,
201 const CSSValue* second_y,
202 const CSSPrimitiveValue* second_radius,
199 CSSGradientRepeat repeat, 203 CSSGradientRepeat repeat,
200 CSSGradientType gradient_type = kCSSRadialGradient) { 204 CSSGradientType gradient_type = kCSSRadialGradient) {
201 return new CSSRadialGradientValue(repeat, gradient_type); 205 return new CSSRadialGradientValue(first_x, first_y, first_radius, second_x,
206 second_y, second_radius, nullptr, nullptr,
207 nullptr, nullptr, repeat, gradient_type);
208 }
209
210 static CSSGradientValue* Create(const CSSValue* center_x,
211 const CSSValue* center_y,
212 const CSSIdentifierValue* shape,
213 const CSSIdentifierValue* sizing_behavior,
214 const CSSPrimitiveValue* horizontal_size,
215 const CSSPrimitiveValue* vertical_size,
216 CSSGradientRepeat repeat,
217 CSSGradientType gradient_type) {
218 return new CSSRadialGradientValue(
219 center_x, center_y, nullptr, center_x, center_y, nullptr, shape,
220 sizing_behavior, horizontal_size, vertical_size, repeat, gradient_type);
202 } 221 }
203 222
204 String CustomCSSText() const; 223 String CustomCSSText() const;
205 224
206 void SetFirstRadius(CSSPrimitiveValue* val) { first_radius_ = val; }
207 void SetSecondRadius(CSSPrimitiveValue* val) { second_radius_ = val; }
208
209 void SetShape(CSSIdentifierValue* val) { shape_ = val; } 225 void SetShape(CSSIdentifierValue* val) { shape_ = val; }
210 void SetSizingBehavior(CSSIdentifierValue* val) { sizing_behavior_ = val; } 226 void SetSizingBehavior(CSSIdentifierValue* val) { sizing_behavior_ = val; }
211 227
212 void SetEndHorizontalSize(CSSPrimitiveValue* val) { 228 void SetEndHorizontalSize(CSSPrimitiveValue* val) {
213 end_horizontal_size_ = val; 229 end_horizontal_size_ = val;
214 } 230 }
215 void SetEndVerticalSize(CSSPrimitiveValue* val) { end_vertical_size_ = val; } 231 void SetEndVerticalSize(CSSPrimitiveValue* val) { end_vertical_size_ = val; }
216 232
217 // Create the gradient for a given size. 233 // Create the gradient for a given size.
218 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&, 234 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&,
219 const IntSize&, 235 const IntSize&,
220 const LayoutObject&); 236 const LayoutObject&);
221 237
222 bool Equals(const CSSRadialGradientValue&) const; 238 bool Equals(const CSSRadialGradientValue&) const;
223 239
224 DECLARE_TRACE_AFTER_DISPATCH(); 240 DECLARE_TRACE_AFTER_DISPATCH();
225 241
226 private: 242 private:
227 CSSRadialGradientValue(CSSGradientRepeat repeat, 243 CSSRadialGradientValue(const CSSValue* first_x,
244 const CSSValue* first_y,
245 const CSSPrimitiveValue* first_radius,
246 const CSSValue* second_x,
247 const CSSValue* second_y,
248 const CSSPrimitiveValue* second_radius,
249 const CSSIdentifierValue* shape,
250 const CSSIdentifierValue* sizing_behavior,
251 const CSSPrimitiveValue* horizontal_size,
252 const CSSPrimitiveValue* vertical_size,
253 CSSGradientRepeat repeat,
228 CSSGradientType gradient_type = kCSSRadialGradient) 254 CSSGradientType gradient_type = kCSSRadialGradient)
229 : CSSGradientValue(kRadialGradientClass, repeat, gradient_type) {} 255 : CSSGradientValue(kRadialGradientClass, repeat, gradient_type),
256 first_x_(first_x),
257 first_y_(first_y),
258 second_x_(second_x),
259 second_y_(second_y),
260 first_radius_(first_radius),
261 second_radius_(second_radius),
262 shape_(shape),
263 sizing_behavior_(sizing_behavior),
264 end_horizontal_size_(horizontal_size),
265 end_vertical_size_(vertical_size) {}
230 266
231 // Resolve points/radii to front end values. 267 Member<const CSSValue> first_x_;
232 float ResolveRadius(CSSPrimitiveValue*, 268 Member<const CSSValue> first_y_;
233 const CSSToLengthConversionData&, 269 Member<const CSSValue> second_x_;
234 float* width_or_height = 0); 270 Member<const CSSValue> second_y_;
235 271
236 // These may be null for non-deprecated gradients. 272 // These may be null for non-deprecated gradients.
237 Member<CSSPrimitiveValue> first_radius_; 273 Member<const CSSPrimitiveValue> first_radius_;
238 Member<CSSPrimitiveValue> second_radius_; 274 Member<const CSSPrimitiveValue> second_radius_;
239 275
240 // The below are only used for non-deprecated gradients. Any of them may be 276 // The below are only used for non-deprecated gradients. Any of them may be
241 // null. 277 // null.
242 Member<CSSIdentifierValue> shape_; 278 Member<const CSSIdentifierValue> shape_;
243 Member<CSSIdentifierValue> sizing_behavior_; 279 Member<const CSSIdentifierValue> sizing_behavior_;
244 280
245 Member<CSSPrimitiveValue> end_horizontal_size_; 281 Member<const CSSPrimitiveValue> end_horizontal_size_;
246 Member<CSSPrimitiveValue> end_vertical_size_; 282 Member<const CSSPrimitiveValue> end_vertical_size_;
247 }; 283 };
248 284
249 DEFINE_CSS_VALUE_TYPE_CASTS(CSSRadialGradientValue, IsRadialGradientValue()); 285 DEFINE_CSS_VALUE_TYPE_CASTS(CSSRadialGradientValue, IsRadialGradientValue());
250 286
251 class CSSConicGradientValue final : public CSSGradientValue { 287 class CSSConicGradientValue final : public CSSGradientValue {
252 public: 288 public:
253 static CSSConicGradientValue* Create(CSSGradientRepeat repeat) { 289 static CSSGradientValue* Create(const CSSValue* x,
254 return new CSSConicGradientValue(repeat); 290 const CSSValue* y,
291 const CSSPrimitiveValue* from_angle,
292 CSSGradientRepeat repeat) {
293 return new CSSConicGradientValue(x, y, from_angle, repeat);
255 } 294 }
256 295
257 String CustomCSSText() const; 296 String CustomCSSText() const;
258 297
259 // Create the gradient for a given size. 298 // Create the gradient for a given size.
260 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&, 299 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&,
261 const IntSize&, 300 const IntSize&,
262 const LayoutObject&); 301 const LayoutObject&);
263 302
264 void SetFromAngle(CSSPrimitiveValue* val) { from_angle_ = val; }
265
266 bool Equals(const CSSConicGradientValue&) const; 303 bool Equals(const CSSConicGradientValue&) const;
267 304
268 DECLARE_TRACE_AFTER_DISPATCH(); 305 DECLARE_TRACE_AFTER_DISPATCH();
269 306
270 private: 307 private:
271 CSSConicGradientValue(CSSGradientRepeat repeat) 308 CSSConicGradientValue(const CSSValue* x,
272 : CSSGradientValue(kConicGradientClass, repeat, kCSSConicGradient) {} 309 const CSSValue* y,
310 const CSSPrimitiveValue* from_angle,
311 CSSGradientRepeat repeat)
312 : CSSGradientValue(kConicGradientClass, repeat, kCSSConicGradient),
313 x_(x),
314 y_(y),
315 from_angle_(from_angle) {}
273 316
274 Member<CSSPrimitiveValue> from_angle_; 317 // Any of these may be null.
318 Member<const CSSValue> x_;
319 Member<const CSSValue> y_;
320 Member<const CSSPrimitiveValue> from_angle_;
275 }; 321 };
276 322
277 DEFINE_CSS_VALUE_TYPE_CASTS(CSSConicGradientValue, IsConicGradientValue()); 323 DEFINE_CSS_VALUE_TYPE_CASTS(CSSConicGradientValue, IsConicGradientValue());
278 324
279 } // namespace blink 325 } // namespace blink
280 326
281 #endif // CSSGradientValue_h 327 #endif // CSSGradientValue_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSGradientValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698