Disentangle the message handling from the receiver selection in LayoutTask::handle_request.

This ensures no fields of the LayoutTask are borrowed when calling repaint or
handle_request_helper, which I'll need later.
This commit is contained in:
Ms2ger 2015-11-06 13:13:23 +01:00
parent ff0acccc06
commit b8d8505463

View file

@ -466,49 +466,67 @@ impl LayoutTask {
fn handle_request<'a>(&'a self, fn handle_request<'a>(&'a self,
possibly_locked_rw_data: &mut Option<MutexGuard<'a, LayoutTaskData>>) possibly_locked_rw_data: &mut Option<MutexGuard<'a, LayoutTaskData>>)
-> bool { -> bool {
let port_from_script = &self.port; enum Request {
let port_from_pipeline = &self.pipeline_port; FromPipeline(LayoutControlMsg),
let port_from_image_cache = &self.image_cache_receiver; FromScript(Msg),
let port_from_font_cache = &self.font_cache_receiver; FromImageCache,
select! { FromFontCache,
msg = port_from_pipeline.recv() => { }
match msg.unwrap() {
LayoutControlMsg::SetVisibleRects(new_visible_rects) => { let request = {
self.handle_request_helper(Msg::SetVisibleRects(new_visible_rects), let port_from_script = &self.port;
possibly_locked_rw_data) let port_from_pipeline = &self.pipeline_port;
} let port_from_image_cache = &self.image_cache_receiver;
LayoutControlMsg::TickAnimations => { let port_from_font_cache = &self.font_cache_receiver;
self.handle_request_helper(Msg::TickAnimations, possibly_locked_rw_data) select! {
} msg = port_from_pipeline.recv() => {
LayoutControlMsg::GetCurrentEpoch(sender) => { Request::FromPipeline(msg.unwrap())
self.handle_request_helper(Msg::GetCurrentEpoch(sender), },
possibly_locked_rw_data) msg = port_from_script.recv() => {
} Request::FromScript(msg.unwrap())
LayoutControlMsg::GetWebFontLoadState(sender) => { },
self.handle_request_helper(Msg::GetWebFontLoadState(sender), msg = port_from_image_cache.recv() => {
possibly_locked_rw_data) msg.unwrap();
} Request::FromImageCache
LayoutControlMsg::ExitNow => { },
self.handle_request_helper(Msg::ExitNow, msg = port_from_font_cache.recv() => {
possibly_locked_rw_data) msg.unwrap();
} Request::FromFontCache
} }
}
};
match request {
Request::FromPipeline(LayoutControlMsg::SetVisibleRects(new_visible_rects)) => {
self.handle_request_helper(Msg::SetVisibleRects(new_visible_rects),
possibly_locked_rw_data)
}, },
msg = port_from_script.recv() => { Request::FromPipeline(LayoutControlMsg::TickAnimations) => {
self.handle_request_helper(msg.unwrap(), possibly_locked_rw_data) self.handle_request_helper(Msg::TickAnimations, possibly_locked_rw_data)
}, },
msg = port_from_image_cache.recv() => { Request::FromPipeline(LayoutControlMsg::GetCurrentEpoch(sender)) => {
msg.unwrap(); self.handle_request_helper(Msg::GetCurrentEpoch(sender), possibly_locked_rw_data)
},
Request::FromPipeline(LayoutControlMsg::GetWebFontLoadState(sender)) => {
self.handle_request_helper(Msg::GetWebFontLoadState(sender),
possibly_locked_rw_data)
},
Request::FromPipeline(LayoutControlMsg::ExitNow) => {
self.handle_request_helper(Msg::ExitNow, possibly_locked_rw_data)
},
Request::FromScript(msg) => {
self.handle_request_helper(msg, possibly_locked_rw_data)
},
Request::FromImageCache => {
self.repaint(possibly_locked_rw_data) self.repaint(possibly_locked_rw_data)
}, },
msg = port_from_font_cache.recv() => { Request::FromFontCache => {
msg.unwrap();
let rw_data = self.lock_rw_data(possibly_locked_rw_data); let rw_data = self.lock_rw_data(possibly_locked_rw_data);
rw_data.outstanding_web_fonts.fetch_sub(1, Ordering::SeqCst); rw_data.outstanding_web_fonts.fetch_sub(1, Ordering::SeqCst);
font_context::invalidate_font_caches(); font_context::invalidate_font_caches();
self.script_chan.send(ConstellationControlMsg::WebFontLoaded(self.id)).unwrap(); self.script_chan.send(ConstellationControlMsg::WebFontLoaded(self.id)).unwrap();
true true
} },
} }
} }