mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Enqueue upgrades
This commit is contained in:
parent
41371208a5
commit
6d9d4add61
12 changed files with 42 additions and 102 deletions
|
@ -5,7 +5,7 @@
|
|||
use dom::bindings::error::{report_pending_exception, throw_dom_exception};
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::DomObject;
|
||||
use dom::customelementregistry::is_valid_custom_element_name;
|
||||
use dom::customelementregistry::{is_valid_custom_element_name, upgrade_element};
|
||||
use dom::document::Document;
|
||||
use dom::element::{CustomElementCreationMode, Element, ElementCreator};
|
||||
use dom::globalscope::GlobalScope;
|
||||
|
@ -81,6 +81,7 @@ use dom::htmlvideoelement::HTMLVideoElement;
|
|||
use dom::svgsvgelement::SVGSVGElement;
|
||||
use html5ever::{LocalName, Prefix, QualName};
|
||||
use js::jsapi::JSAutoCompartment;
|
||||
use script_thread::ScriptThread;
|
||||
use servo_config::prefs::PREFS;
|
||||
|
||||
fn create_svg_element(name: QualName,
|
||||
|
@ -127,8 +128,11 @@ fn create_html_element(name: QualName,
|
|||
if let Some(definition) = definition {
|
||||
if definition.is_autonomous() {
|
||||
match mode {
|
||||
// TODO: Handle asynchronous CE creation. Relies on CE upgrades.
|
||||
CustomElementCreationMode::Asynchronous => {},
|
||||
CustomElementCreationMode::Asynchronous => {
|
||||
let result = Root::upcast(HTMLElement::new(name.local.clone(), prefix.clone(), document));
|
||||
ScriptThread::enqueue_upgrade_reaction(&*result, definition);
|
||||
return result;
|
||||
},
|
||||
CustomElementCreationMode::Synchronous => {
|
||||
let local_name = name.local.clone();
|
||||
return match definition.create_element(document, prefix.clone()) {
|
||||
|
@ -155,9 +159,17 @@ fn create_html_element(name: QualName,
|
|||
},
|
||||
}
|
||||
} else {
|
||||
// Steps 5.1-5.2
|
||||
let element = create_native_html_element(name, prefix, document, creator);
|
||||
element.set_is(definition.name.clone());
|
||||
// TODO: Enqueue custom element upgrade
|
||||
match mode {
|
||||
// Step 5.3
|
||||
CustomElementCreationMode::Synchronous =>
|
||||
upgrade_element(definition, &*element),
|
||||
// Step 5.4
|
||||
CustomElementCreationMode::Asynchronous =>
|
||||
ScriptThread::enqueue_upgrade_reaction(&*element, definition),
|
||||
}
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::CustomElementRegistryBinding::CustomElemen
|
|||
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding::ElementDefinitionOptions;
|
||||
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
|
@ -281,17 +282,28 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
|
|||
self.element_definition_is_running.set(false);
|
||||
|
||||
// Step 11
|
||||
let definition = CustomElementDefinition::new(name.clone(),
|
||||
local_name,
|
||||
constructor_,
|
||||
observed_attributes,
|
||||
callbacks);
|
||||
let definition = Rc::new(CustomElementDefinition::new(name.clone(),
|
||||
local_name.clone(),
|
||||
constructor_,
|
||||
observed_attributes,
|
||||
callbacks));
|
||||
|
||||
// Step 12
|
||||
self.definitions.borrow_mut().insert(name.clone(), Rc::new(definition));
|
||||
self.definitions.borrow_mut().insert(name.clone(), definition.clone());
|
||||
|
||||
// TODO: Step 13, 14, 15
|
||||
// Handle custom element upgrades
|
||||
// Step 13
|
||||
let document = self.window.Document();
|
||||
|
||||
// Steps 14-15
|
||||
for candidate in document.upcast::<Node>().traverse_preorder().filter_map(Root::downcast::<Element>) {
|
||||
let is = candidate.get_is();
|
||||
if *candidate.local_name() == local_name &&
|
||||
*candidate.namespace() == ns!(html) &&
|
||||
(extends.is_none() || is.as_ref() == Some(&name))
|
||||
{
|
||||
ScriptThread::enqueue_upgrade_reaction(&*candidate, definition.clone());
|
||||
}
|
||||
}
|
||||
|
||||
// Step 16, 16.3
|
||||
if let Some(promise) = self.when_defined.borrow_mut().remove(&name) {
|
||||
|
@ -464,7 +476,7 @@ impl CustomElementDefinition {
|
|||
|
||||
/// https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element
|
||||
#[allow(unsafe_code)]
|
||||
fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Element) {
|
||||
pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Element) {
|
||||
// TODO: Steps 1-2
|
||||
// Track custom element state
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ use dom::bindings::str::{DOMString, USVString};
|
|||
use dom::bindings::xmlname::namespace_from_domstring;
|
||||
use dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};
|
||||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::customelementregistry::CallbackReaction;
|
||||
use dom::customelementregistry::{CallbackReaction, try_upgrade_element};
|
||||
use dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument};
|
||||
use dom::documentfragment::DocumentFragment;
|
||||
use dom::documenttype::DocumentType;
|
||||
|
@ -1639,12 +1639,13 @@ impl Node {
|
|||
for descendant in kid.traverse_preorder().filter_map(Root::downcast::<Element>) {
|
||||
// Step 7.7.2.
|
||||
if descendant.is_connected() {
|
||||
// Step 7.7.2.1.
|
||||
if descendant.get_custom_element_definition().is_some() {
|
||||
// Step 7.7.2.1.
|
||||
ScriptThread::enqueue_callback_reaction(&*descendant, CallbackReaction::Connected);
|
||||
} else {
|
||||
// Step 7.7.2.2.
|
||||
try_upgrade_element(&*descendant);
|
||||
}
|
||||
// TODO: Step 7.7.2.2.
|
||||
// Try to upgrade descendant.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue