Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 case LengthTypePC: | 153 case LengthTypePC: |
| 154 return value * 6 / cssPixelsPerInch; | 154 return value * 6 / cssPixelsPerInch; |
| 155 } | 155 } |
| 156 | 156 |
| 157 ASSERT_NOT_REACHED(); | 157 ASSERT_NOT_REACHED(); |
| 158 return 0; | 158 return 0; |
| 159 } | 159 } |
| 160 | 160 |
| 161 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe ngthMode mode, ExceptionState& es) const | 161 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe ngthMode mode, ExceptionState& es) const |
| 162 { | 162 { |
| 163 float width = 0; | 163 FloatSize viewportSize; |
|
pdr.
2013/11/11 21:03:14
Nit: I think we prefer to return the FloatSize and
f(malita)
2013/11/11 21:14:29
Doh, good point - if we only have one out-param no
f(malita)
2013/11/11 21:50:05
On second thought, this causes a subtle change in
| |
| 164 float height = 0; | 164 if (!determineViewport(viewportSize)) { |
| 165 if (!determineViewport(width, height)) { | |
| 166 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 165 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 167 return 0; | 166 return 0; |
| 168 } | 167 } |
| 169 | 168 |
| 170 switch (mode) { | 169 switch (mode) { |
| 171 case LengthModeWidth: | 170 case LengthModeWidth: |
| 172 return value / width * 100; | 171 return value / viewportSize.width() * 100; |
| 173 case LengthModeHeight: | 172 case LengthModeHeight: |
| 174 return value / height * 100; | 173 return value / viewportSize.height() * 100; |
| 175 case LengthModeOther: | 174 case LengthModeOther: |
| 176 return value / (sqrtf((width * width + height * height) / 2)) * 100; | 175 return value / sqrtf(viewportSize.diagonalLengthSquared() / 2) * 100; |
|
pdr.
2013/11/11 21:03:14
square root of length squared? Please refactor for
f(malita)
2013/11/11 21:14:29
The name is misleading, there's no redundant squar
pdr.
2013/11/11 21:16:31
Gah, I just spaced out here. You're right. Carry o
| |
| 177 }; | 176 }; |
| 178 | 177 |
| 179 ASSERT_NOT_REACHED(); | 178 ASSERT_NOT_REACHED(); |
| 180 return 0; | 179 return 0; |
| 181 } | 180 } |
| 182 | 181 |
| 183 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe ngthMode mode, ExceptionState& es) const | 182 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe ngthMode mode, ExceptionState& es) const |
| 184 { | 183 { |
| 185 float width = 0; | 184 FloatSize viewportSize; |
| 186 float height = 0; | 185 if (!determineViewport(viewportSize)) { |
| 187 if (!determineViewport(width, height)) { | |
| 188 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 186 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 189 return 0; | 187 return 0; |
| 190 } | 188 } |
| 191 | 189 |
| 192 switch (mode) { | 190 switch (mode) { |
| 193 case LengthModeWidth: | 191 case LengthModeWidth: |
| 194 return value * width; | 192 return value * viewportSize.width(); |
| 195 case LengthModeHeight: | 193 case LengthModeHeight: |
| 196 return value * height; | 194 return value * viewportSize.height(); |
| 197 case LengthModeOther: | 195 case LengthModeOther: |
| 198 return value * sqrtf((width * width + height * height) / 2); | 196 return value * sqrtf(viewportSize.diagonalLengthSquared() / 2); |
| 199 }; | 197 }; |
| 200 | 198 |
| 201 ASSERT_NOT_REACHED(); | 199 ASSERT_NOT_REACHED(); |
| 202 return 0; | 200 return 0; |
| 203 } | 201 } |
| 204 | 202 |
| 205 static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte xt) | 203 static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte xt) |
| 206 { | 204 { |
| 207 if (!context) | 205 if (!context) |
| 208 return 0; | 206 return 0; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 if (!style) { | 270 if (!style) { |
| 273 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 271 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
| 274 return 0; | 272 return 0; |
| 275 } | 273 } |
| 276 | 274 |
| 277 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg | 275 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg |
| 278 // if this causes problems in real world cases maybe it would be best to rem ove this | 276 // if this causes problems in real world cases maybe it would be best to rem ove this |
| 279 return value * ceilf(style->fontMetrics().xHeight()); | 277 return value * ceilf(style->fontMetrics().xHeight()); |
| 280 } | 278 } |
| 281 | 279 |
| 282 bool SVGLengthContext::determineViewport(float& width, float& height) const | 280 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const |
| 283 { | 281 { |
| 284 if (!m_context) | 282 if (!m_context) |
| 285 return false; | 283 return false; |
| 286 | 284 |
| 287 // If an overriden viewport is given, it has precedence. | 285 // If an overriden viewport is given, it has precedence. |
| 288 if (!m_overridenViewport.isEmpty()) { | 286 if (!m_overridenViewport.isEmpty()) { |
| 289 width = m_overridenViewport.width(); | 287 viewportSize = m_overridenViewport.size(); |
| 290 height = m_overridenViewport.height(); | |
| 291 return true; | 288 return true; |
| 292 } | 289 } |
| 293 | 290 |
| 294 // SVGLengthContext should NEVER be used to resolve width/height values for <svg> elements, | 291 // Root <svg> element lengths are resolved against the top level viewport. |
| 295 // as they require special treatment, due the relationship with the CSS widt h/height properties. | 292 if (m_context->isOutermostSVGSVGElement()) { |
| 296 ASSERT(m_context->document().documentElement() != m_context); | 293 viewportSize = toSVGSVGElement(m_context)->currentViewportSize(); |
| 294 return true; | |
| 295 } | |
| 297 | 296 |
| 298 // Take size from nearest viewport element. | 297 // Take size from nearest viewport element. |
| 299 SVGElement* viewportElement = m_context->viewportElement(); | 298 SVGElement* viewportElement = m_context->viewportElement(); |
| 300 if (!viewportElement || !viewportElement->isSVGSVGElement()) | 299 if (!viewportElement || !viewportElement->isSVGSVGElement()) |
| 301 return false; | 300 return false; |
| 302 | 301 |
| 303 const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement ); | 302 const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement ); |
| 304 FloatSize viewportSize = svg->currentViewBoxRect().size(); | 303 viewportSize = svg->currentViewBoxRect().size(); |
| 305 if (viewportSize.isEmpty()) | 304 if (viewportSize.isEmpty()) |
| 306 viewportSize = svg->currentViewportSize(); | 305 viewportSize = svg->currentViewportSize(); |
| 307 | 306 |
| 308 width = viewportSize.width(); | |
| 309 height = viewportSize.height(); | |
| 310 return true; | 307 return true; |
| 311 } | 308 } |
| 312 | 309 |
| 313 } | 310 } |
| OLD | NEW |