mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Use rust types for background-size.
Hopefully straight-forward. Differential Revision: https://phabricator.services.mozilla.com/D19625
This commit is contained in:
parent
1e6338e1ee
commit
07cb325402
6 changed files with 27 additions and 137 deletions
|
@ -3797,80 +3797,12 @@ fn static_assert() {
|
|||
% endfor
|
||||
|
||||
<%self:simple_image_array_property name="size" shorthand="${shorthand}" field_name="mSize">
|
||||
use crate::gecko_bindings::structs::nsStyleImageLayers_Size_Dimension;
|
||||
use crate::gecko_bindings::structs::nsStyleImageLayers_Size_DimensionType;
|
||||
use crate::gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImageLayers_Size};
|
||||
use crate::values::generics::background::BackgroundSize;
|
||||
|
||||
let mut width = nsStyleCoord_CalcValue::new();
|
||||
let mut height = nsStyleCoord_CalcValue::new();
|
||||
|
||||
let (w_type, h_type) = match servo {
|
||||
BackgroundSize::Explicit { width: explicit_width, height: explicit_height } => {
|
||||
let mut w_type = nsStyleImageLayers_Size_DimensionType::eAuto;
|
||||
let mut h_type = nsStyleImageLayers_Size_DimensionType::eAuto;
|
||||
if let Some(w) = explicit_width.to_calc_value() {
|
||||
width = w;
|
||||
w_type = nsStyleImageLayers_Size_DimensionType::eLengthPercentage;
|
||||
}
|
||||
if let Some(h) = explicit_height.to_calc_value() {
|
||||
height = h;
|
||||
h_type = nsStyleImageLayers_Size_DimensionType::eLengthPercentage;
|
||||
}
|
||||
(w_type, h_type)
|
||||
}
|
||||
BackgroundSize::Cover => {
|
||||
(
|
||||
nsStyleImageLayers_Size_DimensionType::eCover,
|
||||
nsStyleImageLayers_Size_DimensionType::eCover,
|
||||
)
|
||||
},
|
||||
BackgroundSize::Contain => {
|
||||
(
|
||||
nsStyleImageLayers_Size_DimensionType::eContain,
|
||||
nsStyleImageLayers_Size_DimensionType::eContain,
|
||||
)
|
||||
},
|
||||
};
|
||||
|
||||
nsStyleImageLayers_Size {
|
||||
mWidth: nsStyleImageLayers_Size_Dimension { _base: width },
|
||||
mHeight: nsStyleImageLayers_Size_Dimension { _base: height },
|
||||
mWidthType: w_type as u8,
|
||||
mHeightType: h_type as u8,
|
||||
}
|
||||
servo
|
||||
</%self:simple_image_array_property>
|
||||
|
||||
pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T {
|
||||
use crate::gecko_bindings::structs::nsStyleCoord_CalcValue as CalcValue;
|
||||
use crate::gecko_bindings::structs::nsStyleImageLayers_Size_DimensionType as DimensionType;
|
||||
use crate::values::computed::NonNegativeLengthPercentageOrAuto;
|
||||
use crate::values::generics::background::BackgroundSize;
|
||||
|
||||
fn to_servo(value: CalcValue, ty: u8) -> NonNegativeLengthPercentageOrAuto {
|
||||
if ty == DimensionType::eAuto as u8 {
|
||||
NonNegativeLengthPercentageOrAuto::auto()
|
||||
} else {
|
||||
debug_assert_eq!(ty, DimensionType::eLengthPercentage as u8);
|
||||
value.into()
|
||||
}
|
||||
}
|
||||
|
||||
longhands::${shorthand}_size::computed_value::List(
|
||||
self.gecko.${image_layers_field}.mLayers.iter().map(|ref layer| {
|
||||
if DimensionType::eCover as u8 == layer.mSize.mWidthType {
|
||||
debug_assert_eq!(layer.mSize.mHeightType, DimensionType::eCover as u8);
|
||||
return BackgroundSize::Cover
|
||||
}
|
||||
if DimensionType::eContain as u8 == layer.mSize.mWidthType {
|
||||
debug_assert_eq!(layer.mSize.mHeightType, DimensionType::eContain as u8);
|
||||
return BackgroundSize::Contain
|
||||
}
|
||||
BackgroundSize::Explicit {
|
||||
width: to_servo(layer.mSize.mWidth._base, layer.mSize.mWidthType),
|
||||
height: to_servo(layer.mSize.mHeight._base, layer.mSize.mHeightType),
|
||||
}
|
||||
}).collect()
|
||||
self.gecko.${image_layers_field}.mLayers.iter().map(|layer| layer.mSize).collect()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue