aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/fragment.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout/fragment.rs')
-rw-r--r--components/layout/fragment.rs95
1 files changed, 49 insertions, 46 deletions
diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs
index c7e1cd1ed04..7b451d608ad 100644
--- a/components/layout/fragment.rs
+++ b/components/layout/fragment.rs
@@ -14,7 +14,7 @@ use flow;
use flow::Flow;
use flow_ref::FlowRef;
use incremental::{self, RestyleDamage};
-use inline::{InlineFragmentContext, InlineMetrics};
+use inline::{InlineFragmentContext, InlineFragmentNodeInfo, InlineMetrics};
use layout_debug;
use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
use text;
@@ -34,7 +34,6 @@ use std::borrow::ToOwned;
use std::cmp::{max, min};
use std::collections::LinkedList;
use std::fmt;
-use std::num::ToPrimitive;
use std::str::FromStr;
use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex};
@@ -48,10 +47,9 @@ use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::{LengthOrPercentageOrNone};
use text::TextRunScanner;
use url::Url;
-use util::geometry::{self, Au, ZERO_POINT};
+use util::geometry::{Au, ZERO_POINT};
use util::logical_geometry::{LogicalRect, LogicalSize, LogicalMargin, WritingMode};
use util::range::*;
-use util::smallvec::SmallVec;
use util::str::is_whitespace;
use util;
@@ -215,9 +213,9 @@ fn clamp_size(size: Au,
let min_size = model::specified(min_size, container_inline_size);
let max_size = model::specified_or_none(max_size, container_inline_size);
- Au::max(min_size, match max_size {
+ max(min_size, match max_size {
None => size,
- Some(max_size) => Au::min(size, max_size),
+ Some(max_size) => min(size, max_size),
})
}
@@ -273,8 +271,8 @@ impl CanvasFragmentInfo {
pub fn new(node: &ThreadSafeLayoutNode) -> CanvasFragmentInfo {
CanvasFragmentInfo {
replaced_image_fragment_info: ReplacedImageFragmentInfo::new(node,
- Some(Au::from_px(node.get_canvas_width() as isize)),
- Some(Au::from_px(node.get_canvas_height() as isize))),
+ Some(Au::from_px(node.get_canvas_width() as i32)),
+ Some(Au::from_px(node.get_canvas_height() as i32))),
renderer: node.get_renderer().map(|rec| Arc::new(Mutex::new(rec))),
}
}
@@ -311,8 +309,8 @@ impl ImageFragmentInfo {
fn convert_length(node: &ThreadSafeLayoutNode, name: &Atom) -> Option<Au> {
let element = node.as_element();
element.get_attr(&ns!(""), name)
- .and_then(|string| string.parse::<isize>().ok())
- .map(|pixels| Au::from_px(pixels))
+ .and_then(|string| string.parse().ok())
+ .map(Au::from_px)
}
let image = url.and_then(|url| layout_context.get_or_request_image(url));
@@ -333,7 +331,7 @@ impl ImageFragmentInfo {
image.height
} else {
image.width
- } as isize)
+ } as i32)
}
None => Au(0)
}
@@ -347,7 +345,7 @@ impl ImageFragmentInfo {
image.width
} else {
image.height
- } as isize)
+ } as i32)
}
None => Au(0)
}
@@ -356,8 +354,8 @@ impl ImageFragmentInfo {
/// Tile an image
pub fn tile_image(position: &mut Au, size: &mut Au,
virtual_position: Au, image_size: u32) {
- let image_size = image_size as isize;
- let delta_pixels = geometry::to_px(virtual_position - *position);
+ let image_size = image_size as i32;
+ let delta_pixels = (virtual_position - *position).to_px();
let tile_count = (delta_pixels + image_size - 1) / image_size;
let offset = Au::from_px(image_size * tile_count);
let new_position = virtual_position - offset;
@@ -453,8 +451,8 @@ impl ReplacedImageFragmentInfo {
if intrinsic_height == Au(0) {
intrinsic_width
} else {
- let ratio = intrinsic_width.to_f32().unwrap() /
- intrinsic_height.to_f32().unwrap();
+ let ratio = intrinsic_width.to_f32_px() /
+ intrinsic_height.to_f32_px();
let specified_height = ReplacedImageFragmentInfo::style_length(
style_block_size,
@@ -468,7 +466,7 @@ impl ReplacedImageFragmentInfo {
style_min_block_size,
style_max_block_size,
Au(0));
- Au((specified_height.to_f32().unwrap() * ratio) as i32)
+ Au::from_f32_px(specified_height.to_f32_px() * ratio)
}
},
MaybeAuto::Specified(w) => w,
@@ -505,8 +503,8 @@ impl ReplacedImageFragmentInfo {
MaybeAuto::Auto => {
let intrinsic_width = fragment_inline_size;
let intrinsic_height = fragment_block_size;
- let scale = intrinsic_width.to_f32().unwrap() / inline_size.to_f32().unwrap();
- Au((intrinsic_height.to_f32().unwrap() / scale) as i32)
+ let scale = intrinsic_width.to_f32_px() / inline_size.to_f32_px();
+ Au::from_f32_px(intrinsic_height.to_f32_px() / scale)
},
MaybeAuto::Specified(h) => {
h
@@ -840,32 +838,37 @@ impl Fragment {
self.restyle_damage | self.specific.restyle_damage()
}
+ pub fn contains_node(&self, node_address: OpaqueNode) -> bool {
+ node_address == self.node ||
+ self.inline_context.as_ref().map_or(false, |ctx| {
+ ctx.contains_node(node_address)
+ })
+ }
+
/// Adds a style to the inline context for this fragment. If the inline context doesn't exist
/// yet, it will be created.
pub fn add_inline_context_style(&mut self,
- style: Arc<ComputedValues>,
+ mut node_info: InlineFragmentNodeInfo,
first_frag: bool,
last_frag: bool) {
if self.inline_context.is_none() {
self.inline_context = Some(InlineFragmentContext::new());
}
- let frag_style = if first_frag && last_frag {
- style.clone()
- } else {
+ if !first_frag || !last_frag {
// Set the border width to zero and the border style to none on
// border sides that are not the outermost for a node container.
// Because with multiple inline fragments they don't have interior
// borders separating each other.
- let mut border_width = style.logical_border_width();
+ let mut border_width = node_info.style.logical_border_width();
if !last_frag {
- border_width.set_right(style.writing_mode, Zero::zero());
+ border_width.set_right(node_info.style.writing_mode, Zero::zero());
}
if !first_frag {
- border_width.set_left(style.writing_mode, Zero::zero());
+ border_width.set_left(node_info.style.writing_mode, Zero::zero());
}
- Arc::new(make_border(&*style, border_width))
+ node_info.style = Arc::new(make_border(&*node_info.style, border_width))
};
- self.inline_context.as_mut().unwrap().styles.push(frag_style);
+ self.inline_context.as_mut().unwrap().nodes.push(node_info);
}
/// Determines which quantities (border/padding/margin/specified) should be included in the
@@ -877,8 +880,7 @@ impl Fragment {
SpecificFragmentInfo::Generic |
SpecificFragmentInfo::GeneratedContent(_) |
SpecificFragmentInfo::Iframe(_) |
- SpecificFragmentInfo::Image(_) |
- SpecificFragmentInfo::InlineBlock(_) => {
+ SpecificFragmentInfo::Image(_) => {
QuantitiesIncludedInIntrinsicInlineSizes::all()
}
SpecificFragmentInfo::Table | SpecificFragmentInfo::TableCell => {
@@ -913,7 +915,8 @@ impl Fragment {
SpecificFragmentInfo::ScannedText(_) |
SpecificFragmentInfo::TableColumn(_) |
SpecificFragmentInfo::UnscannedText(_) |
- SpecificFragmentInfo::InlineAbsoluteHypothetical(_) => {
+ SpecificFragmentInfo::InlineAbsoluteHypothetical(_) |
+ SpecificFragmentInfo::InlineBlock(_) => {
QuantitiesIncludedInIntrinsicInlineSizes::empty()
}
}
@@ -964,8 +967,8 @@ impl Fragment {
let flags = self.quantities_included_in_intrinsic_inline_size();
let style = self.style();
let specified = if flags.contains(INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED) {
- Au::max(model::specified(style.min_inline_size(), Au(0)),
- MaybeAuto::from_style(style.content_inline_size(), Au(0)).specified_or_zero())
+ max(model::specified(style.min_inline_size(), Au(0)),
+ MaybeAuto::from_style(style.content_inline_size(), Au(0)).specified_or_zero())
} else {
Au(0)
};
@@ -1000,10 +1003,10 @@ impl Fragment {
match self.inline_context {
None => style_border_width,
Some(ref inline_fragment_context) => {
- inline_fragment_context.styles
+ inline_fragment_context.nodes
.iter()
.fold(style_border_width,
- |acc, style| acc + style.logical_border_width())
+ |acc, node| acc + node.style.logical_border_width())
}
}
}
@@ -1092,10 +1095,10 @@ impl Fragment {
match self.inline_context {
None => style_padding,
Some(ref inline_fragment_context) => {
- inline_fragment_context.styles
+ inline_fragment_context.nodes
.iter()
- .fold(style_padding, |acc, style| {
- acc + model::padding_from_style(&**style,
+ .fold(style_padding, |acc, node| {
+ acc + model::padding_from_style(&*node.style,
Au(0))
})
}
@@ -1136,9 +1139,9 @@ impl Fragment {
};
if let Some(ref inline_fragment_context) = self.inline_context {
- for style in inline_fragment_context.styles.iter() {
- if style.get_box().position == position::T::relative {
- rel_pos = rel_pos + from_style(&**style, containing_block_size);
+ for node in inline_fragment_context.nodes.iter() {
+ if node.style.get_box().position == position::T::relative {
+ rel_pos = rel_pos + from_style(&*node.style, containing_block_size);
}
}
}
@@ -1282,10 +1285,10 @@ impl Fragment {
// Take borders and padding for parent inline fragments into account, if necessary.
if self.is_primary_fragment() {
if let Some(ref context) = self.inline_context {
- for style in context.styles.iter() {
- let border_width = style.logical_border_width().inline_start_end();
+ for node in context.nodes.iter() {
+ let border_width = node.style.logical_border_width().inline_start_end();
let padding_inline_size =
- model::padding_from_style(&**style, Au(0)).inline_start_end();
+ model::padding_from_style(&*node.style, Au(0)).inline_start_end();
result.surrounding_size = result.surrounding_size + border_width +
padding_inline_size;
}
@@ -2097,11 +2100,11 @@ impl<'a> Iterator for InlineStyleIterator<'a> {
Some(ref inline_context) => inline_context,
};
let inline_style_index = self.inline_style_index;
- if inline_style_index == inline_context.styles.len() {
+ if inline_style_index == inline_context.nodes.len() {
return None
}
self.inline_style_index += 1;
- Some(&*inline_context.styles[inline_style_index])
+ Some(&*inline_context.nodes[inline_style_index].style)
}
}