Commit 0800969a authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Simplify CSSUnitValue conversion.

Currently, when we convert a CSSUnitValue to a different unit, we
essentially consult a NxN table to figure out the scale factor, where
N is the number of units.

An easier way is to first convert to the canonical unit, then convert
from the canonical unit to the target unit. This only requires a lookup
table of size N instead of NxN, greatly simplifying the code.

Bug: 776173
Change-Id: Icb28386938f9cb7de4d917c72426154b8f45d6e6
Reviewed-on: https://chromium-review.googlesource.com/798930Reviewed-by: default avatarnainar <nainar@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520848}
parent e1b7ac80
...@@ -24,8 +24,11 @@ test(() => { ...@@ -24,8 +24,11 @@ test(() => {
}, 'Converting a CSSUnitValue to an incompatible unit throws TypeError'); }, 'Converting a CSSUnitValue to an incompatible unit throws TypeError');
test(() => { test(() => {
assert_style_value_equals(CSS.number(1).to('number'), CSS.number(1)); for (const unit of gValidUnits) {
assert_style_value_equals(CSS.px(1).to('px'), CSS.px(1)); // FIXME(778495): Remove this check onec all the units are supported.
if (CSS[unit])
assert_style_value_equals(CSS[unit](1).to(unit), CSS[unit](1));
}
}, 'Converting a CSSUnitValue to its own unit returns itself'); }, 'Converting a CSSUnitValue to its own unit returns itself');
// TODO(776173): cssUnitValue_toMethod.html has more comprehensive tests of converting // TODO(776173): cssUnitValue_toMethod.html has more comprehensive tests of converting
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment