mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
parent
f159b5cb10
commit
5821ff77db
8 changed files with 38 additions and 97 deletions
|
@ -24,6 +24,7 @@ use std::sync::Arc;
|
||||||
use style::context::{StyleContext, SharedStyleContext};
|
use style::context::{StyleContext, SharedStyleContext};
|
||||||
use style::logical_geometry::LogicalSize;
|
use style::logical_geometry::LogicalSize;
|
||||||
use style::properties::ServoComputedValues;
|
use style::properties::ServoComputedValues;
|
||||||
|
use style::values::Either;
|
||||||
use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
|
||||||
|
|
||||||
pub struct MulticolFlow {
|
pub struct MulticolFlow {
|
||||||
|
@ -102,7 +103,7 @@ impl Flow for MulticolFlow {
|
||||||
let column_gap = column_style.column_gap.0.unwrap_or_else(||
|
let column_gap = column_style.column_gap.0.unwrap_or_else(||
|
||||||
self.block_flow.fragment.style.get_font().font_size);
|
self.block_flow.fragment.style.get_font().font_size);
|
||||||
let mut column_count;
|
let mut column_count;
|
||||||
if let Some(column_width) = column_style.column_width.0 {
|
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 Some(specified_column_count) = column_style.column_count.0 {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use gecko_bindings::structs::{NS_RADIUS_CLOSEST_SIDE, NS_RADIUS_FARTHEST_SIDE};
|
||||||
use gecko_bindings::structs::nsStyleCoord;
|
use gecko_bindings::structs::nsStyleCoord;
|
||||||
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use values::Either;
|
use values::{Auto, Either};
|
||||||
use values::computed::{Angle, LengthOrPercentageOrNone, Number};
|
use values::computed::{Angle, LengthOrPercentageOrNone, Number};
|
||||||
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
use values::computed::basic_shape::ShapeRadius;
|
use values::computed::basic_shape::ShapeRadius;
|
||||||
|
@ -187,6 +187,20 @@ impl GeckoStyleCoordConvertible for Angle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GeckoStyleCoordConvertible for Auto {
|
||||||
|
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||||
|
coord.set_value(CoordDataValue::Auto)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||||
|
if let CoordDataValue::Auto = coord.as_value() {
|
||||||
|
Some(Auto)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
||||||
(((rgba.alpha * 255.0).round() as u32) << 24) |
|
(((rgba.alpha * 255.0).round() as u32) << 24) |
|
||||||
(((rgba.blue * 255.0).round() as u32) << 16) |
|
(((rgba.blue * 255.0).round() as u32) << 16) |
|
||||||
|
|
|
@ -493,6 +493,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
|
||||||
|
|
||||||
# Types used with predefined_type()-defined properties that we can auto-generate.
|
# Types used with predefined_type()-defined properties that we can auto-generate.
|
||||||
predefined_types = {
|
predefined_types = {
|
||||||
|
"length::LengthOrAuto": impl_style_coord,
|
||||||
"Length": impl_style_coord,
|
"Length": impl_style_coord,
|
||||||
"LengthOrPercentage": impl_style_coord,
|
"LengthOrPercentage": impl_style_coord,
|
||||||
"LengthOrPercentageOrAuto": impl_style_coord,
|
"LengthOrPercentageOrAuto": impl_style_coord,
|
||||||
|
@ -2326,16 +2327,7 @@ clip-path
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Column"
|
<%self:impl_trait style_struct_name="Column"
|
||||||
skip_longhands="column-width column-count column-gap -moz-column-rule-width">
|
skip_longhands="column-count column-gap -moz-column-rule-width">
|
||||||
|
|
||||||
pub fn set_column_width(&mut self, v: longhands::column_width::computed_value::T) {
|
|
||||||
match v.0 {
|
|
||||||
Some(au) => self.gecko.mColumnWidth.set(au),
|
|
||||||
None => self.gecko.mColumnWidth.set_value(CoordDataValue::Auto),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
${impl_coord_copy('column_width', 'mColumnWidth')}
|
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
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) {
|
||||||
|
|
|
@ -7,86 +7,13 @@
|
||||||
<% data.new_style_struct("Column", inherited=False) %>
|
<% data.new_style_struct("Column", inherited=False) %>
|
||||||
|
|
||||||
// FIXME: This prop should be animatable.
|
// FIXME: This prop should be animatable.
|
||||||
<%helpers:longhand name="column-width" experimental="True" animatable="False">
|
${helpers.predefined_type("column-width",
|
||||||
use std::fmt;
|
"length::LengthOrAuto",
|
||||||
use style_traits::ToCss;
|
"Either::Second(Auto)",
|
||||||
use values::HasViewportPercentage;
|
parse_method="parse_non_negative_length",
|
||||||
|
animatable=False,
|
||||||
|
experimental=True)}
|
||||||
|
|
||||||
impl HasViewportPercentage for SpecifiedValue {
|
|
||||||
fn has_viewport_percentage(&self) -> bool {
|
|
||||||
match *self {
|
|
||||||
SpecifiedValue::Specified(length) => length.has_viewport_percentage(),
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
pub enum SpecifiedValue {
|
|
||||||
Auto,
|
|
||||||
Specified(specified::Length),
|
|
||||||
}
|
|
||||||
|
|
||||||
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(l) => l.to_css(dest),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod computed_value {
|
|
||||||
use app_units::Au;
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
pub struct T(pub Option<Au>);
|
|
||||||
}
|
|
||||||
|
|
||||||
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(l) => l.to_css(dest),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
|
||||||
computed_value::T(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
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(l) =>
|
|
||||||
computed_value::T(Some(l.to_computed_value(context)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
|
||||||
match *computed {
|
|
||||||
computed_value::T(None) => SpecifiedValue::Auto,
|
|
||||||
computed_value::T(Some(l)) =>
|
|
||||||
SpecifiedValue::Specified(ToComputedValue::from_computed_value(&l))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
specified::Length::parse_non_negative(input).map(SpecifiedValue::Specified)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:longhand>
|
|
||||||
|
|
||||||
// FIXME: This prop should be animatable.
|
// FIXME: This prop should be animatable.
|
||||||
<%helpers:longhand name="column-count" experimental="True" animatable="False">
|
<%helpers:longhand name="column-count" experimental="True" animatable="False">
|
||||||
|
|
|
@ -1145,7 +1145,10 @@ impl ComputedValues {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_multicol(&self) -> bool {
|
pub fn is_multicol(&self) -> bool {
|
||||||
let style = self.get_column();
|
let style = self.get_column();
|
||||||
style.column_count.0.is_some() || style.column_width.0.is_some()
|
match style.column_width {
|
||||||
|
Either::First(_width) => true,
|
||||||
|
Either::Second(_auto) => style.column_count.0.is_some(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves the currentColor keyword.
|
/// Resolves the currentColor keyword.
|
||||||
|
|
|
@ -7,7 +7,7 @@ use ordered_float::NotNaN;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use super::{Number, ToComputedValue, Context};
|
use super::{Number, ToComputedValue, Context};
|
||||||
use values::{CSSFloat, Either, None_, specified};
|
use values::{Auto, CSSFloat, Either, None_, specified};
|
||||||
|
|
||||||
pub use cssparser::Color as CSSColor;
|
pub use cssparser::Color as CSSColor;
|
||||||
pub use super::image::{EndingShape as GradientShape, Gradient, GradientKind, Image};
|
pub use super::image::{EndingShape as GradientShape, Gradient, GradientKind, Image};
|
||||||
|
@ -471,6 +471,8 @@ impl ToCss for LengthOrPercentageOrNone {
|
||||||
|
|
||||||
pub type LengthOrNone = Either<Length, None_>;
|
pub type LengthOrNone = Either<Length, None_>;
|
||||||
|
|
||||||
|
pub type LengthOrAuto = Either<Length, Auto>;
|
||||||
|
|
||||||
pub type LengthOrNumber = Either<Length, Number>;
|
pub type LengthOrNumber = Either<Length, Number>;
|
||||||
|
|
||||||
pub type Length = Au;
|
pub type Length = Au;
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::ops::Mul;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use style_traits::values::specified::AllowedNumericType;
|
use style_traits::values::specified::AllowedNumericType;
|
||||||
use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time};
|
use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time};
|
||||||
use values::{CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_};
|
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_};
|
||||||
use values::computed::Context;
|
use values::computed::Context;
|
||||||
|
|
||||||
pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||||
|
@ -345,7 +345,7 @@ impl Parse for Length {
|
||||||
|
|
||||||
impl<T> Either<Length, T> {
|
impl<T> Either<Length, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parse_non_negative_length(input: &mut Parser) -> Result<Either<Length, T>, ()> {
|
pub fn parse_non_negative_length(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||||
Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First)
|
Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -953,6 +953,8 @@ impl Parse for LengthOrPercentageOrNone {
|
||||||
|
|
||||||
pub type LengthOrNone = Either<Length, None_>;
|
pub type LengthOrNone = Either<Length, None_>;
|
||||||
|
|
||||||
|
pub type LengthOrAuto = Either<Length, Auto>;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub enum LengthOrPercentageOrAutoOrContent {
|
pub enum LengthOrPercentageOrAutoOrContent {
|
||||||
|
|
|
@ -536,11 +536,11 @@ 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::properties::longhands::column_count::SpecifiedValue as ColumnCount;
|
||||||
use style::properties::longhands::column_width::SpecifiedValue as ColumnWidth;
|
use style::values::{Auto, Either};
|
||||||
|
|
||||||
let mut properties = Vec::new();
|
let mut properties = Vec::new();
|
||||||
|
|
||||||
let width = DeclaredValue::Value(ColumnWidth::Auto);
|
let width = DeclaredValue::Value(Either::Second(Auto));
|
||||||
let count = DeclaredValue::Value(ColumnCount::Auto);
|
let count = DeclaredValue::Value(ColumnCount::Auto);
|
||||||
|
|
||||||
properties.push(PropertyDeclaration::ColumnWidth(width));
|
properties.push(PropertyDeclaration::ColumnWidth(width));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue