aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian J. Burg <burg@cs.washington.edu>2012-09-17 15:51:06 -0700
committerBrian J. Burg <burg@cs.washington.edu>2012-09-17 17:24:31 -0700
commitbcdc2ac597906fe7b6cd57be362e88b5a2b745bf (patch)
tree769da76ae2a6b058f64d33c3cebbd3b9237d8656
parenteb9a6c0597b8fd59ee01d611a1538d566e386c91 (diff)
downloadservo-bcdc2ac597906fe7b6cd57be362e88b5a2b745bf.tar.gz
servo-bcdc2ac597906fe7b6cd57be362e88b5a2b745bf.zip
Shuffle around code in layout/base.rs to have better locality; move DebugMethods trait to own file
-rw-r--r--src/servo/dom/base.rs27
-rw-r--r--src/servo/layout/base.rs217
-rw-r--r--src/servo/layout/debug.rs5
-rwxr-xr-xsrc/servo/servo.rc1
4 files changed, 129 insertions, 121 deletions
diff --git a/src/servo/dom/base.rs b/src/servo/dom/base.rs
index 302e3e54b21..fe712c63ec1 100644
--- a/src/servo/dom/base.rs
+++ b/src/servo/dom/base.rs
@@ -14,6 +14,7 @@ use js::jsapi::{JSClass, JSObject, JSPropertySpec, JSContext, jsid, jsval, JSBoo
use js::rust::{bare_compartment, compartment, methods};
use js::{JSPROP_ENUMERATE, JSPROP_SHARED};
use layout::base::Box;
+use layout::debug::DebugMethods;
use ptr::null;
use std::arc::ARC;
use util::tree;
@@ -81,6 +82,32 @@ impl NodeTree : tree::ReadMethods<Node> {
}
}
+
+impl Node : DebugMethods {
+ /* Dumps the subtree rooted at this node, for debugging. */
+ fn dump() {
+ self.dump_indent(0u);
+ }
+ /* Dumps the node tree, for debugging, with indentation. */
+ fn dump_indent(indent: uint) {
+ let mut s = ~"";
+ for uint::range(0u, indent) |_i| {
+ s += ~" ";
+ }
+
+ s += self.debug_str();
+ debug!("%s", s);
+
+ for NodeTree.each_child(self) |kid| {
+ kid.dump_indent(indent + 1u)
+ }
+ }
+
+ fn debug_str() -> ~str {
+ fmt!("%?", self.read(|n| copy n.kind ))
+ }
+}
+
enum NodeKind {
Doctype(DoctypeData),
Comment(~str),
diff --git a/src/servo/layout/base.rs b/src/servo/layout/base.rs
index e36bbab296a..2d32368feff 100644
--- a/src/servo/layout/base.rs
+++ b/src/servo/layout/base.rs
@@ -14,6 +14,7 @@ use geom::size::Size2D;
use gfx::geometry::au;
use image::{Image, ImageHolder};
use layout::block::BlockFlowData;
+use layout::debug::DebugMethods;
use layout::inline::InlineFlowData;
use layout::root::RootFlowData;
use layout::text::TextBoxData;
@@ -25,6 +26,20 @@ use util::color::Color;
use util::tree;
use vec::{push, push_all};
+struct FlowLayoutData {
+ mut min_width: au,
+ mut pref_width: au,
+ mut position: Rect<au>,
+}
+
+fn FlowLayoutData() -> FlowLayoutData {
+ FlowLayoutData {
+ min_width: au(0),
+ pref_width: au(0),
+ position : au::zero_rect(),
+ }
+}
+
/* The type of the formatting context, and data specific to each
context, such as lineboxes or float lists */
enum FlowContextData {
@@ -69,12 +84,87 @@ impl @FlowContext : cmp::Eq {
pure fn ne(&&other: @FlowContext) -> bool { !box::ptr_eq(self, other) }
}
+impl @FlowContext {
+ fn bubble_widths() {
+ match self.kind {
+ BlockFlow(*) => self.bubble_widths_block(),
+ InlineFlow(*) => self.bubble_widths_inline(),
+ RootFlow(*) => self.bubble_widths_root(),
+ _ => fail fmt!("Tried to bubble_widths of flow: %?", self.kind)
+ }
+ }
+
+ fn assign_widths() {
+ match self.kind {
+ BlockFlow(*) => self.assign_widths_block(),
+ InlineFlow(*) => self.assign_widths_inline(),
+ RootFlow(*) => self.assign_widths_root(),
+ _ => fail fmt!("Tried to assign_widths of flow: %?", self.kind)
+ }
+ }
+
+ fn assign_height() {
+ match self.kind {
+ BlockFlow(*) => self.assign_height_block(),
+ InlineFlow(*) => self.assign_height_inline(),
+ RootFlow(*) => self.assign_height_root(),
+ _ => fail fmt!("Tried to assign_height of flow: %?", self.kind)
+ }
+ }
+}
+
+/* The tree holding FlowContexts */
+enum FlowTree { FlowTree }
+
+impl FlowTree : tree::ReadMethods<@FlowContext> {
+ fn each_child(ctx: @FlowContext, f: fn(&&@FlowContext) -> bool) {
+ tree::each_child(self, ctx, f)
+ }
+
+ fn with_tree_fields<R>(&&b: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
+ f(b.tree)
+ }
+}
+
+impl FlowTree : tree::WriteMethods<@FlowContext> {
+ fn add_child(parent: @FlowContext, child: @FlowContext) {
+ assert !box::ptr_eq(parent, child);
+ tree::add_child(self, parent, child)
+ }
+
+ fn with_tree_fields<R>(&&b: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
+ f(b.tree)
+ }
+}
+
+
/* A box's kind influences how its styles are interpreted during
layout. For example, replaced content such as images are resized
differently than tables, text, or other content.
It also holds data specific to different box types, such as text.
*/
+
+struct BoxLayoutData {
+ mut min_width: au,
+ mut pref_width: au,
+ mut position: Rect<au>,
+
+ mut font_size: Length,
+ mut background_image: Option<ImageHolder>,
+}
+
+fn BoxLayoutData() -> BoxLayoutData {
+ BoxLayoutData {
+ min_width: au(0),
+ pref_width: au(0),
+ position : au::zero_rect(),
+
+ font_size : Px(0.0),
+ background_image : None,
+ }
+}
+
enum BoxData {
GenericBox,
ImageBox(Size2D<au>),
@@ -134,7 +224,9 @@ impl @Box {
// how to compute its own min and pref widths, and should
// probably cache them.
TextBox(d) => d.runs.foldl(au(0), |sum, run| {
- au::max(sum, run.min_break_width())
+ let ret = au::max(sum, run.min_break_width());
+ debug!("text min width: %?px", au::to_px(ret));
+ ret
})
}
}
@@ -156,7 +248,9 @@ impl @Box {
// how to compute its own min and pref widths, and should
// probably cache them.
TextBox(d) => d.runs.foldl(au(0), |sum, run| {
- au::max(sum, run.size().width)
+ let ret = au::max(sum, run.size().width);
+ debug!("text pref width: %?px", au::to_px(ret));
+ ret
})
}
}
@@ -199,41 +293,6 @@ impl @Box {
}
}
-struct FlowLayoutData {
- mut min_width: au,
- mut pref_width: au,
- mut position: Rect<au>,
-}
-
-
-fn FlowLayoutData() -> FlowLayoutData {
- FlowLayoutData {
- min_width: au(0),
- pref_width: au(0),
- position : au::zero_rect(),
- }
-}
-
-struct BoxLayoutData {
- mut min_width: au,
- mut pref_width: au,
- mut position: Rect<au>,
-
- mut font_size: Length,
- mut background_image: Option<ImageHolder>,
-}
-
-fn BoxLayoutData() -> BoxLayoutData {
- BoxLayoutData {
- min_width: au(0),
- pref_width: au(0),
- position : au::zero_rect(),
-
- font_size : Px(0.0),
- background_image : None,
- }
-}
-
// FIXME: Why do these have to be redefined for each node type?
/* The tree holding boxes */
@@ -260,67 +319,8 @@ impl BoxTree : tree::WriteMethods<@Box> {
}
}
-/* The tree holding FlowContexts */
-enum FlowTree { FlowTree }
-
-impl FlowTree : tree::ReadMethods<@FlowContext> {
- fn each_child(ctx: @FlowContext, f: fn(&&@FlowContext) -> bool) {
- tree::each_child(self, ctx, f)
- }
-
- fn with_tree_fields<R>(&&b: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
- f(b.tree)
- }
-}
-
-impl FlowTree : tree::WriteMethods<@FlowContext> {
- fn add_child(parent: @FlowContext, child: @FlowContext) {
- assert !box::ptr_eq(parent, child);
- tree::add_child(self, parent, child)
- }
-
- fn with_tree_fields<R>(&&b: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
- f(b.tree)
- }
-}
-
-impl @FlowContext {
- fn bubble_widths() {
- match self.kind {
- BlockFlow(*) => self.bubble_widths_block(),
- InlineFlow(*) => self.bubble_widths_inline(),
- RootFlow(*) => self.bubble_widths_root(),
- _ => fail fmt!("Tried to bubble_widths of flow: %?", self.kind)
- }
- }
-
- fn assign_widths() {
- match self.kind {
- BlockFlow(*) => self.assign_widths_block(),
- InlineFlow(*) => self.assign_widths_inline(),
- RootFlow(*) => self.assign_widths_root(),
- _ => fail fmt!("Tried to assign_widths of flow: %?", self.kind)
- }
- }
-
- fn assign_height() {
- match self.kind {
- BlockFlow(*) => self.assign_height_block(),
- InlineFlow(*) => self.assign_height_inline(),
- RootFlow(*) => self.assign_height_root(),
- _ => fail fmt!("Tried to assign_height of flow: %?", self.kind)
- }
- }
-}
-
// Debugging
-trait DebugMethods {
- fn dump();
- fn dump_indent(ident: uint);
- fn debug_str() -> ~str;
-}
-
impl @FlowContext : DebugMethods {
fn dump() {
self.dump_indent(0u);
@@ -363,31 +363,6 @@ impl @FlowContext : DebugMethods {
}
}
-impl Node : DebugMethods {
- /* Dumps the subtree rooted at this node, for debugging. */
- fn dump() {
- self.dump_indent(0u);
- }
- /* Dumps the node tree, for debugging, with indentation. */
- fn dump_indent(indent: uint) {
- let mut s = ~"";
- for uint::range(0u, indent) |_i| {
- s += ~" ";
- }
-
- s += self.debug_str();
- debug!("%s", s);
-
- for NodeTree.each_child(self) |kid| {
- kid.dump_indent(indent + 1u)
- }
- }
-
- fn debug_str() -> ~str {
- fmt!("%?", self.read(|n| copy n.kind ))
- }
-}
-
impl @Box : DebugMethods {
fn dump() {
self.dump_indent(0u);
diff --git a/src/servo/layout/debug.rs b/src/servo/layout/debug.rs
new file mode 100644
index 00000000000..2bb010e25a8
--- /dev/null
+++ b/src/servo/layout/debug.rs
@@ -0,0 +1,5 @@
+trait DebugMethods {
+ fn dump();
+ fn dump_indent(ident: uint);
+ fn debug_str() -> ~str;
+}
diff --git a/src/servo/servo.rc b/src/servo/servo.rc
index 8705ac30f7d..12782355e32 100755
--- a/src/servo/servo.rc
+++ b/src/servo/servo.rc
@@ -55,6 +55,7 @@ mod layout {
mod base;
mod block;
mod box_builder;
+ mod debug;
mod display_list_builder;
mod inline;
mod layout_task;