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

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

Issue 2817523002: Cleanup CSSGradientValue (Closed)
Patch Set: some more comments 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 "platform/wtf/RefPtr.h" 32 #include "platform/wtf/RefPtr.h"
33 #include "platform/wtf/Vector.h" 33 #include "platform/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 // Any of these may be null.
186 Member<const CSSValue> first_x_;
187 Member<const CSSValue> first_y_;
188 Member<const CSSValue> second_x_;
189 Member<const CSSValue> second_y_;
190 Member<const CSSPrimitiveValue> angle_;
192 }; 191 };
193 192
194 DEFINE_CSS_VALUE_TYPE_CASTS(CSSLinearGradientValue, IsLinearGradientValue()); 193 DEFINE_CSS_VALUE_TYPE_CASTS(CSSLinearGradientValue, IsLinearGradientValue());
195 194
196 class CSSRadialGradientValue final : public CSSGradientValue { 195 class CSSRadialGradientValue final : public CSSGradientValue {
197 public: 196 public:
198 static CSSRadialGradientValue* Create( 197 static CSSGradientValue* Create(
198 const CSSValue* first_x,
199 const CSSValue* first_y,
200 const CSSPrimitiveValue* first_radius,
201 const CSSValue* second_x,
202 const CSSValue* second_y,
203 const CSSPrimitiveValue* second_radius,
199 CSSGradientRepeat repeat, 204 CSSGradientRepeat repeat,
200 CSSGradientType gradient_type = kCSSRadialGradient) { 205 CSSGradientType gradient_type = kCSSRadialGradient) {
201 return new CSSRadialGradientValue(repeat, gradient_type); 206 return new CSSRadialGradientValue(first_x, first_y, first_radius, second_x,
207 second_y, second_radius, nullptr, nullptr,
208 nullptr, nullptr, repeat, gradient_type);
209 }
210
211 static CSSGradientValue* Create(const CSSValue* center_x,
212 const CSSValue* center_y,
213 const CSSIdentifierValue* shape,
214 const CSSIdentifierValue* sizing_behavior,
215 const CSSPrimitiveValue* horizontal_size,
216 const CSSPrimitiveValue* vertical_size,
217 CSSGradientRepeat repeat,
218 CSSGradientType gradient_type) {
219 return new CSSRadialGradientValue(
220 center_x, center_y, nullptr, center_x, center_y, nullptr, shape,
221 sizing_behavior, horizontal_size, vertical_size, repeat, gradient_type);
202 } 222 }
203 223
204 String CustomCSSText() const; 224 String CustomCSSText() const;
205 225
206 void SetFirstRadius(CSSPrimitiveValue* val) { first_radius_ = val; }
207 void SetSecondRadius(CSSPrimitiveValue* val) { second_radius_ = val; }
208
209 void SetShape(CSSIdentifierValue* val) { shape_ = val; } 226 void SetShape(CSSIdentifierValue* val) { shape_ = val; }
210 void SetSizingBehavior(CSSIdentifierValue* val) { sizing_behavior_ = val; } 227 void SetSizingBehavior(CSSIdentifierValue* val) { sizing_behavior_ = val; }
211 228
212 void SetEndHorizontalSize(CSSPrimitiveValue* val) { 229 void SetEndHorizontalSize(CSSPrimitiveValue* val) {
213 end_horizontal_size_ = val; 230 end_horizontal_size_ = val;
214 } 231 }
215 void SetEndVerticalSize(CSSPrimitiveValue* val) { end_vertical_size_ = val; } 232 void SetEndVerticalSize(CSSPrimitiveValue* val) { end_vertical_size_ = val; }
216 233
217 // Create the gradient for a given size. 234 // Create the gradient for a given size.
218 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&, 235 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&,
219 const IntSize&, 236 const IntSize&,
220 const LayoutObject&); 237 const LayoutObject&);
221 238
222 bool Equals(const CSSRadialGradientValue&) const; 239 bool Equals(const CSSRadialGradientValue&) const;
223 240
224 DECLARE_TRACE_AFTER_DISPATCH(); 241 DECLARE_TRACE_AFTER_DISPATCH();
225 242
226 private: 243 private:
227 CSSRadialGradientValue(CSSGradientRepeat repeat, 244 CSSRadialGradientValue(const CSSValue* first_x,
245 const CSSValue* first_y,
246 const CSSPrimitiveValue* first_radius,
247 const CSSValue* second_x,
248 const CSSValue* second_y,
249 const CSSPrimitiveValue* second_radius,
250 const CSSIdentifierValue* shape,
251 const CSSIdentifierValue* sizing_behavior,
252 const CSSPrimitiveValue* horizontal_size,
253 const CSSPrimitiveValue* vertical_size,
254 CSSGradientRepeat repeat,
228 CSSGradientType gradient_type = kCSSRadialGradient) 255 CSSGradientType gradient_type = kCSSRadialGradient)
229 : CSSGradientValue(kRadialGradientClass, repeat, gradient_type) {} 256 : CSSGradientValue(kRadialGradientClass, repeat, gradient_type),
257 first_x_(first_x),
258 first_y_(first_y),
259 second_x_(second_x),
260 second_y_(second_y),
261 first_radius_(first_radius),
262 second_radius_(second_radius),
263 shape_(shape),
264 sizing_behavior_(sizing_behavior),
265 end_horizontal_size_(horizontal_size),
266 end_vertical_size_(vertical_size) {}
230 267
231 // Resolve points/radii to front end values. 268 // Any of these may be null.
232 float ResolveRadius(CSSPrimitiveValue*, 269 Member<const CSSValue> first_x_;
233 const CSSToLengthConversionData&, 270 Member<const CSSValue> first_y_;
234 float* width_or_height = 0); 271 Member<const CSSValue> second_x_;
272 Member<const CSSValue> second_y_;
235 273
236 // These may be null for non-deprecated gradients. 274 // These may be null for non-deprecated gradients.
237 Member<CSSPrimitiveValue> first_radius_; 275 Member<const CSSPrimitiveValue> first_radius_;
238 Member<CSSPrimitiveValue> second_radius_; 276 Member<const CSSPrimitiveValue> second_radius_;
239 277
240 // The below are only used for non-deprecated gradients. Any of them may be 278 // The below are only used for non-deprecated gradients. Any of them may be
241 // null. 279 // null.
242 Member<CSSIdentifierValue> shape_; 280 Member<const CSSIdentifierValue> shape_;
243 Member<CSSIdentifierValue> sizing_behavior_; 281 Member<const CSSIdentifierValue> sizing_behavior_;
244 282
245 Member<CSSPrimitiveValue> end_horizontal_size_; 283 Member<const CSSPrimitiveValue> end_horizontal_size_;
246 Member<CSSPrimitiveValue> end_vertical_size_; 284 Member<const CSSPrimitiveValue> end_vertical_size_;
247 }; 285 };
248 286
249 DEFINE_CSS_VALUE_TYPE_CASTS(CSSRadialGradientValue, IsRadialGradientValue()); 287 DEFINE_CSS_VALUE_TYPE_CASTS(CSSRadialGradientValue, IsRadialGradientValue());
250 288
251 class CSSConicGradientValue final : public CSSGradientValue { 289 class CSSConicGradientValue final : public CSSGradientValue {
252 public: 290 public:
253 static CSSConicGradientValue* Create(CSSGradientRepeat repeat) { 291 static CSSGradientValue* Create(const CSSValue* x,
254 return new CSSConicGradientValue(repeat); 292 const CSSValue* y,
293 const CSSPrimitiveValue* from_angle,
294 CSSGradientRepeat repeat) {
295 return new CSSConicGradientValue(x, y, from_angle, repeat);
255 } 296 }
256 297
257 String CustomCSSText() const; 298 String CustomCSSText() const;
258 299
259 // Create the gradient for a given size. 300 // Create the gradient for a given size.
260 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&, 301 PassRefPtr<Gradient> CreateGradient(const CSSToLengthConversionData&,
261 const IntSize&, 302 const IntSize&,
262 const LayoutObject&); 303 const LayoutObject&);
263 304
264 void SetFromAngle(CSSPrimitiveValue* val) { from_angle_ = val; }
265
266 bool Equals(const CSSConicGradientValue&) const; 305 bool Equals(const CSSConicGradientValue&) const;
267 306
268 DECLARE_TRACE_AFTER_DISPATCH(); 307 DECLARE_TRACE_AFTER_DISPATCH();
269 308
270 private: 309 private:
271 CSSConicGradientValue(CSSGradientRepeat repeat) 310 CSSConicGradientValue(const CSSValue* x,
272 : CSSGradientValue(kConicGradientClass, repeat, kCSSConicGradient) {} 311 const CSSValue* y,
312 const CSSPrimitiveValue* from_angle,
313 CSSGradientRepeat repeat)
314 : CSSGradientValue(kConicGradientClass, repeat, kCSSConicGradient),
315 x_(x),
316 y_(y),
317 from_angle_(from_angle) {}
273 318
274 Member<CSSPrimitiveValue> from_angle_; 319 // Any of these may be null.
320 Member<const CSSValue> x_;
321 Member<const CSSValue> y_;
322 Member<const CSSPrimitiveValue> from_angle_;
275 }; 323 };
276 324
277 DEFINE_CSS_VALUE_TYPE_CASTS(CSSConicGradientValue, IsConicGradientValue()); 325 DEFINE_CSS_VALUE_TYPE_CASTS(CSSConicGradientValue, IsConicGradientValue());
278 326
279 } // namespace blink 327 } // namespace blink
280 328
281 #endif // CSSGradientValue_h 329 #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