mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
Refactor layout_task a little
This commit is contained in:
parent
ad937a6167
commit
e6c8ee9913
1 changed files with 94 additions and 86 deletions
|
@ -85,38 +85,6 @@ fn Layout(render_task: RenderTask,
|
||||||
|
|
||||||
impl Layout {
|
impl Layout {
|
||||||
|
|
||||||
fn handle_query(query: LayoutQuery,
|
|
||||||
reply_chan: comm::Chan<LayoutQueryResponse>) {
|
|
||||||
match query {
|
|
||||||
ContentBox(node) => {
|
|
||||||
// TODO: extract me to a method when I get sibling arms
|
|
||||||
let response = match node.aux(|a| copy *a).flow {
|
|
||||||
None => Err(()),
|
|
||||||
Some(flow) => {
|
|
||||||
let start_val : Option<Rect<au>> = None;
|
|
||||||
let rect = do flow.foldl_boxes_for_node(node, start_val) |acc, box| {
|
|
||||||
match acc {
|
|
||||||
Some(acc) => Some(acc.union(&box.content_box())),
|
|
||||||
None => Some(box.content_box())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match rect {
|
|
||||||
None => Err(()),
|
|
||||||
Some(rect) => {
|
|
||||||
let size = Size2D(au::to_px(rect.size.width),
|
|
||||||
au::to_px(rect.size.height));
|
|
||||||
Ok(ContentSize(move size))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
reply_chan.send(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start() {
|
fn start() {
|
||||||
while self.handle_request() {
|
while self.handle_request() {
|
||||||
// loop indefinitely
|
// loop indefinitely
|
||||||
|
@ -126,12 +94,23 @@ impl Layout {
|
||||||
fn handle_request() -> bool {
|
fn handle_request() -> bool {
|
||||||
|
|
||||||
match self.from_content.recv() {
|
match self.from_content.recv() {
|
||||||
|
BuildMsg(move node, move styles, move doc_url,
|
||||||
|
move to_content, move window_size, move join_chan) => {
|
||||||
|
self.handle_build(node, styles, doc_url, to_content, window_size, join_chan);
|
||||||
|
}
|
||||||
QueryMsg(query, chan) => self.handle_query(query, chan),
|
QueryMsg(query, chan) => self.handle_query(query, chan),
|
||||||
ExitMsg => {
|
ExitMsg => {
|
||||||
debug!("layout: ExitMsg received");
|
debug!("layout: ExitMsg received");
|
||||||
return false
|
return false
|
||||||
},
|
}
|
||||||
BuildMsg(node, styles, doc_url, to_content, window_size, join_chan) => {
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_build(node: Node, styles: ARC<Stylesheet>, doc_url: Url,
|
||||||
|
to_content: comm::Chan<Event>, window_size: Size2D<uint>,
|
||||||
|
join_chan: pipes::Chan<()>) {
|
||||||
debug!("layout: received layout request for: %s", doc_url.to_str());
|
debug!("layout: received layout request for: %s", doc_url.to_str());
|
||||||
debug!("layout: parsed Node tree");
|
debug!("layout: parsed Node tree");
|
||||||
debug!("%?", node.dump());
|
debug!("%?", node.dump());
|
||||||
|
@ -197,10 +176,39 @@ impl Layout {
|
||||||
// Tell content we're done
|
// Tell content we're done
|
||||||
join_chan.send(());
|
join_chan.send(());
|
||||||
|
|
||||||
} // BuildMsg
|
}
|
||||||
} // match
|
|
||||||
|
|
||||||
true
|
|
||||||
|
fn handle_query(query: LayoutQuery,
|
||||||
|
reply_chan: comm::Chan<LayoutQueryResponse>) {
|
||||||
|
match query {
|
||||||
|
ContentBox(node) => {
|
||||||
|
// TODO: extract me to a method when I get sibling arms
|
||||||
|
let response = match node.aux(|a| copy *a).flow {
|
||||||
|
None => Err(()),
|
||||||
|
Some(flow) => {
|
||||||
|
let start_val : Option<Rect<au>> = None;
|
||||||
|
let rect = do flow.foldl_boxes_for_node(node, start_val) |acc, box| {
|
||||||
|
match acc {
|
||||||
|
Some(acc) => Some(acc.union(&box.content_box())),
|
||||||
|
None => Some(box.content_box())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match rect {
|
||||||
|
None => Err(()),
|
||||||
|
Some(rect) => {
|
||||||
|
let size = Size2D(au::to_px(rect.size.width),
|
||||||
|
au::to_px(rect.size.height));
|
||||||
|
Ok(ContentSize(move size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
reply_chan.send(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When images can't be loaded in time to display they trigger
|
// When images can't be loaded in time to display they trigger
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue