mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
More detach shadow changes
This commit is contained in:
parent
d4be72d386
commit
ef02196dd8
5 changed files with 32 additions and 9 deletions
|
@ -2478,9 +2478,6 @@ impl Document {
|
||||||
if let Some(ref media_controls) = self.media_controls.borrow_mut().remove(id) {
|
if let Some(ref media_controls) = self.media_controls.borrow_mut().remove(id) {
|
||||||
let media_controls = DomRoot::from_ref(&**media_controls);
|
let media_controls = DomRoot::from_ref(&**media_controls);
|
||||||
media_controls.Host().detach_shadow();
|
media_controls.Host().detach_shadow();
|
||||||
media_controls
|
|
||||||
.upcast::<Node>()
|
|
||||||
.dirty(NodeDamage::OtherNodeDamage);
|
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(false, "Trying to unregister unknown media controls");
|
debug_assert!(false, "Trying to unregister unknown media controls");
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,7 +505,6 @@ impl Element {
|
||||||
pub fn detach_shadow(&self) {
|
pub fn detach_shadow(&self) {
|
||||||
if let Some(ref shadow_root) = self.shadow_root() {
|
if let Some(ref shadow_root) = self.shadow_root() {
|
||||||
shadow_root.detach();
|
shadow_root.detach();
|
||||||
self.node.owner_doc().unregister_shadow_root(shadow_root);
|
|
||||||
self.ensure_rare_data().shadow_root = None;
|
self.ensure_rare_data().shadow_root = None;
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(false, "Trying to detach a non-attached shadow root");
|
debug_assert!(false, "Trying to detach a non-attached shadow root");
|
||||||
|
|
|
@ -1787,8 +1787,8 @@ impl HTMLMediaElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_controls(&self) {
|
fn remove_controls(&self) {
|
||||||
if let Some(ref id) = *self.media_controls_id.borrow() {
|
if let Some(id) = self.media_controls_id.borrow_mut().take() {
|
||||||
document_from_node(self).unregister_media_controls(id);
|
document_from_node(self).unregister_media_controls(&id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRootBinding::ShadowRootMethods;
|
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRootBinding::ShadowRootMethods;
|
||||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::{self, ShadowRootMode};
|
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::{self, ShadowRootMode};
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
|
@ -78,13 +79,25 @@ impl ShadowRoot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detach(&self) {
|
pub fn detach(&self) {
|
||||||
self.host.set(None);
|
self.document.unregister_shadow_root(&self);
|
||||||
let node = self.upcast::<Node>();
|
let node = self.upcast::<Node>();
|
||||||
node.set_containing_shadow_root(None);
|
node.set_containing_shadow_root(None);
|
||||||
node.set_flag(NodeFlags::IS_CONNECTED, false);
|
|
||||||
for child in node.traverse_preorder(ShadowIncluding::No) {
|
for child in node.traverse_preorder(ShadowIncluding::No) {
|
||||||
child.set_flag(NodeFlags::IS_CONNECTED, false);
|
if node.RemoveChild(&child).is_err() {
|
||||||
|
warn!("Could not remove shadow root child");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if self
|
||||||
|
.host
|
||||||
|
.get()
|
||||||
|
.unwrap()
|
||||||
|
.upcast::<Node>()
|
||||||
|
.RemoveChild(&node)
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
warn!("Could not detach shadow root");
|
||||||
|
}
|
||||||
|
self.host.set(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_focused_element(&self) -> Option<DomRoot<Element>> {
|
pub fn get_focused_element(&self) -> Option<DomRoot<Element>> {
|
||||||
|
|
|
@ -74,11 +74,22 @@
|
||||||
|
|
||||||
class MediaControls {
|
class MediaControls {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.nonce = Date.now();
|
||||||
// Get the instance of the shadow root where these controls live.
|
// Get the instance of the shadow root where these controls live.
|
||||||
this.controls = document.servoGetMediaControls("@@@id@@@");
|
this.controls = document.servoGetMediaControls("@@@id@@@");
|
||||||
// Get the instance of the host of these controls.
|
// Get the instance of the host of these controls.
|
||||||
this.media = this.controls.host;
|
this.media = this.controls.host;
|
||||||
|
|
||||||
|
this.shutthingDown = false;
|
||||||
|
this.mutationObserver = new MutationObserver(() => {
|
||||||
|
// We can only get here if the `controls` attribute is removed.
|
||||||
|
this.shutthingDown = true;
|
||||||
|
this.mutationObserver.disconnect();
|
||||||
|
});
|
||||||
|
this.mutationObserver.observe(this.media, {
|
||||||
|
attributeFilter: ["controls"]
|
||||||
|
});
|
||||||
|
|
||||||
// Create root element and load markup.
|
// Create root element and load markup.
|
||||||
this.root = document.createElement("div");
|
this.root = document.createElement("div");
|
||||||
this.root.classList.add("root");
|
this.root.classList.add("root");
|
||||||
|
@ -203,6 +214,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
render(from = this.state) {
|
render(from = this.state) {
|
||||||
|
if (this.shutthingDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const isAudioOnly = this.media.localName == "audio";
|
const isAudioOnly = this.media.localName == "audio";
|
||||||
if (!isAudioOnly) {
|
if (!isAudioOnly) {
|
||||||
// XXX This should ideally use clientHeight/clientWidth,
|
// XXX This should ideally use clientHeight/clientWidth,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue