mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Consistently indent stuff, add a bit of documentation driving by.
This commit is contained in:
parent
b023791af5
commit
277ef70d39
14 changed files with 435 additions and 296 deletions
|
@ -182,15 +182,24 @@ pub fn arc_ptr_eq<T: 'static>(a: &Arc<T>, b: &Arc<T>) -> bool {
|
||||||
(a as *const T) == (b as *const T)
|
(a as *const T) == (b as *const T)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize_comma_separated_list<W, T>(dest: &mut W, list: &[T])
|
/// Serializes as CSS a comma-separated list of any `T` that supports being
|
||||||
-> fmt::Result where W: fmt::Write, T: ToCss {
|
/// serialized as CSS.
|
||||||
if list.len() > 0 {
|
pub fn serialize_comma_separated_list<W, T>(dest: &mut W,
|
||||||
for item in &list[..list.len()-1] {
|
list: &[T])
|
||||||
try!(item.to_css(dest));
|
-> fmt::Result
|
||||||
try!(write!(dest, ", "));
|
where W: fmt::Write,
|
||||||
|
T: ToCss,
|
||||||
|
{
|
||||||
|
if list.is_empty() {
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
list[list.len()-1].to_css(dest)
|
|
||||||
} else {
|
try!(list[0].to_css(dest));
|
||||||
|
|
||||||
|
for item in list.iter().skip(1) {
|
||||||
|
try!(write!(dest, ", "));
|
||||||
|
try!(item.to_css(dest));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -407,7 +407,8 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
|
||||||
-> fmt::Result
|
-> fmt::Result
|
||||||
where W: fmt::Write,
|
where W: fmt::Write,
|
||||||
I: Iterator<Item=&'a PropertyDeclaration>,
|
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||||
N: ToCss {
|
N: ToCss
|
||||||
|
{
|
||||||
try!(handle_first_serialization(dest, is_first_serialization));
|
try!(handle_first_serialization(dest, is_first_serialization));
|
||||||
|
|
||||||
// Overflow does not behave like a normal shorthand. When overflow-x and overflow-y are not of equal
|
// Overflow does not behave like a normal shorthand. When overflow-x and overflow-y are not of equal
|
||||||
|
@ -525,4 +526,3 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars
|
||||||
super::deduplicate_property_declarations(&mut block);
|
super::deduplicate_property_declarations(&mut block);
|
||||||
block
|
block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,16 +73,21 @@
|
||||||
use values::{computed, specified};
|
use values::{computed, specified};
|
||||||
${caller.body()}
|
${caller.body()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The definition of the computed value for ${name}.
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
pub use super::single_value::computed_value as single_value;
|
pub use super::single_value::computed_value as single_value;
|
||||||
pub use self::single_value::T as SingleComputedValue;
|
pub use self::single_value::T as SingleComputedValue;
|
||||||
|
/// The computed value, effectively a list of single values.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct T(pub Vec<single_value::T>);
|
pub struct T(pub Vec<single_value::T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
impl ToCss for computed_value::T {
|
||||||
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,
|
||||||
|
{
|
||||||
let mut iter = self.0.iter();
|
let mut iter = self.0.iter();
|
||||||
if let Some(val) = iter.next() {
|
if let Some(val) = iter.next() {
|
||||||
try!(val.to_css(dest));
|
try!(val.to_css(dest));
|
||||||
|
@ -101,12 +106,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The specified value of ${name}.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
|
pub struct SpecifiedValue(pub Vec<single_value::SpecifiedValue>);
|
||||||
|
|
||||||
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,
|
||||||
|
{
|
||||||
let mut iter = self.0.iter();
|
let mut iter = self.0.iter();
|
||||||
if let Some(val) = iter.next() {
|
if let Some(val) = iter.next() {
|
||||||
try!(val.to_css(dest));
|
try!(val.to_css(dest));
|
||||||
|
@ -405,7 +413,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LonghandsToSerialize<'a> {
|
impl<'a> LonghandsToSerialize<'a> {
|
||||||
pub fn from_iter<I: Iterator<Item=&'a PropertyDeclaration>>(iter: I) -> Result<Self, ()> {
|
/// Tries to get a serializable set of longhands given a set of
|
||||||
|
/// property declarations.
|
||||||
|
pub fn from_iter<I>(iter: I) -> Result<Self, ()>
|
||||||
|
where I: Iterator<Item=&'a PropertyDeclaration>,
|
||||||
|
{
|
||||||
// Define all of the expected variables that correspond to the shorthand
|
// Define all of the expected variables that correspond to the shorthand
|
||||||
% for sub_property in shorthand.sub_properties:
|
% for sub_property in shorthand.sub_properties:
|
||||||
let mut ${sub_property.ident} = None;
|
let mut ${sub_property.ident} = None;
|
||||||
|
@ -446,7 +458,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||||
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,
|
||||||
|
{
|
||||||
let mut all_flags = SerializeFlags::all();
|
let mut all_flags = SerializeFlags::all();
|
||||||
let mut with_variables = false;
|
let mut with_variables = false;
|
||||||
% for sub_property in shorthand.sub_properties:
|
% for sub_property in shorthand.sub_properties:
|
||||||
|
@ -477,7 +491,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser,
|
/// Parse the given shorthand and fill the result into the
|
||||||
|
/// `declarations` vector.
|
||||||
|
pub fn parse(context: &ParserContext,
|
||||||
|
input: &mut Parser,
|
||||||
declarations: &mut Vec<PropertyDeclaration>)
|
declarations: &mut Vec<PropertyDeclaration>)
|
||||||
-> Result<(), ()> {
|
-> Result<(), ()> {
|
||||||
input.look_for_var_functions();
|
input.look_for_var_functions();
|
||||||
|
|
|
@ -92,6 +92,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
use values::HasViewportPercentage;
|
use values::HasViewportPercentage;
|
||||||
use values::specified::position::HorizontalPosition;
|
use values::specified::position::HorizontalPosition;
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::position::HorizontalPosition;
|
use values::computed::position::HorizontalPosition;
|
||||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||||
|
@ -99,14 +100,17 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
pub type T = HorizontalPosition;
|
pub type T = HorizontalPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub type SpecifiedValue = HorizontalPosition;
|
pub type SpecifiedValue = HorizontalPosition;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
use values::computed::position::HorizontalPosition;
|
use values::computed::position::HorizontalPosition;
|
||||||
HorizontalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
HorizontalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
use values::specified::position::Keyword;
|
use values::specified::position::Keyword;
|
||||||
HorizontalPosition {
|
HorizontalPosition {
|
||||||
|
@ -115,6 +119,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||||
use values::specified::{LengthOrPercentage, Percentage};
|
use values::specified::{LengthOrPercentage, Percentage};
|
||||||
HorizontalPosition {
|
HorizontalPosition {
|
||||||
|
@ -123,6 +128,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
HorizontalPosition::parse(context, input)
|
HorizontalPosition::parse(context, input)
|
||||||
|
@ -135,6 +141,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
use values::HasViewportPercentage;
|
use values::HasViewportPercentage;
|
||||||
use values::specified::position::VerticalPosition;
|
use values::specified::position::VerticalPosition;
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::position::VerticalPosition;
|
use values::computed::position::VerticalPosition;
|
||||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||||
|
@ -142,14 +149,17 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
pub type T = VerticalPosition;
|
pub type T = VerticalPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub type SpecifiedValue = VerticalPosition;
|
pub type SpecifiedValue = VerticalPosition;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
use values::computed::position::VerticalPosition;
|
use values::computed::position::VerticalPosition;
|
||||||
VerticalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
VerticalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||||
use values::specified::position::Keyword;
|
use values::specified::position::Keyword;
|
||||||
VerticalPosition {
|
VerticalPosition {
|
||||||
|
@ -158,6 +168,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||||
use values::specified::{LengthOrPercentage, Percentage};
|
use values::specified::{LengthOrPercentage, Percentage};
|
||||||
VerticalPosition {
|
VerticalPosition {
|
||||||
|
@ -166,6 +177,8 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
VerticalPosition::parse(context, input)
|
VerticalPosition::parse(context, input)
|
||||||
|
@ -199,6 +212,7 @@ ${helpers.single_keyword("background-origin",
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::HasViewportPercentage;
|
use values::HasViewportPercentage;
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use values::computed::LengthOrPercentageOrAuto;
|
use values::computed::LengthOrPercentageOrAuto;
|
||||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||||
|
@ -254,6 +268,7 @@ ${helpers.single_keyword("background-origin",
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub struct ExplicitSize {
|
pub struct ExplicitSize {
|
||||||
pub width: specified::LengthOrPercentageOrAuto,
|
pub width: specified::LengthOrPercentageOrAuto,
|
||||||
pub height: specified::LengthOrPercentageOrAuto,
|
pub height: specified::LengthOrPercentageOrAuto,
|
||||||
|
|
|
@ -46,7 +46,8 @@
|
||||||
|
|
||||||
impl ToCss for T {
|
impl ToCss for T {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||||
where W: ::std::fmt::Write {
|
where W: ::std::fmt::Write,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
% for value in values:
|
% for value in values:
|
||||||
T::${to_rust_ident(value)} => dest.write_str("${value}"),
|
T::${to_rust_ident(value)} => dest.write_str("${value}"),
|
||||||
|
@ -55,9 +56,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
|
||||||
|
/// The initial display value.
|
||||||
|
#[inline]
|
||||||
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::T::${to_rust_ident(values[0])}
|
computed_value::T::${to_rust_ident(values[0])}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parse a display value.
|
||||||
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||||
|
@ -144,8 +150,7 @@ ${helpers.single_keyword("clear", "none left right both",
|
||||||
|
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
<%helpers:longhand name="vertical-align"
|
<%helpers:longhand name="vertical-align" animatable="True">
|
||||||
animatable="True">
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::HasViewportPercentage;
|
use values::HasViewportPercentage;
|
||||||
|
@ -165,6 +170,7 @@ ${helpers.single_keyword("clear", "none left right both",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The `vertical-align` value.
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -190,7 +196,7 @@ ${helpers.single_keyword("clear", "none left right both",
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
input.try(|i| specified::LengthOrPercentage::parse(context, i))
|
input.try(|i| specified::LengthOrPercentage::parse(context, i))
|
||||||
.map(SpecifiedValue::LengthOrPercentage)
|
.map(SpecifiedValue::LengthOrPercentage)
|
||||||
.or_else(|()| {
|
.or_else(|_| {
|
||||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||||
% for keyword in vertical_align_keywords:
|
% for keyword in vertical_align_keywords:
|
||||||
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
|
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
|
||||||
|
@ -199,11 +205,16 @@ ${helpers.single_keyword("clear", "none left right both",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The computed value for `vertical-align`.
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::{CSSFloat, computed};
|
use values::{CSSFloat, computed};
|
||||||
|
|
||||||
|
/// The keywords are the same, and the `LengthOrPercentage` is computed
|
||||||
|
/// here.
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -224,8 +235,12 @@ ${helpers.single_keyword("clear", "none left right both",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The initial computed value for `vertical-align`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_initial_value() -> computed_value::T { computed_value::T::baseline }
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
|
computed_value::T::baseline
|
||||||
|
}
|
||||||
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
impl ToComputedValue for SpecifiedValue {
|
||||||
type ComputedValue = computed_value::T;
|
type ComputedValue = computed_value::T;
|
||||||
|
@ -275,9 +290,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
gecko_constant_prefix="NS_STYLE_OVERFLOW")}
|
gecko_constant_prefix="NS_STYLE_OVERFLOW")}
|
||||||
|
|
||||||
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
|
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
|
||||||
<%helpers:longhand name="overflow-y"
|
<%helpers:longhand name="overflow-y" need_clone="True" animatable="False">
|
||||||
need_clone="True"
|
|
||||||
animatable="False">
|
|
||||||
use super::overflow_x;
|
use super::overflow_x;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -295,6 +308,12 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// The specified and computed value for overflow-y is a wrapper on top of
|
||||||
|
/// `overflow-x`, so we re-use the logic, but prevent errors from mistakenly
|
||||||
|
/// assign one to other.
|
||||||
|
///
|
||||||
|
/// TODO(Manishearth, emilio): We may want to just use the same value.
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
@ -303,16 +322,19 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
|
|
||||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn get_initial_value() -> computed_value::T {
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
computed_value::T(overflow_x::get_initial_value())
|
computed_value::T(overflow_x::get_initial_value())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||||
overflow_x::parse(context, input).map(SpecifiedValue)
|
overflow_x::parse(context, input).map(SpecifiedValue)
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
// TODO(pcwalton): Multiple transitions.
|
|
||||||
<%helpers:longhand name="transition-duration"
|
<%helpers:longhand name="transition-duration"
|
||||||
need_index="True"
|
need_index="True"
|
||||||
animatable="False">
|
animatable="False">
|
||||||
|
@ -369,7 +391,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
// TODO(pcwalton): Lots more timing functions.
|
// TODO(pcwalton): Lots more timing functions.
|
||||||
// TODO(pcwalton): Multiple transitions.
|
|
||||||
<%helpers:longhand name="transition-timing-function"
|
<%helpers:longhand name="transition-timing-function"
|
||||||
need_index="True"
|
need_index="True"
|
||||||
animatable="False">
|
animatable="False">
|
||||||
|
|
|
@ -315,7 +315,10 @@ ${helpers.single_keyword("font-variant-caps",
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
pub type T = Au;
|
pub type T = Au;
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
|
||||||
|
#[inline]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub fn get_initial_value() -> computed_value::T {
|
||||||
Au::from_px(FONT_MEDIUM_PX)
|
Au::from_px(FONT_MEDIUM_PX)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,8 +160,8 @@ pub mod shorthands {
|
||||||
|
|
||||||
/// A module with all the code related to animated properties.
|
/// A module with all the code related to animated properties.
|
||||||
///
|
///
|
||||||
/// This needs to be loaded at least after all longhand modules, given they
|
/// This needs to be "included" by mako at least after all longhand modules,
|
||||||
/// populate the global data.
|
/// given they populate the global data.
|
||||||
pub mod animated_properties {
|
pub mod animated_properties {
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
|
@ -467,15 +467,21 @@ impl ShorthandId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serializes possible shorthand name with value to input buffer given a list of longhand declarations.
|
/// Serializes the possible shorthand name with value to input buffer given
|
||||||
/// On success, returns true if shorthand value is written and false if no shorthand value is present.
|
/// a list of longhand declarations.
|
||||||
|
///
|
||||||
|
/// On success, returns true if the shorthand value is written, or false if
|
||||||
|
/// no shorthand value is present.
|
||||||
pub fn serialize_shorthand_to_buffer<'a, W, I>(self,
|
pub fn serialize_shorthand_to_buffer<'a, W, I>(self,
|
||||||
dest: &mut W,
|
dest: &mut W,
|
||||||
declarations: I,
|
declarations: I,
|
||||||
is_first_serialization: &mut bool,
|
is_first_serialization: &mut bool,
|
||||||
importance: Importance)
|
importance: Importance)
|
||||||
-> Result<bool, fmt::Error>
|
-> Result<bool, fmt::Error>
|
||||||
where W: Write, I: IntoIterator<Item=&'a PropertyDeclaration>, I::IntoIter: Clone {
|
where W: Write,
|
||||||
|
I: IntoIterator<Item=&'a PropertyDeclaration>,
|
||||||
|
I::IntoIter: Clone,
|
||||||
|
{
|
||||||
match self.get_shorthand_appendable_value(declarations) {
|
match self.get_shorthand_appendable_value(declarations) {
|
||||||
None => Ok(false),
|
None => Ok(false),
|
||||||
Some(appendable_value) => {
|
Some(appendable_value) => {
|
||||||
|
@ -490,9 +496,12 @@ impl ShorthandId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_shorthand_appendable_value<'a, I>(self, declarations: I)
|
fn get_shorthand_appendable_value<'a, I>(self,
|
||||||
|
declarations: I)
|
||||||
-> Option<AppendableValue<'a, I::IntoIter>>
|
-> Option<AppendableValue<'a, I::IntoIter>>
|
||||||
where I: IntoIterator<Item=&'a PropertyDeclaration>, I::IntoIter: Clone {
|
where I: IntoIterator<Item=&'a PropertyDeclaration>,
|
||||||
|
I::IntoIter: Clone,
|
||||||
|
{
|
||||||
let declarations = declarations.into_iter();
|
let declarations = declarations.into_iter();
|
||||||
|
|
||||||
// Only cloning iterators (a few pointers each) not declarations.
|
// Only cloning iterators (a few pointers each) not declarations.
|
||||||
|
@ -509,10 +518,8 @@ impl ShorthandId {
|
||||||
if declarations2.all(|d| d.with_variables_from_shorthand(self) == Some(css)) {
|
if declarations2.all(|d| d.with_variables_from_shorthand(self) == Some(css)) {
|
||||||
return Some(AppendableValue::Css(css));
|
return Some(AppendableValue::Css(css));
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if !declarations3.any(|d| d.with_variables()) {
|
if !declarations3.any(|d| d.with_variables()) {
|
||||||
return Some(AppendableValue::DeclarationsForShorthand(self, declarations));
|
return Some(AppendableValue::DeclarationsForShorthand(self, declarations));
|
||||||
|
@ -522,28 +529,40 @@ impl ShorthandId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Servo's representation of a declared value for a given `T`, which is the
|
||||||
|
/// declared value for that property.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub enum DeclaredValue<T> {
|
pub enum DeclaredValue<T> {
|
||||||
|
/// A known specified value from the stylesheet.
|
||||||
Value(T),
|
Value(T),
|
||||||
|
/// A value that contained any css variables.
|
||||||
WithVariables {
|
WithVariables {
|
||||||
|
/// The css serialization for this value.
|
||||||
css: String,
|
css: String,
|
||||||
|
/// The first token type for this serialization.
|
||||||
first_token_type: TokenSerializationType,
|
first_token_type: TokenSerializationType,
|
||||||
|
/// The base url.
|
||||||
base_url: ServoUrl,
|
base_url: ServoUrl,
|
||||||
|
/// The shorthand this came from.
|
||||||
from_shorthand: Option<ShorthandId>,
|
from_shorthand: Option<ShorthandId>,
|
||||||
},
|
},
|
||||||
|
/// The `initial` keyword.
|
||||||
Initial,
|
Initial,
|
||||||
|
/// The `inherit` keyword.
|
||||||
Inherit,
|
Inherit,
|
||||||
|
/// The `unset` keyword.
|
||||||
Unset,
|
Unset,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
|
impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
|
||||||
fn has_viewport_percentage(&self) -> bool {
|
fn has_viewport_percentage(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
DeclaredValue::Value(ref v)
|
DeclaredValue::Value(ref v) => v.has_viewport_percentage(),
|
||||||
=> v.has_viewport_percentage(),
|
DeclaredValue::WithVariables { .. } => {
|
||||||
DeclaredValue::WithVariables { .. }
|
panic!("DeclaredValue::has_viewport_percentage without \
|
||||||
=> panic!("DeclaredValue::has_viewport_percentage without resolving variables!"),
|
resolving variables!")
|
||||||
|
},
|
||||||
DeclaredValue::Initial |
|
DeclaredValue::Initial |
|
||||||
DeclaredValue::Inherit |
|
DeclaredValue::Inherit |
|
||||||
DeclaredValue::Unset => false,
|
DeclaredValue::Unset => false,
|
||||||
|
@ -621,7 +640,9 @@ impl fmt::Debug for PropertyId {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for PropertyId {
|
impl ToCss for PropertyId {
|
||||||
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,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
PropertyId::Longhand(id) => dest.write_str(id.name()),
|
PropertyId::Longhand(id) => dest.write_str(id.name()),
|
||||||
PropertyId::Shorthand(id) => dest.write_str(id.name()),
|
PropertyId::Shorthand(id) => dest.write_str(id.name()),
|
||||||
|
@ -1156,12 +1177,15 @@ pub struct ComputedValues {
|
||||||
% endfor
|
% endfor
|
||||||
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
shareable: bool,
|
shareable: bool,
|
||||||
|
/// The writing mode of this computed values struct.
|
||||||
pub writing_mode: WritingMode,
|
pub writing_mode: WritingMode,
|
||||||
|
/// The root element's computed font size.
|
||||||
pub root_font_size: Au,
|
pub root_font_size: Au,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
impl ComputedValues {
|
impl ComputedValues {
|
||||||
|
/// Construct a `ComputedValues` instance.
|
||||||
pub fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
pub fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
shareable: bool,
|
shareable: bool,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
|
@ -1828,6 +1852,11 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>,
|
||||||
style
|
style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Modifies the style for an anonymous flow so it resets all its non-inherited
|
||||||
|
/// style structs, and set their borders and outlines to zero.
|
||||||
|
///
|
||||||
|
/// Also, it gets a new display value, which is honored except when it's
|
||||||
|
/// `inline`.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
pub fn modify_style_for_anonymous_flow(style: &mut Arc<ComputedValues>,
|
pub fn modify_style_for_anonymous_flow(style: &mut Arc<ComputedValues>,
|
||||||
new_display_value: longhands::display::computed_value::T) {
|
new_display_value: longhands::display::computed_value::T) {
|
||||||
|
@ -1870,12 +1899,17 @@ pub fn modify_style_for_anonymous_flow(style: &mut Arc<ComputedValues>,
|
||||||
outline.outline_width = Au(0);
|
outline.outline_width = Au(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alters the given style to accommodate replaced content. This is called in flow construction. It
|
/// Alters the given style to accommodate replaced content. This is called in
|
||||||
/// handles cases like `<div style="position: absolute">foo bar baz</div>` (in which `foo`, `bar`,
|
/// flow construction. It handles cases like:
|
||||||
/// and `baz` must not be absolutely-positioned) and cases like `<sup>Foo</sup>` (in which the
|
|
||||||
/// `vertical-align: top` style of `sup` must not propagate down into `Foo`).
|
|
||||||
///
|
///
|
||||||
/// FIXME(#5625, pcwalton): It would probably be cleaner and faster to do this in the cascade.
|
/// <div style="position: absolute">foo bar baz</div>
|
||||||
|
///
|
||||||
|
/// (in which `foo`, `bar`, and `baz` must not be absolutely-positioned) and
|
||||||
|
/// cases like `<sup>Foo</sup>` (in which the `vertical-align: top` style of
|
||||||
|
/// `sup` must not propagate down into `Foo`).
|
||||||
|
///
|
||||||
|
/// FIXME(#5625, pcwalton): It would probably be cleaner and faster to do this
|
||||||
|
/// in the cascade.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn modify_style_for_replaced_content(style: &mut Arc<ComputedValues>) {
|
pub fn modify_style_for_replaced_content(style: &mut Arc<ComputedValues>) {
|
||||||
|
@ -1908,11 +1942,11 @@ pub fn modify_style_for_replaced_content(style: &mut Arc<ComputedValues>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjusts borders as appropriate to account for a fragment's status as the first or last fragment
|
/// Adjusts borders as appropriate to account for a fragment's status as the
|
||||||
/// within the range of an element.
|
/// first or last fragment within the range of an element.
|
||||||
///
|
///
|
||||||
/// Specifically, this function sets border widths to zero on the sides for which the fragment is
|
/// Specifically, this function sets border widths to zero on the sides for
|
||||||
/// not outermost.
|
/// which the fragment is not outermost.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValues>,
|
pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValues>,
|
||||||
|
@ -1964,7 +1998,8 @@ pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValues>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjusts the `position` property as necessary for the outer fragment wrapper of an inline-block.
|
/// Adjusts the `position` property as necessary for the outer fragment wrapper
|
||||||
|
/// of an inline-block.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn modify_style_for_outer_inline_block_fragment(style: &mut Arc<ComputedValues>) {
|
pub fn modify_style_for_outer_inline_block_fragment(style: &mut Arc<ComputedValues>) {
|
||||||
|
@ -1973,10 +2008,11 @@ pub fn modify_style_for_outer_inline_block_fragment(style: &mut Arc<ComputedValu
|
||||||
box_style.position = longhands::position::computed_value::T::static_
|
box_style.position = longhands::position::computed_value::T::static_
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjusts the `position` and `padding` properties as necessary to account for text.
|
/// Adjusts the `position` and `padding` properties as necessary to account for
|
||||||
|
/// text.
|
||||||
///
|
///
|
||||||
/// Text is never directly relatively positioned; it's always contained within an element that is
|
/// Text is never directly relatively positioned; it's always contained within
|
||||||
/// itself relatively positioned.
|
/// an element that is itself relatively positioned.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn modify_style_for_text(style: &mut Arc<ComputedValues>) {
|
pub fn modify_style_for_text(style: &mut Arc<ComputedValues>) {
|
||||||
|
@ -2010,8 +2046,8 @@ pub fn modify_style_for_text(style: &mut Arc<ComputedValues>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjusts the `clip` property so that an inline absolute hypothetical fragment doesn't clip its
|
/// Adjusts the `clip` property so that an inline absolute hypothetical fragment
|
||||||
/// children.
|
/// doesn't clip its children.
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
pub fn modify_style_for_inline_absolute_hypothetical_fragment(style: &mut Arc<ComputedValues>) {
|
pub fn modify_style_for_inline_absolute_hypothetical_fragment(style: &mut Arc<ComputedValues>) {
|
||||||
if style.get_effects().clip.0.is_some() {
|
if style.get_effects().clip.0.is_some() {
|
||||||
|
|
|
@ -7,8 +7,16 @@ use style_traits::ToCss;
|
||||||
use values::specified::{BorderStyle, CSSColor};
|
use values::specified::{BorderStyle, CSSColor};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
pub fn serialize_four_sides<W, I>(dest: &mut W, top: &I, right: &I, bottom: &I, left: &I)
|
#[allow(missing_docs)]
|
||||||
-> fmt::Result where W: fmt::Write, I: ToCss + PartialEq {
|
pub fn serialize_four_sides<W, I>(dest: &mut W,
|
||||||
|
top: &I,
|
||||||
|
right: &I,
|
||||||
|
bottom: &I,
|
||||||
|
left: &I)
|
||||||
|
-> fmt::Result
|
||||||
|
where W: fmt::Write,
|
||||||
|
I: ToCss + PartialEq,
|
||||||
|
{
|
||||||
|
|
||||||
if left == right {
|
if left == right {
|
||||||
let horizontal_value = left;
|
let horizontal_value = left;
|
||||||
|
@ -85,8 +93,10 @@ fn serialize_directional_border<W, I>(dest: &mut W,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub fn is_overflow_shorthand<'a, I>(appendable_value: &AppendableValue<'a, I>) -> bool
|
pub fn is_overflow_shorthand<'a, I>(appendable_value: &AppendableValue<'a, I>) -> bool
|
||||||
where I: Iterator<Item=&'a PropertyDeclaration> {
|
where I: Iterator<Item=&'a PropertyDeclaration>
|
||||||
|
{
|
||||||
if let AppendableValue::DeclarationsForShorthand(shorthand, _) = *appendable_value {
|
if let AppendableValue::DeclarationsForShorthand(shorthand, _) = *appendable_value {
|
||||||
if let ShorthandId::Overflow = shorthand {
|
if let ShorthandId::Overflow = shorthand {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -268,7 +268,8 @@ impl CssRule {
|
||||||
/// Note that only some types of rules can contain rules. An empty slice is
|
/// Note that only some types of rules can contain rules. An empty slice is
|
||||||
/// used for others.
|
/// used for others.
|
||||||
pub fn with_nested_rules_and_mq<F, R>(&self, mut f: F) -> R
|
pub fn with_nested_rules_and_mq<F, R>(&self, mut f: F) -> R
|
||||||
where F: FnMut(&[CssRule], Option<&MediaList>) -> R {
|
where F: FnMut(&[CssRule], Option<&MediaList>) -> R
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
CssRule::Import(ref lock) => {
|
CssRule::Import(ref lock) => {
|
||||||
let rule = lock.read();
|
let rule = lock.read();
|
||||||
|
|
|
@ -72,9 +72,13 @@ pub trait ToComputedValue {
|
||||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self;
|
fn from_computed_value(computed: &Self::ComputedValue) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A marker trait to represent that the specified value is also the computed
|
||||||
|
/// value.
|
||||||
pub trait ComputedValueAsSpecified {}
|
pub trait ComputedValueAsSpecified {}
|
||||||
|
|
||||||
impl<T> ToComputedValue for T where T: ComputedValueAsSpecified + Clone {
|
impl<T> ToComputedValue for T
|
||||||
|
where T: ComputedValueAsSpecified + Clone,
|
||||||
|
{
|
||||||
type ComputedValue = T;
|
type ComputedValue = T;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -34,7 +34,8 @@ macro_rules! define_numbered_css_keyword_enum {
|
||||||
|
|
||||||
impl ToCss for $name {
|
impl ToCss for $name {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||||
where W: ::std::fmt::Write {
|
where W: ::std::fmt::Write,
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
$( $name::$variant => dest.write_str($css) ),+
|
$( $name::$variant => dest.write_str($css) ),+
|
||||||
}
|
}
|
||||||
|
@ -46,17 +47,26 @@ macro_rules! define_numbered_css_keyword_enum {
|
||||||
pub mod computed;
|
pub mod computed;
|
||||||
pub mod specified;
|
pub mod specified;
|
||||||
|
|
||||||
|
/// A CSS float value.
|
||||||
pub type CSSFloat = f32;
|
pub type CSSFloat = f32;
|
||||||
|
|
||||||
|
/// The default font size.
|
||||||
pub const FONT_MEDIUM_PX: i32 = 16;
|
pub const FONT_MEDIUM_PX: i32 = 16;
|
||||||
|
|
||||||
|
/// A trait used to represent whether this value has viewport units.
|
||||||
pub trait HasViewportPercentage {
|
pub trait HasViewportPercentage {
|
||||||
|
/// Returns true if this value has viewport units.
|
||||||
fn has_viewport_percentage(&self) -> bool;
|
fn has_viewport_percentage(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A trait used as a marker to represent that a given value has no viewport
|
||||||
|
/// units.
|
||||||
pub trait NoViewportPercentage {}
|
pub trait NoViewportPercentage {}
|
||||||
|
|
||||||
impl<T> HasViewportPercentage for T where T: NoViewportPercentage {
|
impl<T> HasViewportPercentage for T
|
||||||
|
where T: NoViewportPercentage,
|
||||||
|
{
|
||||||
|
#[inline]
|
||||||
fn has_viewport_percentage(&self) -> bool {
|
fn has_viewport_percentage(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,22 @@ pub use super::image::{SizeKeyword, VerticalDirection};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
/// A font relative length.
|
||||||
pub enum FontRelativeLength {
|
pub enum FontRelativeLength {
|
||||||
|
/// A "em" value: https://drafts.csswg.org/css-values/#em
|
||||||
Em(CSSFloat),
|
Em(CSSFloat),
|
||||||
|
/// A "ex" value: https://drafts.csswg.org/css-values/#ex
|
||||||
Ex(CSSFloat),
|
Ex(CSSFloat),
|
||||||
|
/// A "ch" value: https://drafts.csswg.org/css-values/#ch
|
||||||
Ch(CSSFloat),
|
Ch(CSSFloat),
|
||||||
|
/// A "rem" value: https://drafts.csswg.org/css-values/#rem
|
||||||
Rem(CSSFloat)
|
Rem(CSSFloat)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for FontRelativeLength {
|
impl ToCss for FontRelativeLength {
|
||||||
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
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
FontRelativeLength::Em(length) => write!(dest, "{}em", length),
|
FontRelativeLength::Em(length) => write!(dest, "{}em", length),
|
||||||
FontRelativeLength::Ex(length) => write!(dest, "{}ex", length),
|
FontRelativeLength::Ex(length) => write!(dest, "{}ex", length),
|
||||||
|
|
|
@ -127,7 +127,7 @@ pub enum ViewportLength {
|
||||||
|
|
||||||
impl ToCss for ViewportLength {
|
impl ToCss for ViewportLength {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
where W: fmt::Write
|
where W: fmt::Write,
|
||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
ViewportLength::Specified(length) => length.to_css(dest),
|
ViewportLength::Specified(length) => length.to_css(dest),
|
||||||
|
@ -545,7 +545,9 @@ impl Cascade {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_stylesheets<'a, I>(stylesheets: I, device: &Device) -> Self
|
pub fn from_stylesheets<'a, I>(stylesheets: I, device: &Device) -> Self
|
||||||
where I: IntoIterator, I::Item: AsRef<Stylesheet> {
|
where I: IntoIterator,
|
||||||
|
I::Item: AsRef<Stylesheet>,
|
||||||
|
{
|
||||||
let mut cascade = Self::new();
|
let mut cascade = Self::new();
|
||||||
for stylesheet in stylesheets {
|
for stylesheet in stylesheets {
|
||||||
stylesheet.as_ref().effective_viewport_rules(device, |rule| {
|
stylesheet.as_ref().effective_viewport_rules(device, |rule| {
|
||||||
|
@ -581,7 +583,10 @@ impl Cascade {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Just a helper trait to be able to implement methods on ViewportConstraints.
|
||||||
pub trait MaybeNew {
|
pub trait MaybeNew {
|
||||||
|
/// Create a ViewportConstraints from a viewport size and a `@viewport`
|
||||||
|
/// rule.
|
||||||
fn maybe_new(initial_viewport: TypedSize2D<f32, ViewportPx>,
|
fn maybe_new(initial_viewport: TypedSize2D<f32, ViewportPx>,
|
||||||
rule: &ViewportRule)
|
rule: &ViewportRule)
|
||||||
-> Option<ViewportConstraints>;
|
-> Option<ViewportConstraints>;
|
||||||
|
|
|
@ -95,7 +95,8 @@ macro_rules! __define_css_keyword_enum__actual {
|
||||||
|
|
||||||
impl ToCss for $name {
|
impl ToCss for $name {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||||
where W: ::std::fmt::Write {
|
where W: ::std::fmt::Write
|
||||||
|
{
|
||||||
match *self {
|
match *self {
|
||||||
$( $name::$variant => dest.write_str($css) ),+
|
$( $name::$variant => dest.write_str($css) ),+
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue