mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +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)",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue