diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-07-22 21:33:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-22 21:33:47 -0400 |
commit | 42b6b18f7631cc111577417574fc6ff5249a23f9 (patch) | |
tree | 451d228c0f2853b6ed20966096c6fc5edae6e149 /components/script/dom/shadowroot.rs | |
parent | 28f7a87186178d24c449f110155b5e3d87c4de0c (diff) | |
parent | 388bb453b7d6042ad775c75ac256e68543713d3c (diff) | |
download | servo-42b6b18f7631cc111577417574fc6ff5249a23f9.tar.gz servo-42b6b18f7631cc111577417574fc6ff5249a23f9.zip |
Auto merge of #23208 - ferjm:media.ui, r=emilio,jdm
Media controls
<strike>This is still highly WIP. It depends on #22743 and so it is based on top of it.
The basic controls functionality is there, but the layout is highly broken. There is a hack to at least make the controls render on top of the video, but it is not correctly positioned. The controls' div container ends up as sibbling of the media element in the flow tree while IIUC it should end up as a child.</strike>
- [X] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [X] These changes fix #22721 and fix #22720
There is at least an extra dependency to improve the functionality and visual aspect: #22728.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23208)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/shadowroot.rs')
-rw-r--r-- | components/script/dom/shadowroot.rs | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index ae108f8109c..d6df87bded8 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -14,7 +14,7 @@ use crate::dom::document::Document; use crate::dom::documentfragment::DocumentFragment; use crate::dom::documentorshadowroot::{DocumentOrShadowRoot, StyleSheetInDocument}; use crate::dom::element::Element; -use crate::dom::node::{Node, NodeDamage, NodeFlags, ShadowIncluding}; +use crate::dom::node::{Node, NodeDamage, NodeFlags, ShadowIncluding, UnbindContext}; use crate::dom::stylesheetlist::{StyleSheetList, StyleSheetListOwner}; use crate::dom::window::Window; use crate::stylesheet_set::StylesheetSetRef; @@ -28,13 +28,20 @@ use style::media_queries::Device; use style::shared_lock::SharedRwLockReadGuard; use style::stylesheets::Stylesheet; +/// Whether a shadow root hosts an User Agent widget. +#[derive(JSTraceable, MallocSizeOf, PartialEq)] +pub enum IsUserAgentWidget { + No, + Yes, +} + // https://dom.spec.whatwg.org/#interface-shadowroot #[dom_struct] pub struct ShadowRoot { document_fragment: DocumentFragment, document_or_shadow_root: DocumentOrShadowRoot, document: Dom<Document>, - host: Dom<Element>, + host: MutNullableDom<Element>, /// List of author styles associated with nodes in this shadow tree. author_styles: DomRefCell<AuthorStyles<StyleSheetInDocument>>, stylesheet_list: MutNullableDom<StyleSheetList>, @@ -55,7 +62,7 @@ impl ShadowRoot { document_fragment, document_or_shadow_root: DocumentOrShadowRoot::new(document.window()), document: Dom::from_ref(document), - host: Dom::from_ref(host), + host: MutNullableDom::new(Some(host)), author_styles: DomRefCell::new(AuthorStyles::new()), stylesheet_list: MutNullableDom::new(None), window: Dom::from_ref(document.window()), @@ -70,6 +77,14 @@ impl ShadowRoot { ) } + pub fn detach(&self) { + self.document.unregister_shadow_root(&self); + let node = self.upcast::<Node>(); + node.set_containing_shadow_root(None); + Node::complete_remove_subtree(&node, &UnbindContext::new(node, None, None, None)); + self.host.set(None); + } + pub fn get_focused_element(&self) -> Option<DomRoot<Element>> { //XXX get retargeted focused element None @@ -123,9 +138,9 @@ impl ShadowRoot { self.document.invalidate_shadow_roots_stylesheets(); self.author_styles.borrow_mut().stylesheets.force_dirty(); // Mark the host element dirty so a reflow will be performed. - self.host - .upcast::<Node>() - .dirty(NodeDamage::NodeStyleDamaged); + if let Some(host) = self.host.get() { + host.upcast::<Node>().dirty(NodeDamage::NodeStyleDamaged); + } } /// Remove any existing association between the provided id and any elements @@ -209,7 +224,8 @@ impl ShadowRootMethods for ShadowRoot { /// https://dom.spec.whatwg.org/#dom-shadowroot-host fn Host(&self) -> DomRoot<Element> { - DomRoot::from_ref(&self.host) + let host = self.host.get(); + host.expect("Trying to get host from a detached shadow root") } // https://drafts.csswg.org/cssom/#dom-document-stylesheets @@ -241,7 +257,10 @@ impl LayoutShadowRootHelpers for LayoutDom<ShadowRoot> { #[inline] #[allow(unsafe_code)] unsafe fn get_host_for_layout(&self) -> LayoutDom<Element> { - (*self.unsafe_get()).host.to_layout() + (*self.unsafe_get()) + .host + .get_inner_as_layout() + .expect("We should never do layout on a detached shadow root") } #[inline] |