mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Implements HTMLDetailsElement toggle
This commit is contained in:
parent
8ab389c10c
commit
ddfa9ca5b4
4 changed files with 71 additions and 24 deletions
|
@ -3309,6 +3309,10 @@ impl Element {
|
|||
let element = self.downcast::<HTMLLabelElement>().unwrap();
|
||||
Some(element as &dyn Activatable)
|
||||
},
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLElement)) => {
|
||||
let element = self.downcast::<HTMLElement>().unwrap();
|
||||
Some(element as &dyn Activatable)
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
element.and_then(|elem| {
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::dom::document::Document;
|
|||
use crate::dom::element::AttributeMutation;
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{window_from_node, Node};
|
||||
use crate::dom::node::{window_from_node, Node, NodeDamage};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::task_source::TaskSource;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -49,6 +49,10 @@ impl HTMLDetailsElement {
|
|||
document,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn toggle(&self) {
|
||||
self.SetOpen(!self.Open());
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLDetailsElementMethods for HTMLDetailsElement {
|
||||
|
@ -83,6 +87,7 @@ impl VirtualMethods for HTMLDetailsElement {
|
|||
}),
|
||||
window.upcast(),
|
||||
);
|
||||
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::activation::Activatable;
|
||||
use crate::dom::attr::Attr;
|
||||
use crate::dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||
use crate::dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNonNull;
|
||||
|
@ -19,9 +20,11 @@ use crate::dom::document::{Document, FocusType};
|
|||
use crate::dom::documentfragment::DocumentFragment;
|
||||
use crate::dom::domstringmap::DOMStringMap;
|
||||
use crate::dom::element::{AttributeMutation, Element};
|
||||
use crate::dom::event::Event;
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::htmlbodyelement::HTMLBodyElement;
|
||||
use crate::dom::htmlbrelement::HTMLBRElement;
|
||||
use crate::dom::htmldetailselement::HTMLDetailsElement;
|
||||
use crate::dom::htmlframesetelement::HTMLFrameSetElement;
|
||||
use crate::dom::htmlhtmlelement::HTMLHtmlElement;
|
||||
use crate::dom::htmlinputelement::{HTMLInputElement, InputType};
|
||||
|
@ -783,6 +786,49 @@ impl HTMLElement {
|
|||
|
||||
None
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-summary-element:activation-behaviour
|
||||
pub fn summary_activation_behavior(&self) {
|
||||
// Step 1
|
||||
if !self.is_summary_for_its_parent_details() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2
|
||||
let parent_details = self.upcast::<Node>().GetParentNode().unwrap();
|
||||
|
||||
// Step 3
|
||||
parent_details
|
||||
.downcast::<HTMLDetailsElement>()
|
||||
.unwrap()
|
||||
.toggle();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#summary-for-its-parent-details
|
||||
fn is_summary_for_its_parent_details(&self) -> bool {
|
||||
// Step 1
|
||||
let summary_node = self.upcast::<Node>();
|
||||
if !summary_node.has_parent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 2
|
||||
let parent = &summary_node.GetParentNode().unwrap();
|
||||
|
||||
// Step 3
|
||||
if !parent.is::<HTMLDetailsElement>() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 4 & 5
|
||||
let first_summary_element = parent
|
||||
.child_elements()
|
||||
.find(|el| el.local_name() == &local_name!("summary"));
|
||||
match first_summary_element {
|
||||
Some(first_summary) => &*first_summary == self.upcast::<Element>(),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLElement {
|
||||
|
@ -819,3 +865,18 @@ impl VirtualMethods for HTMLElement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Activatable for HTMLElement {
|
||||
fn as_element(&self) -> &Element {
|
||||
self.upcast::<Element>()
|
||||
}
|
||||
|
||||
fn is_instance_activatable(&self) -> bool {
|
||||
self.as_element().local_name() == &local_name!("summary")
|
||||
}
|
||||
|
||||
// Basically used to make the HTMLSummaryElement activatable (which has no IDL definition)
|
||||
fn activation_behavior(&self, _event: &Event, _target: &EventTarget) {
|
||||
self.summary_activation_behavior();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
[activation-behavior.html]
|
||||
type: testharness
|
||||
[Should open a closed details if all conditions are met]
|
||||
expected: FAIL
|
||||
|
||||
[Should close an open details if all conditions are met]
|
||||
expected: FAIL
|
||||
|
||||
[Should open a closed details even if the details is not being rendered]
|
||||
expected: FAIL
|
||||
|
||||
[Should open a closed details even if the summary is not being rendered]
|
||||
expected: FAIL
|
||||
|
||||
[Should open a closed details if a span element precedes the summary]
|
||||
expected: FAIL
|
||||
|
||||
[Should open a closed details if another summary element *nested inside a span* precedes the summary]
|
||||
expected: FAIL
|
||||
|
||||
[toggle events should be coalesced even when using the activation behavior of a summary]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue