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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); | 89 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); |
| 90 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) { | 90 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) { |
| 91 SVGLengthContext lengthContext(context); | 91 SVGLengthContext lengthContext(context); |
| 92 return x.value(lengthContext); | 92 return x.value(lengthContext); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t o be resolved in user space and then be considered in objectBoundingBox space. | 95 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t o be resolved in user space and then be considered in objectBoundingBox space. |
| 96 return x.valueAsPercentage(); | 96 return x.valueAsPercentage(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode) const | 99 static inline LayoutStyle* layoutStyleForLengthResolving(const SVGElement* conte xt) |
|
fs
2015/02/25 13:43:11
Please restore this to where it originally was. (A
Erik Dahlström (inactive)
2015/02/25 13:54:50
Done.
| |
| 100 { | 100 { |
| 101 if (!context) | |
| 102 return 0; | |
| 103 | |
| 104 const ContainerNode* currentContext = context; | |
| 105 do { | |
| 106 if (currentContext->renderer()) | |
| 107 return currentContext->renderer()->style(); | |
| 108 currentContext = currentContext->parentNode(); | |
| 109 } while (currentContext); | |
| 110 | |
| 111 // There must be at least a LayoutSVGRoot renderer, carrying a style. | |
| 112 ASSERT_NOT_REACHED(); | |
| 113 return 0; | |
| 114 } | |
| 115 | |
| 116 float SVGLengthContext::valueForLength(const Length& length, const LayoutStyle& style, SVGLengthMode mode) const | |
| 117 { | |
| 118 return valueForLengthWithZoom(length, style.effectiveZoom(), mode); | |
| 119 } | |
| 120 | |
| 121 float SVGLengthContext::valueForLengthWithZoom(const Length& length, float zoom, SVGLengthMode mode) const | |
| 122 { | |
| 123 ASSERT(zoom != 0); | |
| 101 float dimension = 0; | 124 float dimension = 0; |
| 102 if (length.isPercent()) { | 125 if (length.isPercent()) { |
| 103 FloatSize viewportSize; | 126 FloatSize viewportSize; |
| 104 determineViewport(viewportSize); | 127 determineViewport(viewportSize); |
| 105 dimension = dimensionForLengthMode(mode, viewportSize); | 128 // The viewport will be unaffected by zoom. |
| 129 dimension = dimensionForLengthMode(mode, viewportSize) * zoom; | |
| 106 } | 130 } |
| 107 return floatValueForLength(length, dimension); | 131 return floatValueForLength(length, dimension) / zoom; |
| 108 } | 132 } |
| 109 | 133 |
| 110 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const | 134 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const |
| 111 { | 135 { |
| 112 switch (fromUnit) { | 136 switch (fromUnit) { |
| 113 case LengthTypeUnknown: | 137 case LengthTypeUnknown: |
| 114 return 0; | 138 return 0; |
| 115 case LengthTypeNumber: | 139 case LengthTypeNumber: |
| 116 return value; | 140 return value; |
| 117 case LengthTypePX: | 141 case LengthTypePX: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 case LengthTypePT: | 196 case LengthTypePT: |
| 173 return value / cssPixelsPerPoint; | 197 return value / cssPixelsPerPoint; |
| 174 case LengthTypePC: | 198 case LengthTypePC: |
| 175 return value / cssPixelsPerPica; | 199 return value / cssPixelsPerPica; |
| 176 } | 200 } |
| 177 | 201 |
| 178 ASSERT_NOT_REACHED(); | 202 ASSERT_NOT_REACHED(); |
| 179 return 0; | 203 return 0; |
| 180 } | 204 } |
| 181 | 205 |
| 182 static inline LayoutStyle* layoutStyleForLengthResolving(const SVGElement* conte xt) | |
| 183 { | |
| 184 if (!context) | |
| 185 return 0; | |
| 186 | |
| 187 const ContainerNode* currentContext = context; | |
| 188 do { | |
| 189 if (currentContext->renderer()) | |
| 190 return currentContext->renderer()->style(); | |
| 191 currentContext = currentContext->parentNode(); | |
| 192 } while (currentContext); | |
| 193 | |
| 194 // There must be at least a LayoutSVGRoot renderer, carrying a style. | |
| 195 ASSERT_NOT_REACHED(); | |
| 196 return 0; | |
| 197 } | |
| 198 | |
| 199 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const | 206 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const |
| 200 { | 207 { |
| 201 LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 208 LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
| 202 if (!style) | 209 if (!style) |
| 203 return 0; | 210 return 0; |
| 204 | 211 |
| 205 float fontSize = style->specifiedFontSize(); | 212 float fontSize = style->specifiedFontSize(); |
| 206 if (!fontSize) | 213 if (!fontSize) |
| 207 return 0; | 214 return 0; |
| 208 | 215 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 | 268 |
| 262 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 269 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
| 263 viewportSize = svg.currentViewBoxRect().size(); | 270 viewportSize = svg.currentViewBoxRect().size(); |
| 264 if (viewportSize.isEmpty()) | 271 if (viewportSize.isEmpty()) |
| 265 viewportSize = svg.currentViewportSize(); | 272 viewportSize = svg.currentViewportSize(); |
| 266 | 273 |
| 267 return true; | 274 return true; |
| 268 } | 275 } |
| 269 | 276 |
| 270 } | 277 } |
| OLD | NEW |