mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
servo: Merge #20079 - Replace IntegerOrAuto with ZIndex (from servo:ZEH-INDEX); r=emilio
It's its only use. Source-Repo: https://github.com/servo/servo Source-Revision: 05b8ba0a48947858ae256b6944b9ddd3c0379fba --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : b407c0b49f9a8d56f97d8533b5b9cb2293c0e646
This commit is contained in:
parent
78df2ae267
commit
6db99d699e
@ -58,7 +58,7 @@ use style::properties::ComputedValues;
|
||||
use style::selector_parser::RestyleDamage;
|
||||
use style::servo::restyle_damage::ServoRestyleDamage;
|
||||
use style::str::char_is_whitespace;
|
||||
use style::values::{self, Either, Auto};
|
||||
use style::values::{self, Either};
|
||||
use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use style::values::computed::counters::ContentItem;
|
||||
use style::values::generics::box_::VerticalAlign;
|
||||
@ -2512,7 +2512,7 @@ impl Fragment {
|
||||
// For absolutely and relatively positioned fragments we only establish a stacking
|
||||
// context if there is a z-index set.
|
||||
// See https://www.w3.org/TR/CSS2/visuren.html#z-index
|
||||
self.style().get_position().z_index != Either::Second(Auto)
|
||||
!self.style().get_position().z_index.is_auto()
|
||||
}
|
||||
|
||||
// Get the effective z-index of this fragment. Z-indices only apply to positioned element
|
||||
|
@ -262,7 +262,6 @@ class Longhand(object):
|
||||
"ImageOrientation",
|
||||
"InitialLetter",
|
||||
"Integer",
|
||||
"IntegerOrAuto",
|
||||
"JustifyContent",
|
||||
"JustifyItems",
|
||||
"JustifySelf",
|
||||
@ -283,6 +282,7 @@ class Longhand(object):
|
||||
"TransformStyle",
|
||||
"XSpan",
|
||||
"XTextZoom",
|
||||
"ZIndex",
|
||||
}
|
||||
return bool(self.keyword)
|
||||
|
||||
|
@ -62,6 +62,7 @@ use values::computed::{NonNegativeLength, ToComputedValue, Percentage};
|
||||
use values::computed::font::{FontSize, SingleFontFamily};
|
||||
use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
use values::computed::outline::OutlineStyle;
|
||||
use values::generics::position::ZIndex;
|
||||
use values::generics::transform::TransformStyle;
|
||||
use computed_values::border_style;
|
||||
|
||||
@ -1750,8 +1751,8 @@ fn static_assert() {
|
||||
|
||||
pub fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) {
|
||||
match v {
|
||||
Either::First(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)),
|
||||
Either::Second(Auto) => self.gecko.mZIndex.set_value(CoordDataValue::Auto),
|
||||
ZIndex::Integer(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)),
|
||||
ZIndex::Auto => self.gecko.mZIndex.set_value(CoordDataValue::Auto),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1771,11 +1772,11 @@ fn static_assert() {
|
||||
|
||||
pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
|
||||
return match self.gecko.mZIndex.as_value() {
|
||||
CoordDataValue::Integer(n) => Either::First(n),
|
||||
CoordDataValue::Auto => Either::Second(Auto),
|
||||
CoordDataValue::Integer(n) => ZIndex::Integer(n),
|
||||
CoordDataValue::Auto => ZIndex::Auto,
|
||||
_ => {
|
||||
debug_assert!(false);
|
||||
Either::First(0)
|
||||
ZIndex::Integer(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,12 +42,14 @@ macro_rules! impl_align_conversions {
|
||||
};
|
||||
}
|
||||
|
||||
${helpers.predefined_type("z-index", "IntegerOrAuto",
|
||||
"Either::Second(Auto)",
|
||||
spec="https://www.w3.org/TR/CSS2/visuren.html#z-index",
|
||||
flags="CREATES_STACKING_CONTEXT",
|
||||
animation_value_type="ComputedValue")}
|
||||
|
||||
${helpers.predefined_type(
|
||||
"z-index",
|
||||
"ZIndex",
|
||||
"computed::ZIndex::auto()",
|
||||
spec="https://www.w3.org/TR/CSS2/visuren.html#z-index",
|
||||
flags="CREATES_STACKING_CONTEXT",
|
||||
animation_value_type="ComputedValue",
|
||||
)}
|
||||
|
||||
// CSS Flexible Box Layout Module Level 1
|
||||
// http://www.w3.org/TR/css3-flexbox/
|
||||
|
@ -68,7 +68,7 @@ pub use self::list::{ListStyleImage, Quotes};
|
||||
pub use self::list::ListStyleType;
|
||||
pub use self::outline::OutlineStyle;
|
||||
pub use self::percentage::Percentage;
|
||||
pub use self::position::{Position, GridAutoFlow, GridTemplateAreas};
|
||||
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position, ZIndex};
|
||||
pub use self::pointing::Cursor;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::pointing::CursorImage;
|
||||
@ -524,20 +524,6 @@ pub type Opacity = CSSFloat;
|
||||
/// A `<integer>` value.
|
||||
pub type Integer = CSSInteger;
|
||||
|
||||
/// <integer> | auto
|
||||
pub type IntegerOrAuto = Either<CSSInteger, Auto>;
|
||||
|
||||
impl IntegerOrAuto {
|
||||
/// Returns the integer value if it is an integer, otherwise return
|
||||
/// the given value.
|
||||
pub fn integer_or(&self, auto_value: CSSInteger) -> CSSInteger {
|
||||
match *self {
|
||||
Either::First(n) => n,
|
||||
Either::Second(Auto) => auto_value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper of Integer, but only accept a value >= 1.
|
||||
pub type PositiveInteger = GreaterThanOrEqualToOne<CSSInteger>;
|
||||
|
||||
|
@ -9,8 +9,9 @@
|
||||
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use values::computed::{LengthOrPercentage, Percentage};
|
||||
use values::computed::{Integer, LengthOrPercentage, Percentage};
|
||||
use values::generics::position::Position as GenericPosition;
|
||||
use values::generics::position::ZIndex as GenericZIndex;
|
||||
pub use values::specified::position::{GridAutoFlow, GridTemplateAreas};
|
||||
|
||||
/// The computed value of a CSS `<position>`
|
||||
@ -49,3 +50,6 @@ impl ToCss for Position {
|
||||
self.vertical.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
/// A computed value for the `z-index` property.
|
||||
pub type ZIndex = GenericZIndex<Integer>;
|
||||
|
@ -24,3 +24,36 @@ impl<H, V> Position<H, V> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic value for the `z-index` property.
|
||||
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)]
|
||||
#[derive(MallocSizeOf, PartialEq, ToAnimatedZero, ToComputedValue, ToCss)]
|
||||
pub enum ZIndex<Integer> {
|
||||
/// An integer value.
|
||||
Integer(Integer),
|
||||
/// The keyword `auto`.
|
||||
Auto,
|
||||
}
|
||||
|
||||
impl<Integer> ZIndex<Integer> {
|
||||
/// Returns `auto`
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
ZIndex::Auto
|
||||
}
|
||||
|
||||
/// Returns whether `self` is `auto`.
|
||||
#[inline]
|
||||
pub fn is_auto(self) -> bool {
|
||||
matches!(self, ZIndex::Auto)
|
||||
}
|
||||
|
||||
/// Returns the integer value if it is an integer, or `auto`.
|
||||
#[inline]
|
||||
pub fn integer_or(self, auto: Integer) -> Integer {
|
||||
match self {
|
||||
ZIndex::Integer(n) => n,
|
||||
ZIndex::Auto => auto,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,8 @@ pub use self::list::ListStyleType;
|
||||
pub use self::outline::OutlineStyle;
|
||||
pub use self::rect::LengthOrNumberRect;
|
||||
pub use self::percentage::Percentage;
|
||||
pub use self::position::{Position, PositionComponent, GridAutoFlow, GridTemplateAreas};
|
||||
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position};
|
||||
pub use self::position::{PositionComponent, ZIndex};
|
||||
pub use self::pointing::Cursor;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::pointing::CursorImage;
|
||||
@ -518,24 +519,6 @@ impl ToCss for Integer {
|
||||
}
|
||||
}
|
||||
|
||||
/// <integer> | auto
|
||||
pub type IntegerOrAuto = Either<Integer, Auto>;
|
||||
|
||||
impl IntegerOrAuto {
|
||||
/// Parse `auto` or a positive integer.
|
||||
pub fn parse_positive<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<IntegerOrAuto, ParseError<'i>> {
|
||||
match IntegerOrAuto::parse(context, input) {
|
||||
Ok(Either::First(integer)) if integer.value() <= 0 => {
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
result => result,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper of Integer, with value >= 1.
|
||||
pub type PositiveInteger = GreaterThanOrEqualToOne<Integer>;
|
||||
|
||||
|
@ -20,7 +20,8 @@ use values::{Either, None_};
|
||||
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage as ComputedLengthOrPercentage};
|
||||
use values::computed::{Context, Percentage, ToComputedValue};
|
||||
use values::generics::position::Position as GenericPosition;
|
||||
use values::specified::{AllowQuirks, LengthOrPercentage};
|
||||
use values::generics::position::ZIndex as GenericZIndex;
|
||||
use values::specified::{AllowQuirks, Integer, LengthOrPercentage};
|
||||
use values::specified::transform::OriginComponent;
|
||||
|
||||
/// The specified value of a CSS `<position>`
|
||||
@ -702,3 +703,18 @@ impl GridTemplateAreas {
|
||||
Either::Second(None_)
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified value for the `z-index` property.
|
||||
pub type ZIndex = GenericZIndex<Integer>;
|
||||
|
||||
impl Parse for ZIndex {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
return Ok(GenericZIndex::Auto);
|
||||
}
|
||||
Ok(GenericZIndex::Integer(Integer::parse(context, input)?))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user