Bug 1529572 - Should resolve absolute units r=longsonr

Firefox only failure.

Differential Revision: https://phabricator.services.mozilla.com/D35614

--HG--
extra : moz-landing-system : lando
This commit is contained in:
violet 2019-06-23 12:51:05 +00:00
Родитель 8a8f7223a9
Коммит 59ab77300a
5 изменённых файлов: 34 добавлений и 29 удалений

Просмотреть файл

@ -213,10 +213,12 @@ float DOMSVGLength::GetValue(ErrorResult& aRv) {
}
return value;
}
if (mUnit == SVGLength_Binding::SVG_LENGTHTYPE_NUMBER ||
mUnit == SVGLength_Binding::SVG_LENGTHTYPE_PX) {
return mValue;
float unitToPx;
if (UserSpaceMetrics::ResolveAbsoluteUnit(mUnit, unitToPx)) {
return mValue * unitToPx;
}
// else [SVGWG issue] Can't convert this length's value to user units
// ReportToConsole
aRv.Throw(NS_ERROR_FAILURE);

Просмотреть файл

@ -204,22 +204,40 @@ float SVGAnimatedLength::GetPixelsPerUnit(nsIFrame* aFrame,
// See https://www.w3.org/TR/css-values-3/#absolute-lengths
static const float DPI = 96.0f;
float SVGAnimatedLength::GetPixelsPerUnit(const UserSpaceMetrics& aMetrics,
uint8_t aUnitType) const {
bool UserSpaceMetrics::ResolveAbsoluteUnit(uint8_t aUnitType, float& aRes) {
switch (aUnitType) {
case SVGLength_Binding::SVG_LENGTHTYPE_NUMBER:
case SVGLength_Binding::SVG_LENGTHTYPE_PX:
return 1;
aRes = 1;
break;
case SVGLength_Binding::SVG_LENGTHTYPE_MM:
return DPI / MM_PER_INCH_FLOAT;
aRes = DPI / MM_PER_INCH_FLOAT;
break;
case SVGLength_Binding::SVG_LENGTHTYPE_CM:
return 10.0f * DPI / MM_PER_INCH_FLOAT;
aRes = 10.0f * DPI / MM_PER_INCH_FLOAT;
break;
case SVGLength_Binding::SVG_LENGTHTYPE_IN:
return DPI;
aRes = DPI;
break;
case SVGLength_Binding::SVG_LENGTHTYPE_PT:
return DPI / POINTS_PER_INCH_FLOAT;
aRes = DPI / POINTS_PER_INCH_FLOAT;
break;
case SVGLength_Binding::SVG_LENGTHTYPE_PC:
return 12.0f * DPI / POINTS_PER_INCH_FLOAT;
aRes = 12.0f * DPI / POINTS_PER_INCH_FLOAT;
break;
default:
return false;
}
return true;
}
float SVGAnimatedLength::GetPixelsPerUnit(const UserSpaceMetrics& aMetrics,
uint8_t aUnitType) const {
float res;
if (UserSpaceMetrics::ResolveAbsoluteUnit(aUnitType, res)) {
return res;
}
switch (aUnitType) {
case SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE:
return aMetrics.GetAxisLength(mCtxType) / 100.0f;
case SVGLength_Binding::SVG_LENGTHTYPE_EMS:

Просмотреть файл

@ -33,6 +33,7 @@ class SVGViewportElement;
class UserSpaceMetrics {
public:
static bool ResolveAbsoluteUnit(uint8_t aUnitType, float& aRes);
virtual ~UserSpaceMetrics() = default;
virtual float GetEmLength() const = 0;

Просмотреть файл

@ -7,19 +7,3 @@
[SVGLength, converting from 'px' to other units (detached), exs]
expected: FAIL
[SVGLength, converting from 'px' to other units (detached), cm]
expected: FAIL
[SVGLength, converting from 'px' to other units (detached), mm]
expected: FAIL
[SVGLength, converting from 'px' to other units (detached), in]
expected: FAIL
[SVGLength, converting from 'px' to other units (detached), pt]
expected: FAIL
[SVGLength, converting from 'px' to other units (detached), pc]
expected: FAIL

Просмотреть файл

@ -72,7 +72,7 @@ test(function() {
var referenceValue = 48 * 2.54 / cssPixelsPerInch;
assert_equals(length.valueAsString, referenceValue.toFixed(2) + "cm");
assert_approx_equals(length.valueInSpecifiedUnits, referenceValue, 0.01);
assert_equals(length.value, 48);
assert_approx_equals(length.value, 48, 0.001);
assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_CM);
}, document.title + ", cm");
@ -119,4 +119,4 @@ test(function() {
assert_equals(length.value, 16);
assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PC);
}, document.title + ", pc");
</script>
</script>