mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Unify DocumentOrShadowRoot implementation
This commit is contained in:
parent
f3e707306f
commit
48975840dd
4 changed files with 238 additions and 161 deletions
|
@ -2,33 +2,25 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRootBinding::ShadowRootMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::{self, ShadowRootMode};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::num::Finite;
|
||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||
use crate::dom::cssstylesheet::CSSStyleSheet;
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::documentfragment::DocumentFragment;
|
||||
use crate::dom::documentorshadowroot::DocumentOrShadowRoot;
|
||||
use crate::dom::documentorshadowroot::{DocumentOrShadowRoot, DocumentOrShadowRootImpl};
|
||||
use crate::dom::element::Element;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node;
|
||||
use crate::dom::stylesheetlist::StyleSheetList;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::windowproxy::WindowProxy;
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::Point2D;
|
||||
use js::jsapi::JS_GetRuntime;
|
||||
use script_layout_interface::message::{NodesFromPointQueryType, QueryMsg};
|
||||
use script_traits::UntrustedNodeAddress;
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-shadowroot
|
||||
#[dom_struct]
|
||||
pub struct ShadowRoot {
|
||||
document_fragment: DocumentFragment,
|
||||
document_or_shadow_root: DocumentOrShadowRootImpl,
|
||||
has_browsing_context: bool,
|
||||
host: Dom<Element>,
|
||||
stylesheet_list: MutNullableDom<StyleSheetList>,
|
||||
|
@ -37,9 +29,14 @@ pub struct ShadowRoot {
|
|||
|
||||
impl ShadowRoot {
|
||||
fn new_inherited(host: &Element, document: &Document) -> ShadowRoot {
|
||||
let has_browsing_context = true;
|
||||
ShadowRoot {
|
||||
document_fragment: DocumentFragment::new_inherited(document),
|
||||
has_browsing_context: true,
|
||||
document_or_shadow_root: DocumentOrShadowRootImpl::new(
|
||||
document.window(),
|
||||
has_browsing_context,
|
||||
),
|
||||
has_browsing_context,
|
||||
host: Dom::from_ref(host),
|
||||
stylesheet_list: MutNullableDom::new(None),
|
||||
window: Dom::from_ref(document.window()),
|
||||
|
@ -59,14 +56,6 @@ impl ShadowRoot {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn GetDocumentElement(&self) -> Option<DomRoot<Element>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn GetBody(&self) -> Option<DomRoot<HTMLElement>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn stylesheet_count(&self) -> usize {
|
||||
//XXX handle shadowroot stylesheets
|
||||
0
|
||||
|
@ -76,13 +65,28 @@ impl ShadowRoot {
|
|||
//XXX handle shadowroot stylesheets
|
||||
None
|
||||
}
|
||||
|
||||
impl_document_or_shadow_root_helpers!();
|
||||
}
|
||||
|
||||
impl ShadowRootMethods for ShadowRoot {
|
||||
/// https://w3c.github.io/webcomponents/spec/shadow/#extensions-to-the-documentorshadowroot-mixin
|
||||
impl_document_or_shadow_root_methods!(ShadowRoot);
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-activeelement
|
||||
fn GetActiveElement(&self) -> Option<DomRoot<Element>> {
|
||||
self.document_or_shadow_root
|
||||
.get_active_element(self.get_focused_element(), None, None)
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint
|
||||
fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<DomRoot<Element>> {
|
||||
// XXX return the result of running the retargeting algorithm with context object
|
||||
// and the original result as input
|
||||
self.document_or_shadow_root.element_from_point(x, y, None)
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint
|
||||
fn ElementsFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Vec<DomRoot<Element>> {
|
||||
// XXX return the result of running the retargeting algorithm with context object
|
||||
// and the original result as input
|
||||
self.document_or_shadow_root.elements_from_point(x, y, None)
|
||||
}
|
||||
|
||||
/// https://dom.spec.whatwg.org/#dom-shadowroot-mode
|
||||
fn Mode(&self) -> ShadowRootMode {
|
||||
|
@ -93,4 +97,14 @@ impl ShadowRootMethods for ShadowRoot {
|
|||
fn Host(&self) -> DomRoot<Element> {
|
||||
DomRoot::from_ref(&self.host)
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-document-stylesheets
|
||||
fn StyleSheets(&self) -> DomRoot<StyleSheetList> {
|
||||
self.stylesheet_list.or_init(|| {
|
||||
StyleSheetList::new(
|
||||
&self.window,
|
||||
DocumentOrShadowRoot::ShadowRoot(Dom::from_ref(self)),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue