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

Side by Side Diff: Source/core/css/CSSGradientValue.cpp

Issue 20061003: Move isValid/isCurrentColor from Color to StyleColor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Color color; 98 Color color;
99 float offset; 99 float offset;
100 bool specified; 100 bool specified;
101 101
102 GradientStop() 102 GradientStop()
103 : offset(0) 103 : offset(0)
104 , specified(false) 104 , specified(false)
105 { } 105 { }
106 }; 106 };
107 107
108 PassRefPtr<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(const TextLinkColors& textLinkColors, Color currentColor) 108 PassRefPtr<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(const TextLinkColors& textLinkColors)
109 { 109 {
110 bool derived = false; 110 bool derived = false;
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 (isLinearGradient())
122 result = static_cast<CSSLinearGradientValue*>(this)->clone(); 122 result = static_cast<CSSLinearGradientValue*>(this)->clone();
123 else if (isRadialGradient()) 123 else if (isRadialGradient())
124 result = static_cast<CSSRadialGradientValue*>(this)->clone(); 124 result = static_cast<CSSRadialGradientValue*>(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());
132 132
133 return result.release(); 133 return result.release();
134 } 134 }
135 135
136 void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend erStyle* rootStyle, float maxLengthForRepeat) 136 void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend erStyle* rootStyle, float maxLengthForRepeat)
137 { 137 {
138 RenderStyle* style = renderer->style(); 138 RenderStyle* style = renderer->style();
139 139
140 if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDe precatedRadialGradient) { 140 if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDe precatedRadialGradient) {
141 sortStopsIfNeeded(); 141 sortStopsIfNeeded();
142 142
143 for (unsigned i = 0; i < m_stops.size(); i++) { 143 for (unsigned i = 0; i < m_stops.size(); i++) {
144 const CSSGradientColorStop& stop = m_stops[i]; 144 const CSSGradientColorStop& stop = m_stops[i];
145 145
146 float offset; 146 float offset;
147 if (stop.m_position->isPercentage()) 147 if (stop.m_position->isPercentage())
148 offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_P ERCENTAGE) / 100; 148 offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_P ERCENTAGE) / 100;
149 else 149 else
150 offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_N UMBER); 150 offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_N UMBER);
151 151
152 gradient->addColorStop(offset, stop.m_resolvedColor); 152 gradient->addColorStop(offset, renderer->resolveColor(stop.m_resolve dColor));
153 } 153 }
154 154
155 // The back end already sorted the stops. 155 // The back end already sorted the stops.
156 gradient->setStopsSorted(true); 156 gradient->setStopsSorted(true);
157 return; 157 return;
158 } 158 }
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 (isLinearGradient())
170 gradientEnd = gradient->p1(); 170 gradientEnd = gradient->p1();
171 else if (isRadialGradient()) 171 else if (isRadialGradient())
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 = renderer->resolveColor(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;
182 else if (stop.m_position->isLength() || stop.m_position->isCalculate dPercentageWithLength()) { 182 else if (stop.m_position->isLength() || stop.m_position->isCalculate dPercentageWithLength()) {
183 if (!computedGradientLength) { 183 if (!computedGradientLength) {
184 FloatSize gradientSize(gradientStart - gradientEnd); 184 FloatSize gradientSize(gradientStart - gradientEnd);
185 gradientLength = gradientSize.diagonalLength(); 185 gradientLength = gradientSize.diagonalLength();
186 } 186 }
187 float length; 187 float length;
(...skipping 976 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

Powered by Google App Engine
This is Rietveld 408576698