Skip to content

Commit

Permalink
Auto merge of #8023 - mrobinson:zindex, r=pcwalton
Browse files Browse the repository at this point in the history
Z-index should be ignored for non-positioned stacking contexts

When a stacking-context is not positioned, its z-index should be
ignored. This is per CSS 2 9.9.1. The only exception to this is when
the z-index is applied to an element with display: flex | inline-flex.
inline-flex does not appear to be implemented at this time so we only
do this for flex.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8023)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Oct 16, 2015
2 parents 96ca6b6 + f2a66af commit 90dd3cd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/layout/display_list_builder.rs
Expand Up @@ -1331,7 +1331,7 @@ impl FragmentDisplayListBuilding for Fragment {
Arc::new(StackingContext::new(display_list,
&border_box,
&overflow,
self.style().get_box().z_index.number_or_zero(),
self.effective_z_index(),
filters,
self.style().get_effects().mix_blend_mode,
transform,
Expand Down
25 changes: 22 additions & 3 deletions components/layout/fragment.rs
Expand Up @@ -35,9 +35,9 @@ use std::fmt;
use std::sync::{Arc, Mutex};
use string_cache::Atom;
use style::computed_values::content::ContentItem;
use style::computed_values::{border_collapse, clear, mix_blend_mode, overflow_wrap, overflow_x};
use style::computed_values::{position, text_align, text_decoration, transform_style, white_space};
use style::computed_values::{word_break, z_index};
use style::computed_values::{border_collapse, clear, display, mix_blend_mode, overflow_wrap};
use style::computed_values::{overflow_x, position, text_align, text_decoration, transform_style};
use style::computed_values::{white_space, word_break, z_index};
use style::properties::ComputedValues;
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::{LengthOrPercentageOrNone};
Expand Down Expand Up @@ -2166,6 +2166,25 @@ impl Fragment {
}
}

// Get the effective z-index of this fragment. Z-indices only apply to positioned element
// per CSS 2 9.9.1 (http://www.w3.org/TR/CSS2/visuren.html#z-index), so this value may differ
// from the value specified in the style.
pub fn effective_z_index(&self) -> i32 {
match self.style().get_box().position {
position::T::static_ => {},
_ => return self.style().get_box().z_index.number_or_zero(),
}

if self.style().get_effects().transform.0.is_some() {
return self.style().get_box().z_index.number_or_zero();
}

match self.style().get_box().display {
display::T::flex => self.style().get_box().z_index.number_or_zero(),
_ => 0,
}
}

/// Computes the overflow rect of this fragment relative to the start of the flow.
pub fn compute_overflow(&self,
flow_size: &Size2D<Au>,
Expand Down
7 changes: 7 additions & 0 deletions tests/wpt/mozilla/tests/css/stacked_layers.html
Expand Up @@ -20,5 +20,12 @@
<div class="grayer box" style="margin-left: 10px; margin-top: 10px; position: fixed;"></div>
<div class="gray box" style="margin-left: 20px; margin-top: 10px; position: absolute; top: 20px; z-index: 5;"> </div>
</div>

<!-- The z-index of the second box should be ignored since it is not a positioned element.
so these boxes stack in tree order. -->
<div class="test grayest box">
<div class="grayer box" style="margin-left: 10px; margin-top: 10px; opacity: 0.999; z-index: -1;"></div>
<div class="gray box" style="margin-left: 20px; margin-top: -40px; opacity: 0.999;"> </div>
</div>
</body>
</html>
7 changes: 6 additions & 1 deletion tests/wpt/mozilla/tests/css/stacked_layers_ref.html
Expand Up @@ -12,12 +12,17 @@
<body>
<div class="test grayest box">
<div class="grayer box" style="margin-left: 10px; margin-top: 10px; position: absolute;"></div>
<div class="gray box" style="margin-left: 20px; margin-top: 10px; position: relative; top: 10px; z-index: 5;"></div>
<div class="gray box" style="margin-left: 20px; margin-top: 20px; position: relative; z-index: 5;"></div>
</div>

<div class="test grayest box">
<div class="grayer box" style="margin-left: 10px; margin-top: 10px; position: absolute;"></div>
<div class="gray box" style="margin-left: 20px; margin-top: 10px; position: absolute; top: 20px; z-index: 5;"></div>
</div>

<div class="test grayest box">
<div class="grayer box" style="margin-left: 10px; margin-top: 10px; position: absolute; opacity: 0.999;"></div>
<div class="gray box" style="margin-left: 20px; margin-top: 20px; position: relative; opacity: 0.999;"></div>
</div>
</body>
</html>

0 comments on commit 90dd3cd

Please sign in to comment.