OLD | NEW |
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 Loading... |
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 gradient = toCSSRadialGradientValue(this)->createGradient(renderer, size
); |
68 gradient = static_cast<CSSRadialGradientValue*>(this)->createGradient(re
nderer, size); | |
69 } | |
70 | 68 |
71 RefPtr<Image> newImage = GeneratorGeneratedImage::create(gradient, size); | 69 RefPtr<Image> newImage = GeneratorGeneratedImage::create(gradient, size); |
72 if (cacheable) | 70 if (cacheable) |
73 putImage(size, newImage); | 71 putImage(size, newImage); |
74 | 72 |
75 return newImage.release(); | 73 return newImage.release(); |
76 } | 74 } |
77 | 75 |
78 // Should only ever be called for deprecated gradients. | 76 // Should only ever be called for deprecated gradients. |
79 static inline bool compareStops(const CSSGradientColorStop& a, const CSSGradient
ColorStop& b) | 77 static inline bool compareStops(const CSSGradientColorStop& a, const CSSGradient
ColorStop& b) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 for (unsigned i = 0; i < m_stops.size(); i++) | 109 for (unsigned i = 0; i < m_stops.size(); i++) |
112 if (m_stops[i].m_color->colorIsDerivedFromElement()) { | 110 if (m_stops[i].m_color->colorIsDerivedFromElement()) { |
113 m_stops[i].m_colorIsDerivedFromElement = true; | 111 m_stops[i].m_colorIsDerivedFromElement = true; |
114 derived = true; | 112 derived = true; |
115 break; | 113 break; |
116 } | 114 } |
117 | 115 |
118 RefPtr<CSSGradientValue> result; | 116 RefPtr<CSSGradientValue> result; |
119 if (!derived) | 117 if (!derived) |
120 result = this; | 118 result = this; |
121 else if (isLinearGradient()) | 119 else if (isLinearGradientValue()) |
122 result = static_cast<CSSLinearGradientValue*>(this)->clone(); | 120 result = toCSSLinearGradientValue(this)->clone(); |
123 else if (isRadialGradient()) | 121 else if (isRadialGradientValue()) |
124 result = static_cast<CSSRadialGradientValue*>(this)->clone(); | 122 result = toCSSRadialGradientValue(this)->clone(); |
125 else { | 123 else { |
126 ASSERT_NOT_REACHED(); | 124 ASSERT_NOT_REACHED(); |
127 return 0; | 125 return 0; |
128 } | 126 } |
129 | 127 |
130 for (unsigned i = 0; i < result->m_stops.size(); i++) | 128 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); | 129 result->m_stops[i].m_resolvedColor = textLinkColors.colorFromPrimitiveVa
lue(result->m_stops[i].m_color.get(), currentColor); |
132 | 130 |
133 return result.release(); | 131 return result.release(); |
134 } | 132 } |
(...skipping 24 matching lines...) Expand all Loading... |
159 | 157 |
160 size_t numStops = m_stops.size(); | 158 size_t numStops = m_stops.size(); |
161 | 159 |
162 Vector<GradientStop> stops(numStops); | 160 Vector<GradientStop> stops(numStops); |
163 | 161 |
164 float gradientLength = 0; | 162 float gradientLength = 0; |
165 bool computedGradientLength = false; | 163 bool computedGradientLength = false; |
166 | 164 |
167 FloatPoint gradientStart = gradient->p0(); | 165 FloatPoint gradientStart = gradient->p0(); |
168 FloatPoint gradientEnd; | 166 FloatPoint gradientEnd; |
169 if (isLinearGradient()) | 167 if (isLinearGradientValue()) |
170 gradientEnd = gradient->p1(); | 168 gradientEnd = gradient->p1(); |
171 else if (isRadialGradient()) | 169 else if (isRadialGradientValue()) |
172 gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0); | 170 gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0); |
173 | 171 |
174 for (size_t i = 0; i < numStops; ++i) { | 172 for (size_t i = 0; i < numStops; ++i) { |
175 const CSSGradientColorStop& stop = m_stops[i]; | 173 const CSSGradientColorStop& stop = m_stops[i]; |
176 | 174 |
177 stops[i].color = stop.m_resolvedColor; | 175 stops[i].color = stop.m_resolvedColor; |
178 | 176 |
179 if (stop.m_position) { | 177 if (stop.m_position) { |
180 if (stop.m_position->isPercentage()) | 178 if (stop.m_position->isPercentage()) |
181 stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveVal
ue::CSS_PERCENTAGE) / 100; | 179 stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveVal
ue::CSS_PERCENTAGE) / 100; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (!gradientRange) { | 260 if (!gradientRange) { |
263 stops.first().offset = 0; | 261 stops.first().offset = 0; |
264 stops.first().color = stops.last().color; | 262 stops.first().color = stops.last().color; |
265 stops.shrink(1); | 263 stops.shrink(1); |
266 numStops = 1; | 264 numStops = 1; |
267 } else { | 265 } else { |
268 float maxExtent = 1; | 266 float maxExtent = 1; |
269 | 267 |
270 // Radial gradients may need to extend further than the endpoints, b
ecause they have | 268 // Radial gradients may need to extend further than the endpoints, b
ecause they have |
271 // to repeat out to the corners of the box. | 269 // to repeat out to the corners of the box. |
272 if (isRadialGradient()) { | 270 if (isRadialGradientValue()) { |
273 if (!computedGradientLength) { | 271 if (!computedGradientLength) { |
274 FloatSize gradientSize(gradientStart - gradientEnd); | 272 FloatSize gradientSize(gradientStart - gradientEnd); |
275 gradientLength = gradientSize.diagonalLength(); | 273 gradientLength = gradientSize.diagonalLength(); |
276 } | 274 } |
277 | 275 |
278 if (maxLengthForRepeat > gradientLength) | 276 if (maxLengthForRepeat > gradientLength) |
279 maxExtent = gradientLength > 0 ? maxLengthForRepeat / gradie
ntLength : 0; | 277 maxExtent = gradientLength > 0 ? maxLengthForRepeat / gradie
ntLength : 0; |
280 } | 278 } |
281 | 279 |
282 size_t originalNumStops = numStops; | 280 size_t originalNumStops = numStops; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 srcStopOrdinal = (srcStopOrdinal + 1) % originalNumStops; | 318 srcStopOrdinal = (srcStopOrdinal + 1) % originalNumStops; |
321 } | 319 } |
322 } | 320 } |
323 } | 321 } |
324 } | 322 } |
325 | 323 |
326 numStops = stops.size(); | 324 numStops = stops.size(); |
327 | 325 |
328 // If the gradient goes outside the 0-1 range, normalize it by moving the en
dpoints, and adjusting the stops. | 326 // 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))
{ | 327 if (numStops > 1 && (stops[0].offset < 0 || stops[numStops - 1].offset > 1))
{ |
330 if (isLinearGradient()) { | 328 if (isLinearGradientValue()) { |
331 float firstOffset = stops[0].offset; | 329 float firstOffset = stops[0].offset; |
332 float lastOffset = stops[numStops - 1].offset; | 330 float lastOffset = stops[numStops - 1].offset; |
333 float scale = lastOffset - firstOffset; | 331 float scale = lastOffset - firstOffset; |
334 | 332 |
335 for (size_t i = 0; i < numStops; ++i) | 333 for (size_t i = 0; i < numStops; ++i) |
336 stops[i].offset = (stops[i].offset - firstOffset) / scale; | 334 stops[i].offset = (stops[i].offset - firstOffset) / scale; |
337 | 335 |
338 FloatPoint p0 = gradient->p0(); | 336 FloatPoint p0 = gradient->p0(); |
339 FloatPoint p1 = gradient->p1(); | 337 FloatPoint p1 = gradient->p1(); |
340 gradient->setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()),
p0.y() + firstOffset * (p1.y() - p0.y()))); | 338 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()))); | 339 gradient->setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0.
x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y()))); |
342 } else if (isRadialGradient()) { | 340 } else if (isRadialGradientValue()) { |
343 // Rather than scaling the points < 0, we truncate them, so only sca
le according to the largest point. | 341 // Rather than scaling the points < 0, we truncate them, so only sca
le according to the largest point. |
344 float firstOffset = 0; | 342 float firstOffset = 0; |
345 float lastOffset = stops[numStops - 1].offset; | 343 float lastOffset = stops[numStops - 1].offset; |
346 float scale = lastOffset - firstOffset; | 344 float scale = lastOffset - firstOffset; |
347 | 345 |
348 // Reset points below 0 to the first visible color. | 346 // Reset points below 0 to the first visible color. |
349 size_t firstZeroOrGreaterIndex = numStops; | 347 size_t firstZeroOrGreaterIndex = numStops; |
350 for (size_t i = 0; i < numStops; ++i) { | 348 for (size_t i = 0; i < numStops; ++i) { |
351 if (stops[i].offset >= 0) { | 349 if (stops[i].offset >= 0) { |
352 firstZeroOrGreaterIndex = i; | 350 firstZeroOrGreaterIndex = i; |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 equalHorizontalAndVerticalSize = compareCSSValuePtr(m_endHorizontalSize,
other.m_endHorizontalSize) && compareCSSValuePtr(m_endVerticalSize, other.m_end
VerticalSize); | 1162 equalHorizontalAndVerticalSize = compareCSSValuePtr(m_endHorizontalSize,
other.m_endHorizontalSize) && compareCSSValuePtr(m_endVerticalSize, other.m_end
VerticalSize); |
1165 else { | 1163 else { |
1166 equalShape = !other.m_shape; | 1164 equalShape = !other.m_shape; |
1167 equalSizingBehavior = !other.m_sizingBehavior; | 1165 equalSizingBehavior = !other.m_sizingBehavior; |
1168 equalHorizontalAndVerticalSize = !other.m_endHorizontalSize && !other.m_
endVerticalSize; | 1166 equalHorizontalAndVerticalSize = !other.m_endHorizontalSize && !other.m_
endVerticalSize; |
1169 } | 1167 } |
1170 return equalShape && equalSizingBehavior && equalHorizontalAndVerticalSize &
& m_stops == other.m_stops; | 1168 return equalShape && equalSizingBehavior && equalHorizontalAndVerticalSize &
& m_stops == other.m_stops; |
1171 } | 1169 } |
1172 | 1170 |
1173 } // namespace WebCore | 1171 } // namespace WebCore |
OLD | NEW |