mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Check whether an element is custom in the spec-compliant way (#35960)
* Check whether element is custom in spec-compliant way Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com> * Update tests Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com> --------- Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
This commit is contained in:
parent
ea35353e9a
commit
62d6759106
6 changed files with 71 additions and 13 deletions
|
@ -166,7 +166,7 @@ impl Attr {
|
|||
|
||||
MutationObserver::queue_a_mutation_record(owner.upcast::<Node>(), mutation);
|
||||
|
||||
if owner.get_custom_element_definition().is_some() {
|
||||
if owner.is_custom() {
|
||||
let reaction = CallbackReaction::AttributeChanged(
|
||||
name,
|
||||
Some(old_value),
|
||||
|
|
|
@ -371,6 +371,11 @@ impl Element {
|
|||
CustomElementState::Uncustomized
|
||||
}
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#concept-element-custom>
|
||||
pub(crate) fn is_custom(&self) -> bool {
|
||||
self.get_custom_element_state() == CustomElementState::Custom
|
||||
}
|
||||
|
||||
pub(crate) fn set_custom_element_definition(&self, definition: Rc<CustomElementDefinition>) {
|
||||
self.ensure_rare_data().custom_element_definition = Some(definition);
|
||||
}
|
||||
|
@ -1580,7 +1585,7 @@ impl Element {
|
|||
|
||||
MutationObserver::queue_a_mutation_record(&self.node, mutation);
|
||||
|
||||
if self.get_custom_element_definition().is_some() {
|
||||
if self.is_custom() {
|
||||
let value = DOMString::from(&**attr.value());
|
||||
let reaction = CallbackReaction::AttributeChanged(name, None, Some(value), namespace);
|
||||
ScriptThread::enqueue_callback_reaction(self, reaction, None);
|
||||
|
@ -1772,9 +1777,11 @@ impl Element {
|
|||
|
||||
MutationObserver::queue_a_mutation_record(&self.node, mutation);
|
||||
|
||||
let reaction =
|
||||
CallbackReaction::AttributeChanged(name, Some(old_value), None, namespace);
|
||||
ScriptThread::enqueue_callback_reaction(self, reaction, None);
|
||||
if self.is_custom() {
|
||||
let reaction =
|
||||
CallbackReaction::AttributeChanged(name, Some(old_value), None, namespace);
|
||||
ScriptThread::enqueue_callback_reaction(self, reaction, None);
|
||||
}
|
||||
|
||||
self.attrs.borrow_mut().remove(idx);
|
||||
attr.set_owner(None);
|
||||
|
@ -2453,7 +2460,7 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
|
|||
}
|
||||
|
||||
// Step 4.
|
||||
if self.get_custom_element_definition().is_some() {
|
||||
if self.is_custom() {
|
||||
let old_name = old_attr.local_name().clone();
|
||||
let old_value = DOMString::from(&**old_attr.value());
|
||||
let new_value = DOMString::from(&**attr.value());
|
||||
|
|
|
@ -422,7 +422,8 @@ impl Node {
|
|||
|
||||
pub(crate) fn as_custom_element(&self) -> Option<DomRoot<Element>> {
|
||||
self.downcast::<Element>().and_then(|element| {
|
||||
if element.get_custom_element_definition().is_some() {
|
||||
if element.is_custom() {
|
||||
assert!(element.get_custom_element_definition().is_some());
|
||||
Some(DomRoot::from_ref(element))
|
||||
} else {
|
||||
None
|
||||
|
@ -2334,7 +2335,7 @@ impl Node {
|
|||
.filter_map(DomRoot::downcast::<Element>)
|
||||
{
|
||||
// Step 7.7.2, whatwg/dom#833
|
||||
if descendant.get_custom_element_definition().is_some() {
|
||||
if descendant.is_custom() {
|
||||
if descendant.is_connected() {
|
||||
ScriptThread::enqueue_callback_reaction(
|
||||
&descendant,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue