| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 case LengthTypePT: | 148 case LengthTypePT: |
| 149 return value / cssPixelsPerPoint; | 149 return value / cssPixelsPerPoint; |
| 150 case LengthTypePC: | 150 case LengthTypePC: |
| 151 return value / cssPixelsPerPica; | 151 return value / cssPixelsPerPica; |
| 152 } | 152 } |
| 153 | 153 |
| 154 ASSERT_NOT_REACHED(); | 154 ASSERT_NOT_REACHED(); |
| 155 return 0; | 155 return 0; |
| 156 } | 156 } |
| 157 | 157 |
| 158 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize&
viewportSize) |
| 159 { |
| 160 switch (mode) { |
| 161 case LengthModeWidth: |
| 162 return viewportSize.width(); |
| 163 case LengthModeHeight: |
| 164 return viewportSize.height(); |
| 165 case LengthModeOther: |
| 166 return sqrtf(viewportSize.diagonalLengthSquared() / 2); |
| 167 } |
| 168 ASSERT_NOT_REACHED(); |
| 169 return 0; |
| 170 } |
| 171 |
| 158 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe
ngthMode mode, ExceptionState& exceptionState) const | 172 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe
ngthMode mode, ExceptionState& exceptionState) const |
| 159 { | 173 { |
| 160 FloatSize viewportSize; | 174 FloatSize viewportSize; |
| 161 if (!determineViewport(viewportSize)) { | 175 if (!determineViewport(viewportSize)) { |
| 162 exceptionState.throwDOMException(NotSupportedError, "The viewport could
not be determined."); | 176 exceptionState.throwDOMException(NotSupportedError, "The viewport could
not be determined."); |
| 163 return 0; | 177 return 0; |
| 164 } | 178 } |
| 165 | 179 |
| 166 switch (mode) { | 180 return value / dimensionForLengthMode(mode, viewportSize) * 100; |
| 167 case LengthModeWidth: | |
| 168 return value / viewportSize.width() * 100; | |
| 169 case LengthModeHeight: | |
| 170 return value / viewportSize.height() * 100; | |
| 171 case LengthModeOther: | |
| 172 return value / sqrtf(viewportSize.diagonalLengthSquared() / 2) * 100; | |
| 173 }; | |
| 174 | |
| 175 ASSERT_NOT_REACHED(); | |
| 176 return 0; | |
| 177 } | 181 } |
| 178 | 182 |
| 179 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, ExceptionState& exceptionState) const | 183 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, ExceptionState& exceptionState) const |
| 180 { | 184 { |
| 181 FloatSize viewportSize; | 185 FloatSize viewportSize; |
| 182 if (!determineViewport(viewportSize)) { | 186 if (!determineViewport(viewportSize)) { |
| 183 exceptionState.throwDOMException(NotSupportedError, "The viewport could
not be determined."); | 187 exceptionState.throwDOMException(NotSupportedError, "The viewport could
not be determined."); |
| 184 return 0; | 188 return 0; |
| 185 } | 189 } |
| 186 return convertValueFromPercentageToUserUnits(value, mode, viewportSize); | 190 return convertValueFromPercentageToUserUnits(value, mode, viewportSize); |
| 187 } | 191 } |
| 188 | 192 |
| 189 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, const FloatSize& viewportSize) | 193 float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
ngthMode mode, const FloatSize& viewportSize) |
| 190 { | 194 { |
| 191 switch (mode) { | 195 return value * dimensionForLengthMode(mode, viewportSize); |
| 192 case LengthModeWidth: | |
| 193 return value * viewportSize.width(); | |
| 194 case LengthModeHeight: | |
| 195 return value * viewportSize.height(); | |
| 196 case LengthModeOther: | |
| 197 return value * sqrtf(viewportSize.diagonalLengthSquared() / 2); | |
| 198 } | |
| 199 | |
| 200 ASSERT_NOT_REACHED(); | |
| 201 return 0; | |
| 202 } | 196 } |
| 203 | 197 |
| 204 float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& v
alue, const FloatSize& viewportSize) | 198 float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& v
alue, const FloatSize& viewportSize) |
| 205 { | 199 { |
| 206 switch (value.unitMode()) { | 200 return value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), view
portSize)); |
| 207 case LengthModeWidth: | |
| 208 return value.scaleByPercentage(viewportSize.width()); | |
| 209 case LengthModeHeight: | |
| 210 return value.scaleByPercentage(viewportSize.height()); | |
| 211 case LengthModeOther: | |
| 212 return value.scaleByPercentage(sqrtf(viewportSize.diagonalLengthSquared(
) / 2)); | |
| 213 } | |
| 214 | |
| 215 ASSERT_NOT_REACHED(); | |
| 216 return 0; | |
| 217 } | 201 } |
| 218 | 202 |
| 219 static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte
xt) | 203 static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte
xt) |
| 220 { | 204 { |
| 221 if (!context) | 205 if (!context) |
| 222 return 0; | 206 return 0; |
| 223 | 207 |
| 224 const ContainerNode* currentContext = context; | 208 const ContainerNode* currentContext = context; |
| 225 do { | 209 do { |
| 226 if (currentContext->renderer()) | 210 if (currentContext->renderer()) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 295 |
| 312 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 296 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
| 313 viewportSize = svg.currentViewBoxRect().size(); | 297 viewportSize = svg.currentViewBoxRect().size(); |
| 314 if (viewportSize.isEmpty()) | 298 if (viewportSize.isEmpty()) |
| 315 viewportSize = svg.currentViewportSize(); | 299 viewportSize = svg.currentViewportSize(); |
| 316 | 300 |
| 317 return true; | 301 return true; |
| 318 } | 302 } |
| 319 | 303 |
| 320 } | 304 } |
| OLD | NEW |