Implement :valid :invalid pseudo classes (#26729)

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
John Poge II 2023-07-21 12:42:03 +02:00 committed by GitHub
parent 2b67392fd5
commit 5f2c6c09cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 324 additions and 241 deletions

View file

@ -10,7 +10,10 @@ use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmloptionelement::HTMLOptionElement;
use crate::dom::node::Node;
use crate::dom::htmlselectelement::HTMLSelectElement;
use crate::dom::node::{BindContext, Node, ShadowIncluding, UnbindContext};
use crate::dom::validation::Validatable;
use crate::dom::validitystate::ValidationFlags;
use crate::dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
@ -53,6 +56,19 @@ impl HTMLOptGroupElement {
proto,
)
}
fn update_select_validity(&self) {
if let Some(select) = self
.upcast::<Node>()
.ancestors()
.filter_map(DomRoot::downcast::<HTMLSelectElement>)
.next()
{
select
.validity_state()
.perform_validation_and_update(ValidationFlags::all());
}
}
}
impl HTMLOptGroupElementMethods for HTMLOptGroupElement {
@ -104,4 +120,27 @@ impl VirtualMethods for HTMLOptGroupElement {
_ => {},
}
}
fn bind_to_tree(&self, context: &BindContext) {
if let Some(ref s) = self.super_type() {
s.bind_to_tree(context);
}
self.update_select_validity();
}
fn unbind_from_tree(&self, context: &UnbindContext) {
self.super_type().unwrap().unbind_from_tree(context);
if let Some(select) = context
.parent
.inclusive_ancestors(ShadowIncluding::No)
.filter_map(DomRoot::downcast::<HTMLSelectElement>)
.next()
{
select
.validity_state()
.perform_validation_and_update(ValidationFlags::all());
}
}
}