mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Use cbindgen for clip / -moz-image-region.
This also fixes some of the issues with -moz-image-region, where we just minted an auto out of the blue. Differential Revision: https://phabricator.services.mozilla.com/D43474
This commit is contained in:
parent
53cd37ce39
commit
b238698691
5 changed files with 52 additions and 194 deletions
|
@ -2162,7 +2162,7 @@ fn static_assert() {
|
|||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="List"
|
||||
skip_longhands="list-style-image list-style-type -moz-image-region">
|
||||
skip_longhands="list-style-image list-style-type">
|
||||
|
||||
pub fn set_list_style_image(&mut self, image: longhands::list_style_image::computed_value::T) {
|
||||
match image {
|
||||
|
@ -2232,178 +2232,12 @@ fn static_assert() {
|
|||
Either::Second(string) => T::String(string),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set__moz_image_region(&mut self, v: longhands::_moz_image_region::computed_value::T) {
|
||||
use crate::values::Either;
|
||||
use crate::values::generics::length::LengthPercentageOrAuto::*;
|
||||
|
||||
match v {
|
||||
Either::Second(_auto) => {
|
||||
self.gecko.mImageRegion.x = 0;
|
||||
self.gecko.mImageRegion.y = 0;
|
||||
self.gecko.mImageRegion.width = 0;
|
||||
self.gecko.mImageRegion.height = 0;
|
||||
}
|
||||
Either::First(rect) => {
|
||||
self.gecko.mImageRegion.x = match rect.left {
|
||||
LengthPercentage(v) => v.to_i32_au(),
|
||||
Auto => 0,
|
||||
};
|
||||
self.gecko.mImageRegion.y = match rect.top {
|
||||
LengthPercentage(v) => v.to_i32_au(),
|
||||
Auto => 0,
|
||||
};
|
||||
self.gecko.mImageRegion.height = match rect.bottom {
|
||||
LengthPercentage(value) => (Au::from(value) - Au(self.gecko.mImageRegion.y)).0,
|
||||
Auto => 0,
|
||||
};
|
||||
self.gecko.mImageRegion.width = match rect.right {
|
||||
LengthPercentage(value) => (Au::from(value) - Au(self.gecko.mImageRegion.x)).0,
|
||||
Auto => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn clone__moz_image_region(&self) -> longhands::_moz_image_region::computed_value::T {
|
||||
use crate::values::{Auto, Either};
|
||||
use crate::values::generics::length::LengthPercentageOrAuto::*;
|
||||
use crate::values::computed::ClipRect;
|
||||
|
||||
// There is no ideal way to detect auto type for structs::nsRect and its components, so
|
||||
// if all components are zero, we use Auto.
|
||||
if self.gecko.mImageRegion.x == 0 &&
|
||||
self.gecko.mImageRegion.y == 0 &&
|
||||
self.gecko.mImageRegion.width == 0 &&
|
||||
self.gecko.mImageRegion.height == 0 {
|
||||
return Either::Second(Auto);
|
||||
}
|
||||
|
||||
Either::First(ClipRect {
|
||||
top: LengthPercentage(Au(self.gecko.mImageRegion.y).into()),
|
||||
right: LengthPercentage(Au(self.gecko.mImageRegion.width + self.gecko.mImageRegion.x).into()),
|
||||
bottom: LengthPercentage(Au(self.gecko.mImageRegion.height + self.gecko.mImageRegion.y).into()),
|
||||
left: LengthPercentage(Au(self.gecko.mImageRegion.x).into()),
|
||||
})
|
||||
}
|
||||
|
||||
${impl_simple_copy('_moz_image_region', 'mImageRegion')}
|
||||
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Table">
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Effects" skip_longhands="clip">
|
||||
pub fn set_clip(&mut self, v: longhands::clip::computed_value::T) {
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_RECT;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_LEFT_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_TOP_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_RIGHT_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_BOTTOM_AUTO;
|
||||
use crate::values::generics::length::LengthPercentageOrAuto::*;
|
||||
use crate::values::Either;
|
||||
|
||||
match v {
|
||||
Either::First(rect) => {
|
||||
self.gecko.mClipFlags = NS_STYLE_CLIP_RECT as u8;
|
||||
self.gecko.mClip.x = match rect.left {
|
||||
LengthPercentage(l) => l.to_i32_au(),
|
||||
Auto => {
|
||||
self.gecko.mClipFlags |= NS_STYLE_CLIP_LEFT_AUTO as u8;
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
self.gecko.mClip.y = match rect.top {
|
||||
LengthPercentage(l) => l.to_i32_au(),
|
||||
Auto => {
|
||||
self.gecko.mClipFlags |= NS_STYLE_CLIP_TOP_AUTO as u8;
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
self.gecko.mClip.height = match rect.bottom {
|
||||
LengthPercentage(l) => (Au::from(l) - Au(self.gecko.mClip.y)).0,
|
||||
Auto => {
|
||||
self.gecko.mClipFlags |= NS_STYLE_CLIP_BOTTOM_AUTO as u8;
|
||||
1 << 30 // NS_MAXSIZE
|
||||
}
|
||||
};
|
||||
|
||||
self.gecko.mClip.width = match rect.right {
|
||||
LengthPercentage(l) => (Au::from(l) - Au(self.gecko.mClip.x)).0,
|
||||
Auto => {
|
||||
self.gecko.mClipFlags |= NS_STYLE_CLIP_RIGHT_AUTO as u8;
|
||||
1 << 30 // NS_MAXSIZE
|
||||
}
|
||||
};
|
||||
},
|
||||
Either::Second(_auto) => {
|
||||
self.gecko.mClipFlags = NS_STYLE_CLIP_AUTO as u8;
|
||||
self.gecko.mClip.x = 0;
|
||||
self.gecko.mClip.y = 0;
|
||||
self.gecko.mClip.width = 0;
|
||||
self.gecko.mClip.height = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_clip_from(&mut self, other: &Self) {
|
||||
self.gecko.mClip = other.gecko.mClip;
|
||||
self.gecko.mClipFlags = other.gecko.mClipFlags;
|
||||
}
|
||||
|
||||
pub fn reset_clip(&mut self, other: &Self) {
|
||||
self.copy_clip_from(other)
|
||||
}
|
||||
|
||||
pub fn clone_clip(&self) -> longhands::clip::computed_value::T {
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_BOTTOM_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_LEFT_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_RIGHT_AUTO;
|
||||
use crate::gecko_bindings::structs::NS_STYLE_CLIP_TOP_AUTO;
|
||||
use crate::values::generics::length::LengthPercentageOrAuto::*;
|
||||
use crate::values::computed::{ClipRect, ClipRectOrAuto};
|
||||
use crate::values::Either;
|
||||
|
||||
if self.gecko.mClipFlags == NS_STYLE_CLIP_AUTO as u8 {
|
||||
return ClipRectOrAuto::auto()
|
||||
}
|
||||
let left = if self.gecko.mClipFlags & NS_STYLE_CLIP_LEFT_AUTO as u8 != 0 {
|
||||
debug_assert_eq!(self.gecko.mClip.x, 0);
|
||||
Auto
|
||||
} else {
|
||||
LengthPercentage(Au(self.gecko.mClip.x).into())
|
||||
};
|
||||
|
||||
let top = if self.gecko.mClipFlags & NS_STYLE_CLIP_TOP_AUTO as u8 != 0 {
|
||||
debug_assert_eq!(self.gecko.mClip.y, 0);
|
||||
Auto
|
||||
} else {
|
||||
LengthPercentage(Au(self.gecko.mClip.y).into())
|
||||
};
|
||||
|
||||
let bottom = if self.gecko.mClipFlags & NS_STYLE_CLIP_BOTTOM_AUTO as u8 != 0 {
|
||||
debug_assert_eq!(self.gecko.mClip.height, 1 << 30); // NS_MAXSIZE
|
||||
Auto
|
||||
} else {
|
||||
LengthPercentage(Au(self.gecko.mClip.y + self.gecko.mClip.height).into())
|
||||
};
|
||||
|
||||
let right = if self.gecko.mClipFlags & NS_STYLE_CLIP_RIGHT_AUTO as u8 != 0 {
|
||||
debug_assert_eq!(self.gecko.mClip.width, 1 << 30); // NS_MAXSIZE
|
||||
Auto
|
||||
} else {
|
||||
LengthPercentage(Au(self.gecko.mClip.x + self.gecko.mClip.width).into())
|
||||
};
|
||||
|
||||
Either::First(ClipRect { top, right, bottom, left })
|
||||
}
|
||||
<%self:impl_trait style_struct_name="Effects">
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="InheritedBox">
|
||||
|
|
|
@ -76,6 +76,7 @@ ${helpers.predefined_type(
|
|||
"ClipRectOrAuto",
|
||||
"computed::ClipRectOrAuto::auto()",
|
||||
engines="gecko",
|
||||
gecko_ffi_name="mImageRegion",
|
||||
animation_value_type="ComputedValue",
|
||||
boxed=True,
|
||||
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-image-region)",
|
||||
|
|
|
@ -683,11 +683,11 @@ impl From<CSSInteger> for PositiveInteger {
|
|||
/// A computed positive `<integer>` value or `none`.
|
||||
pub type PositiveIntegerOrNone = Either<PositiveInteger, None_>;
|
||||
|
||||
/// rect(...)
|
||||
pub type ClipRect = generics::ClipRect<LengthOrAuto>;
|
||||
/// rect(...) | auto
|
||||
pub type ClipRect = generics::GenericClipRect<LengthOrAuto>;
|
||||
|
||||
/// rect(...) | auto
|
||||
pub type ClipRectOrAuto = Either<ClipRect, Auto>;
|
||||
pub type ClipRectOrAuto = generics::GenericClipRectOrAuto<ClipRect>;
|
||||
|
||||
/// The computed value of a grid `<track-breadth>`
|
||||
pub type TrackBreadth = GenericTrackBreadth<LengthPercentage>;
|
||||
|
@ -707,18 +707,3 @@ pub type GridLine = GenericGridLine<Integer>;
|
|||
|
||||
/// `<grid-template-rows> | <grid-template-columns>`
|
||||
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthPercentage, Integer>;
|
||||
|
||||
impl ClipRectOrAuto {
|
||||
/// Return an auto (default for clip-rect and image-region) value
|
||||
pub fn auto() -> Self {
|
||||
Either::Second(Auto)
|
||||
}
|
||||
|
||||
/// Check if it is auto
|
||||
pub fn is_auto(&self) -> bool {
|
||||
match *self {
|
||||
Either::Second(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,9 +272,47 @@ pub struct ZeroToOne<T>(pub T);
|
|||
ToShmem,
|
||||
)]
|
||||
#[css(function = "rect", comma)]
|
||||
pub struct ClipRect<LengthOrAuto> {
|
||||
#[repr(C)]
|
||||
pub struct GenericClipRect<LengthOrAuto> {
|
||||
pub top: LengthOrAuto,
|
||||
pub right: LengthOrAuto,
|
||||
pub bottom: LengthOrAuto,
|
||||
pub left: LengthOrAuto,
|
||||
}
|
||||
|
||||
pub use self::GenericClipRect as ClipRect;
|
||||
|
||||
/// Either a clip-rect or `auto`.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(
|
||||
Animate,
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericClipRectOrAuto<R> {
|
||||
Auto,
|
||||
Rect(R),
|
||||
}
|
||||
|
||||
pub use self::GenericClipRectOrAuto as ClipRectOrAuto;
|
||||
|
||||
impl<L> ClipRectOrAuto<L> {
|
||||
/// Returns the `auto` value.
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
ClipRectOrAuto::Auto
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as Generic
|
|||
use super::generics::grid::{TrackList as GenericTrackList, TrackSize as GenericTrackSize};
|
||||
use super::generics::transform::IsParallelTo;
|
||||
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative};
|
||||
use super::{Auto, CSSFloat, CSSInteger, Either, None_};
|
||||
use super::{CSSFloat, CSSInteger, Either, None_};
|
||||
use crate::context::QuirksMode;
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::serialize_atom_identifier;
|
||||
|
@ -639,7 +639,7 @@ pub type GridLine = GenericGridLine<Integer>;
|
|||
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthPercentage, Integer>;
|
||||
|
||||
/// rect(...)
|
||||
pub type ClipRect = generics::ClipRect<LengthOrAuto>;
|
||||
pub type ClipRect = generics::GenericClipRect<LengthOrAuto>;
|
||||
|
||||
impl Parse for ClipRect {
|
||||
fn parse<'i, 't>(
|
||||
|
@ -652,7 +652,7 @@ impl Parse for ClipRect {
|
|||
|
||||
impl ClipRect {
|
||||
/// Parses a rect(<top>, <left>, <bottom>, <right>), allowing quirks.
|
||||
pub fn parse_quirky<'i, 't>(
|
||||
fn parse_quirky<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
|
@ -696,7 +696,7 @@ impl ClipRect {
|
|||
}
|
||||
|
||||
/// rect(...) | auto
|
||||
pub type ClipRectOrAuto = Either<ClipRect, Auto>;
|
||||
pub type ClipRectOrAuto = generics::GenericClipRectOrAuto<ClipRect>;
|
||||
|
||||
impl ClipRectOrAuto {
|
||||
/// Parses a ClipRect or Auto, allowing quirks.
|
||||
|
@ -706,10 +706,10 @@ impl ClipRectOrAuto {
|
|||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(v) = input.try(|i| ClipRect::parse_quirky(context, i, allow_quirks)) {
|
||||
Ok(Either::First(v))
|
||||
} else {
|
||||
Auto::parse(context, input).map(Either::Second)
|
||||
return Ok(generics::GenericClipRectOrAuto::Rect(v))
|
||||
}
|
||||
input.expect_ident_matching("auto")?;
|
||||
Ok(generics::GenericClipRectOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue