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

Side by Side Diff: Source/core/svg/SVGLengthContext.cpp

Issue 889563002: Make RenderObject::style() return a const object (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated change after Doug's review. Created 5 years, 10 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
« no previous file with comments | « Source/core/svg/SVGGraphicsElement.cpp ('k') | Source/core/svg/SVGStopElement.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) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 5 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 case LengthTypePT: 172 case LengthTypePT:
173 return value / cssPixelsPerPoint; 173 return value / cssPixelsPerPoint;
174 case LengthTypePC: 174 case LengthTypePC:
175 return value / cssPixelsPerPica; 175 return value / cssPixelsPerPica;
176 } 176 }
177 177
178 ASSERT_NOT_REACHED(); 178 ASSERT_NOT_REACHED();
179 return 0; 179 return 0;
180 } 180 }
181 181
182 static inline LayoutStyle* layoutStyleForLengthResolving(const SVGElement* conte xt) 182 static inline const LayoutStyle* layoutStyleForLengthResolving(const SVGElement* context)
183 { 183 {
184 if (!context) 184 if (!context)
185 return 0; 185 return 0;
186 186
187 const ContainerNode* currentContext = context; 187 const ContainerNode* currentContext = context;
188 do { 188 do {
189 if (currentContext->renderer()) 189 if (currentContext->renderer())
190 return currentContext->renderer()->style(); 190 return currentContext->renderer()->style();
191 currentContext = currentContext->parentNode(); 191 currentContext = currentContext->parentNode();
192 } while (currentContext); 192 } while (currentContext);
193 193
194 // There must be at least a LayoutSVGRoot renderer, carrying a style. 194 // There must be at least a LayoutSVGRoot renderer, carrying a style.
195 ASSERT_NOT_REACHED(); 195 ASSERT_NOT_REACHED();
196 return 0; 196 return 0;
197 } 197 }
198 198
199 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const 199 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const
200 { 200 {
201 LayoutStyle* style = layoutStyleForLengthResolving(m_context); 201 const LayoutStyle* style = layoutStyleForLengthResolving(m_context);
202 if (!style) 202 if (!style)
203 return 0; 203 return 0;
204 204
205 float fontSize = style->specifiedFontSize(); 205 float fontSize = style->specifiedFontSize();
206 if (!fontSize) 206 if (!fontSize)
207 return 0; 207 return 0;
208 208
209 return value / fontSize; 209 return value / fontSize;
210 } 210 }
211 211
212 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const 212 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const
213 { 213 {
214 LayoutStyle* style = layoutStyleForLengthResolving(m_context); 214 const LayoutStyle* style = layoutStyleForLengthResolving(m_context);
215 if (!style) 215 if (!style)
216 return 0; 216 return 0;
217 return value * style->specifiedFontSize(); 217 return value * style->specifiedFontSize();
218 } 218 }
219 219
220 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const 220 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const
221 { 221 {
222 LayoutStyle* style = layoutStyleForLengthResolving(m_context); 222 const LayoutStyle* style = layoutStyleForLengthResolving(m_context);
223 if (!style) 223 if (!style)
224 return 0; 224 return 0;
225 225
226 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg 226 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg
227 // if this causes problems in real world cases maybe it would be best to rem ove this 227 // if this causes problems in real world cases maybe it would be best to rem ove this
228 float xHeight = ceilf(style->fontMetrics().xHeight()); 228 float xHeight = ceilf(style->fontMetrics().xHeight());
229 if (!xHeight) 229 if (!xHeight)
230 return 0; 230 return 0;
231 231
232 return value / xHeight; 232 return value / xHeight;
233 } 233 }
234 234
235 float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const 235 float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const
236 { 236 {
237 LayoutStyle* style = layoutStyleForLengthResolving(m_context); 237 const LayoutStyle* style = layoutStyleForLengthResolving(m_context);
238 if (!style) 238 if (!style)
239 return 0; 239 return 0;
240 240
241 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg 241 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg
242 // if this causes problems in real world cases maybe it would be best to rem ove this 242 // if this causes problems in real world cases maybe it would be best to rem ove this
243 return value * ceilf(style->fontMetrics().xHeight()); 243 return value * ceilf(style->fontMetrics().xHeight());
244 } 244 }
245 245
246 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const 246 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const
247 { 247 {
(...skipping 13 matching lines...) Expand all
261 261
262 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); 262 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement);
263 viewportSize = svg.currentViewBoxRect().size(); 263 viewportSize = svg.currentViewBoxRect().size();
264 if (viewportSize.isEmpty()) 264 if (viewportSize.isEmpty())
265 viewportSize = svg.currentViewportSize(); 265 viewportSize = svg.currentViewportSize();
266 266
267 return true; 267 return true;
268 } 268 }
269 269
270 } 270 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGGraphicsElement.cpp ('k') | Source/core/svg/SVGStopElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698