mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
style: Use Rust types for perspective and z-index.
Differential Revision: https://phabricator.services.mozilla.com/D20381
This commit is contained in:
parent
6428ed726d
commit
74d7d5bc42
8 changed files with 17 additions and 87 deletions
|
@ -89,6 +89,8 @@ include = [
|
||||||
"BackgroundSize",
|
"BackgroundSize",
|
||||||
"BorderImageSlice",
|
"BorderImageSlice",
|
||||||
"NonNegativeLengthOrNumberRect",
|
"NonNegativeLengthOrNumberRect",
|
||||||
|
"Perspective",
|
||||||
|
"ZIndex",
|
||||||
]
|
]
|
||||||
item_types = ["enums", "structs", "typedefs"]
|
item_types = ["enums", "structs", "typedefs"]
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
|
||||||
use crate::values::computed::{Angle, Length, LengthPercentage};
|
use crate::values::computed::{Angle, Length, LengthPercentage};
|
||||||
use crate::values::computed::{Number, NumberOrPercentage, Percentage};
|
use crate::values::computed::{Number, NumberOrPercentage, Percentage};
|
||||||
use crate::values::generics::basic_shape::ShapeRadius;
|
use crate::values::generics::basic_shape::ShapeRadius;
|
||||||
use crate::values::generics::box_::Perspective;
|
|
||||||
use crate::values::generics::gecko::ScrollSnapPoint;
|
use crate::values::generics::gecko::ScrollSnapPoint;
|
||||||
use crate::values::generics::grid::{TrackBreadth, TrackKeyword};
|
use crate::values::generics::grid::{TrackBreadth, TrackKeyword};
|
||||||
use crate::values::generics::length::LengthPercentageOrAuto;
|
use crate::values::generics::length::LengthPercentageOrAuto;
|
||||||
|
@ -330,27 +329,6 @@ impl GeckoStyleCoordConvertible for ScrollSnapPoint<LengthPercentage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<L> GeckoStyleCoordConvertible for Perspective<L>
|
|
||||||
where
|
|
||||||
L: GeckoStyleCoordConvertible,
|
|
||||||
{
|
|
||||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
|
||||||
match *self {
|
|
||||||
Perspective::None => coord.set_value(CoordDataValue::None),
|
|
||||||
Perspective::Length(ref l) => l.to_gecko_style_coord(coord),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
|
||||||
use crate::gecko_bindings::structs::root::nsStyleUnit;
|
|
||||||
|
|
||||||
if coord.unit() == nsStyleUnit::eStyleUnit_None {
|
|
||||||
return Some(Perspective::None);
|
|
||||||
}
|
|
||||||
Some(Perspective::Length(L::from_gecko_style_coord(coord)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a given RGBA value to `nscolor`.
|
/// Convert a given RGBA value to `nscolor`.
|
||||||
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
||||||
((rgba.alpha as u32) << 24) |
|
((rgba.alpha as u32) << 24) |
|
||||||
|
|
|
@ -60,7 +60,6 @@ use crate::values::computed::BorderStyle;
|
||||||
use crate::values::computed::font::FontSize;
|
use crate::values::computed::font::FontSize;
|
||||||
use crate::values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
use crate::values::computed::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
use crate::values::generics::column::ColumnCount;
|
use crate::values::generics::column::ColumnCount;
|
||||||
use crate::values::generics::position::ZIndex;
|
|
||||||
use crate::values::generics::transform::TransformStyle;
|
use crate::values::generics::transform::TransformStyle;
|
||||||
use crate::values::generics::url::UrlOrNone;
|
use crate::values::generics::url::UrlOrNone;
|
||||||
|
|
||||||
|
@ -1378,7 +1377,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
||||||
"Opacity": impl_simple,
|
"Opacity": impl_simple,
|
||||||
"OverflowWrap": impl_simple,
|
"OverflowWrap": impl_simple,
|
||||||
"OverflowAnchor": impl_simple,
|
"OverflowAnchor": impl_simple,
|
||||||
"Perspective": impl_style_coord,
|
"Perspective": impl_simple,
|
||||||
"Position": impl_simple,
|
"Position": impl_simple,
|
||||||
"RGBAColor": impl_rgba_color,
|
"RGBAColor": impl_rgba_color,
|
||||||
"SVGLength": impl_svg_length,
|
"SVGLength": impl_svg_length,
|
||||||
|
@ -1389,6 +1388,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
||||||
"TransformOrigin": impl_transform_origin,
|
"TransformOrigin": impl_transform_origin,
|
||||||
"UserSelect": impl_simple,
|
"UserSelect": impl_simple,
|
||||||
"url::UrlOrNone": impl_css_url,
|
"url::UrlOrNone": impl_css_url,
|
||||||
|
"ZIndex": impl_simple,
|
||||||
}
|
}
|
||||||
|
|
||||||
def longhand_method(longhand):
|
def longhand_method(longhand):
|
||||||
|
@ -1655,7 +1655,7 @@ fn static_assert() {
|
||||||
|
|
||||||
<% skip_position_longhands = " ".join(x.ident for x in SIDES + GRID_LINES) %>
|
<% skip_position_longhands = " ".join(x.ident for x in SIDES + GRID_LINES) %>
|
||||||
<%self:impl_trait style_struct_name="Position"
|
<%self:impl_trait style_struct_name="Position"
|
||||||
skip_longhands="${skip_position_longhands} z-index order
|
skip_longhands="${skip_position_longhands} order
|
||||||
align-content justify-content align-self
|
align-content justify-content align-self
|
||||||
justify-self align-items justify-items
|
justify-self align-items justify-items
|
||||||
grid-auto-rows grid-auto-columns
|
grid-auto-rows grid-auto-columns
|
||||||
|
@ -1665,38 +1665,6 @@ fn static_assert() {
|
||||||
<% impl_split_style_coord(side.ident, "mOffset", side.index) %>
|
<% impl_split_style_coord(side.ident, "mOffset", side.index) %>
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
pub fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) {
|
|
||||||
match v {
|
|
||||||
ZIndex::Integer(n) => self.gecko.mZIndex.set_value(CoordDataValue::Integer(n)),
|
|
||||||
ZIndex::Auto => self.gecko.mZIndex.set_value(CoordDataValue::Auto),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_z_index_from(&mut self, other: &Self) {
|
|
||||||
use crate::gecko_bindings::structs::nsStyleUnit;
|
|
||||||
// z-index is never a calc(). If it were, we'd be leaking here, so
|
|
||||||
// assert that it isn't.
|
|
||||||
debug_assert_ne!(self.gecko.mZIndex.unit(), nsStyleUnit::eStyleUnit_Calc);
|
|
||||||
unsafe {
|
|
||||||
self.gecko.mZIndex.copy_from_unchecked(&other.gecko.mZIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset_z_index(&mut self, other: &Self) {
|
|
||||||
self.copy_z_index_from(other)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
|
|
||||||
return match self.gecko.mZIndex.as_value() {
|
|
||||||
CoordDataValue::Integer(n) => ZIndex::Integer(n),
|
|
||||||
CoordDataValue::Auto => ZIndex::Auto,
|
|
||||||
_ => {
|
|
||||||
debug_assert!(false);
|
|
||||||
ZIndex::Integer(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
% for kind in ["align", "justify"]:
|
% for kind in ["align", "justify"]:
|
||||||
${impl_simple_type_with_conversion(kind + "_content")}
|
${impl_simple_type_with_conversion(kind + "_content")}
|
||||||
${impl_simple_type_with_conversion(kind + "_self")}
|
${impl_simple_type_with_conversion(kind + "_self")}
|
||||||
|
|
|
@ -74,6 +74,7 @@ pub enum AnimationIterationCount<Number> {
|
||||||
Copy,
|
Copy,
|
||||||
Debug,
|
Debug,
|
||||||
MallocSizeOf,
|
MallocSizeOf,
|
||||||
|
Parse,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
SpecifiedValueInfo,
|
SpecifiedValueInfo,
|
||||||
ToAnimatedValue,
|
ToAnimatedValue,
|
||||||
|
@ -81,13 +82,16 @@ pub enum AnimationIterationCount<Number> {
|
||||||
ToComputedValue,
|
ToComputedValue,
|
||||||
ToCss,
|
ToCss,
|
||||||
)]
|
)]
|
||||||
pub enum Perspective<NonNegativeLength> {
|
#[repr(C, u8)]
|
||||||
|
pub enum GenericPerspective<NonNegativeLength> {
|
||||||
/// A non-negative length.
|
/// A non-negative length.
|
||||||
Length(NonNegativeLength),
|
Length(NonNegativeLength),
|
||||||
/// The keyword `none`.
|
/// The keyword `none`.
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use self::GenericPerspective as Perspective;
|
||||||
|
|
||||||
impl<L> Perspective<L> {
|
impl<L> Perspective<L> {
|
||||||
/// Returns `none`.
|
/// Returns `none`.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -45,18 +45,22 @@ impl<H, V> Position<H, V> {
|
||||||
Debug,
|
Debug,
|
||||||
MallocSizeOf,
|
MallocSizeOf,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
Parse,
|
||||||
SpecifiedValueInfo,
|
SpecifiedValueInfo,
|
||||||
ToAnimatedZero,
|
ToAnimatedZero,
|
||||||
ToComputedValue,
|
ToComputedValue,
|
||||||
ToCss,
|
ToCss,
|
||||||
)]
|
)]
|
||||||
pub enum ZIndex<Integer> {
|
#[repr(C, u8)]
|
||||||
|
pub enum GenericZIndex<I> {
|
||||||
/// An integer value.
|
/// An integer value.
|
||||||
Integer(Integer),
|
Integer(I),
|
||||||
/// The keyword `auto`.
|
/// The keyword `auto`.
|
||||||
Auto,
|
Auto,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use self::GenericZIndex as ZIndex;
|
||||||
|
|
||||||
impl<Integer> ZIndex<Integer> {
|
impl<Integer> ZIndex<Integer> {
|
||||||
/// Returns `auto`
|
/// Returns `auto`
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -862,20 +862,6 @@ impl Parse for Contain {
|
||||||
/// A specified value for the `perspective` property.
|
/// A specified value for the `perspective` property.
|
||||||
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
||||||
|
|
||||||
impl Parse for Perspective {
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
|
||||||
return Ok(GenericPerspective::None);
|
|
||||||
}
|
|
||||||
Ok(GenericPerspective::Length(NonNegativeLength::parse(
|
|
||||||
context, input,
|
|
||||||
)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A given transition property, that is either `All`, a longhand or shorthand
|
/// A given transition property, that is either `All`, a longhand or shorthand
|
||||||
/// property, or an unsupported or custom property.
|
/// property, or an unsupported or custom property.
|
||||||
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue)]
|
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||||
|
|
|
@ -585,7 +585,7 @@ impl Parse for PositiveInteger {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
Integer::parse_positive(context, input).map(GreaterThanOrEqualToOne::<Integer>)
|
Integer::parse_positive(context, input).map(GreaterThanOrEqualToOne)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -731,15 +731,3 @@ impl GridTemplateAreas {
|
||||||
|
|
||||||
/// A specified value for the `z-index` property.
|
/// A specified value for the `z-index` property.
|
||||||
pub type ZIndex = GenericZIndex<Integer>;
|
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…
Add table
Add a link
Reference in a new issue