Move Element::matches_environment to MediaList (#39034)

It more logically matches `MediaList`, and it allows us to
call this method with a document. This is required when
parsing Link headers, as they don't have an associated
element, but they do have a document.

Part of #35035

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This commit is contained in:
Tim van der Lippe 2025-09-04 08:21:01 +02:00 committed by GitHub
parent aac6aa6c70
commit fc6bee8b81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 34 deletions

View file

@ -75,6 +75,7 @@ use crate::dom::html::htmlformelement::{FormControl, HTMLFormElement};
use crate::dom::html::htmlmapelement::HTMLMapElement;
use crate::dom::html::htmlpictureelement::HTMLPictureElement;
use crate::dom::html::htmlsourceelement::HTMLSourceElement;
use crate::dom::medialist::MediaList;
use crate::dom::mouseevent::MouseEvent;
use crate::dom::node::{BindContext, Node, NodeDamage, NodeTraits, ShadowIncluding, UnbindContext};
use crate::dom::performanceresourcetiming::InitiatorType;
@ -713,7 +714,7 @@ impl HTMLImageElement {
// Step 4.6
if let Some(x) = element.get_attribute(&ns!(), &local_name!("media")) {
if !elem.matches_environment(&x.value()) {
if !MediaList::matches_environment(&elem.owner_document(), &x.value()) {
continue;
}
}

View file

@ -339,7 +339,7 @@ impl VirtualMethods for HTMLLinkElement {
}
let matches_media_environment =
self.upcast::<Element>().matches_environment(&attr.value());
MediaList::matches_environment(&self.owner_document(), &attr.value());
self.previous_media_environment_matched
.set(matches_media_environment);
},
@ -573,7 +573,7 @@ impl HTMLLinkElement {
None => "",
};
if !element.matches_environment(mq_str) {
if !MediaList::matches_environment(&document, mq_str) {
return;
}