diff options
author | Corey Farwell <coreyf@rwell.org> | 2015-11-12 17:32:37 -0500 |
---|---|---|
committer | Corey Farwell <coreyf@rwell.org> | 2015-11-12 17:32:37 -0500 |
commit | 607cb0eeb724378827659c3daefff3622fc8c10d (patch) | |
tree | a8c464f3d3145e15ea58b0b0ed889fadab1a3954 /components/script/script_task.rs | |
parent | 022b06e564b2556d671476ddad392d1f86ce45d6 (diff) | |
download | servo-607cb0eeb724378827659c3daefff3622fc8c10d.tar.gz servo-607cb0eeb724378827659c3daefff3622fc8c10d.zip |
Consolidate 'subpage finding' script_task logic
Diffstat (limited to 'components/script/script_task.rs')
-rw-r--r-- | components/script/script_task.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs index a824c3fb3dd..189e31f1b51 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -722,6 +722,12 @@ impl ScriptTask { self.page.borrow().as_ref().unwrap().clone() } + /// Find a child page of the root page by pipeline id. Returns `None` if the root page does + /// not exist or the subpage cannot be found. + fn find_subpage(&self, pipeline_id: PipelineId) -> Option<Rc<Page>> { + self.page.borrow().as_ref().and_then(|page| page.find(pipeline_id)) + } + pub fn get_cx(&self) -> *mut JSContext { self.js_runtime.cx() } @@ -1112,13 +1118,10 @@ impl ScriptTask { } fn handle_resize(&self, id: PipelineId, size: WindowSizeData) { - let page = self.page.borrow(); - if let Some(ref page) = page.as_ref() { - if let Some(ref page) = page.find(id) { - let window = page.window(); - window.set_resize_event(size); - return; - } + if let Some(ref page) = self.find_subpage(id) { + let window = page.window(); + window.set_resize_event(size); + return; } let mut loads = self.incomplete_loads.borrow_mut(); if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) { @@ -1513,10 +1516,8 @@ impl ScriptTask { /// Handles a Web font being loaded. Does nothing if the page no longer exists. fn handle_web_font_loaded(&self, pipeline_id: PipelineId) { - if let Some(page) = self.page.borrow().as_ref() { - if let Some(page) = page.find(pipeline_id) { - self.rebuild_and_force_reflow(&*page, ReflowReason::WebFontLoaded); - } + if let Some(ref page) = self.find_subpage(pipeline_id) { + self.rebuild_and_force_reflow(page, ReflowReason::WebFontLoaded); } } |