mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Serialize a bunch of image properties with Servo.
I had to fix the conversion for BackgroundSize too, hopefully we can simplify all this using cbindgen in the future instead of CalcValue. Differential Revision: https://phabricator.services.mozilla.com/D7580
This commit is contained in:
parent
0d5d5a9c82
commit
7345af613a
4 changed files with 63 additions and 19 deletions
|
@ -17,7 +17,7 @@ use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataVa
|
|||
use std::f32::consts::PI;
|
||||
use stylesheets::{Origin, RulesMutateError};
|
||||
use values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image};
|
||||
use values::computed::{Integer, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use values::computed::{Integer, LengthOrPercentage, LengthOrPercentageOrAuto, NonNegativeLengthOrPercentageOrAuto};
|
||||
use values::computed::{Percentage, TextAlign};
|
||||
use values::computed::image::LineDirection;
|
||||
use values::computed::url::ComputedImageUrl;
|
||||
|
@ -106,6 +106,26 @@ impl From<nsStyleCoord_CalcValue> for LengthOrPercentageOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME(emilio): A lot of these impl From should probably become explicit or
|
||||
// disappear as we move more stuff to cbindgen.
|
||||
impl From<nsStyleCoord_CalcValue> for NonNegativeLengthOrPercentageOrAuto {
|
||||
fn from(other: nsStyleCoord_CalcValue) -> Self {
|
||||
use values::generics::NonNegative;
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
NonNegative(if other.mLength < 0 || other.mPercent < 0. {
|
||||
LengthOrPercentageOrAuto::Calc(
|
||||
CalcLengthOrPercentage::with_clamping_mode(
|
||||
Au(other.mLength).into(),
|
||||
if other.mHasPercent { Some(Percentage(other.mPercent)) } else { None },
|
||||
AllowedNumericType::NonNegative,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
other.into()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Angle> for CoordDataValue {
|
||||
fn from(reference: Angle) -> Self {
|
||||
match reference {
|
||||
|
|
|
@ -273,14 +273,18 @@ impl ToComputedValue for SpecifiedImageUrl {
|
|||
}
|
||||
}
|
||||
|
||||
fn serialize_computed_url<W>(url_value_data: &URLValueData, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
fn serialize_computed_url<W>(
|
||||
url_value_data: &URLValueData,
|
||||
dest: &mut CssWriter<W>,
|
||||
get_url: unsafe extern "C" fn(*const URLValueData, *mut nsCString) -> (),
|
||||
) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
dest.write_str("url(")?;
|
||||
unsafe {
|
||||
let mut string = nsCString::new();
|
||||
bindings::Gecko_GetComputedURLSpec(url_value_data, &mut string);
|
||||
get_url(url_value_data, &mut string);
|
||||
string.as_str_unchecked().to_css(dest)?;
|
||||
}
|
||||
dest.write_char(')')
|
||||
|
@ -298,7 +302,11 @@ impl ToCss for ComputedUrl {
|
|||
where
|
||||
W: Write,
|
||||
{
|
||||
serialize_computed_url(&self.0.url_value._base, dest)
|
||||
serialize_computed_url(
|
||||
&self.0.url_value._base,
|
||||
dest,
|
||||
bindings::Gecko_GetComputedURLSpec,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -319,7 +327,11 @@ impl ToCss for ComputedImageUrl {
|
|||
where
|
||||
W: Write,
|
||||
{
|
||||
serialize_computed_url(&self.0.image_value._base, dest)
|
||||
serialize_computed_url(
|
||||
&self.0.image_value._base,
|
||||
dest,
|
||||
bindings::Gecko_GetComputedImageURLSpec,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4005,7 +4005,6 @@ fn static_assert() {
|
|||
pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T {
|
||||
use gecko_bindings::structs::nsStyleCoord_CalcValue as CalcValue;
|
||||
use gecko_bindings::structs::nsStyleImageLayers_Size_DimensionType as DimensionType;
|
||||
use values::generics::NonNegative;
|
||||
use values::computed::NonNegativeLengthOrPercentageOrAuto;
|
||||
use values::generics::background::BackgroundSize;
|
||||
|
||||
|
@ -4014,7 +4013,7 @@ fn static_assert() {
|
|||
NonNegativeLengthOrPercentageOrAuto::auto()
|
||||
} else {
|
||||
debug_assert_eq!(ty, DimensionType::eLengthPercentage as u8);
|
||||
NonNegative(value.into())
|
||||
value.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -202,21 +202,34 @@ impl ToCss for CalcLengthOrPercentage {
|
|||
{
|
||||
use num_traits::Zero;
|
||||
|
||||
let (length, percentage) = match (self.length, self.percentage) {
|
||||
(l, None) => return l.to_css(dest),
|
||||
(l, Some(p)) if l.px() == 0. => return p.to_css(dest),
|
||||
(l, Some(p)) => (l, p),
|
||||
};
|
||||
let length = self.unclamped_length();
|
||||
match self.percentage {
|
||||
Some(p) => {
|
||||
if length.px() == 0. && self.clamping_mode.clamp(p.0) == p.0 {
|
||||
return p.to_css(dest);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
if self.clamping_mode.clamp(length.px()) == length.px() {
|
||||
return length.to_css(dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dest.write_str("calc(")?;
|
||||
percentage.to_css(dest)?;
|
||||
|
||||
dest.write_str(if length.px() < Zero::zero() {
|
||||
" - "
|
||||
if let Some(percentage) = self.percentage {
|
||||
percentage.to_css(dest)?;
|
||||
if length.px() != 0. {
|
||||
dest.write_str(if length.px() < Zero::zero() {
|
||||
" - "
|
||||
} else {
|
||||
" + "
|
||||
})?;
|
||||
length.abs().to_css(dest)?;
|
||||
}
|
||||
} else {
|
||||
" + "
|
||||
})?;
|
||||
length.abs().to_css(dest)?;
|
||||
length.to_css(dest)?;
|
||||
}
|
||||
|
||||
dest.write_str(")")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue