mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Fix parsing methods of column-{gap,width}
This commit is contained in:
parent
d2ae3d8bed
commit
19978f2087
5 changed files with 76 additions and 15 deletions
|
@ -11,7 +11,7 @@ use cssparser::RGBA;
|
|||
use gecko_bindings::structs::{nsStyleCoord, StyleShapeRadius};
|
||||
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use std::cmp::max;
|
||||
use values::{Auto, Either, None_};
|
||||
use values::{Auto, Either, None_, Normal};
|
||||
use values::computed::{Angle, LengthOrPercentageOrNone, Number};
|
||||
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use values::computed::basic_shape::ShapeRadius;
|
||||
|
@ -223,6 +223,20 @@ impl GeckoStyleCoordConvertible for None_ {
|
|||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Normal {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Normal)
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
if let CoordDataValue::Normal = coord.as_value() {
|
||||
Some(Normal)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a given RGBA value to `nscolor`.
|
||||
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
||||
((rgba.alpha as u32) << 24) |
|
||||
|
|
|
@ -627,6 +627,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
|
|||
# Types used with predefined_type()-defined properties that we can auto-generate.
|
||||
predefined_types = {
|
||||
"length::LengthOrAuto": impl_style_coord,
|
||||
"length::LengthOrNormal": impl_style_coord,
|
||||
"Length": impl_absolute_length,
|
||||
"Position": impl_position,
|
||||
"LengthOrPercentage": impl_style_coord,
|
||||
|
@ -3010,7 +3011,7 @@ clip-path
|
|||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Column"
|
||||
skip_longhands="column-count column-gap column-rule-width">
|
||||
skip_longhands="column-count column-rule-width">
|
||||
|
||||
#[allow(unused_unsafe)]
|
||||
pub fn set_column_count(&mut self, v: longhands::column_count::computed_value::T) {
|
||||
|
@ -3026,17 +3027,6 @@ clip-path
|
|||
|
||||
${impl_simple_copy('column_count', 'mColumnCount')}
|
||||
|
||||
pub fn set_column_gap(&mut self, v: longhands::column_gap::computed_value::T) {
|
||||
use values::Either;
|
||||
|
||||
match v {
|
||||
Either::First(len) => self.gecko.mColumnGap.set(len),
|
||||
Either::Second(_normal) => self.gecko.mColumnGap.set_value(CoordDataValue::Normal),
|
||||
}
|
||||
}
|
||||
|
||||
<%call expr="impl_coord_copy('column_gap', 'mColumnGap')"></%call>
|
||||
|
||||
<% impl_app_units("column_rule_width", "mColumnRuleWidth", need_clone=True,
|
||||
round_to_pixels=True) %>
|
||||
</%self:impl_trait>
|
||||
|
|
|
@ -496,10 +496,24 @@ impl Parse for Length {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Either<Length, T> {
|
||||
impl Either<Length, Normal> {
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse_non_negative_length(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if input.try(|input| Normal::parse(context, input)).is_ok() {
|
||||
return Ok(Either::Second(Normal));
|
||||
}
|
||||
Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
||||
impl Either<Length, Auto> {
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if input.try(|input| Auto::parse(context, input)).is_ok() {
|
||||
return Ok(Either::Second(Auto));
|
||||
}
|
||||
Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue