Rewrite SVGLengthContext::ResolveRectangle to use Lengths

Rewrite said function to first resolve the SVGLength arguments to
Lengths, and then resolve those to user units. This avoids second-
guessing the underlying "type" of the SVGLength by relying on the same
code used to do this operation everywhere else.

Since percentage value in objectBoundingBox units are resolved using:

  r = reference * v / 100.0f

this is retained as a special case, since it affects a number of
tests. This is often more precise when `v` is a percentage (i.e often an
integer) than the alternative:

  r = reference * (v * 1.0f / 100.0f)

which is now the "common case" for non-percentage values.

This eliminates the use of `SVGLength::ScaleByPercentage()` from this
code-path.

Bug: 1286904
Change-Id: I6e3e82966be94eded1ed9d697215f98d1e06cec2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4118766
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/main@{#1091309}
diff --git a/css/filter-effects/filter-region-calc-001.html b/css/filter-effects/filter-region-calc-001.html
new file mode 100644
index 0000000..7f894ef
--- /dev/null
+++ b/css/filter-effects/filter-region-calc-001.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<title>SVG Filters: &lt;filter> with filter region using calc() for 'width'</title>
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#FilterProperty">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#ColorInterpolationFiltersProperty">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#FilterElement">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#feFloodElement">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#element-attrdef-filter-width">
+<link rel="match" href="reference/green-100x100.html">
+<style>
+#target {
+  width: 200px;
+  height: 100px;
+  background-color: red;
+  filter: url(#f);
+}
+</style>
+<div id="target"></div>
+<svg width="0" height="0">
+  <filter id="f" x="0" y="0" width="calc(25% + 0.25px)" height="1"
+          color-interpolation-filters="sRGB">
+    <feFlood flood-color="green"/>
+  </filter>
+</svg>
diff --git a/css/filter-effects/filter-region-units-001.html b/css/filter-effects/filter-region-units-001.html
new file mode 100644
index 0000000..332ca10
--- /dev/null
+++ b/css/filter-effects/filter-region-units-001.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<title>SVG Filters: &lt;filter> with filter region using  for 'width' w/ objectBoundingBox units</title>
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#FilterProperty">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#ColorInterpolationFiltersProperty">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#FilterElement">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#feFloodElement">
+<link rel="help" href="https://drafts.fxtf.org/filter-effects/#element-attrdef-filter-width">
+<link rel="match" href="reference/green-100x100.html">
+<style>
+#target {
+  width: 10px;
+  height: 100px;
+  background-color: red;
+  filter: url(#f);
+}
+</style>
+<div id="target"></div>
+<svg width="0" height="0">
+  <filter id="f" x="0" y="0" width="1em" height="1" font-size="10px"
+          color-interpolation-filters="sRGB">
+    <feFlood flood-color="green"/>
+  </filter>
+</svg>