2014-10-15 05:33:28 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
//! Implements sequential traversals over the DOM and flow trees.
|
|
|
|
|
2015-10-01 00:19:33 +03:00
|
|
|
use app_units::Au;
|
2017-02-08 04:16:05 +03:00
|
|
|
use context::LayoutContext;
|
2018-01-07 17:53:18 +03:00
|
|
|
use display_list::{DisplayListBuildState, StackingContextCollectionState};
|
2017-06-14 17:25:05 +03:00
|
|
|
use euclid::{Point2D, Vector2D};
|
2016-03-26 04:38:41 +03:00
|
|
|
use floats::SpeculatedFloatPlacement;
|
2017-12-15 21:44:50 +03:00
|
|
|
use flow::{Flow, ImmutableFlowUtils, FlowFlags, GetBaseFlow};
|
2017-05-30 19:28:26 +03:00
|
|
|
use fragment::{FragmentBorderBoxIterator, CoordinateSystem};
|
2015-03-10 08:24:47 +03:00
|
|
|
use generated_content::ResolveGeneratedContent;
|
2017-04-23 07:55:22 +03:00
|
|
|
use incremental::RelayoutMode;
|
2016-12-15 03:48:42 +03:00
|
|
|
use servo_config::opts;
|
2017-10-31 02:25:45 +03:00
|
|
|
use style::servo::restyle_damage::ServoRestyleDamage;
|
2016-09-27 04:57:59 +03:00
|
|
|
use traversal::{AssignBSizes, AssignISizes, BubbleISizes, BuildDisplayList};
|
2017-08-08 22:04:23 +03:00
|
|
|
use traversal::{InorderFlowTraversal, PostorderFlowTraversal, PreorderFlowTraversal};
|
2018-02-24 18:06:16 +03:00
|
|
|
use webrender_api::LayoutPoint;
|
2015-01-05 04:51:48 +03:00
|
|
|
|
2017-02-08 04:16:05 +03:00
|
|
|
pub fn resolve_generated_content(root: &mut Flow, layout_context: &LayoutContext) {
|
2017-08-08 22:04:23 +03:00
|
|
|
ResolveGeneratedContent::new(&layout_context).traverse(root, 0);
|
2015-03-10 08:24:47 +03:00
|
|
|
}
|
|
|
|
|
2017-08-08 22:04:23 +03:00
|
|
|
/// Run the main layout passes sequentially.
|
|
|
|
pub fn reflow(root: &mut Flow, layout_context: &LayoutContext, relayout_mode: RelayoutMode) {
|
2014-10-29 02:21:48 +03:00
|
|
|
fn doit(flow: &mut Flow,
|
|
|
|
assign_inline_sizes: AssignISizes,
|
2017-04-23 07:55:22 +03:00
|
|
|
assign_block_sizes: AssignBSizes,
|
|
|
|
relayout_mode: RelayoutMode) {
|
|
|
|
// Force reflow children during this traversal. This is needed when we failed
|
|
|
|
// the float speculation of a block formatting context and need to fix it.
|
|
|
|
if relayout_mode == RelayoutMode::Force {
|
2017-12-15 21:44:50 +03:00
|
|
|
flow.mut_base()
|
2017-05-30 19:28:26 +03:00
|
|
|
.restyle_damage
|
2017-10-31 02:25:45 +03:00
|
|
|
.insert(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW);
|
2017-04-23 07:55:22 +03:00
|
|
|
}
|
|
|
|
|
2014-10-15 05:33:28 +04:00
|
|
|
if assign_inline_sizes.should_process(flow) {
|
|
|
|
assign_inline_sizes.process(flow);
|
|
|
|
}
|
|
|
|
|
2017-12-15 21:44:50 +03:00
|
|
|
for kid in flow.mut_base().child_iter_mut() {
|
2017-04-23 07:55:22 +03:00
|
|
|
doit(kid, assign_inline_sizes, assign_block_sizes, relayout_mode);
|
2014-10-15 05:33:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if assign_block_sizes.should_process(flow) {
|
|
|
|
assign_block_sizes.process(flow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 07:33:25 +04:00
|
|
|
if opts::get().bubble_inline_sizes_separately {
|
2017-05-30 19:28:26 +03:00
|
|
|
let bubble_inline_sizes = BubbleISizes {
|
|
|
|
layout_context: &layout_context,
|
|
|
|
};
|
2017-08-08 22:04:23 +03:00
|
|
|
bubble_inline_sizes.traverse(root);
|
2014-10-15 05:33:28 +04:00
|
|
|
}
|
|
|
|
|
2017-05-30 19:28:26 +03:00
|
|
|
let assign_inline_sizes = AssignISizes {
|
|
|
|
layout_context: &layout_context,
|
|
|
|
};
|
|
|
|
let assign_block_sizes = AssignBSizes {
|
|
|
|
layout_context: &layout_context,
|
|
|
|
};
|
2014-10-15 05:33:28 +04:00
|
|
|
|
2017-04-23 07:55:22 +03:00
|
|
|
doit(root, assign_inline_sizes, assign_block_sizes, relayout_mode);
|
2014-10-15 05:33:28 +04:00
|
|
|
}
|
|
|
|
|
2016-11-02 21:55:07 +03:00
|
|
|
pub fn build_display_list_for_subtree<'a>(flow_root: &mut Flow,
|
2017-02-08 04:16:05 +03:00
|
|
|
layout_context: &'a LayoutContext)
|
2016-11-02 21:55:07 +03:00
|
|
|
-> DisplayListBuildState<'a> {
|
2017-09-15 22:43:40 +03:00
|
|
|
let mut state = StackingContextCollectionState::new(layout_context.id);
|
2017-01-10 15:48:31 +03:00
|
|
|
flow_root.collect_stacking_contexts(&mut state);
|
2016-11-02 21:55:07 +03:00
|
|
|
|
2017-09-15 22:43:40 +03:00
|
|
|
let state = DisplayListBuildState::new(layout_context, state);
|
2017-05-30 19:28:26 +03:00
|
|
|
let mut build_display_list = BuildDisplayList {
|
|
|
|
state: state,
|
|
|
|
};
|
2016-08-25 12:52:24 +03:00
|
|
|
build_display_list.traverse(flow_root);
|
2016-11-02 21:55:07 +03:00
|
|
|
build_display_list.state
|
2014-10-15 05:33:28 +04:00
|
|
|
}
|
2014-11-03 22:03:37 +03:00
|
|
|
|
2017-05-30 19:28:26 +03:00
|
|
|
pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut Flow, iterator: &mut FragmentBorderBoxIterator) {
|
2015-01-05 04:51:48 +03:00
|
|
|
fn doit(flow: &mut Flow,
|
2015-08-04 03:39:43 +03:00
|
|
|
level: i32,
|
2015-01-05 04:51:48 +03:00
|
|
|
iterator: &mut FragmentBorderBoxIterator,
|
|
|
|
stacking_context_position: &Point2D<Au>) {
|
2015-08-04 03:39:43 +03:00
|
|
|
flow.iterate_through_fragment_border_boxes(iterator, level, stacking_context_position);
|
2014-11-03 22:03:37 +03:00
|
|
|
|
2017-12-15 21:44:50 +03:00
|
|
|
for kid in flow.mut_base().child_iter_mut() {
|
2017-05-30 19:28:26 +03:00
|
|
|
let mut stacking_context_position = *stacking_context_position;
|
|
|
|
if kid.is_block_flow() && kid.as_block().fragment.establishes_stacking_context() {
|
|
|
|
stacking_context_position = Point2D::new(kid.as_block().fragment.margin.inline_start, Au(0)) +
|
2017-12-15 21:44:50 +03:00
|
|
|
kid.base().stacking_relative_position +
|
2017-06-14 17:25:05 +03:00
|
|
|
stacking_context_position.to_vector();
|
2017-05-30 19:28:26 +03:00
|
|
|
let relative_position = kid.as_block()
|
2017-09-05 23:36:47 +03:00
|
|
|
.stacking_relative_border_box(CoordinateSystem::Own);
|
2017-05-30 19:28:26 +03:00
|
|
|
if let Some(matrix) = kid.as_block()
|
|
|
|
.fragment
|
|
|
|
.transform_matrix(&relative_position) {
|
2018-02-24 18:06:16 +03:00
|
|
|
let transform_matrix = matrix.transform_point2d(&LayoutPoint::zero());
|
2017-05-30 19:28:26 +03:00
|
|
|
stacking_context_position = stacking_context_position +
|
2017-06-14 17:25:05 +03:00
|
|
|
Vector2D::new(Au::from_f32_px(transform_matrix.x),
|
|
|
|
Au::from_f32_px(transform_matrix.y))
|
2017-05-30 19:28:26 +03:00
|
|
|
}
|
|
|
|
}
|
2015-08-16 17:37:40 +03:00
|
|
|
doit(kid, level + 1, iterator, &stacking_context_position);
|
2014-11-03 22:03:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-25 12:52:24 +03:00
|
|
|
doit(root, 0, iterator, &Point2D::zero());
|
2014-11-03 22:03:37 +03:00
|
|
|
}
|
2016-03-19 22:23:27 +03:00
|
|
|
|
|
|
|
pub fn store_overflow(layout_context: &LayoutContext, flow: &mut Flow) {
|
2017-12-15 21:44:50 +03:00
|
|
|
if !flow.base().restyle_damage.contains(ServoRestyleDamage::STORE_OVERFLOW) {
|
2017-05-30 19:28:26 +03:00
|
|
|
return;
|
2016-03-19 22:23:27 +03:00
|
|
|
}
|
|
|
|
|
2017-12-15 21:44:50 +03:00
|
|
|
for kid in flow.mut_base().child_iter_mut() {
|
2016-03-19 22:23:27 +03:00
|
|
|
store_overflow(layout_context, kid);
|
|
|
|
}
|
|
|
|
|
|
|
|
flow.store_overflow(layout_context);
|
|
|
|
|
2017-12-15 21:44:50 +03:00
|
|
|
flow.mut_base()
|
2017-05-30 19:28:26 +03:00
|
|
|
.restyle_damage
|
2017-10-31 02:25:45 +03:00
|
|
|
.remove(ServoRestyleDamage::STORE_OVERFLOW);
|
2016-03-19 22:23:27 +03:00
|
|
|
}
|
|
|
|
|
2016-03-26 04:38:41 +03:00
|
|
|
/// Guesses how much inline size will be taken up by floats on the left and right sides of the
|
|
|
|
/// given flow. This is needed to speculatively calculate the inline sizes of block formatting
|
|
|
|
/// contexts. The speculation typically succeeds, but if it doesn't we have to lay it out again.
|
|
|
|
pub fn guess_float_placement(flow: &mut Flow) {
|
2017-12-15 21:44:50 +03:00
|
|
|
if !flow.base().restyle_damage.intersects(ServoRestyleDamage::REFLOW) {
|
2017-05-30 19:28:26 +03:00
|
|
|
return;
|
2016-03-26 04:38:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let mut floats_in = SpeculatedFloatPlacement::compute_floats_in_for_first_child(flow);
|
2017-12-15 21:44:50 +03:00
|
|
|
for kid in flow.mut_base().child_iter_mut() {
|
|
|
|
if kid.base().flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) {
|
2016-04-16 02:55:12 +03:00
|
|
|
// Do not propagate floats in or out, but do propogate between kids.
|
|
|
|
guess_float_placement(kid);
|
|
|
|
} else {
|
|
|
|
floats_in.compute_floats_in(kid);
|
2017-12-15 21:44:50 +03:00
|
|
|
kid.mut_base().speculated_float_placement_in = floats_in;
|
2016-04-16 02:55:12 +03:00
|
|
|
guess_float_placement(kid);
|
2017-12-15 21:44:50 +03:00
|
|
|
floats_in = kid.base().speculated_float_placement_out;
|
2016-04-16 02:55:12 +03:00
|
|
|
}
|
2016-03-26 04:38:41 +03:00
|
|
|
}
|
|
|
|
floats_in.compute_floats_out(flow);
|
2017-12-15 21:44:50 +03:00
|
|
|
flow.mut_base().speculated_float_placement_out = floats_in
|
2016-03-26 04:38:41 +03:00
|
|
|
}
|