mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Split Page code out of script_task.rs #2530
This commit is contained in:
parent
4c5437c58b
commit
94ec3cde8a
8 changed files with 455 additions and 418 deletions
|
@ -4339,7 +4339,7 @@ class CGBindingRoot(CGThing):
|
||||||
'dom::bindings::proxyhandler::{FillPropertyDescriptor, GetExpandoObject}',
|
'dom::bindings::proxyhandler::{FillPropertyDescriptor, GetExpandoObject}',
|
||||||
'dom::bindings::proxyhandler::{getPropertyDescriptor}',
|
'dom::bindings::proxyhandler::{getPropertyDescriptor}',
|
||||||
'dom::bindings::str::ByteString',
|
'dom::bindings::str::ByteString',
|
||||||
'script_task::JSPageInfo',
|
'page::JSPageInfo',
|
||||||
'libc',
|
'libc',
|
||||||
'servo_util::str::DOMString',
|
'servo_util::str::DOMString',
|
||||||
'std::mem',
|
'std::mem',
|
||||||
|
@ -5214,7 +5214,7 @@ class GlobalGenRoots():
|
||||||
'dom::bindings::codegen',
|
'dom::bindings::codegen',
|
||||||
'dom::bindings::js::{JS, JSRef}',
|
'dom::bindings::js::{JS, JSRef}',
|
||||||
'dom::window::Window',
|
'dom::window::Window',
|
||||||
'script_task::JSPageInfo',
|
'page::JSPageInfo',
|
||||||
])
|
])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -14,7 +14,7 @@ use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, ElementNodeTypeId, window_from_node};
|
use dom::node::{Node, ElementNodeTypeId, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use script_task::IterablePage;
|
use page::IterablePage;
|
||||||
use servo_msg::constellation_msg::{PipelineId, SubpageId};
|
use servo_msg::constellation_msg::{PipelineId, SubpageId};
|
||||||
use servo_msg::constellation_msg::{IFrameSandboxed, IFrameUnsandboxed};
|
use servo_msg::constellation_msg::{IFrameSandboxed, IFrameUnsandboxed};
|
||||||
use servo_msg::constellation_msg::{ConstellationChan, LoadIframeUrlMsg};
|
use servo_msg::constellation_msg::{ConstellationChan, LoadIframeUrlMsg};
|
||||||
|
|
|
@ -8,7 +8,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
use script_task::{Page};
|
use page::Page;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use serialize::{Encoder, Encodable};
|
use serialize::{Encoder, Encodable};
|
||||||
|
|
|
@ -17,7 +17,8 @@ use dom::navigator::Navigator;
|
||||||
use dom::performance::Performance;
|
use dom::performance::Performance;
|
||||||
|
|
||||||
use layout_interface::{ReflowForDisplay, DocumentDamageLevel};
|
use layout_interface::{ReflowForDisplay, DocumentDamageLevel};
|
||||||
use script_task::{ExitWindowMsg, FireTimerMsg, Page, ScriptChan, TriggerLoadMsg, TriggerFragmentMsg};
|
use page::Page;
|
||||||
|
use script_task::{ExitWindowMsg, FireTimerMsg, ScriptChan, TriggerLoadMsg, TriggerFragmentMsg};
|
||||||
use servo_msg::compositor_msg::ScriptListener;
|
use servo_msg::compositor_msg::ScriptListener;
|
||||||
use servo_net::image_cache_task::ImageCacheTask;
|
use servo_net::image_cache_task::ImageCacheTask;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
|
@ -14,7 +14,7 @@ use dom::htmlformelement::HTMLFormElement;
|
||||||
use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods};
|
use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods};
|
||||||
use dom::types::*;
|
use dom::types::*;
|
||||||
use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
||||||
use script_task::Page;
|
use page::Page;
|
||||||
|
|
||||||
use hubbub::hubbub;
|
use hubbub::hubbub;
|
||||||
use hubbub::hubbub::{NullNs, HtmlNs, MathMlNs, SvgNs, XLinkNs, XmlNs, XmlNsNs};
|
use hubbub::hubbub::{NullNs, HtmlNs, MathMlNs, SvgNs, XLinkNs, XmlNs, XmlNsNs};
|
||||||
|
|
436
src/components/script/page.rs
Normal file
436
src/components/script/page.rs
Normal file
|
@ -0,0 +1,436 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
||||||
|
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||||
|
use dom::bindings::js::OptionalRootable;
|
||||||
|
use dom::bindings::trace::{Traceable, Untraceable};
|
||||||
|
use dom::bindings::utils::GlobalStaticData;
|
||||||
|
use dom::document::{Document, DocumentMethods, DocumentHelpers};
|
||||||
|
use dom::element::{Element, AttributeHandlers};
|
||||||
|
use dom::node::{Node, NodeHelpers};
|
||||||
|
use dom::window::Window;
|
||||||
|
use layout_interface::{DocumentDamage};
|
||||||
|
use layout_interface::{DocumentDamageLevel, HitTestQuery, HitTestResponse, LayoutQuery, MouseOverQuery, MouseOverResponse};
|
||||||
|
use layout_interface::{LayoutChan, QueryMsg};
|
||||||
|
use layout_interface::{Reflow, ReflowGoal, ReflowMsg};
|
||||||
|
use layout_interface::UntrustedNodeAddress;
|
||||||
|
use script_task::ScriptChan;
|
||||||
|
|
||||||
|
use geom::point::Point2D;
|
||||||
|
use geom::size::TypedSize2D;
|
||||||
|
use js::rust::Cx;
|
||||||
|
use servo_msg::compositor_msg::PerformingLayout;
|
||||||
|
use servo_msg::compositor_msg::ScriptListener;
|
||||||
|
use servo_msg::constellation_msg::ConstellationChan;
|
||||||
|
use servo_msg::constellation_msg::{PipelineId, SubpageId};
|
||||||
|
use servo_net::resource_task::ResourceTask;
|
||||||
|
use servo_util::geometry::PagePx;
|
||||||
|
use servo_util::namespace::Null;
|
||||||
|
use servo_util::str::DOMString;
|
||||||
|
use std::cell::{Cell, RefCell, Ref, RefMut};
|
||||||
|
use std::comm::{channel, Receiver, Empty, Disconnected};
|
||||||
|
use std::mem::replace;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
use serialize::{Encoder, Encodable};
|
||||||
|
|
||||||
|
/// Encapsulates a handle to a frame and its associated layout information.
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct Page {
|
||||||
|
/// Pipeline id associated with this page.
|
||||||
|
pub id: PipelineId,
|
||||||
|
|
||||||
|
/// Subpage id associated with this page, if any.
|
||||||
|
pub subpage_id: Option<SubpageId>,
|
||||||
|
|
||||||
|
/// Unique id for last reflow request; used for confirming completion reply.
|
||||||
|
pub last_reflow_id: Traceable<Cell<uint>>,
|
||||||
|
|
||||||
|
/// The outermost frame containing the document, window, and page URL.
|
||||||
|
pub frame: Traceable<RefCell<Option<Frame>>>,
|
||||||
|
|
||||||
|
/// A handle for communicating messages to the layout task.
|
||||||
|
pub layout_chan: Untraceable<LayoutChan>,
|
||||||
|
|
||||||
|
/// The port that we will use to join layout. If this is `None`, then layout is not running.
|
||||||
|
pub layout_join_port: Untraceable<RefCell<Option<Receiver<()>>>>,
|
||||||
|
|
||||||
|
/// What parts of the document are dirty, if any.
|
||||||
|
damage: Traceable<RefCell<Option<DocumentDamage>>>,
|
||||||
|
|
||||||
|
/// The current size of the window, in pixels.
|
||||||
|
pub window_size: Untraceable<Cell<TypedSize2D<PagePx, f32>>>,
|
||||||
|
|
||||||
|
js_info: Traceable<RefCell<Option<JSPageInfo>>>,
|
||||||
|
|
||||||
|
/// Cached copy of the most recent url loaded by the script
|
||||||
|
/// TODO(tkuehn): this currently does not follow any particular caching policy
|
||||||
|
/// and simply caches pages forever (!). The bool indicates if reflow is required
|
||||||
|
/// when reloading.
|
||||||
|
url: Untraceable<RefCell<Option<(Url, bool)>>>,
|
||||||
|
|
||||||
|
next_subpage_id: Untraceable<Cell<SubpageId>>,
|
||||||
|
|
||||||
|
/// Pending resize event, if any.
|
||||||
|
pub resize_event: Untraceable<Cell<Option<TypedSize2D<PagePx, f32>>>>,
|
||||||
|
|
||||||
|
/// Pending scroll to fragment event, if any
|
||||||
|
pub fragment_node: Cell<Option<JS<Element>>>,
|
||||||
|
|
||||||
|
/// Associated resource task for use by DOM objects like XMLHttpRequest
|
||||||
|
pub resource_task: Untraceable<ResourceTask>,
|
||||||
|
|
||||||
|
/// A handle for communicating messages to the constellation task.
|
||||||
|
pub constellation_chan: Untraceable<ConstellationChan>,
|
||||||
|
|
||||||
|
// Child Pages.
|
||||||
|
pub children: Traceable<RefCell<Vec<Rc<Page>>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PageIterator {
|
||||||
|
stack: Vec<Rc<Page>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait IterablePage {
|
||||||
|
fn iter(&self) -> PageIterator;
|
||||||
|
fn find(&self, id: PipelineId) -> Option<Rc<Page>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IterablePage for Rc<Page> {
|
||||||
|
fn iter(&self) -> PageIterator {
|
||||||
|
PageIterator {
|
||||||
|
stack: vec!(self.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn find(&self, id: PipelineId) -> Option<Rc<Page>> {
|
||||||
|
if self.id == id { return Some(self.clone()); }
|
||||||
|
for page in self.children.deref().borrow().iter() {
|
||||||
|
let found = page.find(id);
|
||||||
|
if found.is_some() { return found; }
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Page {
|
||||||
|
pub fn new(id: PipelineId, subpage_id: Option<SubpageId>,
|
||||||
|
layout_chan: LayoutChan,
|
||||||
|
window_size: TypedSize2D<PagePx, f32>, resource_task: ResourceTask,
|
||||||
|
constellation_chan: ConstellationChan,
|
||||||
|
js_context: Rc<Cx>) -> Page {
|
||||||
|
let js_info = JSPageInfo {
|
||||||
|
dom_static: GlobalStaticData(),
|
||||||
|
js_context: Untraceable::new(js_context),
|
||||||
|
};
|
||||||
|
Page {
|
||||||
|
id: id,
|
||||||
|
subpage_id: subpage_id,
|
||||||
|
frame: Traceable::new(RefCell::new(None)),
|
||||||
|
layout_chan: Untraceable::new(layout_chan),
|
||||||
|
layout_join_port: Untraceable::new(RefCell::new(None)),
|
||||||
|
damage: Traceable::new(RefCell::new(None)),
|
||||||
|
window_size: Untraceable::new(Cell::new(window_size)),
|
||||||
|
js_info: Traceable::new(RefCell::new(Some(js_info))),
|
||||||
|
url: Untraceable::new(RefCell::new(None)),
|
||||||
|
next_subpage_id: Untraceable::new(Cell::new(SubpageId(0))),
|
||||||
|
resize_event: Untraceable::new(Cell::new(None)),
|
||||||
|
fragment_node: Cell::new(None),
|
||||||
|
last_reflow_id: Traceable::new(Cell::new(0)),
|
||||||
|
resource_task: Untraceable::new(resource_task),
|
||||||
|
constellation_chan: Untraceable::new(constellation_chan),
|
||||||
|
children: Traceable::new(RefCell::new(vec!())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// must handle root case separately
|
||||||
|
pub fn remove(&self, id: PipelineId) -> Option<Rc<Page>> {
|
||||||
|
let remove_idx = {
|
||||||
|
self.children
|
||||||
|
.deref()
|
||||||
|
.borrow_mut()
|
||||||
|
.mut_iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|&(_idx, ref page_tree)| {
|
||||||
|
// FIXME: page_tree has a lifetime such that it's unusable for anything.
|
||||||
|
let page_tree_id = page_tree.id;
|
||||||
|
page_tree_id == id
|
||||||
|
})
|
||||||
|
.map(|(idx, _)| idx)
|
||||||
|
};
|
||||||
|
match remove_idx {
|
||||||
|
Some(idx) => return Some(self.children.deref().borrow_mut().remove(idx).unwrap()),
|
||||||
|
None => {
|
||||||
|
for page_tree in self.children.deref().borrow_mut().mut_iter() {
|
||||||
|
match page_tree.remove(id) {
|
||||||
|
found @ Some(_) => return found,
|
||||||
|
None => (), // keep going...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator<Rc<Page>> for PageIterator {
|
||||||
|
fn next(&mut self) -> Option<Rc<Page>> {
|
||||||
|
if !self.stack.is_empty() {
|
||||||
|
let next = self.stack.pop().unwrap();
|
||||||
|
for child in next.children.deref().borrow().iter() {
|
||||||
|
self.stack.push(child.clone());
|
||||||
|
}
|
||||||
|
Some(next.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Page {
|
||||||
|
pub fn mut_js_info<'a>(&'a self) -> RefMut<'a, Option<JSPageInfo>> {
|
||||||
|
self.js_info.deref().borrow_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn js_info<'a>(&'a self) -> Ref<'a, Option<JSPageInfo>> {
|
||||||
|
self.js_info.deref().borrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn url<'a>(&'a self) -> Ref<'a, Option<(Url, bool)>> {
|
||||||
|
self.url.deref().borrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mut_url<'a>(&'a self) -> RefMut<'a, Option<(Url, bool)>> {
|
||||||
|
self.url.deref().borrow_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn frame<'a>(&'a self) -> Ref<'a, Option<Frame>> {
|
||||||
|
self.frame.deref().borrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mut_frame<'a>(&'a self) -> RefMut<'a, Option<Frame>> {
|
||||||
|
self.frame.deref().borrow_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_next_subpage_id(&self) -> SubpageId {
|
||||||
|
let subpage_id = self.next_subpage_id.deref().get();
|
||||||
|
let SubpageId(id_num) = subpage_id;
|
||||||
|
self.next_subpage_id.deref().set(SubpageId(id_num + 1));
|
||||||
|
subpage_id
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds the given damage.
|
||||||
|
pub fn damage(&self, level: DocumentDamageLevel) {
|
||||||
|
let root = match *self.frame() {
|
||||||
|
None => return,
|
||||||
|
Some(ref frame) => frame.document.root().GetDocumentElement()
|
||||||
|
};
|
||||||
|
match root.root() {
|
||||||
|
None => {},
|
||||||
|
Some(root) => {
|
||||||
|
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||||
|
let mut damage = *self.damage.deref().borrow_mut();
|
||||||
|
match damage {
|
||||||
|
None => {}
|
||||||
|
Some(ref mut damage) => {
|
||||||
|
// FIXME(pcwalton): This is wrong. We should trace up to the nearest ancestor.
|
||||||
|
damage.root = root.to_trusted_node_address();
|
||||||
|
damage.level.add(level);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*self.damage.deref().borrow_mut() = Some(DocumentDamage {
|
||||||
|
root: root.to_trusted_node_address(),
|
||||||
|
level: level,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_url(&self) -> Url {
|
||||||
|
self.url().get_ref().ref0().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sends a ping to layout and waits for the response. The response will arrive when the
|
||||||
|
/// layout task has finished any pending request messages.
|
||||||
|
pub fn join_layout(&self) {
|
||||||
|
let mut layout_join_port = self.layout_join_port.deref().borrow_mut();
|
||||||
|
if layout_join_port.is_some() {
|
||||||
|
let join_port = replace(&mut *layout_join_port, None);
|
||||||
|
match join_port {
|
||||||
|
Some(ref join_port) => {
|
||||||
|
match join_port.try_recv() {
|
||||||
|
Err(Empty) => {
|
||||||
|
info!("script: waiting on layout");
|
||||||
|
join_port.recv();
|
||||||
|
}
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(Disconnected) => {
|
||||||
|
fail!("Layout task failed while script was waiting for a result.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("script: layout joined")
|
||||||
|
}
|
||||||
|
None => fail!("reader forked but no join port?"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sends the given query to layout.
|
||||||
|
pub fn query_layout<T: Send>(&self,
|
||||||
|
query: LayoutQuery,
|
||||||
|
response_port: Receiver<T>)
|
||||||
|
-> T {
|
||||||
|
self.join_layout();
|
||||||
|
let LayoutChan(ref chan) = *self.layout_chan;
|
||||||
|
chan.send(QueryMsg(query));
|
||||||
|
response_port.recv()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reflows the page if it's possible to do so. This method will wait until the layout task has
|
||||||
|
/// completed its current action, join the layout task, and then request a new layout run. It
|
||||||
|
/// won't wait for the new layout computation to finish.
|
||||||
|
///
|
||||||
|
/// If there is no window size yet, the page is presumed invisible and no reflow is performed.
|
||||||
|
///
|
||||||
|
/// This function fails if there is no root frame.
|
||||||
|
pub fn reflow(&self,
|
||||||
|
goal: ReflowGoal,
|
||||||
|
script_chan: ScriptChan,
|
||||||
|
compositor: &ScriptListener) {
|
||||||
|
|
||||||
|
let root = match *self.frame() {
|
||||||
|
None => return,
|
||||||
|
Some(ref frame) => {
|
||||||
|
frame.document.root().GetDocumentElement()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match root.root() {
|
||||||
|
None => {},
|
||||||
|
Some(root) => {
|
||||||
|
debug!("script: performing reflow for goal {:?}", goal);
|
||||||
|
|
||||||
|
// Now, join the layout so that they will see the latest changes we have made.
|
||||||
|
self.join_layout();
|
||||||
|
|
||||||
|
// Tell the user that we're performing layout.
|
||||||
|
compositor.set_ready_state(PerformingLayout);
|
||||||
|
|
||||||
|
// Layout will let us know when it's done.
|
||||||
|
let (join_chan, join_port) = channel();
|
||||||
|
let mut layout_join_port = self.layout_join_port.deref().borrow_mut();
|
||||||
|
*layout_join_port = Some(join_port);
|
||||||
|
|
||||||
|
let last_reflow_id = self.last_reflow_id.deref();
|
||||||
|
last_reflow_id.set(last_reflow_id.get() + 1);
|
||||||
|
|
||||||
|
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||||
|
let mut damage = self.damage.deref().borrow_mut();
|
||||||
|
let window_size = self.window_size.deref().get();
|
||||||
|
|
||||||
|
// Send new document and relevant styles to layout.
|
||||||
|
let reflow = box Reflow {
|
||||||
|
document_root: root.to_trusted_node_address(),
|
||||||
|
url: self.get_url(),
|
||||||
|
goal: goal,
|
||||||
|
window_size: window_size,
|
||||||
|
script_chan: script_chan,
|
||||||
|
script_join_chan: join_chan,
|
||||||
|
damage: replace(&mut *damage, None).unwrap(),
|
||||||
|
id: last_reflow_id.get(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let LayoutChan(ref chan) = *self.layout_chan;
|
||||||
|
chan.send(ReflowMsg(reflow));
|
||||||
|
|
||||||
|
debug!("script: layout forked")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Attempt to find a named element in this page's document.
|
||||||
|
pub fn find_fragment_node(&self, fragid: DOMString) -> Option<Temporary<Element>> {
|
||||||
|
let document = self.frame().get_ref().document.root();
|
||||||
|
match document.deref().GetElementById(fragid.to_string()) {
|
||||||
|
Some(node) => Some(node),
|
||||||
|
None => {
|
||||||
|
let doc_node: &JSRef<Node> = NodeCast::from_ref(&*document);
|
||||||
|
let mut anchors = doc_node.traverse_preorder()
|
||||||
|
.filter(|node| node.is_anchor_element());
|
||||||
|
anchors.find(|node| {
|
||||||
|
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||||
|
elem.get_attribute(Null, "name").root().map_or(false, |attr| {
|
||||||
|
attr.deref().value_ref() == fragid.as_slice()
|
||||||
|
})
|
||||||
|
}).map(|node| Temporary::from_rooted(ElementCast::to_ref(&node).unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hit_test(&self, point: &Point2D<f32>) -> Option<UntrustedNodeAddress> {
|
||||||
|
let frame = self.frame();
|
||||||
|
let document = frame.get_ref().document.root();
|
||||||
|
let root = document.deref().GetDocumentElement().root();
|
||||||
|
if root.is_none() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let root = root.unwrap();
|
||||||
|
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||||
|
let (chan, port) = channel();
|
||||||
|
let address = match self.query_layout(HitTestQuery(root.to_trusted_node_address(), *point, chan), port) {
|
||||||
|
Ok(HitTestResponse(node_address)) => {
|
||||||
|
Some(node_address)
|
||||||
|
}
|
||||||
|
Err(()) => {
|
||||||
|
debug!("layout query error");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
address
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_nodes_under_mouse(&self, point: &Point2D<f32>) -> Option<Vec<UntrustedNodeAddress>> {
|
||||||
|
let frame = self.frame();
|
||||||
|
let document = frame.get_ref().document.root();
|
||||||
|
let root = document.deref().GetDocumentElement().root();
|
||||||
|
if root.is_none() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let root = root.unwrap();
|
||||||
|
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||||
|
let (chan, port) = channel();
|
||||||
|
let address = match self.query_layout(MouseOverQuery(root.to_trusted_node_address(), *point, chan), port) {
|
||||||
|
Ok(MouseOverResponse(node_address)) => {
|
||||||
|
Some(node_address)
|
||||||
|
}
|
||||||
|
Err(()) => {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Information for one frame in the browsing context.
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct Frame {
|
||||||
|
/// The document for this frame.
|
||||||
|
pub document: JS<Document>,
|
||||||
|
/// The window object for this frame.
|
||||||
|
pub window: JS<Window>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Encapsulation of the javascript information associated with each frame.
|
||||||
|
#[deriving(Encodable)]
|
||||||
|
pub struct JSPageInfo {
|
||||||
|
/// Global static data related to the DOM.
|
||||||
|
pub dom_static: GlobalStaticData,
|
||||||
|
/// The JavaScript context.
|
||||||
|
pub js_context: Untraceable<Rc<Cx>>,
|
||||||
|
}
|
|
@ -181,4 +181,5 @@ pub mod html {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod layout_interface;
|
pub mod layout_interface;
|
||||||
|
pub mod page;
|
||||||
pub mod script_task;
|
pub mod script_task;
|
||||||
|
|
|
@ -6,14 +6,13 @@
|
||||||
//! and layout tasks.
|
//! and layout tasks.
|
||||||
|
|
||||||
use dom::bindings::codegen::RegisterBindings;
|
use dom::bindings::codegen::RegisterBindings;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, ElementCast, EventCast};
|
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, EventCast};
|
||||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalSettable};
|
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalSettable};
|
||||||
use dom::bindings::js::OptionalRootable;
|
use dom::bindings::js::OptionalRootable;
|
||||||
use dom::bindings::trace::{Traceable, Untraceable};
|
use dom::bindings::utils::Reflectable;
|
||||||
use dom::bindings::utils::{Reflectable, GlobalStaticData};
|
|
||||||
use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap};
|
use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap};
|
||||||
use dom::document::{Document, HTMLDocument, DocumentMethods, DocumentHelpers};
|
use dom::document::{Document, HTMLDocument, DocumentHelpers};
|
||||||
use dom::element::{Element, AttributeHandlers};
|
use dom::element::{Element};
|
||||||
use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent};
|
use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent};
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
use dom::uievent::UIEvent;
|
use dom::uievent::UIEvent;
|
||||||
|
@ -25,13 +24,12 @@ use dom::xmlhttprequest::{TrustedXHRAddress, XMLHttpRequest, XHRProgress};
|
||||||
use html::hubbub_html_parser::HtmlParserResult;
|
use html::hubbub_html_parser::HtmlParserResult;
|
||||||
use html::hubbub_html_parser::{HtmlDiscoveredStyle, HtmlDiscoveredScript};
|
use html::hubbub_html_parser::{HtmlDiscoveredStyle, HtmlDiscoveredScript};
|
||||||
use html::hubbub_html_parser;
|
use html::hubbub_html_parser;
|
||||||
use layout_interface::{AddStylesheetMsg, DocumentDamage};
|
use layout_interface::AddStylesheetMsg;
|
||||||
use layout_interface::{DocumentDamageLevel, HitTestQuery, HitTestResponse, LayoutQuery, MouseOverQuery, MouseOverResponse};
|
use layout_interface::{LayoutChan, MatchSelectorsDocumentDamage};
|
||||||
use layout_interface::{LayoutChan, MatchSelectorsDocumentDamage, QueryMsg};
|
use layout_interface::{ReflowDocumentDamage, ReflowForDisplay};
|
||||||
use layout_interface::{Reflow, ReflowDocumentDamage, ReflowForDisplay, ReflowGoal, ReflowMsg};
|
|
||||||
use layout_interface::ContentChangedDocumentDamage;
|
use layout_interface::ContentChangedDocumentDamage;
|
||||||
use layout_interface::UntrustedNodeAddress;
|
|
||||||
use layout_interface;
|
use layout_interface;
|
||||||
|
use page::{Page, IterablePage, Frame};
|
||||||
|
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use geom::size::TypedSize2D;
|
use geom::size::TypedSize2D;
|
||||||
|
@ -42,7 +40,7 @@ use js::jsval::NullValue;
|
||||||
use js::rust::{Cx, RtUtils};
|
use js::rust::{Cx, RtUtils};
|
||||||
use js::rust::with_compartment;
|
use js::rust::with_compartment;
|
||||||
use js;
|
use js;
|
||||||
use servo_msg::compositor_msg::{FinishedLoading, LayerId, Loading, PerformingLayout};
|
use servo_msg::compositor_msg::{FinishedLoading, LayerId, Loading};
|
||||||
use servo_msg::compositor_msg::{ScriptListener};
|
use servo_msg::compositor_msg::{ScriptListener};
|
||||||
use servo_msg::constellation_msg::{ConstellationChan, LoadCompleteMsg, LoadUrlMsg, NavigationDirection};
|
use servo_msg::constellation_msg::{ConstellationChan, LoadCompleteMsg, LoadUrlMsg, NavigationDirection};
|
||||||
use servo_msg::constellation_msg::{PipelineId, SubpageId, Failure, FailureMsg};
|
use servo_msg::constellation_msg::{PipelineId, SubpageId, Failure, FailureMsg};
|
||||||
|
@ -51,10 +49,8 @@ use servo_net::image_cache_task::ImageCacheTask;
|
||||||
use servo_net::resource_task::ResourceTask;
|
use servo_net::resource_task::ResourceTask;
|
||||||
use servo_util::geometry::{PagePx, to_frac_px};
|
use servo_util::geometry::{PagePx, to_frac_px};
|
||||||
use servo_util::task::send_on_failure;
|
use servo_util::task::send_on_failure;
|
||||||
use servo_util::namespace::Null;
|
use std::cell::RefCell;
|
||||||
use servo_util::str::DOMString;
|
use std::comm::{channel, Sender, Receiver};
|
||||||
use std::cell::{Cell, RefCell, Ref, RefMut};
|
|
||||||
use std::comm::{channel, Sender, Receiver, Empty, Disconnected};
|
|
||||||
use std::mem::replace;
|
use std::mem::replace;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -120,403 +116,6 @@ impl ScriptChan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encapsulates a handle to a frame and its associated layout information.
|
|
||||||
#[deriving(Encodable)]
|
|
||||||
pub struct Page {
|
|
||||||
/// Pipeline id associated with this page.
|
|
||||||
pub id: PipelineId,
|
|
||||||
|
|
||||||
/// Subpage id associated with this page, if any.
|
|
||||||
pub subpage_id: Option<SubpageId>,
|
|
||||||
|
|
||||||
/// Unique id for last reflow request; used for confirming completion reply.
|
|
||||||
last_reflow_id: Traceable<Cell<uint>>,
|
|
||||||
|
|
||||||
/// The outermost frame containing the document, window, and page URL.
|
|
||||||
pub frame: Traceable<RefCell<Option<Frame>>>,
|
|
||||||
|
|
||||||
/// A handle for communicating messages to the layout task.
|
|
||||||
pub layout_chan: Untraceable<LayoutChan>,
|
|
||||||
|
|
||||||
/// The port that we will use to join layout. If this is `None`, then layout is not running.
|
|
||||||
layout_join_port: Untraceable<RefCell<Option<Receiver<()>>>>,
|
|
||||||
|
|
||||||
/// What parts of the document are dirty, if any.
|
|
||||||
damage: Traceable<RefCell<Option<DocumentDamage>>>,
|
|
||||||
|
|
||||||
/// The current size of the window, in pixels.
|
|
||||||
window_size: Untraceable<Cell<TypedSize2D<PagePx, f32>>>,
|
|
||||||
|
|
||||||
js_info: Traceable<RefCell<Option<JSPageInfo>>>,
|
|
||||||
|
|
||||||
/// Cached copy of the most recent url loaded by the script
|
|
||||||
/// TODO(tkuehn): this currently does not follow any particular caching policy
|
|
||||||
/// and simply caches pages forever (!). The bool indicates if reflow is required
|
|
||||||
/// when reloading.
|
|
||||||
url: Untraceable<RefCell<Option<(Url, bool)>>>,
|
|
||||||
|
|
||||||
next_subpage_id: Untraceable<Cell<SubpageId>>,
|
|
||||||
|
|
||||||
/// Pending resize event, if any.
|
|
||||||
resize_event: Untraceable<Cell<Option<TypedSize2D<PagePx, f32>>>>,
|
|
||||||
|
|
||||||
/// Pending scroll to fragment event, if any
|
|
||||||
fragment_node: Cell<Option<JS<Element>>>,
|
|
||||||
|
|
||||||
/// Associated resource task for use by DOM objects like XMLHttpRequest
|
|
||||||
pub resource_task: Untraceable<ResourceTask>,
|
|
||||||
|
|
||||||
/// A handle for communicating messages to the constellation task.
|
|
||||||
pub constellation_chan: Untraceable<ConstellationChan>,
|
|
||||||
|
|
||||||
// Child Pages.
|
|
||||||
pub children: Traceable<RefCell<Vec<Rc<Page>>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PageIterator {
|
|
||||||
stack: Vec<Rc<Page>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait IterablePage {
|
|
||||||
fn iter(&self) -> PageIterator;
|
|
||||||
fn find(&self, id: PipelineId) -> Option<Rc<Page>>;
|
|
||||||
}
|
|
||||||
impl IterablePage for Rc<Page> {
|
|
||||||
fn iter(&self) -> PageIterator {
|
|
||||||
PageIterator {
|
|
||||||
stack: vec!(self.clone()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn find(&self, id: PipelineId) -> Option<Rc<Page>> {
|
|
||||||
if self.id == id { return Some(self.clone()); }
|
|
||||||
for page in self.children.deref().borrow().iter() {
|
|
||||||
let found = page.find(id);
|
|
||||||
if found.is_some() { return found; }
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Page {
|
|
||||||
fn new(id: PipelineId, subpage_id: Option<SubpageId>,
|
|
||||||
layout_chan: LayoutChan,
|
|
||||||
window_size: TypedSize2D<PagePx, f32>, resource_task: ResourceTask,
|
|
||||||
constellation_chan: ConstellationChan,
|
|
||||||
js_context: Rc<Cx>) -> Page {
|
|
||||||
let js_info = JSPageInfo {
|
|
||||||
dom_static: GlobalStaticData(),
|
|
||||||
js_context: Untraceable::new(js_context),
|
|
||||||
};
|
|
||||||
Page {
|
|
||||||
id: id,
|
|
||||||
subpage_id: subpage_id,
|
|
||||||
frame: Traceable::new(RefCell::new(None)),
|
|
||||||
layout_chan: Untraceable::new(layout_chan),
|
|
||||||
layout_join_port: Untraceable::new(RefCell::new(None)),
|
|
||||||
damage: Traceable::new(RefCell::new(None)),
|
|
||||||
window_size: Untraceable::new(Cell::new(window_size)),
|
|
||||||
js_info: Traceable::new(RefCell::new(Some(js_info))),
|
|
||||||
url: Untraceable::new(RefCell::new(None)),
|
|
||||||
next_subpage_id: Untraceable::new(Cell::new(SubpageId(0))),
|
|
||||||
resize_event: Untraceable::new(Cell::new(None)),
|
|
||||||
fragment_node: Cell::new(None),
|
|
||||||
last_reflow_id: Traceable::new(Cell::new(0)),
|
|
||||||
resource_task: Untraceable::new(resource_task),
|
|
||||||
constellation_chan: Untraceable::new(constellation_chan),
|
|
||||||
children: Traceable::new(RefCell::new(vec!())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// must handle root case separately
|
|
||||||
pub fn remove(&self, id: PipelineId) -> Option<Rc<Page>> {
|
|
||||||
let remove_idx = {
|
|
||||||
self.children
|
|
||||||
.deref()
|
|
||||||
.borrow_mut()
|
|
||||||
.mut_iter()
|
|
||||||
.enumerate()
|
|
||||||
.find(|&(_idx, ref page_tree)| {
|
|
||||||
// FIXME: page_tree has a lifetime such that it's unusable for anything.
|
|
||||||
let page_tree_id = page_tree.id;
|
|
||||||
page_tree_id == id
|
|
||||||
})
|
|
||||||
.map(|(idx, _)| idx)
|
|
||||||
};
|
|
||||||
match remove_idx {
|
|
||||||
Some(idx) => return Some(self.children.deref().borrow_mut().remove(idx).unwrap()),
|
|
||||||
None => {
|
|
||||||
for page_tree in self.children.deref().borrow_mut().mut_iter() {
|
|
||||||
match page_tree.remove(id) {
|
|
||||||
found @ Some(_) => return found,
|
|
||||||
None => (), // keep going...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator<Rc<Page>> for PageIterator {
|
|
||||||
fn next(&mut self) -> Option<Rc<Page>> {
|
|
||||||
if !self.stack.is_empty() {
|
|
||||||
let next = self.stack.pop().unwrap();
|
|
||||||
for child in next.children.deref().borrow().iter() {
|
|
||||||
self.stack.push(child.clone());
|
|
||||||
}
|
|
||||||
Some(next.clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Page {
|
|
||||||
pub fn mut_js_info<'a>(&'a self) -> RefMut<'a, Option<JSPageInfo>> {
|
|
||||||
self.js_info.deref().borrow_mut()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn js_info<'a>(&'a self) -> Ref<'a, Option<JSPageInfo>> {
|
|
||||||
self.js_info.deref().borrow()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn url<'a>(&'a self) -> Ref<'a, Option<(Url, bool)>> {
|
|
||||||
self.url.deref().borrow()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mut_url<'a>(&'a self) -> RefMut<'a, Option<(Url, bool)>> {
|
|
||||||
self.url.deref().borrow_mut()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn frame<'a>(&'a self) -> Ref<'a, Option<Frame>> {
|
|
||||||
self.frame.deref().borrow()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mut_frame<'a>(&'a self) -> RefMut<'a, Option<Frame>> {
|
|
||||||
self.frame.deref().borrow_mut()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_next_subpage_id(&self) -> SubpageId {
|
|
||||||
let subpage_id = self.next_subpage_id.deref().get();
|
|
||||||
let SubpageId(id_num) = subpage_id;
|
|
||||||
self.next_subpage_id.deref().set(SubpageId(id_num + 1));
|
|
||||||
subpage_id
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Adds the given damage.
|
|
||||||
pub fn damage(&self, level: DocumentDamageLevel) {
|
|
||||||
let root = match *self.frame() {
|
|
||||||
None => return,
|
|
||||||
Some(ref frame) => frame.document.root().GetDocumentElement()
|
|
||||||
};
|
|
||||||
match root.root() {
|
|
||||||
None => {},
|
|
||||||
Some(root) => {
|
|
||||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
|
||||||
let mut damage = *self.damage.deref().borrow_mut();
|
|
||||||
match damage {
|
|
||||||
None => {}
|
|
||||||
Some(ref mut damage) => {
|
|
||||||
// FIXME(pcwalton): This is wrong. We should trace up to the nearest ancestor.
|
|
||||||
damage.root = root.to_trusted_node_address();
|
|
||||||
damage.level.add(level);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*self.damage.deref().borrow_mut() = Some(DocumentDamage {
|
|
||||||
root: root.to_trusted_node_address(),
|
|
||||||
level: level,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_url(&self) -> Url {
|
|
||||||
self.url().get_ref().ref0().clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sends a ping to layout and waits for the response. The response will arrive when the
|
|
||||||
/// layout task has finished any pending request messages.
|
|
||||||
pub fn join_layout(&self) {
|
|
||||||
let mut layout_join_port = self.layout_join_port.deref().borrow_mut();
|
|
||||||
if layout_join_port.is_some() {
|
|
||||||
let join_port = replace(&mut *layout_join_port, None);
|
|
||||||
match join_port {
|
|
||||||
Some(ref join_port) => {
|
|
||||||
match join_port.try_recv() {
|
|
||||||
Err(Empty) => {
|
|
||||||
info!("script: waiting on layout");
|
|
||||||
join_port.recv();
|
|
||||||
}
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(Disconnected) => {
|
|
||||||
fail!("Layout task failed while script was waiting for a result.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("script: layout joined")
|
|
||||||
}
|
|
||||||
None => fail!("reader forked but no join port?"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sends the given query to layout.
|
|
||||||
pub fn query_layout<T: Send>(&self,
|
|
||||||
query: LayoutQuery,
|
|
||||||
response_port: Receiver<T>)
|
|
||||||
-> T {
|
|
||||||
self.join_layout();
|
|
||||||
let LayoutChan(ref chan) = *self.layout_chan;
|
|
||||||
chan.send(QueryMsg(query));
|
|
||||||
response_port.recv()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reflows the page if it's possible to do so. This method will wait until the layout task has
|
|
||||||
/// completed its current action, join the layout task, and then request a new layout run. It
|
|
||||||
/// won't wait for the new layout computation to finish.
|
|
||||||
///
|
|
||||||
/// If there is no window size yet, the page is presumed invisible and no reflow is performed.
|
|
||||||
///
|
|
||||||
/// This function fails if there is no root frame.
|
|
||||||
pub fn reflow(&self,
|
|
||||||
goal: ReflowGoal,
|
|
||||||
script_chan: ScriptChan,
|
|
||||||
compositor: &ScriptListener) {
|
|
||||||
|
|
||||||
let root = match *self.frame() {
|
|
||||||
None => return,
|
|
||||||
Some(ref frame) => {
|
|
||||||
frame.document.root().GetDocumentElement()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match root.root() {
|
|
||||||
None => {},
|
|
||||||
Some(root) => {
|
|
||||||
debug!("script: performing reflow for goal {:?}", goal);
|
|
||||||
|
|
||||||
// Now, join the layout so that they will see the latest changes we have made.
|
|
||||||
self.join_layout();
|
|
||||||
|
|
||||||
// Tell the user that we're performing layout.
|
|
||||||
compositor.set_ready_state(PerformingLayout);
|
|
||||||
|
|
||||||
// Layout will let us know when it's done.
|
|
||||||
let (join_chan, join_port) = channel();
|
|
||||||
let mut layout_join_port = self.layout_join_port.deref().borrow_mut();
|
|
||||||
*layout_join_port = Some(join_port);
|
|
||||||
|
|
||||||
let last_reflow_id = self.last_reflow_id.deref();
|
|
||||||
last_reflow_id.set(last_reflow_id.get() + 1);
|
|
||||||
|
|
||||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
|
||||||
let mut damage = self.damage.deref().borrow_mut();
|
|
||||||
let window_size = self.window_size.deref().get();
|
|
||||||
|
|
||||||
// Send new document and relevant styles to layout.
|
|
||||||
let reflow = box Reflow {
|
|
||||||
document_root: root.to_trusted_node_address(),
|
|
||||||
url: self.get_url(),
|
|
||||||
goal: goal,
|
|
||||||
window_size: window_size,
|
|
||||||
script_chan: script_chan,
|
|
||||||
script_join_chan: join_chan,
|
|
||||||
damage: replace(&mut *damage, None).unwrap(),
|
|
||||||
id: last_reflow_id.get(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let LayoutChan(ref chan) = *self.layout_chan;
|
|
||||||
chan.send(ReflowMsg(reflow));
|
|
||||||
|
|
||||||
debug!("script: layout forked")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Attempt to find a named element in this page's document.
|
|
||||||
fn find_fragment_node(&self, fragid: DOMString) -> Option<Temporary<Element>> {
|
|
||||||
let document = self.frame().get_ref().document.root();
|
|
||||||
match document.deref().GetElementById(fragid.to_string()) {
|
|
||||||
Some(node) => Some(node),
|
|
||||||
None => {
|
|
||||||
let doc_node: &JSRef<Node> = NodeCast::from_ref(&*document);
|
|
||||||
let mut anchors = doc_node.traverse_preorder()
|
|
||||||
.filter(|node| node.is_anchor_element());
|
|
||||||
anchors.find(|node| {
|
|
||||||
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
|
||||||
elem.get_attribute(Null, "name").root().map_or(false, |attr| {
|
|
||||||
attr.deref().value_ref() == fragid.as_slice()
|
|
||||||
})
|
|
||||||
}).map(|node| Temporary::from_rooted(ElementCast::to_ref(&node).unwrap()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn hit_test(&self, point: &Point2D<f32>) -> Option<UntrustedNodeAddress> {
|
|
||||||
let frame = self.frame();
|
|
||||||
let document = frame.get_ref().document.root();
|
|
||||||
let root = document.deref().GetDocumentElement().root();
|
|
||||||
if root.is_none() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let root = root.unwrap();
|
|
||||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
|
||||||
let (chan, port) = channel();
|
|
||||||
let address = match self.query_layout(HitTestQuery(root.to_trusted_node_address(), *point, chan), port) {
|
|
||||||
Ok(HitTestResponse(node_address)) => {
|
|
||||||
Some(node_address)
|
|
||||||
}
|
|
||||||
Err(()) => {
|
|
||||||
debug!("layout query error");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
address
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_nodes_under_mouse(&self, point: &Point2D<f32>) -> Option<Vec<UntrustedNodeAddress>> {
|
|
||||||
let frame = self.frame();
|
|
||||||
let document = frame.get_ref().document.root();
|
|
||||||
let root = document.deref().GetDocumentElement().root();
|
|
||||||
if root.is_none() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let root = root.unwrap();
|
|
||||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
|
||||||
let (chan, port) = channel();
|
|
||||||
let address = match self.query_layout(MouseOverQuery(root.to_trusted_node_address(), *point, chan), port) {
|
|
||||||
Ok(MouseOverResponse(node_address)) => {
|
|
||||||
Some(node_address)
|
|
||||||
}
|
|
||||||
Err(()) => {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
address
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information for one frame in the browsing context.
|
|
||||||
#[deriving(Encodable)]
|
|
||||||
pub struct Frame {
|
|
||||||
/// The document for this frame.
|
|
||||||
pub document: JS<Document>,
|
|
||||||
/// The window object for this frame.
|
|
||||||
pub window: JS<Window>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encapsulation of the javascript information associated with each frame.
|
|
||||||
#[deriving(Encodable)]
|
|
||||||
pub struct JSPageInfo {
|
|
||||||
/// Global static data related to the DOM.
|
|
||||||
pub dom_static: GlobalStaticData,
|
|
||||||
/// The JavaScript context.
|
|
||||||
pub js_context: Untraceable<Rc<Cx>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct StackRootTLS;
|
struct StackRootTLS;
|
||||||
|
|
||||||
impl StackRootTLS {
|
impl StackRootTLS {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue