diff --git a/src/servo/layout/display_list_builder.rs b/src/servo/layout/display_list_builder.rs new file mode 100644 index 00000000000..7a212e139d3 --- /dev/null +++ b/src/servo/layout/display_list_builder.rs @@ -0,0 +1,93 @@ +export build_display_list; + +import dl = display_list; +import dom::rcu::Scope; +import gfx::geometry::{au, au_to_px, box, px_to_au}; +import gfx::renderer; +import layout::base::*; +import util::color::methods; + +import geom::point::Point2D; +import geom::rect::Rect; + +#[doc = " + +Builds a display list for a box and all its children + +"] +fn build_display_list(box : @Box) -> dl::display_list { + ret build_display_list_from_origin(box, Point2D(au(0), au(0))); +} + +#[doc=" + +Builds a display list for a box and all its children. + +# Arguments + +* `box` - The box to build the display list for. +* `origin` - The coordinates of upper-left corner of the box containing the + passed-in box. + +"] +fn build_display_list_from_origin(box: @Box, origin: Point2D) + -> dl::display_list { + let box_origin = Point2D( + px_to_au(au_to_px(origin.x) + au_to_px(box.bounds.origin.x)), + px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y))); + #debug("Handed origin %?, box has bounds %?, starting with origin %?", origin, copy box.bounds, box_origin); + + let mut list = [box_to_display_item(box, box_origin)]; + + for btree.each_child(box) {|c| + #debug("Recursively building display list with origin %?", box_origin); + list += build_display_list_from_origin(c, box_origin); + } + + #debug("display_list: %?", list); + ret list; +} + +#[doc=" + +Creates a display list item for a single block. +Args: +-box: the box to build the display list for +-origin: the coordinates of upper-left corner of the passed in box. + +"] +fn box_to_display_item(box: @Box, origin: Point2D) -> dl::display_item { + let mut item; + + #debug("request to display a box from origin %?", origin); + + let bounds = Rect(origin, copy box.bounds.size); + + alt (box.appearance.background_image, box.appearance.background_color) { + (some(image), some(*)) | (some(image), none) { + item = dl::display_item({ + item_type: dl::display_item_image(~copy *image), + bounds: bounds + }); + } + (none, some(col)) { + #debug("Assigning color %? to box with bounds %?", col, bounds); + item = dl::display_item({ + item_type: dl::display_item_solid_color(col.red, col.green, col.blue), + bounds: bounds + }); + } + (none, none) { + let r = rand::rng(); + item = dl::display_item({ + item_type: dl::display_item_solid_color(r.next() as u8, + r.next() as u8, + r.next() as u8), + bounds: bounds + }); + } + } + + #debug("layout: display item: %?", item); + ret item; +} diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index 5385c3367c2..1b0297de9a4 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -3,20 +3,14 @@ rendered. "]; -import box_builder::box_builder_methods; -import dl = display_list; -import dom::base::Node; -import dom::rcu::Scope; +import display_list_builder::build_display_list; +import dom::base::{Node}; import dom::style::stylesheet; -import gfx::geometry::{au, au_to_px, box, px_to_au}; -import gfx::renderer; -import layout::base::*; -import layout::style::apply::ApplyStyleBoxMethods; +import gfx::geometry::px_to_au; +import base::{NodeMethods, layout_methods}; import layout::style::style::style_methods; -import util::color::methods; - -import geom::point::Point2D; -import geom::rect::Rect; +import box_builder::box_builder_methods; +import layout::style::apply::ApplyStyleBoxMethods; import task::*; import comm::*; @@ -56,80 +50,3 @@ fn layout(to_renderer: chan) -> chan { } } } - -#[doc=" - -Builds a display list for a box and all its children. - -# Arguments - -* `box` - The box to build the display list for. -* `origin` - The coordinates of upper-left corner of the box containing the - passed-in box. - -"] -fn build_display_list_from_origin(box: @Box, origin: Point2D) - -> dl::display_list { - let box_origin = Point2D( - px_to_au(au_to_px(origin.x) + au_to_px(box.bounds.origin.x)), - px_to_au(au_to_px(origin.y) + au_to_px(box.bounds.origin.y))); - #debug("Handed origin %?, box has bounds %?, starting with origin %?", origin, copy box.bounds, box_origin); - - let mut list = [box_to_display_item(box, box_origin)]; - - for btree.each_child(box) {|c| - #debug("Recursively building display list with origin %?", box_origin); - list += build_display_list_from_origin(c, box_origin); - } - - #debug("display_list: %?", list); - ret list; -} - -fn build_display_list(box : @Box) -> dl::display_list { - ret build_display_list_from_origin(box, Point2D(au(0), au(0))); -} - -#[doc=" - -Creates a display list item for a single block. -Args: --box: the box to build the display list for --origin: the coordinates of upper-left corner of the passed in box. - -"] -fn box_to_display_item(box: @Box, origin: Point2D) -> dl::display_item { - let mut item; - - #debug("request to display a box from origin %?", origin); - - let bounds = Rect(origin, copy box.bounds.size); - - alt (box.appearance.background_image, box.appearance.background_color) { - (some(image), some(*)) | (some(image), none) { - item = dl::display_item({ - item_type: dl::display_item_image(~copy *image), - bounds: bounds - }); - } - (none, some(col)) { - #debug("Assigning color %? to box with bounds %?", col, bounds); - item = dl::display_item({ - item_type: dl::display_item_solid_color(col.red, col.green, col.blue), - bounds: bounds - }); - } - (none, none) { - let r = rand::rng(); - item = dl::display_item({ - item_type: dl::display_item_solid_color(r.next() as u8, - r.next() as u8, - r.next() as u8), - bounds: bounds - }); - } - } - - #debug("layout: display item: %?", item); - ret item; -} diff --git a/src/servo/servo.rc b/src/servo/servo.rc index 66fcb0d7158..34947cd7325 100755 --- a/src/servo/servo.rc +++ b/src/servo/servo.rc @@ -44,6 +44,7 @@ mod layout { mod block; mod box_builder; mod display_list; + mod display_list_builder; mod inline; mod layout_task; mod text;