mirror of
https://github.com/servo/servo.git
synced 2025-06-20 07:08:59 +01:00
Implement Window::get_cx() to reduce code repetition.
This commit is contained in:
parent
fc9fdf30a6
commit
da2cf6cbd7
8 changed files with 19 additions and 19 deletions
|
@ -23,7 +23,7 @@ impl Comment {
|
|||
|
||||
pub fn Constructor(owner: @mut Window, data: &DOMString) -> Fallible<AbstractNode<ScriptView>> {
|
||||
let s = null_str_as_empty(data);
|
||||
let cx = (*owner.page).js_info.get_ref().js_compartment.cx.ptr;
|
||||
let cx = owner.get_cx();
|
||||
let comment = @Comment::new(s, owner.Document());
|
||||
Ok(unsafe { Node::as_abstract_node(cx, comment) })
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ impl Document {
|
|||
}
|
||||
|
||||
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> {
|
||||
let cx = owner.page.js_info.get_ref().js_compartment.cx.ptr;
|
||||
let cx = owner.get_cx();
|
||||
|
||||
let document = AbstractDocument::as_abstract(cx, @mut Document::new(None, XML));
|
||||
|
||||
|
@ -241,14 +241,12 @@ impl Document {
|
|||
}
|
||||
|
||||
fn get_cx(&self) -> *JSContext {
|
||||
let win = self.window.get_ref();
|
||||
win.page.js_info.get_ref().js_compartment.cx.ptr
|
||||
self.window.get_ref().get_cx()
|
||||
}
|
||||
|
||||
fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
||||
let win = self.window.get_ref();
|
||||
let cx = win.page.js_info.get_ref().js_compartment.cx.ptr;
|
||||
(win.reflector().get_jsobject(), cx)
|
||||
(win.reflector().get_jsobject(), win.get_cx())
|
||||
}
|
||||
|
||||
pub fn GetElementsByTagName(&self, tag: &DOMString) -> @mut HTMLCollection {
|
||||
|
|
|
@ -26,7 +26,7 @@ impl DOMParser {
|
|||
};
|
||||
|
||||
// TODO(tkuehn): This just handles the top-level page. Need to handle subframes.
|
||||
let cx = owner.page.js_info.get_ref().js_compartment.cx.ptr;
|
||||
let cx = owner.get_cx();
|
||||
let scope = owner.reflector().get_jsobject();
|
||||
parser.wrap_object_shared(cx, scope);
|
||||
parser
|
||||
|
@ -40,7 +40,7 @@ impl DOMParser {
|
|||
_s: &DOMString,
|
||||
ty: DOMParserBinding::SupportedType)
|
||||
-> Fallible<AbstractDocument> {
|
||||
let cx = (*self.owner.page).js_info.get_ref().js_compartment.cx.ptr;
|
||||
let cx = self.owner.get_cx();
|
||||
let document = match ty {
|
||||
Text_html => {
|
||||
HTMLDocument::new(None)
|
||||
|
|
|
@ -278,12 +278,11 @@ impl Element {
|
|||
let win = document.with_base(|doc| doc.window).expect("no window");
|
||||
let node = abstract_self;
|
||||
assert!(node.is_element());
|
||||
let page = win.page;
|
||||
let (port, chan) = comm::stream();
|
||||
let (rects, cx, scope) =
|
||||
match page.query_layout(ContentBoxesQuery(node, chan), port) {
|
||||
match win.page.query_layout(ContentBoxesQuery(node, chan), port) {
|
||||
ContentBoxesResponse(rects) => {
|
||||
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
|
||||
let cx = win.get_cx();
|
||||
let scope = win.reflector().get_jsobject();
|
||||
let rects = do rects.map |r| {
|
||||
ClientRect::new(
|
||||
|
@ -304,13 +303,12 @@ 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).expect("no window");
|
||||
let page = win.page;
|
||||
let node = abstract_self;
|
||||
assert!(node.is_element());
|
||||
let (port, chan) = comm::stream();
|
||||
match page.query_layout(ContentBoxQuery(node, chan), port) {
|
||||
match win.page.query_layout(ContentBoxQuery(node, chan), port) {
|
||||
ContentBoxResponse(rect) => {
|
||||
let cx = page.js_info.get_ref().js_compartment.cx.ptr;
|
||||
let cx = win.get_cx();
|
||||
let scope = win.reflector().get_jsobject();
|
||||
ClientRect::new(
|
||||
rect.origin.y.to_f32(),
|
||||
|
|
|
@ -29,8 +29,7 @@ impl HTMLDocument {
|
|||
parent: Document::new(window, HTML)
|
||||
};
|
||||
|
||||
let compartment = window.get_ref().page.js_info.get_ref().js_compartment;
|
||||
AbstractDocument::as_abstract(compartment.cx.ptr, doc)
|
||||
AbstractDocument::as_abstract(window.get_ref().get_cx(), doc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -651,8 +651,7 @@ impl Node<ScriptView> {
|
|||
|
||||
pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
||||
let win = self.owner_doc.with_base(|doc| doc.window.unwrap());
|
||||
let cx = win.page.js_info.get_ref().js_compartment.cx.ptr;
|
||||
(win.reflector().get_jsobject(), cx)
|
||||
(win.reflector().get_jsobject(), win.get_cx())
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#concept-node-replace-all
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Text {
|
|||
}
|
||||
|
||||
pub fn Constructor(owner: @mut Window, text: &DOMString) -> Fallible<AbstractNode<ScriptView>> {
|
||||
let cx = owner.page.js_info.get_ref().js_compartment.cx.ptr;
|
||||
let cx = owner.get_cx();
|
||||
let text = @Text::new(null_str_as_empty(text), owner.Document());
|
||||
Ok(unsafe { Node::as_abstract_node(cx, text) })
|
||||
}
|
||||
|
|
|
@ -50,6 +50,12 @@ pub struct Window {
|
|||
next_timer_handle: i32,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn get_cx(&self) -> *JSObject {
|
||||
self.page.js_info.get_ref().js_compartment.cx.ptr
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl Drop for Window {
|
||||
fn drop(&self) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue