Truly independent web browser
LibWeb: Implement SVGGeometryElement.isPointInFill()
Jelle Raaijmakers155a15bcff24
diff --git a/Libraries/LibWeb/CSS/ComputedValues.h b/Libraries/LibWeb/CSS/ComputedValues.hindex 7e94e215ff6..d67458044c2 100644--- a/Libraries/LibWeb/CSS/ComputedValues.h+++ b/Libraries/LibWeb/CSS/ComputedValues.h@@ -491,6 +491,7 @@ public:Clear clear() const { return static_cast<Clear>(m_noninherited.box->clear); }Color caret_color() const { return m_inherited.ui->caret_color_value(); }ColorInterpolation color_interpolation() const { return m_inherited.svg->color_interpolation_value(); }+ FillRule fill_rule() const { return m_inherited.svg->fill_rule_value(); }PreferredColorScheme color_scheme() const { return m_inherited.ui->color_scheme_value(); }ContentVisibility content_visibility() const { return static_cast<ContentVisibility>(m_inherited.box->content_visibility); }ReadonlySpan<ComputedValuesFFI::ComputedCursor> cursor() const { return m_inherited.ui->cursor_span(); }@@ -758,6 +759,7 @@ public:Optional<URL> fill_url_value() const { return paint_url_value(fill); }Optional<URL> stroke_url_value() const { return paint_url_value(stroke); }+ FillRule fill_rule_value() const { return static_cast<FillRule>(fill_rule); }StrokeLinecap stroke_linecap_value() const { return static_cast<StrokeLinecap>(stroke_linecap); }StrokeLinejoin stroke_linejoin_value() const { return static_cast<StrokeLinejoin>(stroke_linejoin); }ColorInterpolation color_interpolation_value() const { return static_cast<ColorInterpolation>(color_interpolation); }diff --git a/Libraries/LibWeb/SVG/SVGGeometryElement.cpp b/Libraries/LibWeb/SVG/SVGGeometryElement.cppindex 7ab10cd5355..48f7181d906 100644--- a/Libraries/LibWeb/SVG/SVGGeometryElement.cpp+++ b/Libraries/LibWeb/SVG/SVGGeometryElement.cpp@@ -6,6 +6,7 @@#include <AK/ScopeGuard.h>#include <LibGC/Heap.h>+#include <LibWeb/Bindings/DOMPointReadOnly.h>#include <LibWeb/CSS/CSSStyleProperties.h>#include <LibWeb/CSS/ElementBoxKind.h>#include <LibWeb/CSS/RustDeclarationBlock.h>@@ -64,7 +65,7 @@ static CSS::StyleRecordID declared_only_style_record(Layout::BegunRead const& re// The geometry of the element in user units, which the geometry queries such as getTotalLength() measure. It is empty// for an element without style.-Gfx::Path SVGGeometryElement::computed_path()+bool SVGGeometryElement::with_computed_values(Function<void(CSSPixelSize viewport_size, CSS::ComputedValues const&)> const& callback){// NB: Update layout so that the viewport size is resolved correctlyLayout::ForcedReadScope read { document() };@@ -79,8 +80,10 @@ Gfx::Path SVGGeometryElement::computed_path()// FIXME: Layout builds each shape's geometry in Rust (svg_geometry_path_of() in svg_formatting_context.rs), while// this reads the get_path() implementations, which duplicate it. Answer from the Rust builders instead, so// a fix to one copy cannot miss the other.- if (auto computed_values = computed_style())- return get_path({ viewport_size.width(), viewport_size.height() }, *computed_values);+ if (auto computed_values = computed_style()) {+ callback({ viewport_size.width(), viewport_size.height() }, *computed_values);+ return true;+ }// NB: An element with no style is either in a subtree that is not rendered, which the style engine answers// without installing anything, or outside the document, where no rule reaches it. The engine of the window's@@ -100,8 +103,45 @@ Gfx::Path SVGGeometryElement::computed_path()};auto view = style_computer.computed_style_record_view(style_read, record);if (!view)- return {};- return get_path({ viewport_size.width(), viewport_size.height() }, *view);+ return false;+ callback({ viewport_size.width(), viewport_size.height() }, *view);+ return true;+}++Gfx::Path SVGGeometryElement::computed_path()+{+ Gfx::Path path;+ with_computed_values([&](CSSPixelSize viewport_size, CSS::ComputedValues const& computed_values) {+ path = get_path(viewport_size, computed_values);+ });+ return path;+}++// https://svgwg.org/svg2-draft/types.html#__svg__SVGGeometryElement__isPointInFill+WebIDL::ExceptionOr<bool> SVGGeometryElement::is_point_in_fill(Bindings::DOMPointInit const& point)+{+ // The isPointInFill method, when invoked, must return true if the point given by point passed to the method, in+ // the coordinate space of an element, is inside the intended path as determined by the winding rule indicated by+ // the fill-rule property of an element; and must return false otherwise. Open subpaths must be implicitly closed+ // when computing the area inside the path, without affecting the actual subpaths. Points on the path itself must be+ // considered to be inside the path.+ // NB: Gfx::Path::contains() closes open subpaths and counts points on the path as inside.++ // The returned value is independent of any visual CSS property but fill-rule+ // If either of the x or y properties on point are infinite or NaN, then the method must return false.+ if (!isfinite(point.x) || !isfinite(point.y))+ return false;++ // If current element is a non-rendered element, and the UA is not able to compute the geometry of the element,+ // then throw an InvalidStateError.+ bool is_point_in_fill = false;+ auto has_geometry = with_computed_values([&](CSSPixelSize viewport_size, CSS::ComputedValues const& computed_values) {+ auto winding_rule = computed_values.fill_rule() == CSS::FillRule::Evenodd ? Gfx::WindingRule::EvenOdd : Gfx::WindingRule::Nonzero;+ is_point_in_fill = get_path(viewport_size, computed_values).contains({ point.x, point.y }, winding_rule);+ });+ if (!has_geometry)+ return WebIDL::InvalidStateError::create(HTML::relevant_realm(*this), "The element's geometry cannot be computed"_utf16);+ return is_point_in_fill;}// https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__getTotalLengthdiff --git a/Libraries/LibWeb/SVG/SVGGeometryElement.h b/Libraries/LibWeb/SVG/SVGGeometryElement.hindex 68366f199a2..503ba194921 100644--- a/Libraries/LibWeb/SVG/SVGGeometryElement.h+++ b/Libraries/LibWeb/SVG/SVGGeometryElement.h@@ -23,6 +23,7 @@ public:virtual Gfx::Path get_path(CSSPixelSize viewport_size, CSS::ComputedValues const&) = 0;Gfx::Path computed_path();+ WebIDL::ExceptionOr<bool> is_point_in_fill(Bindings::DOMPointInit const&);WebIDL::ExceptionOr<float> get_total_length();WebIDL::ExceptionOr<GC::Ref<Geometry::DOMPoint>> get_point_at_length(float distance);@@ -33,6 +34,8 @@ protected:virtual void visit_edges(Cell::Visitor&) override;private:+ bool with_computed_values(Function<void(CSSPixelSize viewport_size, CSS::ComputedValues const&)> const&);+GC::Ptr<SVGAnimatedNumber> m_path_length;};diff --git a/Libraries/LibWeb/SVG/SVGGeometryElement.idl b/Libraries/LibWeb/SVG/SVGGeometryElement.idlindex 124c555c3b2..74f271739fc 100644--- a/Libraries/LibWeb/SVG/SVGGeometryElement.idl+++ b/Libraries/LibWeb/SVG/SVGGeometryElement.idl@@ -3,7 +3,7 @@interface SVGGeometryElement : SVGGraphicsElement {[SameObject] readonly attribute SVGAnimatedNumber pathLength;- [FIXME] boolean isPointInFill(optional DOMPointInit point = {});+ boolean isPointInFill(optional DOMPointInit point = {});[FIXME] boolean isPointInStroke(optional DOMPointInit point = {});float getTotalLength();DOMPoint getPointAtLength(float distance);diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/content-visibility/content-visibility-svg-path.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/content-visibility/content-visibility-svg-path.txtnew file mode 100644index 00000000000..0b5d7100890--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/content-visibility/content-visibility-svg-path.txt@@ -0,0 +1,15 @@+Harness status: OK++Found 9 tests++3 Pass+6 Fail+Pass getTotalLength() should return nonzero value in a c-v:hidden subtree.+Pass getPointAtLength() should return nonzero values in a c-v:hidden subtree.+Pass isPointInFill() should return true in a c-v:hidden subtree.+Fail isPointInStroke() should return true in a c-v:hidden subtree.+Fail checkIntersection() should return true in a c-v:hidden subtree.+Fail checkEnclosure() should return true in a c-v:hidden subtree.+Fail getIntersectionList() should return items in a c-v:hidden subtree.+Fail getEnclosureList() should return items in a c-v:hidden subtree.+Fail path getBBox() should return nonzero values in a c-v:hidden subtree.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/content-visibility/content-visibility-svg-rect.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/content-visibility/content-visibility-svg-rect.txtnew file mode 100644index 00000000000..b9225cfd9e7--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/content-visibility/content-visibility-svg-rect.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++3 Pass+1 Fail+Pass getTotalLength() should return nonzero value in a c-v:hidden subtree.+Pass getPointAtLength() should return nonzero values in a c-v:hidden subtree.+Pass isPointInFill() should return true in a c-v:hidden subtree.+Fail isPointInStroke() should return true in a c-v:hidden subtree.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txtindex c15235857c5..e665b31e195 100644--- a/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/idlharness.window.txt@@ -2,8 +2,8 @@ Harness status: OKFound 1780 tests-1168 Pass-612 Fail+1181 Pass+599 FailPass idl_test setupPass idl_test validationPass Partial interface Document: original interface defined@@ -83,7 +83,7 @@ Pass SVGGeometryElement interface: existence and properties of interface prototyPass SVGGeometryElement interface: existence and properties of interface prototype object's "constructor" propertyPass SVGGeometryElement interface: existence and properties of interface prototype object's @@unscopables propertyPass SVGGeometryElement interface: attribute pathLength-Fail SVGGeometryElement interface: operation isPointInFill(optional DOMPointInit)+Pass SVGGeometryElement interface: operation isPointInFill(optional DOMPointInit)Fail SVGGeometryElement interface: operation isPointInStroke(optional DOMPointInit)Pass SVGGeometryElement interface: operation getTotalLength()Pass SVGGeometryElement interface: operation getPointAtLength(float)@@ -871,8 +871,8 @@ Pass SVGRectElement interface: objects.rect must inherit property "height" withPass SVGRectElement interface: objects.rect must inherit property "rx" with the proper typePass SVGRectElement interface: objects.rect must inherit property "ry" with the proper typePass SVGGeometryElement interface: objects.rect must inherit property "pathLength" with the proper type-Fail SVGGeometryElement interface: objects.rect must inherit property "isPointInFill(optional DOMPointInit)" with the proper type-Fail SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.rect with too few arguments must throw TypeError+Pass SVGGeometryElement interface: objects.rect must inherit property "isPointInFill(optional DOMPointInit)" with the proper type+Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.rect with too few arguments must throw TypeErrorFail SVGGeometryElement interface: objects.rect must inherit property "isPointInStroke(optional DOMPointInit)" with the proper typeFail SVGGeometryElement interface: calling isPointInStroke(optional DOMPointInit) on objects.rect with too few arguments must throw TypeErrorPass SVGGeometryElement interface: objects.rect must inherit property "getTotalLength()" with the proper type@@ -905,8 +905,8 @@ Pass SVGCircleElement interface: objects.circle must inherit property "cx" withPass SVGCircleElement interface: objects.circle must inherit property "cy" with the proper typePass SVGCircleElement interface: objects.circle must inherit property "r" with the proper typePass SVGGeometryElement interface: objects.circle must inherit property "pathLength" with the proper type-Fail SVGGeometryElement interface: objects.circle must inherit property "isPointInFill(optional DOMPointInit)" with the proper type-Fail SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.circle with too few arguments must throw TypeError+Pass SVGGeometryElement interface: objects.circle must inherit property "isPointInFill(optional DOMPointInit)" with the proper type+Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.circle with too few arguments must throw TypeErrorFail SVGGeometryElement interface: objects.circle must inherit property "isPointInStroke(optional DOMPointInit)" with the proper typeFail SVGGeometryElement interface: calling isPointInStroke(optional DOMPointInit) on objects.circle with too few arguments must throw TypeErrorPass SVGGeometryElement interface: objects.circle must inherit property "getTotalLength()" with the proper type@@ -941,8 +941,8 @@ Pass SVGEllipseElement interface: objects.ellipse must inherit property "cy" witPass SVGEllipseElement interface: objects.ellipse must inherit property "rx" with the proper typePass SVGEllipseElement interface: objects.ellipse must inherit property "ry" with the proper typePass SVGGeometryElement interface: objects.ellipse must inherit property "pathLength" with the proper type-Fail SVGGeometryElement interface: objects.ellipse must inherit property "isPointInFill(optional DOMPointInit)" with the proper type-Fail SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.ellipse with too few arguments must throw TypeError+Pass SVGGeometryElement interface: objects.ellipse must inherit property "isPointInFill(optional DOMPointInit)" with the proper type+Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.ellipse with too few arguments must throw TypeErrorFail SVGGeometryElement interface: objects.ellipse must inherit property "isPointInStroke(optional DOMPointInit)" with the proper typeFail SVGGeometryElement interface: calling isPointInStroke(optional DOMPointInit) on objects.ellipse with too few arguments must throw TypeErrorPass SVGGeometryElement interface: objects.ellipse must inherit property "getTotalLength()" with the proper type@@ -977,8 +977,8 @@ Pass SVGLineElement interface: objects.line must inherit property "y1" with thePass SVGLineElement interface: objects.line must inherit property "x2" with the proper typePass SVGLineElement interface: objects.line must inherit property "y2" with the proper typePass SVGGeometryElement interface: objects.line must inherit property "pathLength" with the proper type-Fail SVGGeometryElement interface: objects.line must inherit property "isPointInFill(optional DOMPointInit)" with the proper type-Fail SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.line with too few arguments must throw TypeError+Pass SVGGeometryElement interface: objects.line must inherit property "isPointInFill(optional DOMPointInit)" with the proper type+Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.line with too few arguments must throw TypeErrorFail SVGGeometryElement interface: objects.line must inherit property "isPointInStroke(optional DOMPointInit)" with the proper typeFail SVGGeometryElement interface: calling isPointInStroke(optional DOMPointInit) on objects.line with too few arguments must throw TypeErrorPass SVGGeometryElement interface: objects.line must inherit property "getTotalLength()" with the proper type@@ -1041,8 +1041,8 @@ Pass Stringification of objects.polylineFail SVGPolylineElement interface: objects.polyline must inherit property "points" with the proper typeFail SVGPolylineElement interface: objects.polyline must inherit property "animatedPoints" with the proper typePass SVGGeometryElement interface: objects.polyline must inherit property "pathLength" with the proper type-Fail SVGGeometryElement interface: objects.polyline must inherit property "isPointInFill(optional DOMPointInit)" with the proper type-Fail SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.polyline with too few arguments must throw TypeError+Pass SVGGeometryElement interface: objects.polyline must inherit property "isPointInFill(optional DOMPointInit)" with the proper type+Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.polyline with too few arguments must throw TypeErrorFail SVGGeometryElement interface: objects.polyline must inherit property "isPointInStroke(optional DOMPointInit)" with the proper typeFail SVGGeometryElement interface: calling isPointInStroke(optional DOMPointInit) on objects.polyline with too few arguments must throw TypeErrorPass SVGGeometryElement interface: objects.polyline must inherit property "getTotalLength()" with the proper type@@ -1073,8 +1073,8 @@ Pass Stringification of objects.polygonFail SVGPolygonElement interface: objects.polygon must inherit property "points" with the proper typeFail SVGPolygonElement interface: objects.polygon must inherit property "animatedPoints" with the proper typePass SVGGeometryElement interface: objects.polygon must inherit property "pathLength" with the proper type-Fail SVGGeometryElement interface: objects.polygon must inherit property "isPointInFill(optional DOMPointInit)" with the proper type-Fail SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.polygon with too few arguments must throw TypeError+Pass SVGGeometryElement interface: objects.polygon must inherit property "isPointInFill(optional DOMPointInit)" with the proper type+Pass SVGGeometryElement interface: calling isPointInFill(optional DOMPointInit) on objects.polygon with too few arguments must throw TypeErrorFail SVGGeometryElement interface: objects.polygon must inherit property "isPointInStroke(optional DOMPointInit)" with the proper typeFail SVGGeometryElement interface: calling isPointInStroke(optional DOMPointInit) on objects.polygon with too few arguments must throw TypeErrorPass SVGGeometryElement interface: objects.polygon must inherit property "getTotalLength()" with the proper typediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.txtindex f6e9453dcb8..c9981336879 100644--- a/Tests/LibWeb/Text/expected/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/path/property/test_style_flush_on_dom_api_with_d_property.txt@@ -2,9 +2,9 @@ Harness status: OKFound 4 tests-2 Pass-2 Fail+3 Pass+1 FailPass getTotalLength() with d propertyPass getPointAtLength() with d property-Fail isPointInFill() with d property+Pass isPointInFill() with d propertyFail isPointInStroke() with d property\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/scripted/ellipse-auto-radii.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/scripted/ellipse-auto-radii.txtindex 96a42d9fbc8..8fcf67b09d7 100644--- a/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/scripted/ellipse-auto-radii.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/shapes/scripted/ellipse-auto-radii.txt@@ -2,12 +2,12 @@ Harness status: OKFound 7 tests-5 Pass-2 Fail+6 Pass+1 FailPass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getTotalLength resolves auto rx/ry.Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getTotalLength returns 0 when both rx and ry are auto.Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getPointAtLength(0) at the 3 o'clock starting point.-Fail SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, isPointInFill resolves auto rx/ry.+Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, isPointInFill resolves auto rx/ry.Fail SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, isPointInStroke with dasharray resolves auto rx/ry.Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getTotalLength resolves auto rx/ry against percentage values on the correct axis.Pass SVG ellipse rx/ry auto resolution affects SVGGeometryElement methods, getPointAtLength(0) with percentage ry uses height-axis resolution.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.isPointInFill-01.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.isPointInFill-01.txtnew file mode 100644index 00000000000..b19645409b5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGeometryElement.isPointInFill-01.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 9 tests++9 Pass+Pass SVGGeometryElement.prototype.isPointInFill, no arguments.+Pass SVGGeometryElement.prototype.isPointInFill, null/undefined.+Pass SVGGeometryElement.prototype.isPointInFill, non-finite argument.+Pass SVGGeometryElement.prototype.isPointInFill, functional test.+Pass SVGGeometryElement.prototype.isPointInFill, functional test with zoom.+Pass SVGGeometryElement.prototype.isPointInFill, points on the shape boundary are inside.+Pass SVGGeometryElement.prototype.isPointInFill, 'fill-rule'.+Pass SVGGeometryElement.prototype.isPointInFill, 'visibility' and 'pointer-events' have no effect.+Pass SVGGeometryElement.prototype.isPointInFill, 'clip-rule' never overrides 'fill-rule'.\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-contain/content-visibility/content-visibility-svg-path.html b/Tests/LibWeb/Text/input/wpt-import/css/css-contain/content-visibility/content-visibility-svg-path.htmlnew file mode 100644index 00000000000..70f6ff2b1e2--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-contain/content-visibility/content-visibility-svg-path.html@@ -0,0 +1,101 @@+<!DOCTYPE html>+<link rel="author" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/css-contain/#content-visibility">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>++<style>+body {+ margin: 0;+ padding: 0;+}+div {+ content-visibility:hidden;+}+path {+ stroke-width: 5px;+ stroke:green;+}+</style>++<div>+ <svg xmlns="http://www.w3.org/2000/svg">+ <path id="path" d="M5 5 L 10 5 L 10 10 L 5 10 Z"/>+ </svg>+</div>++<script>+ test(() => {+ const pathElement = document.getElementById('path');+ const length = pathElement.getTotalLength();+ assert_greater_than(length, 0, 'length');+ }, `getTotalLength() should return nonzero value in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ const point = pathElement.getPointAtLength(0);+ assert_greater_than(point.x, 0, 'point.x');+ assert_greater_than(point.y, 0, 'point.y');+ }, `getPointAtLength() should return nonzero values in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ const inFill = pathElement.isPointInFill({ x: 7, y: 7});+ assert_true(inFill, 'fill');+ }, `isPointInFill() should return true in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ const inStroke = pathElement.isPointInStroke({ x: 7, y: 7});+ assert_true(inStroke, 'stroke');+ }, `isPointInStroke() should return true in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ var rect = pathElement.ownerSVGElement.createSVGRect();+ rect.x = 10;+ rect.y = 10;+ rect.width = 50;+ rect.height = 50;+ const intersection = pathElement.ownerSVGElement.checkIntersection(pathElement, rect);+ assert_true(intersection, 'intersection');+ }, `checkIntersection() should return true in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ var rect = pathElement.ownerSVGElement.createSVGRect();+ rect.width = 50;+ rect.height = 50;+ const enclosed = pathElement.ownerSVGElement.checkEnclosure(pathElement, rect);+ assert_true(enclosed, 'enclosure');+ }, `checkEnclosure() should return true in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ var rect = pathElement.ownerSVGElement.createSVGRect();+ rect.x = 10;+ rect.y = 10;+ rect.width = 50;+ rect.height = 50;+ const intersectionList = pathElement.ownerSVGElement.getIntersectionList(rect, null);+ assert_greater_than(intersectionList.length, 0, 'intersection');+ }, `getIntersectionList() should return items in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ var rect = pathElement.ownerSVGElement.createSVGRect();+ rect.width = 50;+ rect.height = 50;+ const enclusureList = pathElement.ownerSVGElement.getEnclosureList(rect, null);+ assert_greater_than(enclusureList.length, 0, 'intersection');+ }, `getEnclosureList() should return items in a c-v:hidden subtree.`);++ test(() => {+ const pathElement = document.getElementById('path');+ const bbox = pathElement.getBBox();+ assert_not_equals(bbox.x, 0, 'x');+ assert_not_equals(bbox.y, 0, 'y');+ assert_not_equals(bbox.width, 0, 'width');+ assert_not_equals(bbox.height, 0, 'height');+ }, `path getBBox() should return nonzero values in a c-v:hidden subtree.`);+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-contain/content-visibility/content-visibility-svg-rect.html b/Tests/LibWeb/Text/input/wpt-import/css/css-contain/content-visibility/content-visibility-svg-rect.htmlnew file mode 100644index 00000000000..a828218f750--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-contain/content-visibility/content-visibility-svg-rect.html@@ -0,0 +1,52 @@+<!DOCTYPE html>+<link rel="author" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/css-contain/#content-visibility">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>++<style>+body {+ margin: 0;+ padding: 0;+}+div {+ content-visibility:hidden;+}+rect {+ stroke-width: 5px;+ stroke:green;+}+</style>++<div>+ <svg xmlns="http://www.w3.org/2000/svg">+ <rect id="rect" x="5" y="5" width="10" height="10"/>+ </svg>+</div>++<script>+ test(() => {+ const rectElement = document.getElementById('rect');+ const length = rectElement.getTotalLength();+ assert_greater_than(length, 0, 'length');+ }, `getTotalLength() should return nonzero value in a c-v:hidden subtree.`);++ test(() => {+ const rectElement = document.getElementById('rect');+ const point = rectElement.getPointAtLength(0);+ assert_greater_than(point.x, 0, 'point.x');+ assert_greater_than(point.y, 0, 'point.y');+ }, `getPointAtLength() should return nonzero values in a c-v:hidden subtree.`);++ test(() => {+ const rectElement = document.getElementById('rect');+ const inFill = rectElement.isPointInFill({ x: 7, y: 7});+ assert_true(inFill, 'fill');+ }, `isPointInFill() should return true in a c-v:hidden subtree.`);++ test(() => {+ const rectElement = document.getElementById('rect');+ const inStroke = rectElement.isPointInStroke({ x: 7, y: 7});+ assert_true(inStroke, 'stroke');+ }, `isPointInStroke() should return true in a c-v:hidden subtree.`);+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.isPointInFill-01.svg b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.isPointInFill-01.svgnew file mode 100644index 00000000000..714deee43d4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGeometryElement.isPointInFill-01.svg@@ -0,0 +1,145 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400"+ xmlns:h="http://www.w3.org/1999/xhtml">+ <title>SVGGeometryElement.prototype.isPointInFill</title>+ <metadata>+ <h:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#InterfaceSVGGeometryElement"/>+ <h:link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGeometryElement__isPointInFill"/>+ </metadata>+ <h:script src="../../../resources/testharness.js"/>+ <h:script src="../../../resources/testharnessreport.js"/>++ <g id="container">+ <circle id="circle-at-origin" r="10" fill="blue"/>+ <ellipse id="ellipse" cx="150" cy="150" rx="200" ry="100"+ fill="blue" fill-opacity="0.1"+ stroke-width="100" stroke="green" stroke-opacity="0.2"/>+ <rect id="basic-rectangle" x="90" y="200" width="100" height="100" fill="lightblue"/>+ <path id="rectangular-outline-evenodd" d="M200,200h100v100h-100z m20,20h60v60h-60z"+ fill="lightblue" fill-rule="evenodd"/>+ <path id="rectangular-outline-nonzero" d="M310,200h100v100h-100z m20,20h60v60h-60z"+ fill="lightblue"/>+ <clipPath>+ <path id="rectangular-outline-nonzero-in-clip" d="M200,200h100v100h-100z m20,20h60v60h-60z"+ fill="lightblue" clip-rule="evenodd"/>+ </clipPath>+ </g>++ <script><![CDATA[+ 'use strict';++ const pointsToTest = [+ { x: 150, y: 150 },+ { x: 275, y: 150 },+ { x: 250, y: 225 },+ { x: 0, y: 0 },+ { x: 275, y: 250 },+ ];+ function testPoints(element) {+ const expected = [true, true, true, false, false];+ pointsToTest.forEach(function(point, index) {+ assert_equals(element.isPointInFill(point),+ expected[index], "point at " + point.x + ", " + point.y);+ });+ }+ function testResultVector(element) {+ return pointsToTest.map(function(point) {+ return element.isPointInFill(point);+ });+ }++ test(function() {+ let circleAtOrigin = document.getElementById("circle-at-origin");+ assert_true(circleAtOrigin.isPointInFill());+ let ellipse = document.getElementById("ellipse");+ assert_false(ellipse.isPointInFill());+ }, document.title + ", no arguments.");++ test(function() {+ let circleAtOrigin = document.getElementById("circle-at-origin");+ assert_true(circleAtOrigin.isPointInFill(null));+ assert_true(circleAtOrigin.isPointInFill(undefined));+ let ellipse = document.getElementById("ellipse");+ assert_false(ellipse.isPointInFill(null));+ assert_false(ellipse.isPointInFill(undefined));+ }, document.title + ", null/undefined.");++ test(function() {+ let circleAtOrigin = document.getElementById("circle-at-origin");+ assert_false(circleAtOrigin.isPointInFill({ x: NaN, y: 0 }), "x is NaN");+ assert_false(circleAtOrigin.isPointInFill({ x: Infinity, y: 0 }), "x is Infinity");+ assert_false(circleAtOrigin.isPointInFill({ x: -Infinity, y: 0 }), "x is -Infinity");+ assert_false(circleAtOrigin.isPointInFill({ x: 0, y: NaN }), "y is NaN");+ assert_false(circleAtOrigin.isPointInFill({ x: 0, y: Infinity }), "y is Infinity");+ assert_false(circleAtOrigin.isPointInFill({ x: 0, y: -Infinity }), "y is -Infinity");+ }, document.title + ", non-finite argument.");++ test(function() {+ testPoints(document.getElementById("ellipse"));+ }, document.title + ", functional test.");++ test(function() {+ const container = document.getElementById("container");+ try {+ container.style.zoom = 3;+ testPoints(document.getElementById("ellipse"));+ } finally {+ container.style.zoom = 1;+ }+ }, document.title + ", functional test with zoom.");++ test(function() {+ const circleAtOrigin = document.getElementById("circle-at-origin");+ assert_true(circleAtOrigin.isPointInFill({ x: 10, y: 0 }), "circle edge 3 o'clock");+ assert_true(circleAtOrigin.isPointInFill({ x: 0, y: 10 }), "circle edge 6 o'clock");+ const evenOdd = document.getElementById("rectangular-outline-evenodd");+ assert_true(evenOdd.isPointInFill({ x: 200, y: 250 }),+ "rectangular path left outside edge");+ assert_true(evenOdd.isPointInFill({ x: 220, y: 250 }),+ "rectangular path left inside edge");+ assert_true(evenOdd.isPointInFill({ x: 250, y: 300 }),+ "rectangular path bottom outside edge");+ assert_true(evenOdd.isPointInFill({ x: 250, y: 280 }),+ "rectangular path bottom inside edge");+ const rectangle = document.getElementById("basic-rectangle");+ assert_true(rectangle.isPointInFill({ x: 140, y: 200 }), "rect top edge");+ assert_true(rectangle.isPointInFill({ x: 190, y: 250 }), "rect right edge");+ assert_true(rectangle.isPointInFill({ x: 140, y: 300 }), "rect bottom edge");+ assert_true(rectangle.isPointInFill({ x: 90, y: 250 }), "rect left edge");+ }, document.title + ", points on the shape boundary are inside.");++ test(function() {+ let evenOdd = document.getElementById("rectangular-outline-evenodd");+ assert_false(evenOdd.isPointInFill({ x: 250, y: 250 }));+ let nonZeroWinding = document.getElementById("rectangular-outline-nonzero");+ assert_true(nonZeroWinding.isPointInFill({ x: 360, y: 250 }));+ }, document.title + ", 'fill-rule'.");++ test(function() {+ let ellipse = document.getElementById("ellipse");+ // Results for 'pointer-events: visiblePainted' and 'visibility: visible'.+ let expectedResults = testResultVector(ellipse);++ const pointerEventValues = [ "bounding-box", "visibleFill",+ "visibleStroke", "visiblePainted", "fill",+ "stroke", "painted", "visible", "all",+ "none" ];++ ellipse.setAttribute("visibility", "visible");+ for (let pointerEventValue of pointerEventValues) {+ ellipse.setAttribute("pointer-events", pointerEventValue);+ assert_array_equals(expectedResults, testResultVector(ellipse));+ }++ ellipse.setAttribute("visibility", "hidden");+ for (let pointerEventValue of pointerEventValues) {+ ellipse.setAttribute("pointer-events", pointerEventValue);+ assert_array_equals(expectedResults, testResultVector(ellipse));+ }+ }, document.title + ", 'visibility' and 'pointer-events' have no effect.");++ test(function() {+ let nonZeroWinding = document.getElementById("rectangular-outline-nonzero-in-clip");+ assert_true(nonZeroWinding.isPointInFill({ x: 250, y: 250 }));+ }, document.title + ", 'clip-rule' never overrides 'fill-rule'.");+ ]]></script>+</svg>