aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/main/layout/inline.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/main/layout/inline.rs')
-rw-r--r--src/components/main/layout/inline.rs465
1 files changed, 232 insertions, 233 deletions
diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs
index a92047bec8d..df9ec106a65 100644
--- a/src/components/main/layout/inline.rs
+++ b/src/components/main/layout/inline.rs
@@ -33,39 +33,39 @@ use style::computed_values::{text_align, vertical_align, white_space};
use style::ComputedValues;
use sync::Arc;
-/// Lineboxes are represented as offsets into the child list, rather than
-/// as an object that "owns" boxes. Choosing a different set of line
+/// `LineFragment`s are represented as offsets into the child list, rather than
+/// as an object that "owns" fragments. Choosing a different set of line
/// breaks requires a new list of offsets, and possibly some splitting and
/// merging of TextFragments.
///
-/// A similar list will keep track of the mapping between CSS boxes and
-/// the corresponding boxes in the inline flow.
+/// A similar list will keep track of the mapping between CSS fragments and
+/// the corresponding fragments in the inline flow.
///
-/// After line breaks are determined, render boxes in the inline flow may
-/// overlap visually. For example, in the case of nested inline CSS boxes,
+/// After line breaks are determined, render fragments in the inline flow may
+/// overlap visually. For example, in the case of nested inline CSS fragments,
/// outer inlines must be at least as large as the inner inlines, for
/// purposes of drawing noninherited things like backgrounds, borders,
/// outlines.
///
/// N.B. roc has an alternative design where the list instead consists of
-/// things like "start outer box, text, start inner box, text, end inner
-/// box, text, end outer box, text". This seems a little complicated to
+/// things like "start outer fragment, text, start inner fragment, text, end inner
+/// fragment, text, end outer fragment, text". This seems a little complicated to
/// serve as the starting point, but the current design doesn't make it
/// hard to try out that alternative.
///
-/// Line boxes also contain some metadata used during line breaking. The
+/// Line fragments also contain some metadata used during line breaking. The
/// green zone is the area that the line can expand to before it collides
/// with a float or a horizontal wall of the containing block. The top
/// left corner of the green zone is the same as that of the line, but
/// the green zone can be taller and wider than the line itself.
-pub struct LineBox {
+pub struct LineFragment {
pub range: Range<LineIndices>,
pub bounds: Rect<Au>,
pub green_zone: Size2D<Au>
}
int_range_index! {
- #[doc = "The index of a box fragment in a flattened vector of DOM elements."]
+ #[doc = "The index of a fragment in a flattened vector of DOM elements."]
struct FragmentIndex(int)
}
@@ -97,8 +97,7 @@ int_range_index! {
/// ~~~
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Zero)]
pub struct LineIndices {
- /// The index of a box fragment into the flattened vector of DOM
- /// elements.
+ /// The index of a fragment into the flattened vector of DOM elements.
///
/// For example, given the HTML below:
///
@@ -199,22 +198,22 @@ pub fn each_char_index(range: &Range<LineIndices>) -> EachIndex<int, CharIndex>
range::each_index(range.begin().char_index, range.end().char_index)
}
-struct LineboxScanner {
+struct LineFragmentScanner {
pub floats: Floats,
- pub new_boxes: Vec<Fragment>,
+ pub new_fragments: Vec<Fragment>,
pub work_list: RingBuf<Fragment>,
- pub pending_line: LineBox,
- pub lines: Vec<LineBox>,
+ pub pending_line: LineFragment,
+ pub lines: Vec<LineFragment>,
pub cur_y: Au,
}
-impl LineboxScanner {
- pub fn new(float_ctx: Floats) -> LineboxScanner {
- LineboxScanner {
+impl LineFragmentScanner {
+ pub fn new(float_ctx: Floats) -> LineFragmentScanner {
+ LineFragmentScanner {
floats: float_ctx,
- new_boxes: Vec::new(),
+ new_fragments: Vec::new(),
work_list: RingBuf::new(),
- pending_line: LineBox {
+ pending_line: LineFragment {
range: Range::empty(),
bounds: Rect(Point2D(Au::new(0), Au::new(0)), Size2D(Au::new(0), Au::new(0))),
green_zone: Size2D(Au::new(0), Au::new(0))
@@ -229,14 +228,14 @@ impl LineboxScanner {
}
fn reset_scanner(&mut self) {
- debug!("Resetting line box scanner's state for flow.");
+ debug!("Resetting LineFragmentScanner's state for flow.");
self.lines = Vec::new();
- self.new_boxes = Vec::new();
+ self.new_fragments = Vec::new();
self.cur_y = Au(0);
- self.reset_linebox();
+ self.reset_line_fragment();
}
- fn reset_linebox(&mut self) {
+ fn reset_line_fragment(&mut self) {
self.pending_line.range.reset(num::zero(), num::zero());
self.pending_line.bounds = Rect(Point2D(Au::new(0), self.cur_y), Size2D(Au::new(0), Au::new(0)));
self.pending_line.green_zone = Size2D(Au::new(0), Au::new(0))
@@ -247,52 +246,52 @@ impl LineboxScanner {
// Swap out temporarily.
let InlineFragments {
- boxes: old_boxes,
+ fragments: old_fragments,
map: mut map
- } = mem::replace(&mut flow.boxes, InlineFragments::new());
+ } = mem::replace(&mut flow.fragments, InlineFragments::new());
- let mut old_box_iter = old_boxes.iter();
+ let mut old_fragment_iter = old_fragments.iter();
loop {
- // acquire the next box to lay out from work list or box list
- let cur_box = if self.work_list.is_empty() {
- match old_box_iter.next() {
+ // acquire the next fragment to lay out from work list or fragment list
+ let cur_fragment = if self.work_list.is_empty() {
+ match old_fragment_iter.next() {
None => break,
Some(fragment) => {
- debug!("LineboxScanner: Working with fragment from flow: b{}",
+ debug!("LineFragmentScanner: Working with fragment from flow: b{}",
fragment.debug_id());
(*fragment).clone()
}
}
} else {
let fragment = self.work_list.pop_front().unwrap();
- debug!("LineboxScanner: Working with box from work list: b{}",
+ debug!("LineFragmentScanner: Working with fragment from work list: b{}",
fragment.debug_id());
fragment
};
- let box_was_appended = match cur_box.white_space() {
- white_space::normal => self.try_append_to_line(cur_box, flow),
- white_space::pre => self.try_append_to_line_by_new_line(cur_box),
+ let fragment_was_appended = match cur_fragment.white_space() {
+ white_space::normal => self.try_append_to_line(cur_fragment, flow),
+ white_space::pre => self.try_append_to_line_by_new_line(cur_fragment),
};
- if !box_was_appended {
- debug!("LineboxScanner: Fragment wasn't appended, because line {:u} was full.",
+ if !fragment_was_appended {
+ debug!("LineFragmentScanner: Fragment wasn't appended, because line {:u} was full.",
self.lines.len());
self.flush_current_line();
} else {
- debug!("LineboxScanner: appended a box to line {:u}", self.lines.len());
+ debug!("LineFragmentScanner: appended a fragment to line {:u}", self.lines.len());
}
}
if self.pending_line.range.length() > num::zero() {
- debug!("LineboxScanner: Partially full linebox {:u} left at end of scanning.",
+ debug!("LineFragmentScanner: Partially full line_fragment {:u} left at end of scanning.",
self.lines.len());
self.flush_current_line();
}
- map.fixup(old_boxes.as_slice(), self.new_boxes.as_slice());
- flow.boxes = InlineFragments {
- boxes: mem::replace(&mut self.new_boxes, Vec::new()),
+ map.fixup(old_fragments.as_slice(), self.new_fragments.as_slice());
+ flow.fragments = InlineFragments {
+ fragments: mem::replace(&mut self.new_fragments, Vec::new()),
map: map,
};
@@ -300,49 +299,49 @@ impl LineboxScanner {
}
fn flush_current_line(&mut self) {
- debug!("LineboxScanner: Flushing line {:u}: {:?}",
+ debug!("LineFragmentScanner: Flushing line {:u}: {:?}",
self.lines.len(), self.pending_line);
// clear line and add line mapping
- debug!("LineboxScanner: Saving information for flushed line {:u}.", self.lines.len());
+ debug!("LineFragmentScanner: Saving information for flushed line {:u}.", self.lines.len());
self.lines.push(self.pending_line);
self.cur_y = self.pending_line.bounds.origin.y + self.pending_line.bounds.size.height;
- self.reset_linebox();
+ self.reset_line_fragment();
}
- // FIXME(eatkinson): this assumes that the tallest box in the line determines the line height
+ // FIXME(eatkinson): this assumes that the tallest fragment in the line determines the line height
// This might not be the case with some weird text fonts.
- fn new_height_for_line(&self, new_box: &Fragment) -> Au {
- let box_height = new_box.content_height();
- if box_height > self.pending_line.bounds.size.height {
- box_height
+ fn new_height_for_line(&self, new_fragment: &Fragment) -> Au {
+ let fragment_height = new_fragment.content_height();
+ if fragment_height > self.pending_line.bounds.size.height {
+ fragment_height
} else {
self.pending_line.bounds.size.height
}
}
- /// Computes the position of a line that has only the provided box. Returns the bounding rect
- /// of the line's green zone (whose origin coincides with the line's origin) and the actual
- /// width of the first box after splitting.
- fn initial_line_placement(&self, first_box: &Fragment, ceiling: Au, flow: &mut InlineFlow)
+ /// Computes the position of a line that has only the provided fragment. Returns the bounding
+ /// rect of the line's green zone (whose origin coincides with the line's origin) and the actual
+ /// width of the first fragment after splitting.
+ fn initial_line_placement(&self, first_fragment: &Fragment, ceiling: Au, flow: &mut InlineFlow)
-> (Rect<Au>, Au) {
- debug!("LineboxScanner: Trying to place first box of line {}", self.lines.len());
+ debug!("LineFragmentScanner: Trying to place first fragment of line {}", self.lines.len());
- let first_box_size = first_box.border_box.size;
- let splittable = first_box.can_split();
- debug!("LineboxScanner: box size: {}, splittable: {}", first_box_size, splittable);
+ let first_fragment_size = first_fragment.border_box.size;
+ let splittable = first_fragment.can_split();
+ debug!("LineFragmentScanner: fragment size: {}, splittable: {}", first_fragment_size, splittable);
- // Initally, pretend a splittable box has 0 width.
+ // Initally, pretend a splittable fragment has 0 width.
// We will move it later if it has nonzero width
// and that causes problems.
let placement_width = if splittable {
Au::new(0)
} else {
- first_box_size.width
+ first_fragment_size.width
};
let info = PlacementInfo {
- size: Size2D(placement_width, first_box_size.height),
+ size: Size2D(placement_width, first_fragment_size.height),
ceiling: ceiling,
max_width: flow.base.position.size.width,
kind: FloatLeft,
@@ -350,33 +349,33 @@ impl LineboxScanner {
let line_bounds = self.floats.place_between_floats(&info);
- debug!("LineboxScanner: found position for line: {} using placement_info: {:?}",
+ debug!("LineFragmentScanner: found position for line: {} using placement_info: {:?}",
line_bounds,
info);
- // Simple case: if the box fits, then we can stop here
- if line_bounds.size.width > first_box_size.width {
- debug!("LineboxScanner: case=box fits");
- return (line_bounds, first_box_size.width);
+ // Simple case: if the fragment fits, then we can stop here
+ if line_bounds.size.width > first_fragment_size.width {
+ debug!("LineFragmentScanner: case=fragment fits");
+ return (line_bounds, first_fragment_size.width);
}
- // If not, but we can't split the box, then we'll place
+ // If not, but we can't split the fragment, then we'll place
// the line here and it will overflow.
if !splittable {
- debug!("LineboxScanner: case=line doesn't fit, but is unsplittable");
- return (line_bounds, first_box_size.width);
+ debug!("LineFragmentScanner: case=line doesn't fit, but is unsplittable");
+ return (line_bounds, first_fragment_size.width);
}
- debug!("LineboxScanner: used to call split_to_width here");
- return (line_bounds, first_box_size.width);
+ debug!("LineFragmentScanner: used to call split_to_width here");
+ return (line_bounds, first_fragment_size.width);
}
- /// Performs float collision avoidance. This is called when adding a box is going to increase
+ /// Performs float collision avoidance. This is called when adding a fragment is going to increase
/// the height, and because of that we will collide with some floats.
///
/// We have two options here:
/// 1) Move the entire line so that it doesn't collide any more.
- /// 2) Break the line and put the new box on the next line.
+ /// 2) Break the line and put the new fragment on the next line.
///
/// The problem with option 1 is that we might move the line and then wind up breaking anyway,
/// which violates the standard.
@@ -386,93 +385,93 @@ impl LineboxScanner {
///
/// Returns false if and only if we should break the line.
fn avoid_floats(&mut self,
- in_box: Fragment,
+ in_fragment: Fragment,
flow: &mut InlineFlow,
new_height: Au,
line_is_empty: bool)
-> bool {
- debug!("LineboxScanner: entering float collision avoider!");
+ debug!("LineFragmentScanner: entering float collision avoider!");
// First predict where the next line is going to be.
let this_line_y = self.pending_line.bounds.origin.y;
- let (next_line, first_box_width) = self.initial_line_placement(&in_box, this_line_y, flow);
+ let (next_line, first_fragment_width) = self.initial_line_placement(&in_fragment, this_line_y, flow);
let next_green_zone = next_line.size;
- let new_width = self.pending_line.bounds.size.width + first_box_width;
+ let new_width = self.pending_line.bounds.size.width + first_fragment_width;
// Now, see if everything can fit at the new location.
if next_green_zone.width >= new_width && next_green_zone.height >= new_height {
- debug!("LineboxScanner: case=adding box collides vertically with floats: moving line");
+ debug!("LineFragmentScanner: case=adding fragment collides vertically with floats: moving line");
self.pending_line.bounds.origin = next_line.origin;
self.pending_line.green_zone = next_green_zone;
assert!(!line_is_empty, "Non-terminating line breaking");
- self.work_list.push_front(in_box);
+ self.work_list.push_front(in_fragment);
return true
}
- debug!("LineboxScanner: case=adding box collides vertically with floats: breaking line");
- self.work_list.push_front(in_box);
+ debug!("LineFragmentScanner: case=adding fragment collides vertically with floats: breaking line");
+ self.work_list.push_front(in_fragment);
false
}
- fn try_append_to_line_by_new_line(&mut self, in_box: Fragment) -> bool {
- if in_box.new_line_pos.len() == 0 {
- debug!("LineboxScanner: Did not find a new-line character, so pushing the box to \
+ fn try_append_to_line_by_new_line(&mut self, in_fragment: Fragment) -> bool {
+ if in_fragment.new_line_pos.len() == 0 {
+ debug!("LineFragmentScanner: Did not find a new-line character, so pushing the fragment to \
the line without splitting.");
- self.push_box_to_line(in_box);
+ self.push_fragment_to_line(in_fragment);
true
} else {
- debug!("LineboxScanner: Found a new-line character, so splitting theline.");
- match in_box.find_split_info_by_new_line() {
+ debug!("LineFragmentScanner: Found a new-line character, so splitting theline.");
+ match in_fragment.find_split_info_by_new_line() {
Some((left, right, run)) => {
- // TODO(bjz): Remove box splitting
- let split_box = |split: SplitInfo| {
+ // TODO(bjz): Remove fragment splitting
+ let split_fragment = |split: SplitInfo| {
let info = ScannedTextFragmentInfo::new(run.clone(), split.range);
let specific = ScannedTextFragment(info);
- let size = Size2D(split.width, in_box.border_box.size.height);
- in_box.transform(size, specific)
+ let size = Size2D(split.width, in_fragment.border_box.size.height);
+ in_fragment.transform(size, specific)
};
- debug!("LineboxScanner: Pushing the box to the left of the new-line character \
+ debug!("LineFragmentScanner: Pushing the fragment to the left of the new-line character \
to the line.");
- let mut left = split_box(left);
+ let mut left = split_fragment(left);
left.new_line_pos = vec!();
- self.push_box_to_line(left);
+ self.push_fragment_to_line(left);
for right in right.move_iter() {
- debug!("LineboxScanner: Deferring the box to the right of the new-line \
+ debug!("LineFragmentScanner: Deferring the fragment to the right of the new-line \
character to the line.");
- let mut right = split_box(right);
- right.new_line_pos = in_box.new_line_pos.clone();
+ let mut right = split_fragment(right);
+ right.new_line_pos = in_fragment.new_line_pos.clone();
self.work_list.push_front(right);
}
},
None => {
- error!("LineboxScanner: This split case makes no sense!")
+ error!("LineFragmentScanner: This split case makes no sense!")
},
}
false
}
}
- /// Tries to append the given box to the line, splitting it if necessary. Returns false only if
+ /// Tries to append the given fragment to the line, splitting it if necessary. Returns false only if
/// we should break the line.
- fn try_append_to_line(&mut self, in_box: Fragment, flow: &mut InlineFlow) -> bool {
+ fn try_append_to_line(&mut self, in_fragment: Fragment, flow: &mut InlineFlow) -> bool {
let line_is_empty = self.pending_line.range.length() == num::zero();
if line_is_empty {
- let (line_bounds, _) = self.initial_line_placement(&in_box, self.cur_y, flow);
+ let (line_bounds, _) = self.initial_line_placement(&in_fragment, self.cur_y, flow);
self.pending_line.bounds.origin = line_bounds.origin;
self.pending_line.green_zone = line_bounds.size;
}
- debug!("LineboxScanner: Trying to append box to line {:u} (box size: {}, green zone: \
+ debug!("LineFragmentScanner: Trying to append fragment to line {:u} (fragment size: {}, green zone: \
{}): {}",
self.lines.len(),
- in_box.border_box.size,
+ in_fragment.border_box.size,
self.pending_line.green_zone,
- in_box);
+ in_fragment);
let green_zone = self.pending_line.green_zone;
@@ -480,87 +479,87 @@ impl LineboxScanner {
// `green_zone.height < self.pending_line.bounds.size.height`, then we committed a line
// that overlaps with floats.
- let new_height = self.new_height_for_line(&in_box);
+ let new_height = self.new_height_for_line(&in_fragment);
if new_height > green_zone.height {
// Uh-oh. Float collision imminent. Enter the float collision avoider
- return self.avoid_floats(in_box, flow, new_height, line_is_empty)
+ return self.avoid_floats(in_fragment, flow, new_height, line_is_empty)
}
// If we're not going to overflow the green zone vertically, we might still do so
- // horizontally. We'll try to place the whole box on this line and break somewhere if it
+ // horizontally. We'll try to place the whole fragment on this line and break somewhere if it
// doesn't fit.
- let new_width = self.pending_line.bounds.size.width + in_box.border_box.size.width;
+ let new_width = self.pending_line.bounds.size.width + in_fragment.border_box.size.width;
if new_width <= green_zone.width {
- debug!("LineboxScanner: case=box fits without splitting");
- self.push_box_to_line(in_box);
+ debug!("LineFragmentScanner: case=fragment fits without splitting");
+ self.push_fragment_to_line(in_fragment);
return true
}
- if !in_box.can_split() {
+ if !in_fragment.can_split() {
// TODO(eatkinson, issue #224): Signal that horizontal overflow happened?
if line_is_empty {
- debug!("LineboxScanner: case=box can't split and line {:u} is empty, so \
+ debug!("LineFragmentScanner: case=fragment can't split and line {:u} is empty, so \
overflowing.",
self.lines.len());
- self.push_box_to_line(in_box);
+ self.push_fragment_to_line(in_fragment);
return true
}
}
let available_width = green_zone.width - self.pending_line.bounds.size.width;
- let split = in_box.find_split_info_for_width(CharIndex(0), available_width, line_is_empty);
+ let split = in_fragment.find_split_info_for_width(CharIndex(0), available_width, line_is_empty);
match split.map(|(left, right, run)| {
- // TODO(bjz): Remove box splitting
- let split_box = |split: SplitInfo| {
+ // TODO(bjz): Remove fragment splitting
+ let split_fragment = |split: SplitInfo| {
let info = ScannedTextFragmentInfo::new(run.clone(), split.range);
let specific = ScannedTextFragment(info);
- let size = Size2D(split.width, in_box.border_box.size.height);
- in_box.transform(size, specific)
+ let size = Size2D(split.width, in_fragment.border_box.size.height);
+ in_fragment.transform(size, specific)
};
- (left.map(|x| { debug!("LineboxScanner: Left split {}", x); split_box(x) }),
- right.map(|x| { debug!("LineboxScanner: Right split {}", x); split_box(x) }))
+ (left.map(|x| { debug!("LineFragmentScanner: Left split {}", x); split_fragment(x) }),
+ right.map(|x| { debug!("LineFragmentScanner: Right split {}", x); split_fragment(x) }))
}) {
None => {
- debug!("LineboxScanner: Tried to split unsplittable render box! Deferring to next \
- line. {}", in_box);
- self.work_list.push_front(in_box);
+ debug!("LineFragmentScanner: Tried to split unsplittable render fragment! Deferring to next \
+ line. {}", in_fragment);
+ self.work_list.push_front(in_fragment);
false
},
- Some((Some(left_box), Some(right_box))) => {
- debug!("LineboxScanner: Line break found! Pushing left box to line and deferring \
- right box to next line.");
- self.push_box_to_line(left_box);
- self.work_list.push_front(right_box);
+ Some((Some(left_fragment), Some(right_fragment))) => {
+ debug!("LineFragmentScanner: Line break found! Pushing left fragment to line and deferring \
+ right fragment to next line.");
+ self.push_fragment_to_line(left_fragment);
+ self.work_list.push_front(right_fragment);
true
},
- Some((Some(left_box), None)) => {
- debug!("LineboxScanner: Pushing left box to line.");
- self.push_box_to_line(left_box);
+ Some((Some(left_fragment), None)) => {
+ debug!("LineFragmentScanner: Pushing left fragment to line.");
+ self.push_fragment_to_line(left_fragment);
true
},
- Some((None, Some(right_box))) => {
- debug!("LineboxScanner: Pushing right box to line.");
- self.push_box_to_line(right_box);
+ Some((None, Some(right_fragment))) => {
+ debug!("LineFragmentScanner: Pushing right fragment to line.");
+ self.push_fragment_to_line(right_fragment);
true
},
Some((None, None)) => {
- error!("LineboxScanner: This split case makes no sense!");
+ error!("LineFragmentScanner: This split case makes no sense!");
true
},
}
}
// An unconditional push
- fn push_box_to_line(&mut self, box_: Fragment) {
- debug!("LineboxScanner: Pushing box {} to line {:u}", box_.debug_id(), self.lines.len());
+ fn push_fragment_to_line(&mut self, fragment: Fragment) {
+ debug!("LineFragmentScanner: Pushing fragment {} to line {:u}", fragment.debug_id(), self.lines.len());
if self.pending_line.range.length() == num::zero() {
- assert!(self.new_boxes.len() <= (u16::MAX as uint));
+ assert!(self.new_fragments.len() <= (u16::MAX as uint));
self.pending_line.range.reset(
LineIndices {
- fragment_index: FragmentIndex(self.new_boxes.len() as int),
+ fragment_index: FragmentIndex(self.new_fragments.len() as int),
char_index: CharIndex(0) /* unused for now */,
},
num::zero()
@@ -571,14 +570,14 @@ impl LineboxScanner {
char_index: CharIndex(0) /* unused for now */ ,
});
self.pending_line.bounds.size.width = self.pending_line.bounds.size.width +
- box_.border_box.size.width;
+ fragment.border_box.size.width;
self.pending_line.bounds.size.height = Au::max(self.pending_line.bounds.size.height,
- box_.border_box.size.height);
- self.new_boxes.push(box_);
+ fragment.border_box.size.height);
+ self.new_fragments.push(fragment);
}
}
-/// Iterator over boxes.
+/// Iterator over fragments.
pub struct FragmentIterator<'a> {
iter: Enumerate<Items<'a,Fragment>>,
map: &'a InlineFragmentMap,
@@ -597,7 +596,7 @@ impl<'a> Iterator<(&'a Fragment, InlineFragmentContext<'a>)> for FragmentIterato
}
}
-/// Mutable iterator over boxes.
+/// Mutable iterator over fragments.
pub struct MutFragmentIterator<'a> {
iter: Enumerate<MutItems<'a,Fragment>>,
map: &'a InlineFragmentMap,
@@ -616,75 +615,75 @@ impl<'a> Iterator<(&'a mut Fragment, InlineFragmentContext<'a>)> for MutFragment
}
}
-/// Represents a list of inline boxes, including element ranges.
+/// Represents a list of inline fragments, including element ranges.
pub struct InlineFragments {
- /// The boxes themselves.
- pub boxes: Vec<Fragment>,
- /// Tracks the elements that made up the boxes above.
+ /// The fragments themselves.
+ pub fragments: Vec<Fragment>,
+ /// Tracks the elements that made up the fragments above.
pub map: InlineFragmentMap,
}
impl InlineFragments {
- /// Creates an empty set of inline boxes.
+ /// Creates an empty set of inline fragments.
pub fn new() -> InlineFragments {
InlineFragments {
- boxes: Vec::new(),
+ fragments: Vec::new(),
map: InlineFragmentMap::new(),
}
}
- /// Returns the number of inline boxes.
+ /// Returns the number of inline fragments.
pub fn len(&self) -> uint {
- self.boxes.len()
+ self.fragments.len()
}
- /// Returns true if this list contains no boxes and false if it contains at least one box.
+ /// Returns true if this list contains no fragments and false if it contains at least one fragment.
pub fn is_empty(&self) -> bool {
self.len() == 0
}
- /// Pushes a new inline box.
+ /// Pushes a new inline fragment.
pub fn push(&mut self, fragment: Fragment, style: Arc<ComputedValues>) {
- self.map.push(style, Range::new(FragmentIndex(self.boxes.len() as int), FragmentIndex(1)));
- self.boxes.push(fragment)
+ self.map.push(style, Range::new(FragmentIndex(self.fragments.len() as int), FragmentIndex(1)));
+ self.fragments.push(fragment)
}
- /// Merges another set of inline boxes with this one.
+ /// Merges another set of inline fragments with this one.
pub fn push_all(&mut self, other: InlineFragments) {
let InlineFragments {
- boxes: other_boxes,
+ fragments: other_fragments,
map: other_map
} = other;
- let adjustment = FragmentIndex(self.boxes.len() as int);
+ let adjustment = FragmentIndex(self.fragments.len() as int);
self.map.push_all(other_map, adjustment);
- self.boxes.push_all_move(other_boxes);
+ self.fragments.push_all_move(other_fragments);
}
- /// Returns an iterator that iterates over all boxes along with the appropriate context.
+ /// Returns an iterator that iterates over all fragments along with the appropriate context.
pub fn iter<'a>(&'a self) -> FragmentIterator<'a> {
FragmentIterator {
- iter: self.boxes.as_slice().iter().enumerate(),
+ iter: self.fragments.as_slice().iter().enumerate(),
map: &self.map,
}
}
- /// Returns an iterator that iterates over all boxes along with the appropriate context and
- /// allows those boxes to be mutated.
+ /// Returns an iterator that iterates over all fragments along with the appropriate context and
+ /// allows those fragments to be mutated.
pub fn mut_iter<'a>(&'a mut self) -> MutFragmentIterator<'a> {
MutFragmentIterator {
- iter: self.boxes.as_mut_slice().mut_iter().enumerate(),
+ iter: self.fragments.as_mut_slice().mut_iter().enumerate(),
map: &self.map,
}
}
- /// A convenience function to return the box at a given index.
+ /// A convenience function to return the fragment at a given index.
pub fn get<'a>(&'a self, index: uint) -> &'a Fragment {
- self.boxes.get(index)
+ self.fragments.get(index)
}
- /// A convenience function to return a mutable reference to the box at a given index.
+ /// A convenience function to return a mutable reference to the fragment at a given index.
pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut Fragment {
- self.boxes.get_mut(index)
+ self.fragments.get_mut(index)
}
}
@@ -694,12 +693,12 @@ pub struct InlineFlow {
pub base: BaseFlow,
/// A vector of all inline fragments. Several fragments may correspond to one node/element.
- pub boxes: InlineFragments,
+ pub fragments: InlineFragments,
- /// A vector of ranges into boxes that represents line positions. These ranges are disjoint and
+ /// A vector of ranges into fragments that represents line positions. These ranges are disjoint and
/// are the result of inline layout. This also includes some metadata used for positioning
/// lines.
- pub lines: Vec<LineBox>,
+ pub lines: Vec<LineFragment>,
/// The minimum height above the baseline for each line, as specified by the line height and
/// font style.
@@ -711,10 +710,10 @@ pub struct InlineFlow {
}
impl InlineFlow {
- pub fn from_boxes(node: ThreadSafeLayoutNode, boxes: InlineFragments) -> InlineFlow {
+ pub fn from_fragments(node: ThreadSafeLayoutNode, fragments: InlineFragments) -> InlineFlow {
InlineFlow {
base: BaseFlow::new(node),
- boxes: boxes,
+ fragments: fragments,
lines: Vec::new(),
minimum_height_above_baseline: Au(0),
minimum_depth_below_baseline: Au(0),
@@ -727,11 +726,11 @@ impl InlineFlow {
return
}
- // TODO(#228): Once we form line boxes and have their cached bounds, we can be smarter and
+ // TODO(#228): Once we form line fragments and have their cached bounds, we can be smarter and
// not recurse on a line if nothing in it can intersect the dirty region.
- debug!("Flow: building display list for {:u} inline boxes", self.boxes.len());
+ debug!("Flow: building display list for {:u} inline fragments", self.fragments.len());
- for (fragment, context) in self.boxes.mut_iter() {
+ for (fragment, context) in self.fragments.mut_iter() {
let rel_offset = fragment.relative_position(&self.base
.absolute_position_info
.relative_containing_block_size,
@@ -744,7 +743,7 @@ impl InlineFlow {
}
// TODO(#225): Should `inline-block` elements have flows as children of the inline flow or
- // should the flow be nested inside the box somehow?
+ // should the flow be nested inside the fragment somehow?
// For now, don't traverse the subtree rooted here.
}
@@ -784,17 +783,17 @@ impl InlineFlow {
(-super_offset - ascent, false)
},
vertical_align::text_top => {
- let box_height = *height_above_baseline + *depth_below_baseline;
+ let fragment_height = *height_above_baseline + *depth_below_baseline;
let prev_depth_below_baseline = *depth_below_baseline;
*height_above_baseline = parent_text_top;
- *depth_below_baseline = box_height - *height_above_baseline;
+ *depth_below_baseline = fragment_height - *height_above_baseline;
(*depth_below_baseline - prev_depth_below_baseline - ascent, false)
},
vertical_align::text_bottom => {
- let box_height = *height_above_baseline + *depth_below_baseline;
+ let fragment_height = *height_above_baseline + *depth_below_baseline;
let prev_depth_below_baseline = *depth_below_baseline;
*depth_below_baseline = parent_text_bottom;
- *height_above_baseline = box_height - *depth_below_baseline;
+ *height_above_baseline = fragment_height - *depth_below_baseline;
(*depth_below_baseline - prev_depth_below_baseline - ascent, false)
},
vertical_align::top => {
@@ -821,17 +820,17 @@ impl InlineFlow {
}
}
- /// Sets box X positions based on alignment for one line.
- fn set_horizontal_box_positions(boxes: &mut InlineFragments,
- line: &LineBox,
- linebox_align: text_align::T) {
+ /// Sets fragment X positions based on alignment for one line.
+ fn set_horizontal_fragment_positions(fragments: &mut InlineFragments,
+ line: &LineFragment,
+ line_fragment_align: text_align::T) {
// Figure out how much width we have.
let slack_width = Au::max(Au(0), line.green_zone.width - line.bounds.size.width);
- // Set the box x positions based on that alignment.
+ // Set the fragment x positions based on that alignment.
let mut offset_x = line.bounds.origin.x;
- offset_x = offset_x + match linebox_align {
- // So sorry, but justified text is more complicated than shuffling linebox
+ offset_x = offset_x + match line_fragment_align {
+ // So sorry, but justified text is more complicated than shuffling line_fragment
// coordinates.
//
// TODO(burg, issue #213): Implement `text-align: justify`.
@@ -841,9 +840,9 @@ impl InlineFlow {
};
for i in each_fragment_index(&line.range) {
- let box_ = boxes.get_mut(i.to_uint());
- let size = box_.border_box.size;
- box_.border_box = Rect(Point2D(offset_x, box_.border_box.origin.y), size);
+ let fragment = fragments.get_mut(i.to_uint());
+ let size = fragment.border_box.size;
+ fragment.border_box = Rect(Point2D(offset_x, fragment.border_box.origin.y), size);
offset_x = offset_x + size.width;
}
}
@@ -883,31 +882,31 @@ impl Flow for InlineFlow {
}
let mut intrinsic_widths = IntrinsicWidths::new();
- for (fragment, context) in self.boxes.mut_iter() {
+ for (fragment, context) in self.fragments.mut_iter() {
debug!("Flow: measuring {}", *fragment);
- let box_intrinsic_widths = fragment.intrinsic_widths(Some(context));
+ let fragment_intrinsic_widths = fragment.intrinsic_widths(Some(context));
intrinsic_widths.minimum_width = geometry::max(intrinsic_widths.minimum_width,
- box_intrinsic_widths.minimum_width);
+ fragment_intrinsic_widths.minimum_width);
intrinsic_widths.preferred_width = geometry::max(intrinsic_widths.preferred_width,
- box_intrinsic_widths.preferred_width);
+ fragment_intrinsic_widths.preferred_width);
}
self.base.intrinsic_widths = intrinsic_widths;
}
- /// Recursively (top-down) determines the actual width of child contexts and boxes. When called
+ /// Recursively (top-down) determines the actual width of child contexts and fragments. When called
/// on this context, the context has had its width set by the parent context.
fn assign_widths(&mut self, _: &mut LayoutContext) {
- // Initialize content box widths if they haven't been initialized already.
+ // Initialize content fragment widths if they haven't been initialized already.
//
- // TODO: Combine this with `LineboxScanner`'s walk in the box list, or put this into `Fragment`.
+ // TODO: Combine this with `LineFragmentScanner`'s walk in the fragment list, or put this into `Fragment`.
debug!("InlineFlow::assign_widths: floats in: {:?}", self.base.floats);
{
let this = &mut *self;
- for (fragment, context) in this.boxes.mut_iter() {
+ for (fragment, context) in this.fragments.mut_iter() {
fragment.assign_replaced_width_if_necessary(self.base.position.size.width,
Some(context))
}
@@ -922,57 +921,57 @@ impl Flow for InlineFlow {
// true. In that case, set the InlineBlockFragment's width to the
// shrink-to-fit width, perform inline flow, and set the block
// flow context's width as the assigned width of the
- // 'inline-block' box that created this flow before recursing.
+ // 'inline-block' fragment that created this flow before recursing.
}
/// Calculate and set the height of this flow. See CSS 2.1 § 10.6.1.
fn assign_height(&mut self, _: &mut LayoutContext) {
debug!("assign_height_inline: assigning height for flow");
- // Divide the boxes into lines.
+ // Divide the fragments into lines.
//
// TODO(#226): Get the CSS `line-height` property from the containing block's style to
- // determine minimum linebox height.
+ // determine minimum line_fragment height.
//
// TODO(#226): Get the CSS `line-height` property from each non-replaced inline element to
- // determine its height for computing linebox height.
+ // determine its height for computing line_fragment height.
//
- // TODO(pcwalton): Cache the linebox scanner?
+ // TODO(pcwalton): Cache the line_fragment scanner?
debug!("assign_height_inline: floats in: {:?}", self.base.floats);
- // assign height for inline boxes
- for (fragment, _) in self.boxes.mut_iter() {
+ // assign height for inline fragments
+ for (fragment, _) in self.fragments.mut_iter() {
fragment.assign_replaced_height_if_necessary();
}
let scanner_floats = self.base.floats.clone();
- let mut scanner = LineboxScanner::new(scanner_floats);
+ let mut scanner = LineFragmentScanner::new(scanner_floats);
scanner.scan_for_lines(self);
// All lines use text alignment of the flow.
let text_align = self.base.flags.text_align();
- // Now, go through each line and lay out the boxes inside.
+ // Now, go through each line and lay out the fragments inside.
let mut line_distance_from_flow_top = Au(0);
for line in self.lines.mut_iter() {
- // Lay out boxes horizontally.
- InlineFlow::set_horizontal_box_positions(&mut self.boxes, line, text_align);
+ // Lay out fragments horizontally.
+ InlineFlow::set_horizontal_fragment_positions(&mut self.fragments, line, text_align);
- // Set the top y position of the current line box.
+ // Set the top y position of the current line fragment.
// `line_height_offset` is updated at the end of the previous loop.
line.bounds.origin.y = line_distance_from_flow_top;
- // Calculate the distance from the baseline to the top and bottom of the line box.
+ // Calculate the distance from the baseline to the top and bottom of the line fragment.
let mut largest_height_above_baseline = self.minimum_height_above_baseline;
let mut largest_depth_below_baseline = self.minimum_depth_below_baseline;
- // Calculate the largest height among boxes with 'top' and 'bottom' values
+ // Calculate the largest height among fragments with 'top' and 'bottom' values
// respectively.
let (mut largest_height_for_top_fragments, mut largest_height_for_bottom_fragments) =
(Au(0), Au(0));
- for box_i in each_fragment_index(&line.range) {
- let fragment = self.boxes.boxes.get_mut(box_i.to_uint());
+ for fragment_i in each_fragment_index(&line.range) {
+ let fragment = self.fragments.fragments.get_mut(fragment_i.to_uint());
let InlineMetrics {
height_above_baseline: mut height_above_baseline,
@@ -981,7 +980,7 @@ impl Flow for InlineFlow {
} = fragment.inline_metrics();
// To calculate text-top and text-bottom value when `vertical-align` is involved,
- // we should find the top and bottom of the content area of the parent box.
+ // we should find the top and bottom of the content area of the parent fragment.
// "Content area" is defined in CSS 2.1 § 10.6.1.
//
// TODO: We should extract em-box info from the font size of the parent and
@@ -999,7 +998,7 @@ impl Flow for InlineFlow {
// content area. But for now we assume it's zero.
let parent_text_bottom = Au(0);
- // Calculate the final height above the baseline for this box.
+ // Calculate the final height above the baseline for this fragment.
//
// The no-update flag decides whether `largest_height_for_top_fragments` and
// `largest_height_for_bottom_fragments` are to be updated or not. This will be set
@@ -1029,26 +1028,26 @@ impl Flow for InlineFlow {
fragment.border_box.origin.y = distance_from_baseline
}
- // Calculate the distance from the baseline to the top of the largest box with a
+ // Calculate the distance from the baseline to the top of the largest fragment with a
// value for `bottom`. Then, if necessary, update `largest_height_above_baseline`.
largest_height_above_baseline =
Au::max(largest_height_above_baseline,
largest_height_for_bottom_fragments - largest_depth_below_baseline);
- // Calculate the distance from baseline to the bottom of the largest box with a value
+ // Calculate the distance from baseline to the bottom of the largest fragment with a value
// for `top`. Then, if necessary, update `largest_depth_below_baseline`.
largest_depth_below_baseline =
Au::max(largest_depth_below_baseline,
largest_height_for_top_fragments - largest_height_above_baseline);
- // Now, the distance from the logical top of the line box to the baseline can be
+ // Now, the distance from the logical top of the line fragment to the baseline can be
// computed as `largest_height_above_baseline`.
let baseline_distance_from_top = largest_height_above_baseline;
// Compute the final positions in the block direction of each fragment. Recall that
// `fragment.border_box.origin.y` was set to the distance from the baseline above.
- for box_i in each_fragment_index(&line.range) {
- let fragment = self.boxes.get_mut(box_i.to_uint());
+ for fragment_i in each_fragment_index(&line.range) {
+ let fragment = self.fragments.get_mut(fragment_i.to_uint());
match fragment.vertical_align() {
vertical_align::top => {
fragment.border_box.origin.y = fragment.border_box.origin.y +
@@ -1066,7 +1065,7 @@ impl Flow for InlineFlow {
}
}
- // This is used to set the top y position of the next line box in the next loop.
+ // This is used to set the top y position of the next line fragment in the next loop.
line.bounds.size.height = largest_height_above_baseline + largest_depth_below_baseline;
line_distance_from_flow_top = line_distance_from_flow_top + line.bounds.size.height;
} // End of `lines.each` loop.
@@ -1087,7 +1086,7 @@ impl Flow for InlineFlow {
impl fmt::Show for InlineFlow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f.buf, "InlineFlow"));
- for (i, (fragment, _)) in self.boxes.iter().enumerate() {
+ for (i, (fragment, _)) in self.fragments.iter().enumerate() {
if i == 0 {
try!(write!(f.buf, ": {}", fragment))
} else {
@@ -1099,7 +1098,7 @@ impl fmt::Show for InlineFlow {
}
/// Information that inline flows keep about a single nested element. This is used to recover the
-/// DOM structure from the flat box list when it's needed.
+/// DOM structure from the flat fragment list when it's needed.
pub struct InlineFragmentRange {
/// The style of the DOM node that this range refers to.
pub style: Arc<ComputedValues>,
@@ -1166,7 +1165,7 @@ impl<'a> Iterator<&'a InlineFragmentRange> for RangeIterator<'a> {
}
/// Information that inline flows keep about nested elements. This is used to recover the DOM
-/// structure from the flat box list when it's needed.
+/// structure from the flat fragment list when it's needed.
pub struct InlineFragmentMap {
list: Vec<InlineFragmentRange>,
}
@@ -1207,7 +1206,7 @@ impl InlineFragmentMap {
&mut self.list.as_mut_slice()[index.to_uint()]
}
- /// Iterates over all ranges that contain the box with the given index, outermost first.
+ /// Iterates over all ranges that contain the fragment with the given index, outermost first.
#[inline(always)]
fn ranges_for_index<'a>(&'a self, index: FragmentIndex) -> RangeIterator<'a> {
RangeIterator {
@@ -1222,10 +1221,10 @@ impl InlineFragmentMap {
/// DOM has changed, then the flow constructor will need to do more complicated surgery than
/// this function can provide.
///
- /// FIXME(#2267, pcwalton): It would be more efficient to not have to clone boxes all the time;
- /// i.e. if `old_boxes` contained less info than the entire range of boxes. See
+ /// FIXME(#2267, pcwalton): It would be more efficient to not have to clone fragments all the time;
+ /// i.e. if `old_fragments` contained less info than the entire range of fragments. See
/// `layout::construct::strip_ignorable_whitespace_from_start` for an example of some code that
- /// needlessly has to clone boxes.
+ /// needlessly has to clone fragments.
pub fn fixup(&mut self, old_fragments: &[Fragment], new_fragments: &[Fragment]) {
// TODO(pcwalton): Post Rust upgrade, use `with_capacity` here.
let old_list = mem::replace(&mut self.list, Vec::new());