aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/document.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r--components/script/dom/document.rs51
1 files changed, 42 insertions, 9 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 2ff1516b231..5b1de4e6b85 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -43,7 +43,7 @@ use crate::dom::cssstylesheet::CSSStyleSheet;
use crate::dom::customelementregistry::CustomElementDefinition;
use crate::dom::customevent::CustomEvent;
use crate::dom::documentfragment::DocumentFragment;
-use crate::dom::documentorshadowroot::DocumentOrShadowRoot;
+use crate::dom::documentorshadowroot::{DocumentOrShadowRoot, DocumentOrShadowRootImpl};
use crate::dom::documenttype::DocumentType;
use crate::dom::domimplementation::DOMImplementation;
use crate::dom::element::CustomElementCreationMode;
@@ -114,7 +114,6 @@ use euclid::Point2D;
use html5ever::{LocalName, Namespace, QualName};
use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcSender};
-use js::jsapi::JS_GetRuntime;
use js::jsapi::{JSContext, JSObject, JSRuntime};
use keyboard_types::{Key, KeyState, Modifiers};
use metrics::{
@@ -133,7 +132,7 @@ use num_traits::ToPrimitive;
use profile_traits::ipc as profile_ipc;
use profile_traits::time::{TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType};
use ref_slice::ref_slice;
-use script_layout_interface::message::{Msg, NodesFromPointQueryType, QueryMsg, ReflowGoal};
+use script_layout_interface::message::{Msg, ReflowGoal};
use script_traits::{AnimationState, DocumentActivity, MouseButton, MouseEventType};
use script_traits::{MsDuration, ScriptMsg, TouchEventType, TouchId, UntrustedNodeAddress};
use servo_arc::Arc;
@@ -267,6 +266,7 @@ impl ::style::stylesheets::StylesheetInDocument for StyleSheetInDocument {
#[dom_struct]
pub struct Document {
node: Node,
+ document_or_shadow_root: DocumentOrShadowRootImpl,
window: Dom<Window>,
implementation: MutNullableDom<DOMImplementation>,
#[ignore_malloc_size_of = "type from external crate"]
@@ -488,6 +488,11 @@ impl Document {
}
#[inline]
+ pub fn browsing_context(&self) -> Option<DomRoot<WindowProxy>> {
+ self.document_or_shadow_root.browsing_context()
+ }
+
+ #[inline]
pub fn window(&self) -> &Window {
&*self.window
}
@@ -2613,10 +2618,12 @@ impl Document {
.and_then(|charset| Encoding::for_label(charset.as_str().as_bytes()))
.unwrap_or(UTF_8);
+ let has_browsing_context = has_browsing_context == HasBrowsingContext::Yes;
Document {
node: Node::new_document_node(),
+ document_or_shadow_root: DocumentOrShadowRootImpl::new(window, has_browsing_context),
window: Dom::from_ref(window),
- has_browsing_context: has_browsing_context == HasBrowsingContext::Yes,
+ has_browsing_context,
implementation: Default::default(),
content_type,
last_modified: last_modified,
@@ -2665,7 +2672,7 @@ impl Document {
deferred_scripts: Default::default(),
asap_in_order_scripts_list: Default::default(),
asap_scripts_set: Default::default(),
- scripting_enabled: has_browsing_context == HasBrowsingContext::Yes,
+ scripting_enabled: has_browsing_context,
animation_frame_ident: Cell::new(0),
animation_frame_list: DomRefCell::new(vec![]),
running_animation_callbacks: Cell::new(false),
@@ -3246,8 +3253,6 @@ impl Document {
}
}
}
-
- impl_document_or_shadow_root_helpers!();
}
impl Element {
@@ -3277,8 +3282,15 @@ impl ProfilerMetadataFactory for Document {
}
impl DocumentMethods for Document {
- // https://w3c.github.io/webcomponents/spec/shadow/#extensions-to-the-documentorshadowroot-mixin
- impl_document_or_shadow_root_methods!(Document);
+ // https://drafts.csswg.org/cssom/#dom-document-stylesheets
+ fn StyleSheets(&self) -> DomRoot<StyleSheetList> {
+ self.stylesheet_list.or_init(|| {
+ StyleSheetList::new(
+ &self.window,
+ DocumentOrShadowRoot::Document(Dom::from_ref(self)),
+ )
+ })
+ }
// https://dom.spec.whatwg.org/#dom-document-implementation
fn Implementation(&self) -> DomRoot<DOMImplementation> {
@@ -3290,6 +3302,15 @@ impl DocumentMethods for Document {
USVString(String::from(self.url().as_str()))
}
+ // 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(),
+ self.GetBody(),
+ self.GetDocumentElement(),
+ )
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-document-hasfocus
fn HasFocus(&self) -> bool {
// Step 1-2.
@@ -4234,6 +4255,18 @@ impl DocumentMethods for Document {
SetOnreadystatechange
);
+ // https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint
+ fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<DomRoot<Element>> {
+ self.document_or_shadow_root
+ .element_from_point(x, y, self.GetDocumentElement())
+ }
+
+ // https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint
+ fn ElementsFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Vec<DomRoot<Element>> {
+ self.document_or_shadow_root
+ .elements_from_point(x, y, self.GetDocumentElement())
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-document-open
fn Open(
&self,