mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Replace Document::{with_base, with_mut_base} by Document::{document, mut_document}.
This commit is contained in:
parent
364256e359
commit
b90766404c
6 changed files with 77 additions and 111 deletions
|
@ -41,7 +41,7 @@ pub trait ReflectableDocument {
|
|||
|
||||
#[deriving(Eq)]
|
||||
pub struct AbstractDocument {
|
||||
document: *Document
|
||||
document: *mut Box<Document>
|
||||
}
|
||||
|
||||
impl AbstractDocument {
|
||||
|
@ -52,6 +52,18 @@ impl AbstractDocument {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn document<'a>(&'a self) -> &'a Document {
|
||||
unsafe {
|
||||
&(*self.document).data
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mut_document<'a>(&'a self) -> &'a mut Document {
|
||||
unsafe {
|
||||
&mut (*self.document).data
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn transmute<T, R>(&self, f: &fn(&T) -> R) -> R {
|
||||
let box: *Box<T> = cast::transmute(self.document);
|
||||
f(&(*box).data)
|
||||
|
@ -62,20 +74,8 @@ impl AbstractDocument {
|
|||
f(&mut (*box).data)
|
||||
}
|
||||
|
||||
pub fn with_base<R>(&self, callback: &fn(&Document) -> R) -> R {
|
||||
unsafe {
|
||||
self.transmute(callback)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_mut_base<R>(&self, callback: &fn(&mut Document) -> R) -> R {
|
||||
unsafe {
|
||||
self.transmute_mut(callback)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_html<R>(&self, callback: &fn(&HTMLDocument) -> R) -> R {
|
||||
match self.with_base(|doc| doc.doctype) {
|
||||
match self.document().doctype {
|
||||
HTML => unsafe { self.transmute(callback) },
|
||||
_ => fail!("attempt to downcast a non-HTMLDocument to HTMLDocument")
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ impl AbstractDocument {
|
|||
|
||||
pub fn from_box<T>(ptr: *mut Box<T>) -> AbstractDocument {
|
||||
AbstractDocument {
|
||||
document: ptr as *Document
|
||||
document: ptr as *mut Box<Document>
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,13 +91,12 @@ impl AbstractDocument {
|
|||
assert!(do root.traverse_preorder().all |node| {
|
||||
node.node().owner_doc() == *self
|
||||
});
|
||||
self.with_mut_base(|document| {
|
||||
|
||||
let document = self.mut_document();
|
||||
document.root = Some(root);
|
||||
// Register elements having "id" attribute to the owner doc.
|
||||
document.register_nodes_with_id(&root);
|
||||
|
||||
document.content_changed();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,19 +151,15 @@ impl ReflectableDocument for Document {
|
|||
|
||||
impl Reflectable for AbstractDocument {
|
||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||
do self.with_mut_base |doc| {
|
||||
unsafe { cast::transmute(doc.reflector()) }
|
||||
}
|
||||
self.document().reflector()
|
||||
}
|
||||
|
||||
fn mut_reflector<'a>(&'a mut self) -> &'a mut Reflector {
|
||||
do self.with_mut_base |doc| {
|
||||
unsafe { cast::transmute(doc.mut_reflector()) }
|
||||
}
|
||||
self.mut_document().mut_reflector()
|
||||
}
|
||||
|
||||
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
|
||||
match self.with_base(|doc| doc.doctype) {
|
||||
match self.document().doctype {
|
||||
HTML => {
|
||||
let doc: @mut HTMLDocument = unsafe { cast::transmute(self.document) };
|
||||
doc.wrap_object_shared(cx, scope)
|
||||
|
@ -176,9 +171,7 @@ impl Reflectable for AbstractDocument {
|
|||
}
|
||||
|
||||
fn GetParentObject(&self, cx: *JSContext) -> Option<@mut Reflectable> {
|
||||
do self.with_mut_base |doc| {
|
||||
doc.GetParentObject(cx)
|
||||
}
|
||||
self.document().GetParentObject(cx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -199,9 +199,8 @@ impl<'self> Element {
|
|||
}
|
||||
|
||||
if abstract_self.is_in_doc() {
|
||||
do self.node.owner_doc().with_base |owner| {
|
||||
owner.content_changed();
|
||||
}
|
||||
let document = self.node.owner_doc();
|
||||
document.document().content_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -286,8 +285,7 @@ impl Element {
|
|||
}
|
||||
|
||||
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
|
||||
let document = self.node.owner_doc();
|
||||
let win = document.with_base(|doc| doc.window);
|
||||
let win = self.node.owner_doc().document().window;
|
||||
let node = abstract_self;
|
||||
assert!(node.is_element());
|
||||
let (port, chan) = comm::stream();
|
||||
|
@ -313,8 +311,7 @@ impl Element {
|
|||
}
|
||||
|
||||
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
|
||||
let document = self.node.owner_doc();
|
||||
let win = document.with_base(|doc| doc.window);
|
||||
let win = self.node.owner_doc().document().window;
|
||||
let node = abstract_self;
|
||||
assert!(node.is_element());
|
||||
let (port, chan) = comm::stream();
|
||||
|
|
|
@ -43,14 +43,12 @@ impl HTMLImageElement {
|
|||
pub fn AfterSetAttr(&mut self, name: &DOMString, _value: &DOMString) {
|
||||
let name = null_str_as_empty(name);
|
||||
if "src" == name {
|
||||
let doc = self.htmlelement.element.node.owner_doc();
|
||||
do doc.with_base |doc| {
|
||||
let window = doc.window;
|
||||
let document = self.htmlelement.element.node.owner_doc();
|
||||
let window = document.document().window;
|
||||
let url = window.page.url.map(|&(ref url, _)| url.clone());
|
||||
self.update_image(window.image_cache_task.clone(), url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Alt(&self) -> DOMString {
|
||||
None
|
||||
|
@ -100,7 +98,7 @@ impl HTMLImageElement {
|
|||
|
||||
pub fn Width(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||
let node = &self.htmlelement.element.node;
|
||||
let page = node.owner_doc().with_base(|doc| doc.window).page;
|
||||
let page = node.owner_doc().document().window.page;
|
||||
let (port, chan) = stream();
|
||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||
ContentBoxResponse(rect) => {
|
||||
|
@ -121,7 +119,7 @@ impl HTMLImageElement {
|
|||
|
||||
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||
let node = &self.htmlelement.element.node;
|
||||
let page = node.owner_doc().with_base(|doc| doc.window).page;
|
||||
let page = node.owner_doc().document().window.page;
|
||||
let (port, chan) = stream();
|
||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||
ContentBoxResponse(rect) => {
|
||||
|
|
|
@ -428,8 +428,8 @@ impl<'self, View> AbstractNode<View> {
|
|||
|
||||
// Issue #1030: should not walk the tree
|
||||
pub fn is_in_doc(&self) -> bool {
|
||||
do self.node().owner_doc().with_base |document| {
|
||||
match document.GetDocumentElement() {
|
||||
let document = self.node().owner_doc();
|
||||
match document.document().GetDocumentElement() {
|
||||
None => false,
|
||||
Some(root) => {
|
||||
let mut node = *self;
|
||||
|
@ -450,7 +450,6 @@ impl<'self, View> AbstractNode<View> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<View> Iterator<AbstractNode<View>> for AbstractNodeChildrenIterator<View> {
|
||||
|
@ -493,26 +492,18 @@ impl Node<ScriptView> {
|
|||
}
|
||||
|
||||
// Unregister elements having "id' from the old doc.
|
||||
do old_doc.with_mut_base |old_doc| {
|
||||
old_doc.unregister_nodes_with_id(&abstract_self);
|
||||
}
|
||||
old_doc.mut_document().unregister_nodes_with_id(&abstract_self);
|
||||
|
||||
// Register elements having "id" attribute to the owner doc.
|
||||
do doc.with_mut_base |doc| {
|
||||
doc.register_nodes_with_id(&abstract_self);
|
||||
}
|
||||
doc.mut_document().register_nodes_with_id(&abstract_self);
|
||||
|
||||
// Signal the old document that it needs to update its display
|
||||
if old_doc != doc {
|
||||
do old_doc.with_base |old_doc| {
|
||||
old_doc.content_changed();
|
||||
}
|
||||
old_doc.document().content_changed();
|
||||
}
|
||||
|
||||
// Signal the new document that it needs to update its display
|
||||
do doc.with_base |doc| {
|
||||
doc.content_changed();
|
||||
}
|
||||
doc.document().content_changed();
|
||||
}
|
||||
|
||||
pub fn new(type_id: NodeTypeId, doc: AbstractDocument) -> Node<ScriptView> {
|
||||
|
@ -682,7 +673,7 @@ impl Node<ScriptView> {
|
|||
}
|
||||
|
||||
pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
||||
let win = self.owner_doc().with_base(|doc| doc.window);
|
||||
let win = self.owner_doc().document().window;
|
||||
(win.reflector().get_jsobject(), win.get_cx())
|
||||
}
|
||||
|
||||
|
@ -714,10 +705,8 @@ impl Node<ScriptView> {
|
|||
let node = if is_empty {
|
||||
None
|
||||
} else {
|
||||
let text_node = do self.owner_doc().with_base |document| {
|
||||
document.CreateTextNode(self.owner_doc(), value)
|
||||
};
|
||||
Some(text_node)
|
||||
let document = self.owner_doc();
|
||||
Some(document.document().CreateTextNode(document, value))
|
||||
};
|
||||
self.replace_all(abstract_self, node);
|
||||
}
|
||||
|
@ -728,9 +717,8 @@ impl Node<ScriptView> {
|
|||
characterdata.data = null_str_as_empty(value);
|
||||
|
||||
// Notify the document that the content of this node is different
|
||||
do self.owner_doc().with_base |doc| {
|
||||
doc.content_changed();
|
||||
}
|
||||
let document = self.owner_doc();
|
||||
document.document().content_changed();
|
||||
}
|
||||
}
|
||||
DoctypeNodeTypeId => {}
|
||||
|
@ -743,9 +731,8 @@ impl Node<ScriptView> {
|
|||
}
|
||||
|
||||
fn wait_until_safe_to_modify_dom(&self) {
|
||||
do self.owner_doc().with_base |doc| {
|
||||
doc.wait_until_safe_to_modify_dom();
|
||||
}
|
||||
let document = self.owner_doc();
|
||||
document.document().wait_until_safe_to_modify_dom();
|
||||
}
|
||||
|
||||
pub fn AppendChild(&mut self,
|
||||
|
@ -810,15 +797,12 @@ impl Node<ScriptView> {
|
|||
|
||||
// Unregister elements having "id' from the owner doc.
|
||||
// This need be called before target nodes are removed from tree.
|
||||
do self.owner_doc.with_mut_base |doc| {
|
||||
doc.unregister_nodes_with_id(&abstract_self);
|
||||
}
|
||||
self.owner_doc.mut_document().unregister_nodes_with_id(&abstract_self);
|
||||
|
||||
abstract_self.remove_child(node);
|
||||
// Signal the document that it needs to update its display.
|
||||
do self.owner_doc().with_base |document| {
|
||||
document.content_changed();
|
||||
}
|
||||
let document = self.owner_doc();
|
||||
document.document().content_changed();
|
||||
Ok(node)
|
||||
}
|
||||
|
||||
|
|
|
@ -253,18 +253,16 @@ impl Traceable for Window {
|
|||
unsafe {
|
||||
match self.page.frame {
|
||||
Some(frame) => {
|
||||
do frame.document.with_base |doc| {
|
||||
(*tracer).debugPrinter = ptr::null();
|
||||
(*tracer).debugPrintIndex = -1;
|
||||
do "document".to_c_str().with_ref |name| {
|
||||
(*tracer).debugPrintArg = name as *libc::c_void;
|
||||
debug!("tracing document");
|
||||
JS_CallTracer(tracer as *JSTracer,
|
||||
doc.reflector_.object,
|
||||
frame.document.reflector().get_jsobject(),
|
||||
JSTRACE_OBJECT as u32);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,9 +214,8 @@ impl<'self> Iterator<@mut Page> for PageTreeIterator<'self> {
|
|||
impl Page {
|
||||
/// Adds the given damage.
|
||||
fn damage(&mut self, level: DocumentDamageLevel) {
|
||||
let root = do self.frame.get_ref().document.with_base |doc| {
|
||||
doc.GetDocumentElement()
|
||||
};
|
||||
let root = self.frame.get_ref().document.document().
|
||||
GetDocumentElement();
|
||||
match root {
|
||||
None => {},
|
||||
Some(root) => {
|
||||
|
@ -277,9 +276,7 @@ impl Page {
|
|||
let root = match self.frame {
|
||||
None => fail!(~"Tried to relayout with no root frame!"),
|
||||
Some(ref frame) => {
|
||||
do frame.document.with_base |doc| {
|
||||
doc.GetDocumentElement()
|
||||
}
|
||||
frame.document.document().GetDocumentElement()
|
||||
}
|
||||
};
|
||||
match root {
|
||||
|
@ -804,9 +801,8 @@ impl ScriptTask {
|
|||
ClickEvent(_button, point) => {
|
||||
debug!("ClickEvent: clicked at %?", point);
|
||||
|
||||
let root = do page.frame.expect("root frame is None").document.with_base |doc| {
|
||||
doc.GetDocumentElement()
|
||||
};
|
||||
let document = page.frame.expect("root frame is None").document;
|
||||
let root = document.document().GetDocumentElement();
|
||||
if root.is_none() {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue