mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Shuffle around code in layout/base.rs to have better locality; move DebugMethods trait to own file
This commit is contained in:
parent
eb9a6c0597
commit
bcdc2ac597
4 changed files with 129 additions and 121 deletions
|
@ -14,6 +14,7 @@ use js::jsapi::{JSClass, JSObject, JSPropertySpec, JSContext, jsid, jsval, JSBoo
|
||||||
use js::rust::{bare_compartment, compartment, methods};
|
use js::rust::{bare_compartment, compartment, methods};
|
||||||
use js::{JSPROP_ENUMERATE, JSPROP_SHARED};
|
use js::{JSPROP_ENUMERATE, JSPROP_SHARED};
|
||||||
use layout::base::Box;
|
use layout::base::Box;
|
||||||
|
use layout::debug::DebugMethods;
|
||||||
use ptr::null;
|
use ptr::null;
|
||||||
use std::arc::ARC;
|
use std::arc::ARC;
|
||||||
use util::tree;
|
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 {
|
enum NodeKind {
|
||||||
Doctype(DoctypeData),
|
Doctype(DoctypeData),
|
||||||
Comment(~str),
|
Comment(~str),
|
||||||
|
|
|
@ -14,6 +14,7 @@ use geom::size::Size2D;
|
||||||
use gfx::geometry::au;
|
use gfx::geometry::au;
|
||||||
use image::{Image, ImageHolder};
|
use image::{Image, ImageHolder};
|
||||||
use layout::block::BlockFlowData;
|
use layout::block::BlockFlowData;
|
||||||
|
use layout::debug::DebugMethods;
|
||||||
use layout::inline::InlineFlowData;
|
use layout::inline::InlineFlowData;
|
||||||
use layout::root::RootFlowData;
|
use layout::root::RootFlowData;
|
||||||
use layout::text::TextBoxData;
|
use layout::text::TextBoxData;
|
||||||
|
@ -25,6 +26,20 @@ use util::color::Color;
|
||||||
use util::tree;
|
use util::tree;
|
||||||
use vec::{push, push_all};
|
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
|
/* The type of the formatting context, and data specific to each
|
||||||
context, such as lineboxes or float lists */
|
context, such as lineboxes or float lists */
|
||||||
enum FlowContextData {
|
enum FlowContextData {
|
||||||
|
@ -69,12 +84,87 @@ impl @FlowContext : cmp::Eq {
|
||||||
pure fn ne(&&other: @FlowContext) -> bool { !box::ptr_eq(self, other) }
|
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
|
/* A box's kind influences how its styles are interpreted during
|
||||||
layout. For example, replaced content such as images are resized
|
layout. For example, replaced content such as images are resized
|
||||||
differently than tables, text, or other content.
|
differently than tables, text, or other content.
|
||||||
|
|
||||||
It also holds data specific to different box types, such as text.
|
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 {
|
enum BoxData {
|
||||||
GenericBox,
|
GenericBox,
|
||||||
ImageBox(Size2D<au>),
|
ImageBox(Size2D<au>),
|
||||||
|
@ -134,7 +224,9 @@ impl @Box {
|
||||||
// how to compute its own min and pref widths, and should
|
// how to compute its own min and pref widths, and should
|
||||||
// probably cache them.
|
// probably cache them.
|
||||||
TextBox(d) => d.runs.foldl(au(0), |sum, run| {
|
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
|
// how to compute its own min and pref widths, and should
|
||||||
// probably cache them.
|
// probably cache them.
|
||||||
TextBox(d) => d.runs.foldl(au(0), |sum, run| {
|
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?
|
// FIXME: Why do these have to be redefined for each node type?
|
||||||
|
|
||||||
/* The tree holding boxes */
|
/* 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
|
// Debugging
|
||||||
|
|
||||||
trait DebugMethods {
|
|
||||||
fn dump();
|
|
||||||
fn dump_indent(ident: uint);
|
|
||||||
fn debug_str() -> ~str;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl @FlowContext : DebugMethods {
|
impl @FlowContext : DebugMethods {
|
||||||
fn dump() {
|
fn dump() {
|
||||||
self.dump_indent(0u);
|
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 {
|
impl @Box : DebugMethods {
|
||||||
fn dump() {
|
fn dump() {
|
||||||
self.dump_indent(0u);
|
self.dump_indent(0u);
|
||||||
|
|
5
src/servo/layout/debug.rs
Normal file
5
src/servo/layout/debug.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
trait DebugMethods {
|
||||||
|
fn dump();
|
||||||
|
fn dump_indent(ident: uint);
|
||||||
|
fn debug_str() -> ~str;
|
||||||
|
}
|
|
@ -55,6 +55,7 @@ mod layout {
|
||||||
mod base;
|
mod base;
|
||||||
mod block;
|
mod block;
|
||||||
mod box_builder;
|
mod box_builder;
|
||||||
|
mod debug;
|
||||||
mod display_list_builder;
|
mod display_list_builder;
|
||||||
mod inline;
|
mod inline;
|
||||||
mod layout_task;
|
mod layout_task;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue