Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layout: Refactor the RenderBox type to save memory and improve the coding style of box.rs #419

Merged
merged 1 commit into from May 8, 2013
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -10,11 +10,11 @@ use newcss::complete::CompleteStyle;

/// Node mixin providing `style` method that returns a `NodeStyle`
pub trait StyledNode {
fn style<'a>(&'a self) -> CompleteStyle<'a>;
fn style(&self) -> CompleteStyle;
}

impl StyledNode for AbstractNode {
fn style<'a>(&'a self) -> CompleteStyle<'a> {
fn style(&self) -> CompleteStyle {
assert!(self.is_element()); // Only elements can have styles
let results = self.get_css_select_results();
results.computed_style()
@@ -23,7 +23,7 @@ pub struct BlockFlowData {
common: FlowData,

/// The associated render box.
box: Option<@mut RenderBox>
box: Option<RenderBox>
}

impl BlockFlowData {
@@ -40,7 +40,7 @@ impl BlockFlowData {
/// merged into this.
pub trait BlockLayout {
fn starts_block_flow(&self) -> bool;
fn with_block_box(&self, &fn(box: &@mut RenderBox) -> ()) -> ();
fn with_block_box(&self, &fn(box: RenderBox) -> ()) -> ();

fn bubble_widths_block(&self, ctx: &LayoutContext);
fn assign_widths_block(&self, ctx: &LayoutContext);
@@ -62,17 +62,17 @@ impl BlockLayout for FlowContext {

/// Get the current flow's corresponding block box, if it exists, and do something with it.
/// This works on both BlockFlow and RootFlow, since they are mostly the same.
fn with_block_box(&self, callback: &fn(box: &@mut RenderBox) -> ()) -> () {
fn with_block_box(&self, callback: &fn(box: RenderBox) -> ()) -> () {
match *self {
BlockFlow(*) => {
let box = self.block().box;
for box.each |b| {
for box.each |&b| {
callback(b);
}
},
RootFlow(*) => {
let mut box = self.root().box;
for box.each |b| {
for box.each |&b| {
callback(b);
}
},
@@ -132,9 +132,12 @@ impl BlockLayout for FlowContext {

// Let the box consume some width. It will return the amount remaining for its children.
do self.with_block_box |box| {
box.d().position.size.width = remaining_width;
let (left_used, right_used) = box.get_used_width();
remaining_width -= left_used.add(&right_used);
do box.with_mut_base |base| {
base.position.size.width = remaining_width;

let (left_used, right_used) = box.get_used_width();
remaining_width -= left_used.add(&right_used);
}
}

for self.each_child |kid| {
@@ -167,9 +170,11 @@ impl BlockLayout for FlowContext {
let _used_bot = Au(0);

do self.with_block_box |box| {
box.d().position.origin.y = Au(0);
box.d().position.size.height = cur_y;
let (_used_top, _used_bot) = box.get_used_height();
do box.with_mut_base |base| {
base.position.origin.y = Au(0);
base.position.size.height = cur_y;
let (_used_top, _used_bot) = box.get_used_height();
}
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.