mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Merge AuExtensionMethods and LocalToCss.
This commit is contained in:
parent
14dc1199df
commit
f82cf3da12
10 changed files with 31 additions and 40 deletions
|
@ -36,7 +36,7 @@ use style::properties::longhands::{display, position};
|
||||||
use style::properties::style_structs;
|
use style::properties::style_structs;
|
||||||
use style::selector_impl::PseudoElement;
|
use style::selector_impl::PseudoElement;
|
||||||
use style::servo::Stylist;
|
use style::servo::Stylist;
|
||||||
use style::values::AuExtensionMethods;
|
use style::values::LocalToCss;
|
||||||
use style_traits::cursor::Cursor;
|
use style_traits::cursor::Cursor;
|
||||||
use wrapper::ThreadSafeLayoutNodeHelpers;
|
use wrapper::ThreadSafeLayoutNodeHelpers;
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ ${helpers.predefined_type(
|
||||||
<%helpers:longhand name="background-position">
|
<%helpers:longhand name="background-position">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::LengthOrPercentage;
|
use values::computed::LengthOrPercentage;
|
||||||
|
|
|
@ -172,7 +172,7 @@ ${helpers.single_keyword("clear", "none left right both", gecko_ffi_name="mBreak
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
use values::{CSSFloat, computed};
|
use values::{CSSFloat, computed};
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<%helpers:longhand name="column-width" experimental="True">
|
<%helpers:longhand name="column-width" experimental="True">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
<%helpers:longhand name="column-gap" experimental="True">
|
<%helpers:longhand name="column-gap" experimental="True">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
|
|
@ -14,7 +14,7 @@ ${helpers.predefined_type("opacity",
|
||||||
<%helpers:longhand name="box-shadow">
|
<%helpers:longhand name="box-shadow">
|
||||||
use cssparser::{self, ToCss};
|
use cssparser::{self, ToCss};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -226,7 +226,7 @@ ${helpers.predefined_type("opacity",
|
||||||
<%helpers:longhand name="clip">
|
<%helpers:longhand name="clip">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
// NB: `top` and `left` are 0 if `auto` per CSS 2.1 11.1.2.
|
// NB: `top` and `left` are 0 if `auto` per CSS 2.1 11.1.2.
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ ${helpers.predefined_type("opacity",
|
||||||
//pub use self::computed_value::T as SpecifiedValue;
|
//pub use self::computed_value::T as SpecifiedValue;
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
use values::specified::{Angle, Length};
|
use values::specified::{Angle, Length};
|
||||||
|
|
||||||
|
@ -1182,7 +1182,7 @@ ${helpers.single_keyword("transform-style", "auto flat preserve-3d")}
|
||||||
|
|
||||||
<%helpers:longhand name="transform-origin">
|
<%helpers:longhand name="transform-origin">
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
use values::specified::{Length, LengthOrPercentage, Percentage};
|
use values::specified::{Length, LengthOrPercentage, Percentage};
|
||||||
|
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
|
|
|
@ -12,7 +12,7 @@ ${helpers.single_keyword("caption-side", "top bottom", extra_gecko_values="right
|
||||||
|
|
||||||
<%helpers:longhand name="border-spacing">
|
<%helpers:longhand name="border-spacing">
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<%helpers:longhand name="line-height">
|
<%helpers:longhand name="line-height">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
use values::CSSFloat;
|
use values::CSSFloat;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||||
|
@ -182,7 +182,7 @@
|
||||||
<%helpers:longhand name="letter-spacing">
|
<%helpers:longhand name="letter-spacing">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -246,7 +246,7 @@
|
||||||
<%helpers:longhand name="word-spacing">
|
<%helpers:longhand name="word-spacing">
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -451,7 +451,7 @@ ${helpers.single_keyword("text-justify",
|
||||||
<%helpers:longhand name="text-shadow">
|
<%helpers:longhand name="text-shadow">
|
||||||
use cssparser::{self, ToCss};
|
use cssparser::{self, ToCss};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
|
|
@ -30,7 +30,7 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::ToCss;
|
use cssparser::ToCss;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
|
|
||||||
impl ToCss for SpecifiedValue {
|
impl ToCss for SpecifiedValue {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
|
|
@ -33,7 +33,7 @@ use logical_geometry::{LogicalMargin, PhysicalSide, WritingMode};
|
||||||
use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
use parser::{ParserContext, ParserContextExtraData, log_css_error};
|
||||||
use selectors::matching::DeclarationBlock;
|
use selectors::matching::DeclarationBlock;
|
||||||
use stylesheets::Origin;
|
use stylesheets::Origin;
|
||||||
use values::AuExtensionMethods;
|
use values::LocalToCss;
|
||||||
use values::computed::{self, TContext, ToComputedValue};
|
use values::computed::{self, TContext, ToComputedValue};
|
||||||
use values::specified::BorderStyle;
|
use values::specified::BorderStyle;
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,9 @@ use std::fmt::{self, Write};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
||||||
// This is a re-implementation of the ToCss trait in cssparser.
|
/// The real ToCss trait can't be implemented for types in crates that don't
|
||||||
// It's done here because the app_units crate shouldn't depend
|
/// depend on each other.
|
||||||
// on cssparser, and it's not possible to implement a trait when
|
pub trait LocalToCss {
|
||||||
// both the trait and the type are defined in different crates.
|
|
||||||
pub trait AuExtensionMethods {
|
|
||||||
/// Serialize `self` in CSS syntax, writing to `dest`.
|
/// Serialize `self` in CSS syntax, writing to `dest`.
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write;
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write;
|
||||||
|
|
||||||
|
@ -29,12 +27,21 @@ pub trait AuExtensionMethods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuExtensionMethods for Au {
|
impl LocalToCss for Au {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
write!(dest, "{}px", self.to_f64_px())
|
write!(dest, "{}px", self.to_f64_px())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LocalToCss for Url {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
try!(dest.write_str("url(\""));
|
||||||
|
try!(write!(CssStringWriter::new(dest), "{}", self));
|
||||||
|
try!(dest.write_str("\")"));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! define_numbered_css_keyword_enum {
|
macro_rules! define_numbered_css_keyword_enum {
|
||||||
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
|
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
|
||||||
define_numbered_css_keyword_enum!($name: $( $css => $variant = $value ),+);
|
define_numbered_css_keyword_enum!($name: $( $css => $variant = $value ),+);
|
||||||
|
@ -67,22 +74,6 @@ macro_rules! define_numbered_css_keyword_enum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The real ToCss trait can’t be implemented for Url
|
|
||||||
/// since neither rust-url or rust-cssparser depend on the other.
|
|
||||||
pub trait LocalToCss {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LocalToCss for Url {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
try!(dest.write_str("url(\""));
|
|
||||||
try!(write!(CssStringWriter::new(dest), "{}", self));
|
|
||||||
try!(dest.write_str("\")"));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub type CSSFloat = f32;
|
pub type CSSFloat = f32;
|
||||||
|
|
||||||
pub const FONT_MEDIUM_PX: i32 = 16;
|
pub const FONT_MEDIUM_PX: i32 = 16;
|
||||||
|
@ -99,7 +90,7 @@ pub mod specified {
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::Mul;
|
use std::ops::Mul;
|
||||||
use style_traits::values::specified::AllowedNumericType;
|
use style_traits::values::specified::AllowedNumericType;
|
||||||
use super::AuExtensionMethods;
|
use super::LocalToCss;
|
||||||
use super::computed::{TContext, ToComputedValue};
|
use super::computed::{TContext, ToComputedValue};
|
||||||
use super::{CSSFloat, FONT_MEDIUM_PX};
|
use super::{CSSFloat, FONT_MEDIUM_PX};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -1569,7 +1560,7 @@ pub mod computed {
|
||||||
use properties::ComputedValues;
|
use properties::ComputedValues;
|
||||||
use properties::style_struct_traits::Font;
|
use properties::style_struct_traits::Font;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use super::AuExtensionMethods;
|
use super::LocalToCss;
|
||||||
use super::specified::AngleOrCorner;
|
use super::specified::AngleOrCorner;
|
||||||
use super::{CSSFloat, specified};
|
use super::{CSSFloat, specified};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue