diff options
author | Tetsuharu OHZEKI <saneyuki.snyk@gmail.com> | 2014-05-14 07:45:44 +0900 |
---|---|---|
committer | Tetsuharu OHZEKI <saneyuki.snyk@gmail.com> | 2014-05-14 13:14:29 +0900 |
commit | facffe0966265abe56f4a210dd6d7f4b792c8452 (patch) | |
tree | 444e8d4c73d926157fcee14df6ab72c65decd311 /src/components/script/dom/window.rs | |
parent | a9f08fd7c4702e96fb993b8c28492ffb7037296d (diff) | |
download | servo-facffe0966265abe56f4a210dd6d7f4b792c8452.tar.gz servo-facffe0966265abe56f4a210dd6d7f4b792c8452.zip |
Move Window helper methods to a WindowHelpers trait
Diffstat (limited to 'src/components/script/dom/window.rs')
-rw-r--r-- | src/components/script/dom/window.rs | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index 7e366492719..8fde7bd8e86 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -288,7 +288,37 @@ impl Reflectable for Window { } } -impl Window { +pub trait WindowHelpers { + fn damage_and_reflow(&self, damage: DocumentDamageLevel); + fn wait_until_safe_to_modify_dom(&self); + fn init_browser_context(&mut self, doc: &JSRef<Document>); +} + +trait PrivateWindowHelpers { + fn set_timeout_or_interval(&mut self, callback: JSVal, timeout: i32, is_interval: bool) -> i32; +} + +impl<'a> WindowHelpers for JSRef<'a, Window> { + fn damage_and_reflow(&self, damage: DocumentDamageLevel) { + // FIXME This should probably be ReflowForQuery, not Display. All queries currently + // currently rely on the display list, which means we can't destroy it by + // doing a query reflow. + self.page().damage(damage); + self.page().reflow(ReflowForDisplay, self.script_chan.clone(), *self.compositor); + } + + fn wait_until_safe_to_modify_dom(&self) { + // FIXME: This disables concurrent layout while we are modifying the DOM, since + // our current architecture is entirely unsafe in the presence of races. + self.page().join_layout(); + } + + fn init_browser_context(&mut self, doc: &JSRef<Document>) { + self.browser_context = Some(BrowserContext::new(doc)); + } +} + +impl<'a> PrivateWindowHelpers for JSRef<'a, Window> { fn set_timeout_or_interval(&mut self, callback: JSVal, timeout: i32, is_interval: bool) -> i32 { let timeout = cmp::max(0, timeout) as u64; let handle = self.next_timer_handle; @@ -346,25 +376,9 @@ impl Window { self.active_timers.insert(timer_id, timer); handle } +} - pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) { - // FIXME This should probably be ReflowForQuery, not Display. All queries currently - // currently rely on the display list, which means we can't destroy it by - // doing a query reflow. - self.page().damage(damage); - self.page().reflow(ReflowForDisplay, self.script_chan.clone(), *self.compositor); - } - - pub fn wait_until_safe_to_modify_dom(&self) { - // FIXME: This disables concurrent layout while we are modifying the DOM, since - // our current architecture is entirely unsafe in the presence of races. - self.page().join_layout(); - } - - pub fn init_browser_context(&mut self, doc: &JSRef<Document>) { - self.browser_context = Some(BrowserContext::new(doc)); - } - +impl Window { pub fn new(cx: *JSContext, page: Rc<Page>, script_chan: ScriptChan, |