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

Remove the "tree" API and clean up flow a bit #412

Merged
merged 6 commits into from May 3, 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

@@ -64,10 +64,10 @@ pub impl FontHandle {

fn get_CGFont(&mut self) -> CGFont {
match self.cgfont {
Some(ref font) => CFWrapper::wrap_shared(*(font.borrow_ref())),
Some(ref font) => font.clone(),
None => {
let cgfont = self.ctfont.copy_to_CGFont();
self.cgfont = Some(CFWrapper::clone(&cgfont));
self.cgfont = Some(cgfont.clone());
cgfont
}
}
@@ -30,9 +30,9 @@ pub impl FontListHandle {

fn get_available_families(&self) -> FontFamilyMap {
let family_names: CFArray<CFStringRef> = core_text::font_collection::get_family_names();
let mut family_map : FontFamilyMap = HashMap::new();
let mut family_map: FontFamilyMap = HashMap::new();
for family_names.each |&strref: &CFStringRef| {
let family_name = CFString::wrap_extern(strref).to_str();
let family_name = CFString::wrap_shared(strref).to_str();
debug!("Creating new FontFamily for family: %s", family_name);

let new_family = @mut FontFamily::new(family_name);
@@ -42,7 +42,7 @@ pub impl FontListHandle {
}

fn load_variations_for_family(&self, family: @mut FontFamily) {
let fam : &mut FontFamily = family; // FIXME: borrow checker workaround
let fam: &mut FontFamily = family; // FIXME: borrow checker workaround
let family_name = &fam.family_name;
debug!("Looking for faces of family: %s", *family_name);

@@ -1,4 +1,7 @@
//use dom::bindings::clientrect::ClientRect;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::utils::WrapperCache;

pub struct ClientRect {
@@ -9,37 +12,41 @@ pub struct ClientRect {
right: f32,
}

pub impl ClientRect {
fn new(top: f32, bottom: f32, left: f32, right: f32) -> @mut ClientRect {
impl ClientRect {
pub fn new(top: f32, bottom: f32, left: f32, right: f32) -> @mut ClientRect {
let rect = @mut ClientRect {
top: top, bottom: bottom, left: left, right: right,
top: top,
bottom: bottom,
left: left,
right: right,
wrapper: WrapperCache::new()
};
rect.init_wrapper();
rect
}

fn Top(&self) -> f32 {
pub fn Top(&self) -> f32 {
self.top
}

fn Bottom(&self) -> f32 {
pub fn Bottom(&self) -> f32 {
self.bottom
}

fn Left(&self) -> f32 {
pub fn Left(&self) -> f32 {
self.left
}

fn Right(&self) -> f32 {
pub fn Right(&self) -> f32 {
self.right
}

fn Width(&self) -> f32 {
pub fn Width(&self) -> f32 {
f32::abs(self.right - self.left)
}

fn Height(&self) -> f32 {
pub fn Height(&self) -> f32 {
f32::abs(self.bottom - self.top)
}
}

@@ -4,15 +4,14 @@

// Block layout.

use core::cell::Cell;

use layout::box::{RenderBox};
use layout::context::LayoutContext;
use layout::display_list_builder::{DisplayListBuilder, FlowDisplayListBuilderMethods};
use layout::flow::{FlowContext, FlowTree, InlineBlockFlow, BlockFlow, RootFlow};
use layout::flow::{BlockFlow, FlowContext, InlineBlockFlow, RootFlow};
use layout::inline::InlineLayout;

use au = gfx::geometry;
use core::cell::Cell;
use geom::point::Point2D;
use geom::rect::Rect;
use gfx::display_list::DisplayList;
@@ -82,7 +81,7 @@ impl BlockLayout for FlowContext {
let mut pref_width = Au(0);

/* find max width from child block contexts */
for FlowTree.each_child(self) |child_ctx| {
for self.each_child |child_ctx| {
assert!(child_ctx.starts_block_flow() || child_ctx.starts_inline_flow());

min_width = au::max(min_width, child_ctx.d().min_width);
@@ -122,7 +121,7 @@ impl BlockLayout for FlowContext {
remaining_width -= left_used.add(&right_used);
}

for FlowTree.each_child(self) |child_ctx| {
for self.each_child |child_ctx| {
assert!(child_ctx.starts_block_flow() || child_ctx.starts_inline_flow());
child_ctx.d().position.origin.x = left_used;
child_ctx.d().position.size.width = remaining_width;
@@ -134,7 +133,7 @@ impl BlockLayout for FlowContext {

let mut cur_y = Au(0);

for FlowTree.each_child(self) |child_ctx| {
for self.each_child |child_ctx| {
child_ctx.d().position.origin.y = cur_y;
cur_y += child_ctx.d().position.size.height;
}
@@ -164,7 +163,7 @@ impl BlockLayout for FlowContext {
// TODO: handle any out-of-flow elements

// go deeper into the flow tree
for FlowTree.each_child(self) |child| {
for self.each_child |child| {
self.build_display_list_for_child(builder, child, dirty, offset, list)
}
}
@@ -14,7 +14,6 @@ use layout::debug::{BoxedMutDebugMethods, DebugMethods};
use layout::flow::*;
use layout::inline::{InlineFlowData, InlineLayout};
use layout::root::RootFlowData;
use util::tree;

use gfx::image::holder::ImageHolder;
use servo_util::range::Range;
@@ -223,9 +222,8 @@ impl BuilderContext {
priv fn attach_child_flow(&self, child: @mut FlowContext) {
let d = self.default_collector.flow.d(); // FIXME: borrow checker workaround
let cd = child.d(); // FIXME: borrow checker workaround
debug!("BuilderContext: Adding child flow f%? of f%?",
d.id, cd.id);
tree::add_child(&FlowTree, self.default_collector.flow, child);
debug!("BuilderContext: Adding child flow f%? of f%?", d.id, cd.id);
self.default_collector.flow.add_child(child);
}

priv fn create_child_flow_of_type(&self,
@@ -332,10 +330,10 @@ pub impl LayoutTreeBuilder {
// eventually be elided or split, but the mapping between
// nodes and FlowContexts should not change during layout.
let flow = &mut this_ctx.default_collector.flow;
for tree::each_child(&FlowTree, flow) |child_flow: &@mut FlowContext| {
for flow.each_child |child_flow: @mut FlowContext| {
let node = child_flow.d().node;
assert!(node.has_layout_data());
node.layout_data().flow = Some(*child_flow);
node.layout_data().flow = Some(child_flow);
}
}

@@ -355,8 +353,8 @@ pub impl LayoutTreeBuilder {
let mut found_child_block = false;

let flow = &mut parent_ctx.default_collector.flow;
for tree::each_child(&FlowTree, flow) |child_ctx: &@mut FlowContext| {
match **child_ctx {
for flow.each_child |child_ctx: @mut FlowContext| {
match *child_ctx {
InlineFlow(*) | InlineBlockFlow(*) => found_child_inline = true,
BlockFlow(*) => found_child_block = true,
_ => {}
@@ -371,24 +369,36 @@ pub impl LayoutTreeBuilder {
// FIXME: this will create refcounted cycles between the removed flow and any
// of its RenderBox or FlowContext children, and possibly keep alive other junk
let parent_flow = parent_ctx.default_collector.flow;

// FIXME: Workaround for the borrow check.
let (first_child, last_child) = {
let parent_flow: &mut FlowContext = parent_flow;
let parent_flow_data = parent_flow.d();
(parent_flow_data.first_child, parent_flow_data.last_child)
};

// check first/last child for whitespace-ness
for tree::first_child(&FlowTree, &parent_flow).each |first_flow: &@mut FlowContext| {
for first_child.each |first_flow: &@mut FlowContext| {
if first_flow.starts_inline_flow() {
let boxes = &mut first_flow.inline().boxes;
if boxes.len() == 1 && boxes[0].is_whitespace_only() {
debug!("LayoutTreeBuilder: pruning whitespace-only first child flow f%d from parent f%d",
first_flow.d().id, parent_flow.d().id);
tree::remove_child(&FlowTree, parent_flow, *first_flow);
debug!("LayoutTreeBuilder: pruning whitespace-only first child flow \
f%d from parent f%d",
first_flow.d().id,
parent_flow.d().id);
parent_flow.remove_child(*first_flow);
}
}
}
for tree::last_child(&FlowTree, &parent_flow).each |last_flow: &@mut FlowContext| {
for last_child.each |last_flow: &@mut FlowContext| {
if last_flow.starts_inline_flow() {
let boxes = &mut last_flow.inline().boxes;
if boxes.len() == 1 && boxes.last().is_whitespace_only() {
debug!("LayoutTreeBuilder: pruning whitespace-only last child flow f%d from parent f%d",
last_flow.d().id, parent_flow.d().id);
tree::remove_child(&FlowTree, parent_flow, *last_flow);
debug!("LayoutTreeBuilder: pruning whitespace-only last child flow \
f%d from parent f%d",
last_flow.d().id,
parent_flow.d().id);
parent_flow.remove_child(*last_flow);
}
}
}
@@ -416,7 +426,7 @@ pub impl LayoutTreeBuilder {
}

fn make_flow(&mut self, ty: FlowContextType, node: AbstractNode) -> @mut FlowContext {
let data = FlowData(self.next_flow_id(), node);
let data = FlowData::new(self.next_flow_id(), node);
let ret = match ty {
Flow_Absolute => @mut AbsoluteFlow(data),
Flow_Block => @mut BlockFlow(data, BlockFlowData()),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.