mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move block layout to a separate file
This commit is contained in:
parent
0d018c7091
commit
cbfbec4dbd
4 changed files with 43 additions and 30 deletions
|
@ -1,12 +1,15 @@
|
||||||
|
#[doc="Fundamental layout structures and algorithms."]
|
||||||
|
|
||||||
import dom::base::{nk_div, nk_img, node_data, node_kind, node};
|
import dom::base::{nk_div, nk_img, node_data, node_kind, node};
|
||||||
import dom::rcu;
|
import dom::rcu;
|
||||||
import dom::rcu::reader_methods;
|
import dom::rcu::reader_methods;
|
||||||
import gfx::geom;
|
import gfx::geom;
|
||||||
import gfx::geom::{size, rect, point, au, zero_size_au};
|
import gfx::geom::{size, rect, point, au, zero_size_au};
|
||||||
|
import /*layout::*/block::block_layout_methods;
|
||||||
import /*layout::*/inline::inline_layout_methods;
|
import /*layout::*/inline::inline_layout_methods;
|
||||||
import /*layout::*/style::style::{computed_style, di_block, di_inline};
|
import /*layout::*/style::style::{computed_style, di_block, di_inline};
|
||||||
import /*layout::*/style::style::style_methods;
|
import /*layout::*/style::style::style_methods;
|
||||||
import util::{tree};
|
import util::tree;
|
||||||
|
|
||||||
enum box_kind {
|
enum box_kind {
|
||||||
bk_block,
|
bk_block,
|
||||||
|
@ -58,7 +61,7 @@ impl of tree::wr_tree_ops<@box> for btree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl block_layout_methods for @box {
|
impl layout_methods for @box {
|
||||||
#[doc="The main reflow routine."]
|
#[doc="The main reflow routine."]
|
||||||
fn reflow(available_width: au) {
|
fn reflow(available_width: au) {
|
||||||
alt self.kind {
|
alt self.kind {
|
||||||
|
@ -68,33 +71,6 @@ impl block_layout_methods for @box {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc="The main reflow routine for block layout."]
|
|
||||||
fn reflow_block(available_width: au) {
|
|
||||||
assert self.kind == bk_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 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 size=%?", self.bounds];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc="The trivial reflow routine for instrinsically-sized frames."]
|
#[doc="The trivial reflow routine for instrinsically-sized frames."]
|
||||||
fn reflow_intrinsic(size: geom::size<au>) {
|
fn reflow_intrinsic(size: geom::size<au>) {
|
||||||
self.bounds.size = size;
|
self.bounds.size = size;
|
||||||
|
|
36
src/servo/layout/block.rs
Normal file
36
src/servo/layout/block.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#[doc="Block layout."]
|
||||||
|
|
||||||
|
import gfx::geom::au;
|
||||||
|
import /*layout::*/base::*; // FIXME: Can't get around import *; resolve bug.
|
||||||
|
import util::tree;
|
||||||
|
|
||||||
|
#[doc="The public block layout methods."]
|
||||||
|
impl block_layout_methods for @box {
|
||||||
|
#[doc="The main reflow routine for block layout."]
|
||||||
|
fn reflow_block(available_width: au) {
|
||||||
|
assert self.kind == bk_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 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 size=%?", self.bounds];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Inline layout.
|
#[doc="Inline layout."]
|
||||||
|
|
||||||
import dom::rcu;
|
import dom::rcu;
|
||||||
import dom::rcu::reader_methods;
|
import dom::rcu::reader_methods;
|
||||||
|
|
|
@ -35,6 +35,7 @@ mod layout {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod base;
|
mod base;
|
||||||
|
mod block;
|
||||||
mod box_builder;
|
mod box_builder;
|
||||||
mod display_list;
|
mod display_list;
|
||||||
mod inline;
|
mod inline;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue