mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Implement :valid :invalid pseudo classes (#26729)
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
2b67392fd5
commit
5f2c6c09cd
30 changed files with 324 additions and 241 deletions
|
@ -22,6 +22,8 @@ use crate::dom::htmlscriptelement::HTMLScriptElement;
|
|||
use crate::dom::htmlselectelement::HTMLSelectElement;
|
||||
use crate::dom::node::{BindContext, Node, ShadowIncluding, UnbindContext};
|
||||
use crate::dom::text::Text;
|
||||
use crate::dom::validation::Validatable;
|
||||
use crate::dom::validitystate::ValidationFlags;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -108,6 +110,7 @@ impl HTMLOptionElement {
|
|||
|
||||
option.SetDefaultSelected(default_selected);
|
||||
option.set_selectedness(selected);
|
||||
option.update_select_validity();
|
||||
Ok(option)
|
||||
}
|
||||
|
||||
|
@ -167,6 +170,19 @@ impl HTMLOptionElement {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(ajeffrey): Provide a way of buffering DOMStrings other than using Strings
|
||||
|
@ -264,6 +280,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
|||
self.dirtiness.set(true);
|
||||
self.selectedness.set(selected);
|
||||
self.pick_if_selected_and_reset();
|
||||
self.update_select_validity();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-option-index
|
||||
|
@ -293,6 +310,7 @@ impl VirtualMethods for HTMLOptionElement {
|
|||
el.check_parent_disabled_state_for_option();
|
||||
},
|
||||
}
|
||||
self.update_select_validity();
|
||||
},
|
||||
&local_name!("selected") => {
|
||||
match mutation {
|
||||
|
@ -309,6 +327,7 @@ impl VirtualMethods for HTMLOptionElement {
|
|||
}
|
||||
},
|
||||
}
|
||||
self.update_select_validity();
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
@ -323,6 +342,7 @@ impl VirtualMethods for HTMLOptionElement {
|
|||
.check_parent_disabled_state_for_option();
|
||||
|
||||
self.pick_if_selected_and_reset();
|
||||
self.update_select_validity();
|
||||
}
|
||||
|
||||
fn unbind_from_tree(&self, context: &UnbindContext) {
|
||||
|
@ -334,6 +354,9 @@ impl VirtualMethods for HTMLOptionElement {
|
|||
.filter_map(DomRoot::downcast::<HTMLSelectElement>)
|
||||
.next()
|
||||
{
|
||||
select
|
||||
.validity_state()
|
||||
.perform_validation_and_update(ValidationFlags::all());
|
||||
select.ask_for_reset();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue