mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Introduce BindContext with in_doc and connected flags
Fix some is_in_doc -> is_connected mistakes
This commit is contained in:
parent
740aae06ba
commit
813b242419
21 changed files with 105 additions and 84 deletions
|
@ -72,8 +72,8 @@ use crate::dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaEle
|
|||
use crate::dom::mutationobserver::{Mutation, MutationObserver};
|
||||
use crate::dom::namednodemap::NamedNodeMap;
|
||||
use crate::dom::node::{document_from_node, window_from_node};
|
||||
use crate::dom::node::{BindContext, NodeDamage, NodeFlags, UnbindContext};
|
||||
use crate::dom::node::{ChildrenMutation, LayoutNodeHelpers, Node};
|
||||
use crate::dom::node::{NodeDamage, NodeFlags, UnbindContext};
|
||||
use crate::dom::nodelist::NodeList;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::servoparser::ServoParser;
|
||||
|
@ -2800,28 +2800,28 @@ impl VirtualMethods for Element {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
if let Some(f) = self.as_maybe_form_control() {
|
||||
f.bind_form_control_to_tree();
|
||||
}
|
||||
|
||||
if !tree_connected {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(shadow_root) = self.upcast::<Node>().owner_shadow_root() {
|
||||
let shadow_root = shadow_root.upcast::<Node>();
|
||||
shadow_root.set_flag(NodeFlags::IS_CONNECTED, tree_connected);
|
||||
shadow_root.set_flag(NodeFlags::IS_CONNECTED, context.tree_connected);
|
||||
for node in shadow_root.children() {
|
||||
node.set_flag(NodeFlags::IS_CONNECTED, tree_connected);
|
||||
node.bind_to_tree(tree_connected);
|
||||
node.set_flag(NodeFlags::IS_CONNECTED, context.tree_connected);
|
||||
node.bind_to_tree(context);
|
||||
}
|
||||
}
|
||||
|
||||
if !context.tree_connected {
|
||||
return;
|
||||
}
|
||||
|
||||
let doc = document_from_node(self);
|
||||
if let Some(ref value) = *self.id_attribute.borrow() {
|
||||
if let Some(shadow_root) = self.upcast::<Node>().owner_shadow_root() {
|
||||
|
@ -2847,8 +2847,7 @@ impl VirtualMethods for Element {
|
|||
|
||||
let doc = document_from_node(self);
|
||||
|
||||
if self.is_shadow_host() {
|
||||
let shadow_root = self.shadow_root.get().unwrap();
|
||||
if let Some(shadow_root) = self.shadow_root.get() {
|
||||
doc.unregister_shadow_root(&shadow_root);
|
||||
let shadow_root = shadow_root.upcast::<Node>();
|
||||
shadow_root.set_flag(NodeFlags::IS_CONNECTED, false);
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::dom::bindings::str::DOMString;
|
|||
use crate::dom::document::Document;
|
||||
use crate::dom::element::{AttributeMutation, Element};
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{document_from_node, Node, UnbindContext};
|
||||
use crate::dom::node::{document_from_node, BindContext, Node, UnbindContext};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever::{LocalName, Prefix};
|
||||
|
@ -63,8 +63,8 @@ impl HTMLBaseElement {
|
|||
|
||||
/// Update the cached base element in response to binding or unbinding from
|
||||
/// a tree.
|
||||
pub fn bind_unbind(&self, tree_connected: bool) {
|
||||
if !tree_connected {
|
||||
pub fn bind_unbind(&self, tree_in_doc: bool) {
|
||||
if !tree_in_doc || self.upcast::<Node>().owner_shadow_root().is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -119,13 +119,13 @@ impl VirtualMethods for HTMLBaseElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
self.super_type().unwrap().bind_to_tree(tree_connected);
|
||||
self.bind_unbind(tree_connected);
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
self.super_type().unwrap().bind_to_tree(context);
|
||||
self.bind_unbind(context.tree_in_doc);
|
||||
}
|
||||
|
||||
fn unbind_from_tree(&self, context: &UnbindContext) {
|
||||
self.super_type().unwrap().unbind_from_tree(context);
|
||||
self.bind_unbind(context.tree_connected);
|
||||
self.bind_unbind(context.tree_in_doc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::dom::document::Document;
|
|||
use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{document_from_node, window_from_node, Node};
|
||||
use crate::dom::node::{document_from_node, window_from_node, BindContext, Node};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use cssparser::RGBA;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -149,12 +149,12 @@ impl VirtualMethods for HTMLBodyElement {
|
|||
.attribute_affects_presentational_hints(attr)
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
if !tree_connected {
|
||||
if !context.tree_in_doc {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
|
|||
use crate::dom::htmlformelement::HTMLFormElement;
|
||||
use crate::dom::htmlformelement::{FormControl, FormDatum, FormDatumValue};
|
||||
use crate::dom::htmlformelement::{FormSubmitter, ResetFrom, SubmittedFrom};
|
||||
use crate::dom::node::{document_from_node, window_from_node, Node, UnbindContext};
|
||||
use crate::dom::node::{document_from_node, window_from_node, BindContext, Node, UnbindContext};
|
||||
use crate::dom::nodelist::NodeList;
|
||||
use crate::dom::validation::Validatable;
|
||||
use crate::dom::validitystate::{ValidationFlags, ValidityState};
|
||||
|
@ -232,9 +232,9 @@ impl VirtualMethods for HTMLButtonElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
self.upcast::<Element>()
|
||||
|
|
|
@ -28,7 +28,7 @@ use crate::dom::htmlhtmlelement::HTMLHtmlElement;
|
|||
use crate::dom::htmlinputelement::{HTMLInputElement, InputType};
|
||||
use crate::dom::htmllabelelement::HTMLLabelElement;
|
||||
use crate::dom::node::{document_from_node, window_from_node};
|
||||
use crate::dom::node::{Node, NodeFlags, ShadowIncluding};
|
||||
use crate::dom::node::{BindContext, Node, NodeFlags, ShadowIncluding};
|
||||
use crate::dom::nodelist::NodeList;
|
||||
use crate::dom::text::Text;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
|
@ -740,9 +740,9 @@ impl VirtualMethods for HTMLElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_in_doc: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_in_doc);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
self.update_sequentially_focusable_status();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::dom::document::{determine_policy_for_token, Document};
|
|||
use crate::dom::element::Element;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::htmlmetaelement::HTMLMetaElement;
|
||||
use crate::dom::node::{document_from_node, Node, ShadowIncluding};
|
||||
use crate::dom::node::{document_from_node, BindContext, Node, ShadowIncluding};
|
||||
use crate::dom::userscripts::load_script;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -81,9 +81,9 @@ impl VirtualMethods for HTMLHeadElement {
|
|||
fn super_type(&self) -> Option<&dyn VirtualMethods> {
|
||||
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
|
||||
}
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
load_script(self);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
|||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, UnbindContext};
|
||||
use crate::dom::node::{
|
||||
document_from_node, window_from_node, BindContext, Node, NodeDamage, UnbindContext,
|
||||
};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::dom::window::ReflowReason;
|
||||
use crate::dom::windowproxy::WindowProxy;
|
||||
|
@ -610,11 +612,12 @@ impl VirtualMethods for HTMLIFrameElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
let tree_connected = context.tree_connected;
|
||||
let iframe = Trusted::new(self);
|
||||
document_from_node(self).add_delayed_task(task!(IFrameDelayedInitialize: move || {
|
||||
let this = iframe.root();
|
||||
|
|
|
@ -33,7 +33,9 @@ use crate::dom::htmlpictureelement::HTMLPictureElement;
|
|||
use crate::dom::htmlsourceelement::HTMLSourceElement;
|
||||
use crate::dom::mouseevent::MouseEvent;
|
||||
use crate::dom::node::UnbindContext;
|
||||
use crate::dom::node::{document_from_node, window_from_node, Node, NodeDamage, ShadowIncluding};
|
||||
use crate::dom::node::{
|
||||
document_from_node, window_from_node, BindContext, Node, NodeDamage, ShadowIncluding,
|
||||
};
|
||||
use crate::dom::performanceresourcetiming::InitiatorType;
|
||||
use crate::dom::progressevent::ProgressEvent;
|
||||
use crate::dom::values::UNSIGNED_LONG_MAX;
|
||||
|
@ -1646,12 +1648,12 @@ impl VirtualMethods for HTMLImageElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
let document = document_from_node(self);
|
||||
if tree_connected {
|
||||
if context.tree_connected {
|
||||
document.register_responsive_image(self);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ use crate::dom::htmlformelement::{ResetFrom, SubmittedFrom};
|
|||
use crate::dom::keyboardevent::KeyboardEvent;
|
||||
use crate::dom::mouseevent::MouseEvent;
|
||||
use crate::dom::node::{document_from_node, window_from_node};
|
||||
use crate::dom::node::{Node, NodeDamage, UnbindContext};
|
||||
use crate::dom::node::{BindContext, Node, NodeDamage, UnbindContext};
|
||||
use crate::dom::nodelist::NodeList;
|
||||
use crate::dom::textcontrol::{TextControlElement, TextControlSelection};
|
||||
use crate::dom::validation::Validatable;
|
||||
|
@ -1422,9 +1422,9 @@ impl VirtualMethods for HTMLInputElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
self.upcast::<Element>()
|
||||
.check_ancestors_disabled_state_for_form_control();
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::dom::element::Element;
|
|||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||
use crate::dom::htmlformelement::{FormControl, HTMLFormElement};
|
||||
use crate::dom::node::{Node, UnbindContext};
|
||||
use crate::dom::node::{BindContext, Node, UnbindContext};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever::{LocalName, Prefix};
|
||||
|
@ -56,9 +56,9 @@ impl VirtualMethods for HTMLLegendElement {
|
|||
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
self.upcast::<Element>()
|
||||
|
|
|
@ -19,7 +19,8 @@ use crate::dom::element::{
|
|||
use crate::dom::element::{AttributeMutation, Element, ElementCreator};
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{
|
||||
document_from_node, stylesheets_owner_from_node, window_from_node, Node, UnbindContext,
|
||||
document_from_node, stylesheets_owner_from_node, window_from_node, BindContext, Node,
|
||||
UnbindContext,
|
||||
};
|
||||
use crate::dom::stylesheet::StyleSheet as DOMStyleSheet;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
|
@ -225,12 +226,12 @@ impl VirtualMethods for HTMLLinkElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
if tree_connected {
|
||||
if context.tree_connected {
|
||||
let element = self.upcast();
|
||||
|
||||
let rel = get_attr(element, &local_name!("rel"));
|
||||
|
|
|
@ -16,7 +16,8 @@ use crate::dom::element::{AttributeMutation, Element};
|
|||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::htmlheadelement::HTMLHeadElement;
|
||||
use crate::dom::node::{
|
||||
document_from_node, stylesheets_owner_from_node, window_from_node, Node, UnbindContext,
|
||||
document_from_node, stylesheets_owner_from_node, window_from_node, BindContext, Node,
|
||||
UnbindContext,
|
||||
};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -175,12 +176,12 @@ impl VirtualMethods for HTMLMetaElement {
|
|||
Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
if tree_connected {
|
||||
if context.tree_connected {
|
||||
self.process_attributes();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ use crate::dom::htmlformelement::HTMLFormElement;
|
|||
use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
|
||||
use crate::dom::htmlscriptelement::HTMLScriptElement;
|
||||
use crate::dom::htmlselectelement::HTMLSelectElement;
|
||||
use crate::dom::node::{Node, UnbindContext};
|
||||
use crate::dom::node::{BindContext, Node, UnbindContext};
|
||||
use crate::dom::text::Text;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
|
@ -235,9 +235,9 @@ impl VirtualMethods for HTMLOptionElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
self.upcast::<Element>()
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
|
|||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{document_from_node, window_from_node};
|
||||
use crate::dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
|
||||
use crate::dom::node::{BindContext, ChildrenMutation, CloneChildrenFlag, Node};
|
||||
use crate::dom::performanceresourcetiming::InitiatorType;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::network_listener::{self, NetworkListener, PreInvoke, ResourceTimingListener};
|
||||
|
@ -778,12 +778,12 @@ impl VirtualMethods for HTMLScriptElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, is_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(is_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
if is_connected && !self.parser_inserted.get() {
|
||||
if context.tree_connected && !self.parser_inserted.get() {
|
||||
let script = Trusted::new(self);
|
||||
document_from_node(self).add_delayed_task(task!(ScriptDelayedInitialize: move || {
|
||||
script.root().prepare();
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelec
|
|||
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use crate::dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
|
||||
use crate::dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement;
|
||||
//use dom::bindings::error::ErrorResult;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
|
@ -25,7 +24,7 @@ use crate::dom::htmlformelement::{FormControl, FormDatum, FormDatumValue, HTMLFo
|
|||
use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
|
||||
use crate::dom::htmloptionelement::HTMLOptionElement;
|
||||
use crate::dom::htmloptionscollection::HTMLOptionsCollection;
|
||||
use crate::dom::node::{window_from_node, Node, UnbindContext};
|
||||
use crate::dom::node::{window_from_node, BindContext, Node, UnbindContext};
|
||||
use crate::dom::nodelist::NodeList;
|
||||
use crate::dom::validation::Validatable;
|
||||
use crate::dom::validitystate::{ValidationFlags, ValidityState};
|
||||
|
@ -382,9 +381,9 @@ impl VirtualMethods for HTMLSelectElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
self.upcast::<Element>()
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::dom::element::AttributeMutation;
|
|||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::htmlimageelement::HTMLImageElement;
|
||||
use crate::dom::htmlmediaelement::HTMLMediaElement;
|
||||
use crate::dom::node::{Node, UnbindContext};
|
||||
use crate::dom::node::{BindContext, Node, UnbindContext};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever::{LocalName, Prefix};
|
||||
|
@ -82,8 +82,8 @@ impl VirtualMethods for HTMLSourceElement {
|
|||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#the-source-element:nodes-are-inserted>
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
self.super_type().unwrap().bind_to_tree(tree_connected);
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
self.super_type().unwrap().bind_to_tree(context);
|
||||
let parent = self.upcast::<Node>().GetParentNode().unwrap();
|
||||
if let Some(media) = parent.downcast::<HTMLMediaElement>() {
|
||||
media.handle_source_child_insertion();
|
||||
|
|
|
@ -13,8 +13,8 @@ use crate::dom::document::Document;
|
|||
use crate::dom::element::{Element, ElementCreator};
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{
|
||||
document_from_node, stylesheets_owner_from_node, window_from_node, ChildrenMutation, Node,
|
||||
UnbindContext,
|
||||
document_from_node, stylesheets_owner_from_node, window_from_node, BindContext,
|
||||
ChildrenMutation, Node, UnbindContext,
|
||||
};
|
||||
use crate::dom::stylesheet::StyleSheet as DOMStyleSheet;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
|
@ -187,14 +187,14 @@ impl VirtualMethods for HTMLStyleElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
self.super_type().unwrap().bind_to_tree(tree_connected);
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
self.super_type().unwrap().bind_to_tree(context);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#update-a-style-block
|
||||
// Handles the case when:
|
||||
// "The element is not on the stack of open elements of an HTML parser or XML parser,
|
||||
// and it becomes connected or disconnected."
|
||||
if tree_connected && !self.in_stack_of_open_elements.get() {
|
||||
if context.tree_connected && !self.in_stack_of_open_elements.get() {
|
||||
self.parse_own_css();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@ use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
|
|||
use crate::dom::htmlformelement::{FormControl, HTMLFormElement};
|
||||
use crate::dom::keyboardevent::KeyboardEvent;
|
||||
use crate::dom::node::{document_from_node, window_from_node};
|
||||
use crate::dom::node::{ChildrenMutation, CloneChildrenFlag, Node, NodeDamage, UnbindContext};
|
||||
use crate::dom::node::{
|
||||
BindContext, ChildrenMutation, CloneChildrenFlag, Node, NodeDamage, UnbindContext,
|
||||
};
|
||||
use crate::dom::nodelist::NodeList;
|
||||
use crate::dom::textcontrol::{TextControlElement, TextControlSelection};
|
||||
use crate::dom::validation::Validatable;
|
||||
|
@ -466,9 +468,9 @@ impl VirtualMethods for HTMLTextAreaElement {
|
|||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
|
||||
self.upcast::<Element>()
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::dom::bindings::root::DomRoot;
|
|||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{ChildrenMutation, Node};
|
||||
use crate::dom::node::{BindContext, ChildrenMutation, Node};
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever::{LocalName, Prefix};
|
||||
|
@ -69,17 +69,17 @@ impl VirtualMethods for HTMLTitleElement {
|
|||
s.children_changed(mutation);
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
if node.is_connected() {
|
||||
if node.is_in_doc() {
|
||||
node.owner_doc().title_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
if tree_connected {
|
||||
if context.tree_in_doc {
|
||||
node.owner_doc().title_changed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -296,7 +296,10 @@ impl Node {
|
|||
node.set_flag(NodeFlags::IS_CONNECTED, parent_is_connected);
|
||||
// Out-of-document elements never have the descendants flag set.
|
||||
debug_assert!(!node.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS));
|
||||
vtable_for(&&*node).bind_to_tree(parent_is_connected);
|
||||
vtable_for(&&*node).bind_to_tree(&BindContext {
|
||||
tree_connected: parent_is_connected,
|
||||
tree_in_doc: parent_in_doc,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3025,6 +3028,14 @@ impl<'a> ChildrenMutation<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// The context of the binding to tree of a node.
|
||||
pub struct BindContext {
|
||||
/// Whether the tree is connected.
|
||||
pub tree_connected: bool,
|
||||
/// Whether the tree is in the document.
|
||||
pub tree_in_doc: bool,
|
||||
}
|
||||
|
||||
/// The context of the unbinding from a tree of a node when one of its
|
||||
/// inclusive ancestors is removed.
|
||||
pub struct UnbindContext<'a> {
|
||||
|
@ -3038,6 +3049,8 @@ pub struct UnbindContext<'a> {
|
|||
pub next_sibling: Option<&'a Node>,
|
||||
/// Whether the tree is connected.
|
||||
pub tree_connected: bool,
|
||||
/// Whether the tree is in doc.
|
||||
pub tree_in_doc: bool,
|
||||
}
|
||||
|
||||
impl<'a> UnbindContext<'a> {
|
||||
|
@ -3054,6 +3067,7 @@ impl<'a> UnbindContext<'a> {
|
|||
prev_sibling: prev_sibling,
|
||||
next_sibling: next_sibling,
|
||||
tree_connected: parent.is_connected(),
|
||||
tree_in_doc: parent.is_in_doc(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ use crate::dom::htmltemplateelement::HTMLTemplateElement;
|
|||
use crate::dom::htmltextareaelement::HTMLTextAreaElement;
|
||||
use crate::dom::htmltitleelement::HTMLTitleElement;
|
||||
use crate::dom::htmlvideoelement::HTMLVideoElement;
|
||||
use crate::dom::node::{ChildrenMutation, CloneChildrenFlag, Node, UnbindContext};
|
||||
use crate::dom::node::{BindContext, ChildrenMutation, CloneChildrenFlag, Node, UnbindContext};
|
||||
use crate::dom::svgsvgelement::SVGSVGElement;
|
||||
use html5ever::LocalName;
|
||||
use style::attr::AttrValue;
|
||||
|
@ -92,9 +92,9 @@ pub trait VirtualMethods {
|
|||
|
||||
/// Called when a Node is appended to a tree, where 'tree_connected' indicates
|
||||
/// whether the tree is part of a Document.
|
||||
fn bind_to_tree(&self, tree_connected: bool) {
|
||||
fn bind_to_tree(&self, context: &BindContext) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.bind_to_tree(tree_connected);
|
||||
s.bind_to_tree(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue