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: Source/core/css/CSSGradientValue.cpp

Issue 25044003: Generate toCSSFooValue for CSS*GradientValues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 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 | « Source/core/css/CSSGradientValue.h ('k') | Source/core/css/CSSImageGeneratorValue.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 // Need to look up our size. Create a string of width*height to use as a hash key. 55 // Need to look up our size. Create a string of width*height to use as a hash key.
56 Image* result = getImage(renderer, size); 56 Image* result = getImage(renderer, size);
57 if (result) 57 if (result)
58 return result; 58 return result;
59 } 59 }
60 60
61 // We need to create an image. 61 // We need to create an image.
62 RefPtr<Gradient> gradient; 62 RefPtr<Gradient> gradient;
63 63
64 if (isLinearGradient()) 64 if (isLinearGradientValue())
65 gradient = static_cast<CSSLinearGradientValue*>(this)->createGradient(re nderer, size); 65 gradient = toCSSLinearGradientValue(this)->createGradient(renderer, size );
66 else { 66 else {
67 ASSERT(isRadialGradient()); 67 ASSERT(isRadialGradientValue());
tkent 2013/09/30 23:54:37 This assertion is redundant.
gyuyoung-inactive 2013/10/01 02:27:42 Exactly right. I missed to remove it. Thx !
68 gradient = static_cast<CSSRadialGradientValue*>(this)->createGradient(re nderer, size); 68 gradient = toCSSRadialGradientValue(this)->createGradient(renderer, size );
69 } 69 }
70 70
71 RefPtr<Image> newImage = GeneratorGeneratedImage::create(gradient, size); 71 RefPtr<Image> newImage = GeneratorGeneratedImage::create(gradient, size);
72 if (cacheable) 72 if (cacheable)
73 putImage(size, newImage); 73 putImage(size, newImage);
74 74
75 return newImage.release(); 75 return newImage.release();
76 } 76 }
77 77
78 // Should only ever be called for deprecated gradients. 78 // Should only ever be called for deprecated gradients.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 for (unsigned i = 0; i < m_stops.size(); i++) 111 for (unsigned i = 0; i < m_stops.size(); i++)
112 if (m_stops[i].m_color->colorIsDerivedFromElement()) { 112 if (m_stops[i].m_color->colorIsDerivedFromElement()) {
113 m_stops[i].m_colorIsDerivedFromElement = true; 113 m_stops[i].m_colorIsDerivedFromElement = true;
114 derived = true; 114 derived = true;
115 break; 115 break;
116 } 116 }
117 117
118 RefPtr<CSSGradientValue> result; 118 RefPtr<CSSGradientValue> result;
119 if (!derived) 119 if (!derived)
120 result = this; 120 result = this;
121 else if (isLinearGradient()) 121 else if (isLinearGradientValue())
122 result = static_cast<CSSLinearGradientValue*>(this)->clone(); 122 result = toCSSLinearGradientValue(this)->clone();
123 else if (isRadialGradient()) 123 else if (isRadialGradientValue())
124 result = static_cast<CSSRadialGradientValue*>(this)->clone(); 124 result = toCSSRadialGradientValue(this)->clone();
125 else { 125 else {
126 ASSERT_NOT_REACHED(); 126 ASSERT_NOT_REACHED();
127 return 0; 127 return 0;
128 } 128 }
129 129
130 for (unsigned i = 0; i < result->m_stops.size(); i++) 130 for (unsigned i = 0; i < result->m_stops.size(); i++)
131 result->m_stops[i].m_resolvedColor = textLinkColors.colorFromPrimitiveVa lue(result->m_stops[i].m_color.get(), currentColor); 131 result->m_stops[i].m_resolvedColor = textLinkColors.colorFromPrimitiveVa lue(result->m_stops[i].m_color.get(), currentColor);
132 132
133 return result.release(); 133 return result.release();
134 } 134 }
(...skipping 24 matching lines...) Expand all
159 159
160 size_t numStops = m_stops.size(); 160 size_t numStops = m_stops.size();
161 161
162 Vector<GradientStop> stops(numStops); 162 Vector<GradientStop> stops(numStops);
163 163
164 float gradientLength = 0; 164 float gradientLength = 0;
165 bool computedGradientLength = false; 165 bool computedGradientLength = false;
166 166
167 FloatPoint gradientStart = gradient->p0(); 167 FloatPoint gradientStart = gradient->p0();
168 FloatPoint gradientEnd; 168 FloatPoint gradientEnd;
169 if (isLinearGradient()) 169 if (isLinearGradientValue())
170 gradientEnd = gradient->p1(); 170 gradientEnd = gradient->p1();
171 else if (isRadialGradient()) 171 else if (isRadialGradientValue())
172 gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0); 172 gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0);
173 173
174 for (size_t i = 0; i < numStops; ++i) { 174 for (size_t i = 0; i < numStops; ++i) {
175 const CSSGradientColorStop& stop = m_stops[i]; 175 const CSSGradientColorStop& stop = m_stops[i];
176 176
177 stops[i].color = stop.m_resolvedColor; 177 stops[i].color = stop.m_resolvedColor;
178 178
179 if (stop.m_position) { 179 if (stop.m_position) {
180 if (stop.m_position->isPercentage()) 180 if (stop.m_position->isPercentage())
181 stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveVal ue::CSS_PERCENTAGE) / 100; 181 stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveVal ue::CSS_PERCENTAGE) / 100;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 if (!gradientRange) { 262 if (!gradientRange) {
263 stops.first().offset = 0; 263 stops.first().offset = 0;
264 stops.first().color = stops.last().color; 264 stops.first().color = stops.last().color;
265 stops.shrink(1); 265 stops.shrink(1);
266 numStops = 1; 266 numStops = 1;
267 } else { 267 } else {
268 float maxExtent = 1; 268 float maxExtent = 1;
269 269
270 // Radial gradients may need to extend further than the endpoints, b ecause they have 270 // Radial gradients may need to extend further than the endpoints, b ecause they have
271 // to repeat out to the corners of the box. 271 // to repeat out to the corners of the box.
272 if (isRadialGradient()) { 272 if (isRadialGradientValue()) {
273 if (!computedGradientLength) { 273 if (!computedGradientLength) {
274 FloatSize gradientSize(gradientStart - gradientEnd); 274 FloatSize gradientSize(gradientStart - gradientEnd);
275 gradientLength = gradientSize.diagonalLength(); 275 gradientLength = gradientSize.diagonalLength();
276 } 276 }
277 277
278 if (maxLengthForRepeat > gradientLength) 278 if (maxLengthForRepeat > gradientLength)
279 maxExtent = gradientLength > 0 ? maxLengthForRepeat / gradie ntLength : 0; 279 maxExtent = gradientLength > 0 ? maxLengthForRepeat / gradie ntLength : 0;
280 } 280 }
281 281
282 size_t originalNumStops = numStops; 282 size_t originalNumStops = numStops;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 srcStopOrdinal = (srcStopOrdinal + 1) % originalNumStops; 320 srcStopOrdinal = (srcStopOrdinal + 1) % originalNumStops;
321 } 321 }
322 } 322 }
323 } 323 }
324 } 324 }
325 325
326 numStops = stops.size(); 326 numStops = stops.size();
327 327
328 // If the gradient goes outside the 0-1 range, normalize it by moving the en dpoints, and adjusting the stops. 328 // If the gradient goes outside the 0-1 range, normalize it by moving the en dpoints, and adjusting the stops.
329 if (numStops > 1 && (stops[0].offset < 0 || stops[numStops - 1].offset > 1)) { 329 if (numStops > 1 && (stops[0].offset < 0 || stops[numStops - 1].offset > 1)) {
330 if (isLinearGradient()) { 330 if (isLinearGradientValue()) {
331 float firstOffset = stops[0].offset; 331 float firstOffset = stops[0].offset;
332 float lastOffset = stops[numStops - 1].offset; 332 float lastOffset = stops[numStops - 1].offset;
333 float scale = lastOffset - firstOffset; 333 float scale = lastOffset - firstOffset;
334 334
335 for (size_t i = 0; i < numStops; ++i) 335 for (size_t i = 0; i < numStops; ++i)
336 stops[i].offset = (stops[i].offset - firstOffset) / scale; 336 stops[i].offset = (stops[i].offset - firstOffset) / scale;
337 337
338 FloatPoint p0 = gradient->p0(); 338 FloatPoint p0 = gradient->p0();
339 FloatPoint p1 = gradient->p1(); 339 FloatPoint p1 = gradient->p1();
340 gradient->setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y()))); 340 gradient->setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y())));
341 gradient->setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0. x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y()))); 341 gradient->setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0. x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y())));
342 } else if (isRadialGradient()) { 342 } else if (isRadialGradientValue()) {
343 // Rather than scaling the points < 0, we truncate them, so only sca le according to the largest point. 343 // Rather than scaling the points < 0, we truncate them, so only sca le according to the largest point.
344 float firstOffset = 0; 344 float firstOffset = 0;
345 float lastOffset = stops[numStops - 1].offset; 345 float lastOffset = stops[numStops - 1].offset;
346 float scale = lastOffset - firstOffset; 346 float scale = lastOffset - firstOffset;
347 347
348 // Reset points below 0 to the first visible color. 348 // Reset points below 0 to the first visible color.
349 size_t firstZeroOrGreaterIndex = numStops; 349 size_t firstZeroOrGreaterIndex = numStops;
350 for (size_t i = 0; i < numStops; ++i) { 350 for (size_t i = 0; i < numStops; ++i) {
351 if (stops[i].offset >= 0) { 351 if (stops[i].offset >= 0) {
352 firstZeroOrGreaterIndex = i; 352 firstZeroOrGreaterIndex = i;
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 equalHorizontalAndVerticalSize = compareCSSValuePtr(m_endHorizontalSize, other.m_endHorizontalSize) && compareCSSValuePtr(m_endVerticalSize, other.m_end VerticalSize); 1164 equalHorizontalAndVerticalSize = compareCSSValuePtr(m_endHorizontalSize, other.m_endHorizontalSize) && compareCSSValuePtr(m_endVerticalSize, other.m_end VerticalSize);
1165 else { 1165 else {
1166 equalShape = !other.m_shape; 1166 equalShape = !other.m_shape;
1167 equalSizingBehavior = !other.m_sizingBehavior; 1167 equalSizingBehavior = !other.m_sizingBehavior;
1168 equalHorizontalAndVerticalSize = !other.m_endHorizontalSize && !other.m_ endVerticalSize; 1168 equalHorizontalAndVerticalSize = !other.m_endHorizontalSize && !other.m_ endVerticalSize;
1169 } 1169 }
1170 return equalShape && equalSizingBehavior && equalHorizontalAndVerticalSize & & m_stops == other.m_stops; 1170 return equalShape && equalSizingBehavior && equalHorizontalAndVerticalSize & & m_stops == other.m_stops;
1171 } 1171 }
1172 1172
1173 } // namespace WebCore 1173 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSGradientValue.h ('k') | Source/core/css/CSSImageGeneratorValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698