Convert back to physical some layout coordinates.

This commit is contained in:
Simon Sapin 2014-08-19 00:56:28 +01:00
parent 36ed8d4212
commit 353b1a17d5
5 changed files with 71 additions and 71 deletions

View file

@ -1110,16 +1110,18 @@ impl BlockFlow {
.relative_containing_block_size, .relative_containing_block_size,
None); None);
// FIXME(#2795): Get the real container size
let container_size = Size2D::zero();
// Add the box that starts the block context. // Add the box that starts the block context.
let mut display_list = DisplayList::new(); let mut display_list = DisplayList::new();
let mut accumulator = let mut accumulator = self.fragment.build_display_list(
self.fragment.build_display_list(&mut display_list, &mut display_list,
layout_context, layout_context,
self.base.abs_position self.base.abs_position + (offset + rel_offset).to_physical(
.add_point(&offset) self.base.writing_mode, container_size),
+ rel_offset, background_border_level,
background_border_level, None);
None);
let mut child_layers = DList::new(); let mut child_layers = DList::new();
for kid in self.base.child_iter() { for kid in self.base.child_iter() {
@ -1592,17 +1594,22 @@ impl Flow for BlockFlow {
} }
fn compute_absolute_position(&mut self) { fn compute_absolute_position(&mut self) {
// FIXME(#2795): Get the real container size
let container_size = Size2D::zero();
if self.is_absolutely_positioned() { if self.is_absolutely_positioned() {
let position_start = self.base.position.start.to_physical(
self.base.writing_mode, container_size);
self.base self.base
.absolute_position_info .absolute_position_info
.absolute_containing_block_position = if self.is_fixed() { .absolute_containing_block_position = if self.is_fixed() {
// The viewport is initially at (0, 0). // The viewport is initially at (0, 0).
self.base.position.start position_start
} else { } else {
// Absolute position of the containing block + position of absolute flow w/r/t the // Absolute position of the containing block + position of absolute flow w/r/t the
// containing block. // containing block.
self.base.absolute_position_info.absolute_containing_block_position self.base.absolute_position_info.absolute_containing_block_position
.add_point(&self.base.position.start) + position_start
}; };
// Set the absolute position, which will be passed down later as part // Set the absolute position, which will be passed down later as part
@ -1622,8 +1629,8 @@ impl Flow for BlockFlow {
if self.is_positioned() { if self.is_positioned() {
self.base.absolute_position_info.absolute_containing_block_position = self.base.absolute_position_info.absolute_containing_block_position =
self.base.abs_position self.base.abs_position
.add_point(&self.generated_containing_block_rect().start) + (self.generated_containing_block_rect().start
+ relative_offset + relative_offset).to_physical(self.base.writing_mode, container_size)
} }
let float_offset = if self.is_float() { let float_offset = if self.is_float() {
@ -1640,14 +1647,14 @@ impl Flow for BlockFlow {
// Process children. // Process children.
let this_position = self.base.abs_position; let this_position = self.base.abs_position;
let writing_mode = self.base.writing_mode;
for kid in self.base.child_iter() { for kid in self.base.child_iter() {
if !kid.is_absolutely_positioned() { if !kid.is_absolutely_positioned() {
let kid_base = flow::mut_base(kid); let kid_base = flow::mut_base(kid);
kid_base.abs_position = kid_base.abs_position = this_position + (
this_position kid_base.position.start
.add_point(&kid_base.position.start)
.add_point(&float_offset) .add_point(&float_offset)
+ relative_offset; + relative_offset).to_physical(writing_mode, container_size);
kid_base.absolute_position_info = absolute_position_info kid_base.absolute_position_info = absolute_position_info
} }
} }

View file

@ -46,13 +46,15 @@ use table_cell::TableCellFlow;
use wrapper::ThreadSafeLayoutNode; use wrapper::ThreadSafeLayoutNode;
use collections::dlist::DList; use collections::dlist::DList;
use geom::Point2D;
use gfx::display_list::DisplayList; use gfx::display_list::DisplayList;
use gfx::render_task::RenderLayer; use gfx::render_task::RenderLayer;
use servo_msg::compositor_msg::LayerId; use servo_msg::compositor_msg::LayerId;
use servo_util::geometry::Au; use servo_util::geometry::Au;
use servo_util::logical_geometry::WritingMode; use servo_util::logical_geometry::WritingMode;
use servo_util::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize}; use servo_util::logical_geometry::{LogicalRect, LogicalSize};
use std::mem; use std::mem;
use std::num::Zero;
use std::fmt; use std::fmt;
use std::iter::Zip; use std::iter::Zip;
use std::sync::atomics::{AtomicUint, Relaxed, SeqCst}; use std::sync::atomics::{AtomicUint, Relaxed, SeqCst};
@ -596,7 +598,7 @@ pub struct AbsolutePositionInfo {
/// The size of the containing block for relatively-positioned descendants. /// The size of the containing block for relatively-positioned descendants.
pub relative_containing_block_size: LogicalSize<Au>, pub relative_containing_block_size: LogicalSize<Au>,
/// The position of the absolute containing block. /// The position of the absolute containing block.
pub absolute_containing_block_position: LogicalPoint<Au>, pub absolute_containing_block_position: Point2D<Au>,
/// Whether the absolute containing block forces positioned descendants to be layerized. /// Whether the absolute containing block forces positioned descendants to be layerized.
/// ///
/// FIXME(pcwalton): Move into `FlowFlags`. /// FIXME(pcwalton): Move into `FlowFlags`.
@ -609,7 +611,7 @@ impl AbsolutePositionInfo {
// of the root layer. // of the root layer.
AbsolutePositionInfo { AbsolutePositionInfo {
relative_containing_block_size: LogicalSize::zero(writing_mode), relative_containing_block_size: LogicalSize::zero(writing_mode),
absolute_containing_block_position: LogicalPoint::zero(writing_mode), absolute_containing_block_position: Zero::zero(),
layers_needed_for_positioned_flows: false, layers_needed_for_positioned_flows: false,
} }
} }
@ -660,7 +662,7 @@ pub struct BaseFlow {
pub collapsible_margins: CollapsibleMargins, pub collapsible_margins: CollapsibleMargins,
/// The position of this flow in page coordinates, computed during display list construction. /// The position of this flow in page coordinates, computed during display list construction.
pub abs_position: LogicalPoint<Au>, pub abs_position: Point2D<Au>,
/// Details about descendants with position 'absolute' or 'fixed' for which we are the /// Details about descendants with position 'absolute' or 'fixed' for which we are the
/// containing block. This is in tree order. This includes any direct children. /// containing block. This is in tree order. This includes any direct children.
@ -724,7 +726,7 @@ impl BaseFlow {
floats: Floats::new(writing_mode), floats: Floats::new(writing_mode),
collapsible_margins: CollapsibleMargins::new(), collapsible_margins: CollapsibleMargins::new(),
abs_position: LogicalPoint::zero(writing_mode), abs_position: Zero::zero(),
abs_descendants: Descendants::new(), abs_descendants: Descendants::new(),
absolute_static_i_offset: Au::new(0), absolute_static_i_offset: Au::new(0),
fixed_static_i_offset: Au::new(0), fixed_static_i_offset: Au::new(0),

View file

@ -37,7 +37,7 @@ use servo_net::image::holder::ImageHolder;
use servo_net::local_image_cache::LocalImageCache; use servo_net::local_image_cache::LocalImageCache;
use servo_util::geometry::Au; use servo_util::geometry::Au;
use servo_util::geometry; use servo_util::geometry;
use servo_util::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, LogicalMargin}; use servo_util::logical_geometry::{LogicalRect, LogicalSize, LogicalMargin};
use servo_util::range::*; use servo_util::range::*;
use servo_util::namespace; use servo_util::namespace;
use servo_util::smallvec::SmallVec; use servo_util::smallvec::SmallVec;
@ -776,15 +776,15 @@ impl Fragment {
fn build_debug_borders_around_text_fragments(&self, fn build_debug_borders_around_text_fragments(&self,
display_list: &mut DisplayList, display_list: &mut DisplayList,
flow_origin: LogicalPoint<Au>, flow_origin: Point2D<Au>,
text_fragment: &ScannedTextFragmentInfo) { text_fragment: &ScannedTextFragmentInfo) {
let mut fragment_bounds = self.border_box.clone();
fragment_bounds.start.i = fragment_bounds.start.i + flow_origin.i;
fragment_bounds.start.b = fragment_bounds.start.b + flow_origin.b;
// FIXME(#2795): Get the real container size // FIXME(#2795): Get the real container size
let container_size = Size2D::zero(); let container_size = Size2D::zero();
let absolute_fragment_bounds = fragment_bounds.to_physical( // Fragment position wrt to the owning flow.
self.style.writing_mode, container_size); let fragment_bounds = self.border_box.to_physical(self.style.writing_mode, container_size);
let absolute_fragment_bounds = Rect(
fragment_bounds.origin + flow_origin,
fragment_bounds.size);
// Compute the text fragment bounds and draw a border surrounding them. // Compute the text fragment bounds and draw a border surrounding them.
let border_display_item = box BorderDisplayItem { let border_display_item = box BorderDisplayItem {
@ -797,13 +797,11 @@ impl Fragment {
// Draw a rectangle representing the baselines. // Draw a rectangle representing the baselines.
let ascent = text_fragment.run.ascent(); let ascent = text_fragment.run.ascent();
let baseline = LogicalRect::new( let mut baseline = self.border_box.clone();
self.style.writing_mode, baseline.start.b = baseline.start.b + ascent;
fragment_bounds.start.i, baseline.size.block = Au(0);
fragment_bounds.start.b + ascent, let mut baseline = baseline.to_physical(self.style.writing_mode, container_size);
fragment_bounds.size.inline, baseline.origin = baseline.origin + flow_origin;
Au(0)
).to_physical(self.style.writing_mode, container_size);
let line_display_item = box LineDisplayItem { let line_display_item = box LineDisplayItem {
base: BaseDisplayItem::new(baseline, self.node, ContentStackingLevel), base: BaseDisplayItem::new(baseline, self.node, ContentStackingLevel),
@ -815,14 +813,14 @@ impl Fragment {
fn build_debug_borders_around_fragment(&self, fn build_debug_borders_around_fragment(&self,
display_list: &mut DisplayList, display_list: &mut DisplayList,
flow_origin: LogicalPoint<Au>) { flow_origin: Point2D<Au>) {
let mut fragment_bounds = self.border_box.clone();
fragment_bounds.start.i = fragment_bounds.start.i + flow_origin.i;
fragment_bounds.start.b = fragment_bounds.start.b + flow_origin.b;
// FIXME(#2795): Get the real container size // FIXME(#2795): Get the real container size
let container_size = Size2D::zero(); let container_size = Size2D::zero();
let absolute_fragment_bounds = fragment_bounds.to_physical( // Fragment position wrt to the owning flow.
self.style.writing_mode, container_size); let fragment_bounds = self.border_box.to_physical(self.style.writing_mode, container_size);
let absolute_fragment_bounds = Rect(
fragment_bounds.origin + flow_origin,
fragment_bounds.size);
// This prints a debug border around the border of this fragment. // This prints a debug border around the border of this fragment.
let border_display_item = box BorderDisplayItem { let border_display_item = box BorderDisplayItem {
@ -845,18 +843,17 @@ impl Fragment {
pub fn build_display_list(&self, pub fn build_display_list(&self,
display_list: &mut DisplayList, display_list: &mut DisplayList,
layout_context: &LayoutContext, layout_context: &LayoutContext,
flow_origin: LogicalPoint<Au>, flow_origin: Point2D<Au>,
background_and_border_level: BackgroundAndBorderLevel, background_and_border_level: BackgroundAndBorderLevel,
inline_fragment_context: Option<InlineFragmentContext>) inline_fragment_context: Option<InlineFragmentContext>)
-> ChildDisplayListAccumulator { -> ChildDisplayListAccumulator {
// Fragment position wrt to the owning flow.
let mut fragment_bounds = self.border_box.clone();
fragment_bounds.start.i = fragment_bounds.start.i + flow_origin.i;
fragment_bounds.start.b = fragment_bounds.start.b + flow_origin.b;
// FIXME(#2795): Get the real container size // FIXME(#2795): Get the real container size
let container_size = Size2D::zero(); let container_size = Size2D::zero();
let absolute_fragment_bounds = fragment_bounds.to_physical( // Fragment position wrt to the owning flow.
self.style.writing_mode, container_size); let fragment_bounds = self.border_box.to_physical(self.style.writing_mode, container_size);
let absolute_fragment_bounds = Rect(
fragment_bounds.origin + flow_origin,
fragment_bounds.size);
debug!("Fragment::build_display_list at rel={}, abs={}: {}", debug!("Fragment::build_display_list at rel={}, abs={}: {}",
self.border_box, self.border_box,
absolute_fragment_bounds, absolute_fragment_bounds,
@ -1413,21 +1410,18 @@ impl Fragment {
#[inline(never)] #[inline(never)]
fn finalize_position_and_size_of_iframe(&self, fn finalize_position_and_size_of_iframe(&self,
iframe_fragment: &IframeFragmentInfo, iframe_fragment: &IframeFragmentInfo,
offset: LogicalPoint<Au>, offset: Point2D<Au>,
layout_context: &LayoutContext) { layout_context: &LayoutContext) {
let inline_start = offset.i + self.margin.inline_start + self.border_padding.inline_start; let mbp = (self.margin + self.border_padding).to_physical(self.style.writing_mode);
let block_start = offset.b + self.margin.block_start + self.border_padding.block_start; let content_size = self.content_box().size.to_physical(self.style.writing_mode);
let inline_size = self.content_box().size.inline;
let block_size = self.content_box().size.block; let left = offset.x + mbp.left;
// FIXME(#2795): Get the real container size let top = offset.y + mbp.top;
let container_size = Size2D::zero(); let width = content_size.width;
let rect = LogicalRect::new( let height = content_size.height;
self.style.writing_mode, let origin = Point2D(geometry::to_frac_px(left) as f32, geometry::to_frac_px(top) as f32);
geometry::to_frac_px(inline_start) as f32, let size = Size2D(geometry::to_frac_px(width) as f32, geometry::to_frac_px(height) as f32);
geometry::to_frac_px(block_start) as f32, let rect = Rect(origin, size);
geometry::to_frac_px(inline_size) as f32,
geometry::to_frac_px(block_size) as f32
).to_physical(self.style.writing_mode, container_size);
debug!("finalizing position and size of iframe for {:?},{:?}", debug!("finalizing position and size of iframe for {:?},{:?}",
iframe_fragment.pipeline_id, iframe_fragment.pipeline_id,

View file

@ -16,7 +16,7 @@ use text;
use wrapper::ThreadSafeLayoutNode; use wrapper::ThreadSafeLayoutNode;
use collections::{Deque, RingBuf}; use collections::{Deque, RingBuf};
use geom::Size2D; use geom::Rect;
use gfx::display_list::ContentLevel; use gfx::display_list::ContentLevel;
use gfx::font::FontMetrics; use gfx::font::FontMetrics;
use gfx::font_context::FontContext; use gfx::font_context::FontContext;
@ -927,12 +927,8 @@ impl InlineFlow {
} }
pub fn build_display_list_inline(&mut self, layout_context: &LayoutContext) { pub fn build_display_list_inline(&mut self, layout_context: &LayoutContext) {
let abs_rect = LogicalRect::from_point_size( let size = self.base.position.size.to_physical(self.base.writing_mode);
self.base.writing_mode, self.base.abs_position, self.base.position.size); if !Rect(self.base.abs_position, size).intersects(&layout_context.shared.dirty) {
// FIXME(#2795): Get the real container size
let container_size = Size2D::zero();
if !abs_rect.to_physical(self.base.writing_mode, container_size)
.intersects(&layout_context.shared.dirty) {
return return
} }
@ -947,7 +943,8 @@ impl InlineFlow {
Some(context)); Some(context));
drop(fragment.build_display_list(&mut self.base.display_list, drop(fragment.build_display_list(&mut self.base.display_list,
layout_context, layout_context,
self.base.abs_position + rel_offset, self.base.abs_position.add_size(
&rel_offset.to_physical(self.base.writing_mode)),
ContentLevel, ContentLevel,
Some(context))); Some(context)));
} }

@ -1 +1 @@
Subproject commit b41f144a3a8b6388d0956f341bcffa5bbaecc899 Subproject commit c733f78e06bd02f7498e93b391e0f6094d91786a