diff options
Diffstat (limited to 'src/servo/layout')
-rw-r--r-- | src/servo/layout/base.rs | 19 | ||||
-rw-r--r-- | src/servo/layout/box_builder.rs | 7 | ||||
-rw-r--r-- | src/servo/layout/inline.rs | 5 | ||||
-rw-r--r-- | src/servo/layout/layout.rs | 2 | ||||
-rw-r--r-- | src/servo/layout/style/style.rs | 72 |
5 files changed, 90 insertions, 15 deletions
diff --git a/src/servo/layout/base.rs b/src/servo/layout/base.rs index ab758daa409..71aab635981 100644 --- a/src/servo/layout/base.rs +++ b/src/servo/layout/base.rs @@ -1,23 +1,24 @@ 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 /*layout::*/inline::inline_layout_methods; +import /*layout::*/style::style::{computed_style, di_block, di_inline}; +import /*layout::*/style::style::style_methods; 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> }; +enum layout_data = { + mut computed_style: computed_style, + mut box: option<@box> +}; + enum ntree { ntree } impl of tree::rd_tree_ops<node> for ntree { fn each_child(node: node, f: fn(node) -> bool) { @@ -53,7 +54,7 @@ impl of tree::wr_tree_ops<@box> for btree { impl block_layout_methods for @box { #[doc="The main reflow routine."] fn reflow(available_width: au) { - alt self.display { + alt self.node.get_computed_style().display { di_block { self.reflow_block(available_width) } di_inline { self.reflow_inline(available_width) } } @@ -61,7 +62,7 @@ impl block_layout_methods for @box { #[doc="The main reflow routine for block layout."] fn reflow_block(available_width: au) { - assert self.display == di_block; + assert self.node.get_computed_style().display == di_block; // Root here is the root of the reflow, not necessarily the doc as // a whole. diff --git a/src/servo/layout/box_builder.rs b/src/servo/layout/box_builder.rs index 814ae32b372..35f1114d10d 100644 --- a/src/servo/layout/box_builder.rs +++ b/src/servo/layout/box_builder.rs @@ -3,8 +3,8 @@ import dom::base::node; import dom::rcu::reader_methods; import gfx::geom; -import /*layout::*/base::{box, btree, di_block, di_inline, ntree, rd_tree_ops}; -import /*layout::*/base::wr_tree_ops; +import /*layout::*/base::{box, btree, ntree, rd_tree_ops, wr_tree_ops}; +import /*layout::*/style::style::{di_block, di_inline}; import util::tree; export box_builder_methods; @@ -12,14 +12,13 @@ export box_builder_methods; fn new_box(n: node) -> @box { @box({tree: tree::empty(), node: n, - mut display: di_block, mut bounds: geom::zero_rect_au()}) } impl box_builder_priv_methods for node { fn construct_boxes() -> @box { let b = new_box(self); - self.set_aux(b); + self.aux::<()>({ |a| a.box = some(b); }); ret b; } } diff --git a/src/servo/layout/inline.rs b/src/servo/layout/inline.rs index b614ad6389f..d11c50f40ae 100644 --- a/src/servo/layout/inline.rs +++ b/src/servo/layout/inline.rs @@ -1,15 +1,16 @@ // 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 /*layout::*/base::*; // FIXME: Can't get around import *; resolve bug. +import /*layout::*/style::style::{di_inline, style_methods}; 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; + assert self.node.get_computed_style().display == di_inline; // FIXME: This is clownshoes inline layout and is not even close to // correct. diff --git a/src/servo/layout/layout.rs b/src/servo/layout/layout.rs index a50edbde92f..93c562a6a6e 100644 --- a/src/servo/layout/layout.rs +++ b/src/servo/layout/layout.rs @@ -11,6 +11,7 @@ import gfx::geom; import gfx::renderer; import dom::base::node; import dom::rcu::scope; +import /*layout::*/style::style::style_methods; import base::*; import box_builder::box_builder_methods; import dl = display_list; @@ -29,6 +30,7 @@ fn layout(to_renderer: chan<renderer::msg>) -> chan<msg> { exit { break; } build(node) { #debug("layout: received layout request"); + node.recompute_style_for_subtree(); let this_box = node.construct_boxes_for_subtree(); this_box.reflow(geom::px_to_au(800)); let dlist = build_display_list(this_box); diff --git a/src/servo/layout/style/style.rs b/src/servo/layout/style/style.rs new file mode 100644 index 00000000000..86ef324043e --- /dev/null +++ b/src/servo/layout/style/style.rs @@ -0,0 +1,72 @@ +#[doc="High-level interface to CSS selector matching."] + +import dom::base::{nk_div, nk_img, node, node_kind}; +import dom::rcu::reader_methods; +import /*layout::*/base::*; // FIXME: resolve bug requires * + +enum computed_style = { + mut display: display +}; + +enum display { + di_block, + di_inline +} + +#[doc="Returns the default style for the given node kind."] +fn default_style_for_node_kind(kind : node_kind) -> computed_style { + alt kind { + nk_div { computed_style({ mut display: di_block }) } + nk_img(*) { computed_style({ mut display: di_block }) } + } +} + +impl style_priv for node { + #[doc=" + Performs CSS selector matching on a node. + + This is, importantly, the function that creates the layout data for + the node (the reader-auxiliary box in the RCU model) and populates it + with the computed style. + "] + fn recompute_style() { + let default_style: computed_style = + default_style_for_node_kind(self.rd { |n| n.kind }); + let the_layout_data = @layout_data({ + mut computed_style: default_style, + mut box: none + }); + self.set_aux(the_layout_data); + } +} + +impl style_methods for node { + #[doc=" + Returns the computed style for the given node. If CSS selector matching + has not yet been performed, fails. + + TODO: Return a safe reference; don't copy. + "] + fn get_computed_style() -> computed_style { + if !self.has_aux() { + fail "get_computed_style() called on a node without a style!"; + } + ret self.aux({ |x| x }).computed_style; + } + + #[doc=" + Performs CSS selector matching on a subtree. + + This is, importantly, the function that creates the layout data for + the node (the reader-auxiliary box in the RCU model) and populates it + with the computed style. + "] + fn recompute_style_for_subtree() { + self.recompute_style(); + for ntree.each_child(self) { + |kid| + kid.recompute_style_for_subtree(); + } + } +} + |