mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Switch z-index to use predefined integer type
This commit is contained in:
parent
b489c4ed90
commit
9233882d49
4 changed files with 17 additions and 78 deletions
|
@ -42,14 +42,14 @@ use std::sync::{Arc, Mutex};
|
||||||
use style::arc_ptr_eq;
|
use style::arc_ptr_eq;
|
||||||
use style::computed_values::{border_collapse, box_sizing, clear, color, display, mix_blend_mode};
|
use style::computed_values::{border_collapse, box_sizing, clear, color, display, mix_blend_mode};
|
||||||
use style::computed_values::{overflow_wrap, overflow_x, position, text_decoration_line, transform};
|
use style::computed_values::{overflow_wrap, overflow_x, position, text_decoration_line, transform};
|
||||||
use style::computed_values::{transform_style, vertical_align, white_space, word_break, z_index};
|
use style::computed_values::{transform_style, vertical_align, white_space, word_break};
|
||||||
use style::computed_values::content::ContentItem;
|
use style::computed_values::content::ContentItem;
|
||||||
use style::logical_geometry::{Direction, LogicalMargin, LogicalRect, LogicalSize, WritingMode};
|
use style::logical_geometry::{Direction, LogicalMargin, LogicalRect, LogicalSize, WritingMode};
|
||||||
use style::properties::ServoComputedValues;
|
use style::properties::ServoComputedValues;
|
||||||
use style::selector_parser::RestyleDamage;
|
use style::selector_parser::RestyleDamage;
|
||||||
use style::servo::restyle_damage::RECONSTRUCT_FLOW;
|
use style::servo::restyle_damage::RECONSTRUCT_FLOW;
|
||||||
use style::str::char_is_whitespace;
|
use style::str::char_is_whitespace;
|
||||||
use style::values::{self, Either};
|
use style::values::{self, Either, Auto};
|
||||||
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
use text;
|
use text;
|
||||||
use text::TextRunScanner;
|
use text::TextRunScanner;
|
||||||
|
@ -2512,15 +2512,15 @@ impl Fragment {
|
||||||
self.style().get_box().overflow_x,
|
self.style().get_box().overflow_x,
|
||||||
self.style().get_box().overflow_y.0) {
|
self.style().get_box().overflow_y.0) {
|
||||||
(position::T::absolute,
|
(position::T::absolute,
|
||||||
z_index::T::Auto,
|
Either::Second(Auto),
|
||||||
overflow_x::T::visible,
|
overflow_x::T::visible,
|
||||||
overflow_x::T::visible) |
|
overflow_x::T::visible) |
|
||||||
(position::T::fixed,
|
(position::T::fixed,
|
||||||
z_index::T::Auto,
|
Either::Second(Auto),
|
||||||
overflow_x::T::visible,
|
overflow_x::T::visible,
|
||||||
overflow_x::T::visible) |
|
overflow_x::T::visible) |
|
||||||
(position::T::relative,
|
(position::T::relative,
|
||||||
z_index::T::Auto,
|
Either::Second(Auto),
|
||||||
overflow_x::T::visible,
|
overflow_x::T::visible,
|
||||||
overflow_x::T::visible) => false,
|
overflow_x::T::visible) => false,
|
||||||
(position::T::absolute, _, _, _) |
|
(position::T::absolute, _, _, _) |
|
||||||
|
@ -2536,15 +2536,15 @@ impl Fragment {
|
||||||
pub fn effective_z_index(&self) -> i32 {
|
pub fn effective_z_index(&self) -> i32 {
|
||||||
match self.style().get_box().position {
|
match self.style().get_box().position {
|
||||||
position::T::static_ => {},
|
position::T::static_ => {},
|
||||||
_ => return self.style().get_position().z_index.number_or_zero(),
|
_ => return self.style().get_position().z_index.integer_or(0),
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.style().get_box().transform.0.is_some() {
|
if self.style().get_box().transform.0.is_some() {
|
||||||
return self.style().get_position().z_index.number_or_zero();
|
return self.style().get_position().z_index.integer_or(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.style().get_box().display {
|
match self.style().get_box().display {
|
||||||
display::T::flex => self.style().get_position().z_index.number_or_zero(),
|
display::T::flex => self.style().get_position().z_index.integer_or(0),
|
||||||
_ => 0,
|
_ => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -962,10 +962,9 @@ fn static_assert() {
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
pub fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) {
|
pub fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) {
|
||||||
use properties::longhands::z_index::computed_value::T;
|
|
||||||
match v {
|
match v {
|
||||||
T::Auto => self.gecko.mZIndex.set_value(CoordDataValue::Auto),
|
Either::First(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)),
|
||||||
T::Number(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)),
|
Either::Second(Auto) => self.gecko.mZIndex.set_value(CoordDataValue::Auto),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -980,13 +979,12 @@ fn static_assert() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
|
pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
|
||||||
use properties::longhands::z_index::computed_value::T;
|
|
||||||
return match self.gecko.mZIndex.as_value() {
|
return match self.gecko.mZIndex.as_value() {
|
||||||
CoordDataValue::Auto => T::Auto,
|
CoordDataValue::Integer(n) => Either::First(n),
|
||||||
CoordDataValue::Integer(n) => T::Number(n),
|
CoordDataValue::Auto => Either::Second(Auto),
|
||||||
_ => {
|
_ => {
|
||||||
debug_assert!(false);
|
debug_assert!(false);
|
||||||
T::Number(0)
|
Either::First(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ use properties::longhands::transform::computed_value::ComputedOperation as Trans
|
||||||
use properties::longhands::transform::computed_value::T as TransformList;
|
use properties::longhands::transform::computed_value::T as TransformList;
|
||||||
use properties::longhands::vertical_align::computed_value::T as VerticalAlign;
|
use properties::longhands::vertical_align::computed_value::T as VerticalAlign;
|
||||||
use properties::longhands::visibility::computed_value::T as Visibility;
|
use properties::longhands::visibility::computed_value::T as Visibility;
|
||||||
use properties::longhands::z_index::computed_value::T as ZIndex;
|
|
||||||
#[cfg(feature = "gecko")] use properties::{PropertyDeclarationId, LonghandId};
|
#[cfg(feature = "gecko")] use properties::{PropertyDeclarationId, LonghandId};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -472,20 +471,6 @@ impl Interpolate for Visibility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-transitions/#animtype-integer
|
|
||||||
impl Interpolate for ZIndex {
|
|
||||||
#[inline]
|
|
||||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
|
||||||
match (*self, *other) {
|
|
||||||
(ZIndex::Number(ref this),
|
|
||||||
ZIndex::Number(ref other)) => {
|
|
||||||
this.interpolate(other, progress).map(ZIndex::Number)
|
|
||||||
}
|
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Interpolate + Copy> Interpolate for Size2D<T> {
|
impl<T: Interpolate + Copy> Interpolate for Size2D<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||||
|
|
|
@ -23,54 +23,10 @@
|
||||||
animatable=True, logical=True)}
|
animatable=True, logical=True)}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
<%helpers:longhand name="z-index" spec="https://www.w3.org/TR/CSS2/visuren.html#z-index" animatable="True">
|
${helpers.predefined_type("z-index", "IntegerOrAuto",
|
||||||
use values::HasViewportPercentage;
|
"Either::Second(Auto)",
|
||||||
use values::computed::ComputedValueAsSpecified;
|
spec="https://www.w3.org/TR/CSS2/visuren.html#z-index",
|
||||||
|
animatable="True")}
|
||||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
|
||||||
no_viewport_percentage!(SpecifiedValue);
|
|
||||||
pub type SpecifiedValue = computed_value::T;
|
|
||||||
pub mod computed_value {
|
|
||||||
use std::fmt;
|
|
||||||
use style_traits::ToCss;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Eq, Copy, Debug)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
pub enum T {
|
|
||||||
Auto,
|
|
||||||
Number(i32),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for T {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
T::Auto => dest.write_str("auto"),
|
|
||||||
T::Number(number) => write!(dest, "{}", number),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl T {
|
|
||||||
pub fn number_or_zero(self) -> i32 {
|
|
||||||
match self {
|
|
||||||
T::Auto => 0,
|
|
||||||
T::Number(value) => value,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
|
||||||
computed_value::T::Auto
|
|
||||||
}
|
|
||||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
|
||||||
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
|
|
||||||
Ok(computed_value::T::Auto)
|
|
||||||
} else {
|
|
||||||
specified::parse_integer(input).map(computed_value::T::Number)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:longhand>
|
|
||||||
|
|
||||||
// CSS Flexible Box Layout Module Level 1
|
// CSS Flexible Box Layout Module Level 1
|
||||||
// http://www.w3.org/TR/css3-flexbox/
|
// http://www.w3.org/TR/css3-flexbox/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue