Allow inline elements to create reference frames

This is important so that transforms applied to elements actually apply
to the display items created for those elements.
This commit is contained in:
Martin Robinson 2018-06-22 18:13:30 +02:00 committed by Glenn Watson
parent 2d4b223cf4
commit d41c512e98
3 changed files with 67 additions and 19 deletions

View file

@ -576,6 +576,12 @@ pub trait FragmentDisplayListBuilding {
state: &mut StackingContextCollectionState,
) -> bool;
fn create_stacking_context_for_inline_block(
&mut self,
base: &BaseFlow,
state: &mut StackingContextCollectionState,
) -> bool;
/// Adds the display items necessary to paint the background of this fragment to the display
/// list if necessary.
fn build_display_list_for_background_if_applicable(
@ -816,6 +822,35 @@ impl FragmentDisplayListBuilding for Fragment {
}
}
fn create_stacking_context_for_inline_block(
&mut self,
base: &BaseFlow,
state: &mut StackingContextCollectionState,
) -> bool {
self.stacking_context_id = state.allocate_stacking_context_info(StackingContextType::Real);
let established_reference_frame = if self.can_establish_reference_frame() {
// WebRender currently creates reference frames automatically, so just add
// a placeholder node to allocate a ClipScrollNodeIndex for this reference frame.
self.established_reference_frame =
Some(state.add_clip_scroll_node(ClipScrollNode::placeholder()));
self.established_reference_frame
} else {
None
};
let current_stacking_context_id = state.current_stacking_context_id;
let stacking_context = self.create_stacking_context(
self.stacking_context_id,
&base,
StackingContextType::Real,
established_reference_frame,
state.current_clipping_and_scrolling,
);
state.add_stacking_context(current_stacking_context_id, stacking_context);
true
}
fn build_display_list_for_background_if_applicable(
&self,
state: &mut DisplayListBuildState,
@ -1562,6 +1597,11 @@ impl FragmentDisplayListBuilding for Fragment {
display_list_section: DisplayListSection,
clip: Rect<Au>,
) {
let previous_clipping_and_scrolling = state.current_clipping_and_scrolling;
if let Some(index) = self.established_reference_frame {
state.current_clipping_and_scrolling = ClippingAndScrolling::simple(index);
}
self.restyle_damage.remove(ServoRestyleDamage::REPAINT);
self.build_display_list_no_damage(
state,
@ -1569,7 +1609,9 @@ impl FragmentDisplayListBuilding for Fragment {
border_painting_mode,
display_list_section,
clip,
)
);
state.current_clipping_and_scrolling = previous_clipping_and_scrolling;
}
fn build_display_list_no_damage(
@ -2861,8 +2903,11 @@ impl InlineFlowDisplayListBuilding for InlineFlow {
.cloned()
.unwrap_or_else(Rect::max_rect);
let previous_cb_clipping_and_scrolling = state.containing_block_clipping_and_scrolling;
for fragment in self.fragments.fragments.iter_mut() {
let previous_cb_clipping_and_scrolling = state.containing_block_clipping_and_scrolling;
state.containing_block_clipping_and_scrolling = previous_cb_clipping_and_scrolling;
if establishes_containing_block_for_absolute(
StackingContextCollectionFlags::empty(),
fragment.style.get_box().position,
@ -2871,26 +2916,20 @@ impl InlineFlowDisplayListBuilding for InlineFlow {
state.current_clipping_and_scrolling;
}
// We clear this here, but it might be set again if we create a stacking context for
// this fragment.
fragment.established_reference_frame = None;
if !fragment.collect_stacking_contexts_for_blocklike_fragment(state) {
if fragment.establishes_stacking_context() {
fragment.stacking_context_id =
state.allocate_stacking_context_info(StackingContextType::Real);
let current_stacking_context_id = state.current_stacking_context_id;
let stacking_context = fragment.create_stacking_context(
fragment.stacking_context_id,
&self.base,
StackingContextType::Real,
None,
state.current_clipping_and_scrolling,
);
state.add_stacking_context(current_stacking_context_id, stacking_context);
} else {
if !fragment.establishes_stacking_context() {
fragment.stacking_context_id = state.current_stacking_context_id;
} else {
fragment.create_stacking_context_for_inline_block(&self.base, state);
}
}
// Reset the containing block clipping and scrolling before each loop iteration,
// so we don't pollute subsequent fragments.
state.containing_block_clipping_and_scrolling = previous_cb_clipping_and_scrolling;
}
}