Truly independent web browser
LibWeb: Run more img relevant mutations
Andreas Kling9d800b4c3d43
diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cppindex 215c24a34ed..1ba9bd4f162 100644--- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp@@ -174,6 +174,32 @@ void HTMLImageElement::adopted_from(DOM::Document& old_document)// FIXME: The current and pending requests may still be pointing at the old document's SharedResourceRequests.}+// https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element:html-element-moving-steps+void HTMLImageElement::moved_from(IsSubtreeRoot is_subtree_root, GC::Ptr<DOM::Node> old_ancestor)+{+ // The img HTML element moving steps, given movedNode, isSubtreeRoot, and oldAncestor are:+ Base::moved_from(is_subtree_root, old_ancestor);++ // 1. If isSubtreeRoot is true and oldAncestor is a picture element, then count this as a relevant mutation for+ // movedNode.+ if (is_subtree_root == IsSubtreeRoot::Yes && is<HTMLPictureElement>(old_ancestor.ptr()))+ update_the_image_data();+}++// https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element:html-element-removing-steps+void HTMLImageElement::removed_from(IsSubtreeRoot is_subtree_root, DOM::Node* old_ancestor, DOM::Node& old_root)+{+ // The img HTML element removing steps, given removedNode, isSubtreeRoot, and oldAncestor are:+ Base::removed_from(is_subtree_root, old_ancestor, old_root);++ // 1. If isSubtreeRoot is true and oldAncestor is a picture element, then count this as a relevant mutation for+ // removedNode.+ if (is_subtree_root == IsSubtreeRoot::Yes && is<HTMLPictureElement>(old_ancestor))+ update_the_image_data();++ // FIXME: 2. Set removedNode's last auto-sizes width to null.+}+void HTMLImageElement::visit_edges(Cell::Visitor& visitor){Base::visit_edges(visitor);@@ -254,12 +280,32 @@ void HTMLImageElement::apply_presentational_hints(Vector<CSS::StyleProperty>& pr});}-void HTMLImageElement::form_associated_element_attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const&, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_)+static ReferrerPolicy::ReferrerPolicy referrer_policy_attribute_state(Optional<Utf16String> const& value)+{+ return ReferrerPolicy::from_string(value.value_or({})).value_or(ReferrerPolicy::ReferrerPolicy::EmptyString);+}++void HTMLImageElement::form_associated_element_attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_){+ // https://html.spec.whatwg.org/multipage/images.html#relevant-mutations+ // The element's crossorigin attribute's state is changed.if (!namespace_.has_value() && name == HTML::AttributeNames::crossorigin) {+ auto old_cors_setting = m_cors_setting;m_cors_setting = cors_setting_attribute_from_keyword(value.map([](auto const& value) { return value.utf16_view(); }));+ if (m_cors_setting != old_cors_setting)+ update_the_image_data();}+ // The element's referrerpolicy attribute's state is changed.+ if (!namespace_.has_value() && name == HTML::AttributeNames::referrerpolicy) {+ if (referrer_policy_attribute_state(old_value) != referrer_policy_attribute_state(value))+ update_the_image_data();+ }++ // The element's src, srcset, or sizes attributes are set, changed, or removed.+ if (name == HTML::AttributeNames::sizes)+ update_the_image_data();+if (name.is_one_of(HTML::AttributeNames::src, HTML::AttributeNames::srcset)) {update_the_image_data(true);// The attribute change can flip is_image_pending() immediately (e.g. an alt-rendering imgdiff --git a/Libraries/LibWeb/HTML/HTMLImageElement.h b/Libraries/LibWeb/HTML/HTMLImageElement.hindex e7364bfb823..b9f39681849 100644--- a/Libraries/LibWeb/HTML/HTMLImageElement.h+++ b/Libraries/LibWeb/HTML/HTMLImageElement.h@@ -138,6 +138,8 @@ private:virtual void finalize() override;virtual void adopted_from(DOM::Document&) override;+ virtual void moved_from(IsSubtreeRoot, GC::Ptr<DOM::Node> old_ancestor) override;+ virtual void removed_from(IsSubtreeRoot, DOM::Node* old_ancestor, DOM::Node& old_root) override;virtual bool is_presentational_hint(Utf16FlyString const&) const override;virtual void apply_presentational_hints(Vector<CSS::StyleProperty>&) const override;diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-img-element/relevant-mutations.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-img-element/relevant-mutations.txtindex e44808cb1a0..d8ecead7ca0 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-img-element/relevant-mutations.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-img-element/relevant-mutations.txt@@ -2,8 +2,8 @@ Harness status: OKFound 113 tests-83 Pass-30 Fail+108 Pass+5 FailPass src setPass src changedPass src removed@@ -25,17 +25,17 @@ Pass crossorigin use-credentials to absent, src absentPass crossorigin use-credentials to empty, src absentPass crossorigin use-credentials to anonymous, src absentPass crossorigin use-credentials to invalid, src absent-Fail crossorigin absent to empty, src already set-Fail crossorigin absent to anonymous, src already set-Fail crossorigin absent to use-credentials, src already set-Fail crossorigin empty to absent, src already set-Fail crossorigin empty to use-credentials, src already set-Fail crossorigin anonymous to absent, src already set-Fail crossorigin anonymous to use-credentials, src already set-Fail crossorigin use-credentials to absent, src already set-Fail crossorigin use-credentials to empty, src already set-Fail crossorigin use-credentials to anonymous, src already set-Fail crossorigin use-credentials to invalid, src already set+Pass crossorigin absent to empty, src already set+Pass crossorigin absent to anonymous, src already set+Pass crossorigin absent to use-credentials, src already set+Pass crossorigin empty to absent, src already set+Pass crossorigin empty to use-credentials, src already set+Pass crossorigin anonymous to absent, src already set+Pass crossorigin anonymous to use-credentials, src already set+Pass crossorigin use-credentials to absent, src already set+Pass crossorigin use-credentials to empty, src already set+Pass crossorigin use-credentials to anonymous, src already set+Pass crossorigin use-credentials to invalid, src already setPass referrerpolicy absent to no-referrer-when-downgrade, src absentPass referrerpolicy absent to no-referrer, src absentPass referrerpolicy empty to no-referrer-when-downgrade, src absent@@ -48,20 +48,20 @@ Pass referrerpolicy no-referrer to absent, src absentPass referrerpolicy no-referrer to empty, src absentPass referrerpolicy no-referrer to no-referrer-when-downgrade, src absentPass referrerpolicy no-referrer to invalid, src absent-Fail referrerpolicy absent to no-referrer-when-downgrade, src already set-Fail referrerpolicy absent to no-referrer, src already set-Fail referrerpolicy empty to no-referrer-when-downgrade, src already set-Fail referrerpolicy empty to no-referrer, src already set-Fail referrerpolicy no-referrer-when-downgrade to absent, src already set-Fail referrerpolicy no-referrer-when-downgrade to empty, src already set-Fail referrerpolicy no-referrer-when-downgrade to no-referrer, src already set-Fail referrerpolicy no-referrer-when-downgrade to invalid, src already set-Fail referrerpolicy no-referrer to absent, src already set-Fail referrerpolicy no-referrer to empty, src already set-Fail referrerpolicy no-referrer to no-referrer-when-downgrade, src already set-Fail referrerpolicy no-referrer to invalid, src already set+Pass referrerpolicy absent to no-referrer-when-downgrade, src already set+Pass referrerpolicy absent to no-referrer, src already set+Pass referrerpolicy empty to no-referrer-when-downgrade, src already set+Pass referrerpolicy empty to no-referrer, src already set+Pass referrerpolicy no-referrer-when-downgrade to absent, src already set+Pass referrerpolicy no-referrer-when-downgrade to empty, src already set+Pass referrerpolicy no-referrer-when-downgrade to no-referrer, src already set+Pass referrerpolicy no-referrer-when-downgrade to invalid, src already set+Pass referrerpolicy no-referrer to absent, src already set+Pass referrerpolicy no-referrer to empty, src already set+Pass referrerpolicy no-referrer to no-referrer-when-downgrade, src already set+Pass referrerpolicy no-referrer to invalid, src already setFail inserted into picture-Fail removed from picture+Pass removed from picturePass parent is picture, previous source insertedPass parent is picture, previous source removedPass parent is picture, previous source has srcset set@@ -77,7 +77,7 @@ Pass parent is picture, previous source has type setPass parent is picture, previous source has type changedPass parent is picture, previous source has type removedPass srcset is set to same value-Fail sizes is set to same value+Pass sizes is set to same valuePass crossorigin state not changed: absent, removeAttributePass crossorigin state not changed: empty to anonymousPass crossorigin state not changed: anonymous to foobar