mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
servo: Stub inline layout computation; move reflow to impls
Source-Repo: https://github.com/servo/servo Source-Revision: 6340a4a0bdd8feac7ec77b6b188373bf040eebb0
This commit is contained in:
parent
5613a8d31d
commit
6638fa96cc
@ -1,13 +1,20 @@
|
||||
import dom::base::{nk_div, nk_img, node_data, node_kind, node};
|
||||
import dom::rcu;
|
||||
import dom::rcu::reader_methods;
|
||||
import inline::inline_layout_methods;
|
||||
import gfx::geom;
|
||||
import gfx::geom::{size, rect, point, au};
|
||||
import util::{tree};
|
||||
|
||||
enum display {
|
||||
di_block,
|
||||
di_inline
|
||||
}
|
||||
|
||||
enum box = {
|
||||
tree: tree::fields<@box>,
|
||||
node: node,
|
||||
mut display: display,
|
||||
mut bounds: geom::rect<au>
|
||||
};
|
||||
|
||||
@ -46,6 +53,7 @@ impl of tree::wr_tree_ops<@box> for btree {
|
||||
fn new_box(n: node) -> @box {
|
||||
@box({tree: tree::empty(),
|
||||
node: n,
|
||||
mut display: di_block,
|
||||
mut bounds: geom::zero_rect_au()})
|
||||
}
|
||||
|
||||
@ -64,38 +72,51 @@ fn linked_subtree(p: node) -> @box {
|
||||
ret p_box;
|
||||
}
|
||||
|
||||
fn reflow_block(root: @box, available_width: au) {
|
||||
// Root here is the root of the reflow, not necessarily the doc as
|
||||
// a whole.
|
||||
//
|
||||
// This routine:
|
||||
// - generates root.bounds.size
|
||||
// - generates root.bounds.origin for each child
|
||||
// - and recursively computes the bounds for each child
|
||||
|
||||
let k = root.node.rd() { |r| r.kind };
|
||||
alt k {
|
||||
nk_img(size) {
|
||||
root.bounds.size = size;
|
||||
ret;
|
||||
}
|
||||
|
||||
nk_div { /* fallthrough */ }
|
||||
impl block_layout_methods for @box {
|
||||
#[doc="The main reflow routine."]
|
||||
fn reflow(available_width: au) {
|
||||
alt self.display {
|
||||
di_block { self.reflow_block(available_width) }
|
||||
di_inline { self.reflow_inline(available_width) }
|
||||
}
|
||||
}
|
||||
|
||||
let mut current_height = 0;
|
||||
for tree::each_child(btree, root) {|c|
|
||||
let mut blk_available_width = available_width;
|
||||
// FIXME subtract borders, margins, etc
|
||||
c.bounds.origin = {mut x: au(0), mut y: au(current_height)};
|
||||
reflow_block(c, blk_available_width);
|
||||
current_height += *c.bounds.size.height;
|
||||
#[doc="The main reflow routine for block layout."]
|
||||
fn reflow_block(available_width: au) {
|
||||
assert self.display == di_block;
|
||||
|
||||
// Root here is the root of the reflow, not necessarily the doc as
|
||||
// a whole.
|
||||
//
|
||||
// This routine:
|
||||
// - generates root.bounds.size
|
||||
// - generates root.bounds.origin for each child
|
||||
// - and recursively computes the bounds for each child
|
||||
|
||||
let k = self.node.rd() { |r| r.kind };
|
||||
alt k {
|
||||
nk_img(size) {
|
||||
self.bounds.size = size;
|
||||
ret;
|
||||
}
|
||||
|
||||
nk_div { /* fallthrough */ }
|
||||
}
|
||||
|
||||
let mut current_height = 0;
|
||||
for tree::each_child(btree, self) {|c|
|
||||
let mut blk_available_width = available_width;
|
||||
// FIXME subtract borders, margins, etc
|
||||
c.bounds.origin = {mut x: au(0), mut y: au(current_height)};
|
||||
c.reflow(blk_available_width);
|
||||
current_height += *c.bounds.size.height;
|
||||
}
|
||||
|
||||
self.bounds.size = {mut width: available_width, // FIXME
|
||||
mut height: au(current_height)};
|
||||
|
||||
#debug["reflow_block root=%? size=%?", k, self.bounds];
|
||||
}
|
||||
|
||||
root.bounds.size = {mut width: available_width, // FIXME
|
||||
mut height: au(current_height)};
|
||||
|
||||
#debug["reflow_block root=%? size=%?", k, root.bounds];
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -150,7 +171,7 @@ mod test {
|
||||
tree::add_child(btree, b3, b1);
|
||||
tree::add_child(btree, b3, b2);
|
||||
|
||||
reflow_block(b3, au(100));
|
||||
b3.reflow_block(au(100));
|
||||
let fb = flat_bounds(b3);
|
||||
#debug["fb=%?", fb];
|
||||
assert fb == [geom::box(au(0), au(0), au(10), au(10)), // n0
|
||||
|
34
servo/src/servo/layout/inline.rs
Normal file
34
servo/src/servo/layout/inline.rs
Normal file
@ -0,0 +1,34 @@
|
||||
// Inline layout.
|
||||
|
||||
import base::*; // FIXME: Can't get around import * due to resolve bug.
|
||||
import dom::rcu;
|
||||
import dom::rcu::reader_methods;
|
||||
import gfx::geom::au;
|
||||
import util::tree;
|
||||
|
||||
#[doc="The main reflow routine for inline layout."]
|
||||
impl inline_layout_methods for @box {
|
||||
fn reflow_inline(available_width: au) {
|
||||
assert self.display == di_inline;
|
||||
|
||||
// FIXME: This is clownshoes inline layout and is not even close to
|
||||
// correct.
|
||||
let y = self.bounds.origin.y;
|
||||
let mut x = 0, inline_available_width = *available_width;
|
||||
let mut current_height = 0;
|
||||
for tree::each_child(btree, self) {
|
||||
|kid|
|
||||
kid.bounds.origin = { mut x: au(x), mut y: y };
|
||||
kid.reflow(au(inline_available_width));
|
||||
inline_available_width -= *kid.bounds.size.width;
|
||||
x += *kid.bounds.size.width;
|
||||
current_height = int::max(current_height, *kid.bounds.size.height);
|
||||
}
|
||||
|
||||
self.bounds.size = { mut width: available_width,
|
||||
mut height: au(current_height) };
|
||||
|
||||
#debug["reflow_inline root=%? size=%?", self, self.bounds];
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import gfx::renderer;
|
||||
import dom::base::node;
|
||||
import dom::rcu::scope;
|
||||
import base::{btree, rd_tree_ops, wr_tree_ops, linked_subtree};
|
||||
import base::block_layout_methods;
|
||||
import dl = display_list;
|
||||
|
||||
enum msg {
|
||||
@ -29,7 +30,7 @@ fn layout(to_renderer: chan<renderer::msg>) -> chan<msg> {
|
||||
build(node) {
|
||||
#debug("layout: received layout request");
|
||||
let box = linked_subtree(node);
|
||||
base::reflow_block(box, geom::px_to_au(800));
|
||||
box.reflow(geom::px_to_au(800));
|
||||
let dlist = build_display_list(box);
|
||||
to_renderer.send(renderer::render(dlist));
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ mod image {
|
||||
mod layout {
|
||||
mod base;
|
||||
mod display_list;
|
||||
mod inline;
|
||||
mod layout;
|
||||
}
|
||||
|
||||
@ -51,4 +52,4 @@ mod util {
|
||||
|
||||
mod content;
|
||||
mod opts;
|
||||
mod engine;
|
||||
mod engine;
|
||||
|
Loading…
Reference in New Issue
Block a user