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

Unified Diff: Source/core/svg/SVGLengthContext.cpp

Issue 901193002: De-ExceptionState-ify SVGLengthContext (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/svg/SVGLengthContext.h ('k') | Source/core/svg/SVGLengthList.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGLengthContext.cpp
diff --git a/Source/core/svg/SVGLengthContext.cpp b/Source/core/svg/SVGLengthContext.cpp
index 40c86bb6f21d2f797a8a86e063768fa856c38f13..383e714a5553020c8435bb33bdd18aef43b9f630 100644
--- a/Source/core/svg/SVGLengthContext.cpp
+++ b/Source/core/svg/SVGLengthContext.cpp
@@ -23,14 +23,9 @@
#include "config.h"
#include "core/svg/SVGLengthContext.h"
-#include "bindings/core/v8/ExceptionMessages.h"
-#include "bindings/core/v8/ExceptionState.h"
-#include "core/SVGNames.h"
#include "core/css/CSSHelper.h"
-#include "core/dom/ExceptionCode.h"
-#include "core/rendering/RenderView.h"
-#include "core/rendering/svg/RenderSVGRoot.h"
-#include "core/rendering/svg/RenderSVGViewportContainer.h"
+#include "core/layout/LayoutObject.h"
+#include "core/rendering/style/RenderStyle.h"
#include "core/svg/SVGSVGElement.h"
#include "platform/fonts/FontMetrics.h"
@@ -91,22 +86,25 @@ float SVGLengthContext::resolveLength(const SVGElement* context, SVGUnitTypes::S
return x->valueAsPercentage();
}
-float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit, ExceptionState& exceptionState) const
+float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const
{
switch (fromUnit) {
case LengthTypeUnknown:
- exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::argumentNullOrIncorrectType(3, "SVGLengthType"));
return 0;
case LengthTypeNumber:
return value;
case LengthTypePX:
return value;
- case LengthTypePercentage:
- return convertValueFromPercentageToUserUnits(value, mode, exceptionState) / 100;
+ case LengthTypePercentage: {
+ FloatSize viewportSize;
+ if (!determineViewport(viewportSize))
+ return 0;
+ return convertValueFromPercentageToUserUnits(value, mode, viewportSize) / 100;
+ }
case LengthTypeEMS:
- return convertValueFromEMSToUserUnits(value, exceptionState);
+ return convertValueFromEMSToUserUnits(value);
case LengthTypeEXS:
- return convertValueFromEXSToUserUnits(value, exceptionState);
+ return convertValueFromEXSToUserUnits(value);
case LengthTypeCM:
return value * cssPixelsPerCentimeter;
case LengthTypeMM:
@@ -123,20 +121,23 @@ float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode,
return 0;
}
-float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mode, SVGLengthType toUnit, ExceptionState& exceptionState) const
+float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mode, SVGLengthType toUnit) const
{
switch (toUnit) {
case LengthTypeUnknown:
- exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::argumentNullOrIncorrectType(3, "SVGLengthType"));
return 0;
case LengthTypeNumber:
return value;
- case LengthTypePercentage:
- return convertValueFromUserUnitsToPercentage(value * 100, mode, exceptionState);
+ case LengthTypePercentage: {
+ FloatSize viewportSize;
+ if (!determineViewport(viewportSize))
+ return 0;
+ return convertValueFromUserUnitsToPercentage(value * 100, mode, viewportSize);
+ }
case LengthTypeEMS:
- return convertValueFromUserUnitsToEMS(value, exceptionState);
+ return convertValueFromUserUnitsToEMS(value);
case LengthTypeEXS:
- return convertValueFromUserUnitsToEXS(value, exceptionState);
+ return convertValueFromUserUnitsToEXS(value);
case LengthTypePX:
return value;
case LengthTypeCM:
@@ -169,27 +170,11 @@ static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize&
return 0;
}
-float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLengthMode mode, ExceptionState& exceptionState) const
+float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLengthMode mode, const FloatSize& viewportSize)
{
- FloatSize viewportSize;
- if (!determineViewport(viewportSize)) {
- exceptionState.throwDOMException(NotSupportedError, "The viewport could not be determined.");
- return 0;
- }
-
return value / dimensionForLengthMode(mode, viewportSize) * 100;
}
-float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLengthMode mode, ExceptionState& exceptionState) const
-{
- FloatSize viewportSize;
- if (!determineViewport(viewportSize)) {
- exceptionState.throwDOMException(NotSupportedError, "The viewport could not be determined.");
- return 0;
- }
- return convertValueFromPercentageToUserUnits(value, mode, viewportSize);
-}
-
float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLengthMode mode, const FloatSize& viewportSize)
{
return value * dimensionForLengthMode(mode, viewportSize);
@@ -217,60 +202,47 @@ static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte
return 0;
}
-float SVGLengthContext::convertValueFromUserUnitsToEMS(float value, ExceptionState& exceptionState) const
+float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const
{
RenderStyle* style = renderStyleForLengthResolving(m_context);
- if (!style) {
- exceptionState.throwDOMException(NotSupportedError, "No context could be found.");
+ if (!style)
return 0;
- }
float fontSize = style->specifiedFontSize();
- if (!fontSize) {
- exceptionState.throwDOMException(NotSupportedError, "No font-size could be determined.");
+ if (!fontSize)
return 0;
- }
return value / fontSize;
}
-float SVGLengthContext::convertValueFromEMSToUserUnits(float value, ExceptionState& exceptionState) const
+float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const
{
RenderStyle* style = renderStyleForLengthResolving(m_context);
- if (!style) {
- exceptionState.throwDOMException(NotSupportedError, "No context could be found.");
+ if (!style)
return 0;
- }
-
return value * style->specifiedFontSize();
}
-float SVGLengthContext::convertValueFromUserUnitsToEXS(float value, ExceptionState& exceptionState) const
+float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const
{
RenderStyle* style = renderStyleForLengthResolving(m_context);
- if (!style) {
- exceptionState.throwDOMException(NotSupportedError, "No context could be found.");
+ if (!style)
return 0;
- }
// Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
// if this causes problems in real world cases maybe it would be best to remove this
float xHeight = ceilf(style->fontMetrics().xHeight());
- if (!xHeight) {
- exceptionState.throwDOMException(NotSupportedError, "No x-height could be determined.");
+ if (!xHeight)
return 0;
- }
return value / xHeight;
}
-float SVGLengthContext::convertValueFromEXSToUserUnits(float value, ExceptionState& exceptionState) const
+float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const
{
RenderStyle* style = renderStyleForLengthResolving(m_context);
- if (!style) {
- exceptionState.throwDOMException(NotSupportedError, "No context could be found.");
+ if (!style)
return 0;
- }
// Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
// if this causes problems in real world cases maybe it would be best to remove this
« no previous file with comments | « Source/core/svg/SVGLengthContext.h ('k') | Source/core/svg/SVGLengthList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698