mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Switch column-count to use predefined integer type
This commit is contained in:
parent
9233882d49
commit
ab0e5c9d99
5 changed files with 22 additions and 93 deletions
|
@ -106,11 +106,14 @@ impl Flow for MulticolFlow {
|
||||||
if let Either::First(column_width) = column_style.column_width {
|
if let Either::First(column_width) = column_style.column_width {
|
||||||
column_count =
|
column_count =
|
||||||
max(1, (content_inline_size + column_gap).0 / (column_width + column_gap).0);
|
max(1, (content_inline_size + column_gap).0 / (column_width + column_gap).0);
|
||||||
if let Some(specified_column_count) = column_style.column_count.0 {
|
if let Either::First(specified_column_count) = column_style.column_count {
|
||||||
column_count = min(column_count, specified_column_count as i32);
|
column_count = min(column_count, specified_column_count as i32);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
column_count = column_style.column_count.0.unwrap() as i32;
|
column_count = match column_style.column_count {
|
||||||
|
Either::First(n) => n,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
column_width =
|
column_width =
|
||||||
max(Au(0), (content_inline_size + column_gap) / column_count - column_gap);
|
max(Au(0), (content_inline_size + column_gap) / column_count - column_gap);
|
||||||
|
|
|
@ -3189,11 +3189,11 @@ clip-path
|
||||||
pub fn set_column_count(&mut self, v: longhands::column_count::computed_value::T) {
|
pub fn set_column_count(&mut self, v: longhands::column_count::computed_value::T) {
|
||||||
use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount};
|
use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount};
|
||||||
|
|
||||||
self.gecko.mColumnCount = match v.0 {
|
self.gecko.mColumnCount = match v {
|
||||||
Some(number) => unsafe {
|
Either::First(number) => unsafe {
|
||||||
cmp::min(number, nsStyleColumn_kMaxColumnCount)
|
cmp::min(number as u32, nsStyleColumn_kMaxColumnCount)
|
||||||
},
|
},
|
||||||
None => NS_STYLE_COLUMN_COUNT_AUTO
|
Either::Second(Auto) => NS_STYLE_COLUMN_COUNT_AUTO
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,90 +19,14 @@ ${helpers.predefined_type("column-width",
|
||||||
|
|
||||||
|
|
||||||
// FIXME: This prop should be animatable.
|
// FIXME: This prop should be animatable.
|
||||||
<%helpers:longhand name="column-count" experimental="True" animatable="False" extra_prefixes="moz"
|
${helpers.predefined_type("column-count", "IntegerOrAuto",
|
||||||
spec="https://drafts.csswg.org/css-multicol/#propdef-column-count">
|
"Either::Second(Auto)",
|
||||||
use std::fmt;
|
parse_method="parse_positive",
|
||||||
use style_traits::ToCss;
|
initial_specified_value="Either::Second(Auto)",
|
||||||
use values::HasViewportPercentage;
|
experimental="True",
|
||||||
|
animatable="False",
|
||||||
no_viewport_percentage!(SpecifiedValue);
|
extra_prefixes="moz",
|
||||||
|
spec="https://drafts.csswg.org/css-multicol/#propdef-column-count")}
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
pub enum SpecifiedValue {
|
|
||||||
Auto,
|
|
||||||
Specified(u32),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for SpecifiedValue {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match *self {
|
|
||||||
SpecifiedValue::Auto => dest.write_str("auto"),
|
|
||||||
SpecifiedValue::Specified(count) => write!(dest, "{}", count),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod computed_value {
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
pub struct T(pub Option<u32>);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
match self.0 {
|
|
||||||
None => dest.write_str("auto"),
|
|
||||||
Some(count) => write!(dest, "{}", count),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
|
||||||
computed_value::T(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
|
||||||
SpecifiedValue::Auto
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
|
||||||
type ComputedValue = computed_value::T;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
|
||||||
match *self {
|
|
||||||
SpecifiedValue::Auto => computed_value::T(None),
|
|
||||||
SpecifiedValue::Specified(count) =>
|
|
||||||
computed_value::T(Some(count))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
|
||||||
match *computed {
|
|
||||||
computed_value::T(None) => SpecifiedValue::Auto,
|
|
||||||
computed_value::T(Some(count)) =>
|
|
||||||
SpecifiedValue::Specified(count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
|
||||||
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
|
|
||||||
Ok(SpecifiedValue::Auto)
|
|
||||||
} else {
|
|
||||||
let count = try!(specified::parse_integer(input));
|
|
||||||
// Zero is invalid
|
|
||||||
if count <= 0 {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
Ok(SpecifiedValue::Specified(count as u32))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:longhand>
|
|
||||||
|
|
||||||
// FIXME: This prop should be animatable.
|
// FIXME: This prop should be animatable.
|
||||||
${helpers.predefined_type("column-gap",
|
${helpers.predefined_type("column-gap",
|
||||||
|
|
|
@ -1536,7 +1536,10 @@ impl ComputedValues {
|
||||||
let style = self.get_column();
|
let style = self.get_column();
|
||||||
match style.column_width {
|
match style.column_width {
|
||||||
Either::First(_width) => true,
|
Either::First(_width) => true,
|
||||||
Either::Second(_auto) => style.column_count.0.is_some(),
|
Either::Second(_auto) => match style.column_count {
|
||||||
|
Either::First(_n) => true,
|
||||||
|
Either::Second(_auto) => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -557,13 +557,12 @@ mod shorthand_serialization {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn columns_should_serialize_correctly() {
|
fn columns_should_serialize_correctly() {
|
||||||
use style::properties::longhands::column_count::SpecifiedValue as ColumnCount;
|
|
||||||
use style::values::{Auto, Either};
|
use style::values::{Auto, Either};
|
||||||
|
|
||||||
let mut properties = Vec::new();
|
let mut properties = Vec::new();
|
||||||
|
|
||||||
let width = Either::Second(Auto);
|
let width = Either::Second(Auto);
|
||||||
let count = ColumnCount::Auto;
|
let count = Either::Second(Auto);
|
||||||
|
|
||||||
properties.push(PropertyDeclaration::ColumnWidth(width));
|
properties.push(PropertyDeclaration::ColumnWidth(width));
|
||||||
properties.push(PropertyDeclaration::ColumnCount(count));
|
properties.push(PropertyDeclaration::ColumnCount(count));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue