mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Return a reference in Document::window()
This commit is contained in:
parent
e889b0914b
commit
409b5e3695
12 changed files with 31 additions and 39 deletions
|
@ -49,7 +49,7 @@ impl BrowsingContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active_window(&self) -> Root<Window> {
|
pub fn active_window(&self) -> Root<Window> {
|
||||||
self.active_document().window()
|
Root::from_ref(self.active_document().window())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn frame_element(&self) -> Option<&Element> {
|
pub fn frame_element(&self) -> Option<&Element> {
|
||||||
|
|
|
@ -232,8 +232,8 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn window(&self) -> Root<Window> {
|
pub fn window(&self) -> &Window {
|
||||||
self.window.root()
|
&*self.window
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -539,8 +539,6 @@ impl Document {
|
||||||
/// Sends this document's title to the compositor.
|
/// Sends this document's title to the compositor.
|
||||||
pub fn send_title_to_compositor(&self) {
|
pub fn send_title_to_compositor(&self) {
|
||||||
let window = self.window();
|
let window = self.window();
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
|
||||||
let window = window.r();
|
|
||||||
let compositor = window.compositor();
|
let compositor = window.compositor();
|
||||||
compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(), Some(self.Title()))).unwrap();
|
compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(), Some(self.Title()))).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -1094,7 +1092,7 @@ impl Document {
|
||||||
IsHTMLDocument::NonHTMLDocument
|
IsHTMLDocument::NonHTMLDocument
|
||||||
};
|
};
|
||||||
let new_doc = Document::new(
|
let new_doc = Document::new(
|
||||||
&*self.window(), None, doctype, None, None,
|
self.window(), None, doctype, None, None,
|
||||||
DocumentSource::NotFromParser, DocumentLoader::new(&self.loader()));
|
DocumentSource::NotFromParser, DocumentLoader::new(&self.loader()));
|
||||||
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
|
new_doc.appropriate_template_contents_owner_document.set(Some(&new_doc));
|
||||||
new_doc
|
new_doc
|
||||||
|
@ -1789,9 +1787,8 @@ impl DocumentMethods for Document {
|
||||||
}
|
}
|
||||||
// Step 4.
|
// Step 4.
|
||||||
*found = true;
|
*found = true;
|
||||||
let window = self.window();
|
|
||||||
let filter = NamedElementFilter { name: name };
|
let filter = NamedElementFilter { name: name };
|
||||||
let collection = HTMLCollection::create(window.r(), root, box filter);
|
let collection = HTMLCollection::create(self.window(), root, box filter);
|
||||||
collection.r().reflector().get_jsobject().get()
|
collection.r().reflector().get_jsobject().get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1849,13 +1846,15 @@ impl DocumentProgressHandler {
|
||||||
fn dispatch_dom_content_loaded(&self) {
|
fn dispatch_dom_content_loaded(&self) {
|
||||||
let document = self.addr.root();
|
let document = self.addr.root();
|
||||||
let window = document.r().window();
|
let window = document.r().window();
|
||||||
let event = Event::new(GlobalRef::Window(window.r()), "DOMContentLoaded".to_owned(),
|
let event = Event::new(GlobalRef::Window(window), "DOMContentLoaded".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let doctarget = EventTargetCast::from_ref(document.r());
|
let doctarget = EventTargetCast::from_ref(document.r());
|
||||||
let _ = doctarget.DispatchEvent(event.r());
|
let _ = doctarget.DispatchEvent(event.r());
|
||||||
|
|
||||||
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::DOMContentLoaded);
|
window.reflow(ReflowGoal::ForDisplay,
|
||||||
|
ReflowQueryType::NoQuery,
|
||||||
|
ReflowReason::DOMContentLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_ready_state_complete(&self) {
|
fn set_ready_state_complete(&self) {
|
||||||
|
@ -1866,16 +1865,15 @@ impl DocumentProgressHandler {
|
||||||
fn dispatch_load(&self) {
|
fn dispatch_load(&self) {
|
||||||
let document = self.addr.root();
|
let document = self.addr.root();
|
||||||
let window = document.r().window();
|
let window = document.r().window();
|
||||||
let event = Event::new(GlobalRef::Window(window.r()), "load".to_owned(),
|
let event = Event::new(GlobalRef::Window(window), "load".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let wintarget = EventTargetCast::from_ref(window.r());
|
let wintarget = EventTargetCast::from_ref(window);
|
||||||
let doctarget = EventTargetCast::from_ref(document.r());
|
let doctarget = EventTargetCast::from_ref(document.r());
|
||||||
event.r().set_trusted(true);
|
event.r().set_trusted(true);
|
||||||
let _ = wintarget.dispatch_event_with_target(doctarget, event.r());
|
let _ = wintarget.dispatch_event_with_target(doctarget, event.r());
|
||||||
|
|
||||||
let window_ref = window.r();
|
let browsing_context = window.browsing_context();
|
||||||
let browsing_context = window_ref.browsing_context();
|
|
||||||
let browsing_context = browsing_context.as_ref().unwrap();
|
let browsing_context = browsing_context.as_ref().unwrap();
|
||||||
|
|
||||||
if let Some(frame_element) = browsing_context.frame_element() {
|
if let Some(frame_element) = browsing_context.frame_element() {
|
||||||
|
@ -1892,9 +1890,9 @@ impl DocumentProgressHandler {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserloadend
|
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowserloadend
|
||||||
document.r().trigger_mozbrowser_event(MozBrowserEvent::LoadEnd);
|
document.r().trigger_mozbrowser_event(MozBrowserEvent::LoadEnd);
|
||||||
|
|
||||||
window_ref.reflow(ReflowGoal::ForDisplay,
|
window.reflow(ReflowGoal::ForDisplay,
|
||||||
ReflowQueryType::NoQuery,
|
ReflowQueryType::NoQuery,
|
||||||
ReflowReason::DocumentLoaded);
|
ReflowReason::DocumentLoaded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1902,7 +1900,7 @@ impl Runnable for DocumentProgressHandler {
|
||||||
fn handler(self: Box<DocumentProgressHandler>) {
|
fn handler(self: Box<DocumentProgressHandler>) {
|
||||||
let document = self.addr.root();
|
let document = self.addr.root();
|
||||||
let window = document.r().window();
|
let window = document.r().window();
|
||||||
if window.r().is_alive() {
|
if window.is_alive() {
|
||||||
match self.task {
|
match self.task {
|
||||||
DocumentProgressTask::DOMContentLoaded => {
|
DocumentProgressTask::DOMContentLoaded => {
|
||||||
self.dispatch_dom_content_loaded();
|
self.dispatch_dom_content_loaded();
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl DOMImplementation {
|
||||||
pub fn new(document: &Document) -> Root<DOMImplementation> {
|
pub fn new(document: &Document) -> Root<DOMImplementation> {
|
||||||
let window = document.window();
|
let window = document.window();
|
||||||
reflect_dom_object(box DOMImplementation::new_inherited(document),
|
reflect_dom_object(box DOMImplementation::new_inherited(document),
|
||||||
GlobalRef::Window(window.r()),
|
GlobalRef::Window(window),
|
||||||
DOMImplementationBinding::Wrap)
|
DOMImplementationBinding::Wrap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
let loader = DocumentLoader::new(&*doc.loader());
|
let loader = DocumentLoader::new(&*doc.loader());
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let doc = Document::new(win.r(), None, IsHTMLDocument::NonHTMLDocument,
|
let doc = Document::new(win, None, IsHTMLDocument::NonHTMLDocument,
|
||||||
None, None, DocumentSource::NotFromParser, loader);
|
None, None, DocumentSource::NotFromParser, loader);
|
||||||
// Step 2-3.
|
// Step 2-3.
|
||||||
let maybe_elem = if qname.is_empty() {
|
let maybe_elem = if qname.is_empty() {
|
||||||
|
@ -114,7 +114,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
let loader = DocumentLoader::new(&*document.loader());
|
let loader = DocumentLoader::new(&*document.loader());
|
||||||
|
|
||||||
// Step 1-2.
|
// Step 1-2.
|
||||||
let doc = Document::new(win.r(), None, IsHTMLDocument::HTMLDocument, None, None,
|
let doc = Document::new(win, None, IsHTMLDocument::HTMLDocument, None, None,
|
||||||
DocumentSource::NotFromParser, loader);
|
DocumentSource::NotFromParser, loader);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -1143,7 +1143,7 @@ impl ElementMethods for Element {
|
||||||
node.owner_doc()
|
node.owner_doc()
|
||||||
};
|
};
|
||||||
let window = doc.r().window();
|
let window = doc.r().window();
|
||||||
NamedNodeMap::new(window.r(), self)
|
NamedNodeMap::new(window, self)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,6 @@ impl HTMLImageElement {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = NodeCast::from_ref(self);
|
||||||
let document = node.owner_doc();
|
let document = node.owner_doc();
|
||||||
let window = document.r().window();
|
let window = document.r().window();
|
||||||
let window = window.r();
|
|
||||||
let image_cache = window.image_cache_task();
|
let image_cache = window.image_cache_task();
|
||||||
match value {
|
match value {
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -106,7 +106,7 @@ static DEFAULT_INPUT_SIZE: u32 = 20;
|
||||||
|
|
||||||
impl HTMLInputElement {
|
impl HTMLInputElement {
|
||||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement {
|
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: &Document) -> HTMLInputElement {
|
||||||
let chan = document.window().r().constellation_chan();
|
let chan = document.window().constellation_chan();
|
||||||
HTMLInputElement {
|
HTMLInputElement {
|
||||||
htmlelement:
|
htmlelement:
|
||||||
HTMLElement::new_inherited_with_flags(NodeFlags::new() | IN_ENABLED_STATE,
|
HTMLElement::new_inherited_with_flags(NodeFlags::new() | IN_ENABLED_STATE,
|
||||||
|
|
|
@ -84,7 +84,7 @@ impl HTMLTextAreaElement {
|
||||||
fn new_inherited(localName: DOMString,
|
fn new_inherited(localName: DOMString,
|
||||||
prefix: Option<DOMString>,
|
prefix: Option<DOMString>,
|
||||||
document: &Document) -> HTMLTextAreaElement {
|
document: &Document) -> HTMLTextAreaElement {
|
||||||
let chan = document.window().r().constellation_chan();
|
let chan = document.window().constellation_chan();
|
||||||
HTMLTextAreaElement {
|
HTMLTextAreaElement {
|
||||||
htmlelement:
|
htmlelement:
|
||||||
HTMLElement::new_inherited_with_flags(NodeFlags::new() | IN_ENABLED_STATE,
|
HTMLElement::new_inherited_with_flags(NodeFlags::new() | IN_ENABLED_STATE,
|
||||||
|
|
|
@ -1341,7 +1341,7 @@ impl Node {
|
||||||
wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box<N>) -> Root<N>)
|
wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box<N>) -> Root<N>)
|
||||||
-> Root<N> {
|
-> Root<N> {
|
||||||
let window = document.window();
|
let window = document.window();
|
||||||
reflect_dom_object(node, GlobalRef::Window(window.r()), wrap_fn)
|
reflect_dom_object(node, GlobalRef::Window(window), wrap_fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_inherited(doc: &Document) -> Node {
|
pub fn new_inherited(doc: &Document) -> Node {
|
||||||
|
@ -1688,7 +1688,7 @@ impl Node {
|
||||||
};
|
};
|
||||||
let window = document.window();
|
let window = document.window();
|
||||||
let loader = DocumentLoader::new(&*document.loader());
|
let loader = DocumentLoader::new(&*document.loader());
|
||||||
let document = Document::new(window.r(), Some((*document.url()).clone()),
|
let document = Document::new(window, Some((*document.url()).clone()),
|
||||||
is_html_doc, None,
|
is_html_doc, None,
|
||||||
None, DocumentSource::NotFromParser, loader);
|
None, DocumentSource::NotFromParser, loader);
|
||||||
NodeCast::from_root(document)
|
NodeCast::from_root(document)
|
||||||
|
@ -1929,7 +1929,7 @@ impl NodeMethods for Node {
|
||||||
self.child_list.or_init(|| {
|
self.child_list.or_init(|| {
|
||||||
let doc = self.owner_doc();
|
let doc = self.owner_doc();
|
||||||
let window = doc.r().window();
|
let window = doc.r().window();
|
||||||
NodeList::new_child_list(window.r(), self)
|
NodeList::new_child_list(window, self)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2428,7 +2428,7 @@ pub fn document_from_node<T: NodeBase + Reflectable>(derived: &T) -> Root<Docume
|
||||||
|
|
||||||
pub fn window_from_node<T: NodeBase + Reflectable>(derived: &T) -> Root<Window> {
|
pub fn window_from_node<T: NodeBase + Reflectable>(derived: &T) -> Root<Window> {
|
||||||
let document = document_from_node(derived);
|
let document = document_from_node(derived);
|
||||||
document.r().window()
|
Root::from_ref(document.r().window())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for Node {
|
impl VirtualMethods for Node {
|
||||||
|
|
|
@ -47,9 +47,8 @@ impl NodeIterator {
|
||||||
root_node: &Node,
|
root_node: &Node,
|
||||||
what_to_show: u32,
|
what_to_show: u32,
|
||||||
filter: Filter) -> Root<NodeIterator> {
|
filter: Filter) -> Root<NodeIterator> {
|
||||||
let window = document.window();
|
|
||||||
reflect_dom_object(box NodeIterator::new_inherited(root_node, what_to_show, filter),
|
reflect_dom_object(box NodeIterator::new_inherited(root_node, what_to_show, filter),
|
||||||
GlobalRef::Window(window.r()),
|
GlobalRef::Window(document.window()),
|
||||||
NodeIteratorBinding::Wrap)
|
NodeIteratorBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,9 @@ impl Range {
|
||||||
start_container: &Node, start_offset: u32,
|
start_container: &Node, start_offset: u32,
|
||||||
end_container: &Node, end_offset: u32)
|
end_container: &Node, end_offset: u32)
|
||||||
-> Root<Range> {
|
-> Root<Range> {
|
||||||
let window = document.window();
|
|
||||||
reflect_dom_object(box Range::new_inherited(start_container, start_offset,
|
reflect_dom_object(box Range::new_inherited(start_container, start_offset,
|
||||||
end_container, end_offset),
|
end_container, end_offset),
|
||||||
GlobalRef::Window(window.r()),
|
GlobalRef::Window(document.window()),
|
||||||
RangeBinding::Wrap)
|
RangeBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,6 @@ impl ServoHTMLParser {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new(base_url: Option<Url>, document: &Document, pipeline: Option<PipelineId>)
|
pub fn new(base_url: Option<Url>, document: &Document, pipeline: Option<PipelineId>)
|
||||||
-> Root<ServoHTMLParser> {
|
-> Root<ServoHTMLParser> {
|
||||||
let window = document.window();
|
|
||||||
let sink = Sink {
|
let sink = Sink {
|
||||||
base_url: base_url,
|
base_url: base_url,
|
||||||
document: JS::from_ref(document),
|
document: JS::from_ref(document),
|
||||||
|
@ -237,14 +236,13 @@ impl ServoHTMLParser {
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
};
|
};
|
||||||
|
|
||||||
reflect_dom_object(box parser, GlobalRef::Window(window.r()),
|
reflect_dom_object(box parser, GlobalRef::Window(document.window()),
|
||||||
ServoHTMLParserBinding::Wrap)
|
ServoHTMLParserBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new_for_fragment(base_url: Option<Url>, document: &Document,
|
pub fn new_for_fragment(base_url: Option<Url>, document: &Document,
|
||||||
fragment_context: FragmentContext) -> Root<ServoHTMLParser> {
|
fragment_context: FragmentContext) -> Root<ServoHTMLParser> {
|
||||||
let window = document.window();
|
|
||||||
let sink = Sink {
|
let sink = Sink {
|
||||||
base_url: base_url,
|
base_url: base_url,
|
||||||
document: JS::from_ref(document),
|
document: JS::from_ref(document),
|
||||||
|
@ -275,7 +273,7 @@ impl ServoHTMLParser {
|
||||||
pipeline: None,
|
pipeline: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
reflect_dom_object(box parser, GlobalRef::Window(window.r()),
|
reflect_dom_object(box parser, GlobalRef::Window(document.window()),
|
||||||
ServoHTMLParserBinding::Wrap)
|
ServoHTMLParserBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,8 @@ impl TreeWalker {
|
||||||
root_node: &Node,
|
root_node: &Node,
|
||||||
what_to_show: u32,
|
what_to_show: u32,
|
||||||
filter: Filter) -> Root<TreeWalker> {
|
filter: Filter) -> Root<TreeWalker> {
|
||||||
let window = document.window();
|
|
||||||
reflect_dom_object(box TreeWalker::new_inherited(root_node, what_to_show, filter),
|
reflect_dom_object(box TreeWalker::new_inherited(root_node, what_to_show, filter),
|
||||||
GlobalRef::Window(window.r()),
|
GlobalRef::Window(document.window()),
|
||||||
TreeWalkerBinding::Wrap)
|
TreeWalkerBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue