mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +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)
|
||||
}
|
||||
|
||||
pub fn serialize_comma_separated_list<W, T>(dest: &mut W, list: &[T])
|
||||
-> fmt::Result where W: fmt::Write, T: ToCss {
|
||||
if list.len() > 0 {
|
||||
for item in &list[..list.len()-1] {
|
||||
try!(item.to_css(dest));
|
||||
try!(write!(dest, ", "));
|
||||
}
|
||||
list[list.len()-1].to_css(dest)
|
||||
} else {
|
||||
Ok(())
|
||||
/// Serializes as CSS a comma-separated list of any `T` that supports being
|
||||
/// serialized as CSS.
|
||||
pub fn serialize_comma_separated_list<W, T>(dest: &mut W,
|
||||
list: &[T])
|
||||
-> fmt::Result
|
||||
where W: fmt::Write,
|
||||
T: ToCss,
|
||||
{
|
||||
if list.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
try!(list[0].to_css(dest));
|
||||
|
||||
for item in list.iter().skip(1) {
|
||||
try!(write!(dest, ", "));
|
||||
try!(item.to_css(dest));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -405,9 +405,10 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
|
|||
importance: Importance,
|
||||
is_first_serialization: &mut bool)
|
||||
-> fmt::Result
|
||||
where W: fmt::Write,
|
||||
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||
N: ToCss {
|
||||
where W: fmt::Write,
|
||||
I: Iterator<Item=&'a PropertyDeclaration>,
|
||||
N: ToCss
|
||||
{
|
||||
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
|
||||
|
@ -525,4 +526,3 @@ pub fn parse_property_declaration_list(context: &ParserContext, input: &mut Pars
|
|||
super::deduplicate_property_declarations(&mut block);
|
||||
block
|
||||
}
|
||||
|
||||
|
|
|
@ -73,16 +73,21 @@
|
|||
use values::{computed, specified};
|
||||
${caller.body()}
|
||||
}
|
||||
|
||||
/// The definition of the computed value for ${name}.
|
||||
pub mod computed_value {
|
||||
pub use super::single_value::computed_value as single_value;
|
||||
pub use self::single_value::T as SingleComputedValue;
|
||||
/// The computed value, effectively a list of single values.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub Vec<single_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();
|
||||
if let Some(val) = iter.next() {
|
||||
try!(val.to_css(dest));
|
||||
|
@ -101,12 +106,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
/// The specified value of ${name}.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub Vec<single_value::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();
|
||||
if let Some(val) = iter.next() {
|
||||
try!(val.to_css(dest));
|
||||
|
@ -405,7 +413,11 @@
|
|||
}
|
||||
|
||||
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
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
let mut ${sub_property.ident} = None;
|
||||
|
@ -446,7 +458,9 @@
|
|||
}
|
||||
|
||||
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 with_variables = false;
|
||||
% 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>)
|
||||
-> Result<(), ()> {
|
||||
input.look_for_var_functions();
|
||||
|
|
|
@ -87,89 +87,102 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
|||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:vector_longhand name="background-position-x" animatable="True">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
use values::specified::position::HorizontalPosition;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
use values::specified::position::HorizontalPosition;
|
||||
|
||||
pub mod computed_value {
|
||||
use values::computed::position::HorizontalPosition;
|
||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||
#[allow(missing_docs)]
|
||||
pub mod computed_value {
|
||||
use values::computed::position::HorizontalPosition;
|
||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||
|
||||
pub type T = HorizontalPosition;
|
||||
}
|
||||
pub type T = HorizontalPosition;
|
||||
}
|
||||
|
||||
pub type SpecifiedValue = HorizontalPosition;
|
||||
#[allow(missing_docs)]
|
||||
pub type SpecifiedValue = HorizontalPosition;
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::position::HorizontalPosition;
|
||||
HorizontalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::position::HorizontalPosition;
|
||||
HorizontalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
use values::specified::position::Keyword;
|
||||
HorizontalPosition {
|
||||
keyword: Some(Keyword::Left),
|
||||
position: None,
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
use values::specified::position::Keyword;
|
||||
HorizontalPosition {
|
||||
keyword: Some(Keyword::Left),
|
||||
position: None,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
HorizontalPosition {
|
||||
keyword: None,
|
||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
HorizontalPosition {
|
||||
keyword: None,
|
||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
HorizontalPosition::parse(context, input)
|
||||
}
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
HorizontalPosition::parse(context, input)
|
||||
}
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
<%helpers:vector_longhand name="background-position-y" animatable="True">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
use values::specified::position::VerticalPosition;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
use values::specified::position::VerticalPosition;
|
||||
|
||||
pub mod computed_value {
|
||||
use values::computed::position::VerticalPosition;
|
||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||
#[allow(missing_docs)]
|
||||
pub mod computed_value {
|
||||
use values::computed::position::VerticalPosition;
|
||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||
|
||||
pub type T = VerticalPosition;
|
||||
}
|
||||
pub type T = VerticalPosition;
|
||||
}
|
||||
|
||||
pub type SpecifiedValue = VerticalPosition;
|
||||
#[allow(missing_docs)]
|
||||
pub type SpecifiedValue = VerticalPosition;
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::position::VerticalPosition;
|
||||
VerticalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
use values::computed::position::VerticalPosition;
|
||||
VerticalPosition(computed::LengthOrPercentage::Percentage(0.0))
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
use values::specified::position::Keyword;
|
||||
VerticalPosition {
|
||||
keyword: Some(Keyword::Top),
|
||||
position: None,
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
use values::specified::position::Keyword;
|
||||
VerticalPosition {
|
||||
keyword: Some(Keyword::Top),
|
||||
position: None,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
VerticalPosition {
|
||||
keyword: None,
|
||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_position_value() -> SpecifiedValue {
|
||||
use values::specified::{LengthOrPercentage, Percentage};
|
||||
VerticalPosition {
|
||||
keyword: None,
|
||||
position: Some(LengthOrPercentage::Percentage(Percentage(0.0))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
VerticalPosition::parse(context, input)
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
VerticalPosition::parse(context, input)
|
||||
}
|
||||
</%helpers:vector_longhand>
|
||||
|
||||
${helpers.single_keyword("background-repeat",
|
||||
|
@ -199,6 +212,7 @@ ${helpers.single_keyword("background-origin",
|
|||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub mod computed_value {
|
||||
use values::computed::LengthOrPercentageOrAuto;
|
||||
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
|
||||
|
@ -254,6 +268,7 @@ ${helpers.single_keyword("background-origin",
|
|||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub struct ExplicitSize {
|
||||
pub width: specified::LengthOrPercentageOrAuto,
|
||||
pub height: specified::LengthOrPercentageOrAuto,
|
||||
|
|
|
@ -46,7 +46,8 @@
|
|||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||
where W: ::std::fmt::Write {
|
||||
where W: ::std::fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
% for value in values:
|
||||
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])}
|
||||
}
|
||||
|
||||
/// Parse a display value.
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
|
@ -144,119 +150,128 @@ ${helpers.single_keyword("clear", "none left right both",
|
|||
|
||||
</%helpers:longhand>
|
||||
|
||||
<%helpers:longhand name="vertical-align"
|
||||
animatable="True">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
<%helpers:longhand name="vertical-align" animatable="True">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::HasViewportPercentage;
|
||||
|
||||
<% vertical_align = data.longhands_by_name["vertical-align"] %>
|
||||
<% vertical_align.keyword = Keyword("vertical-align",
|
||||
"baseline sub super top text-top middle bottom text-bottom",
|
||||
extra_gecko_values="middle-with-baseline") %>
|
||||
<% vertical_align_keywords = vertical_align.keyword.values_for(product) %>
|
||||
<% vertical_align = data.longhands_by_name["vertical-align"] %>
|
||||
<% vertical_align.keyword = Keyword("vertical-align",
|
||||
"baseline sub super top text-top middle bottom text-bottom",
|
||||
extra_gecko_values="middle-with-baseline") %>
|
||||
<% vertical_align_keywords = vertical_align.keyword.values_for(product) %>
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::LengthOrPercentage(length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
SpecifiedValue::LengthOrPercentage(length) => length.has_viewport_percentage(),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
% for keyword in vertical_align_keywords:
|
||||
${to_rust_ident(keyword)},
|
||||
% endfor
|
||||
LengthOrPercentage(specified::LengthOrPercentage),
|
||||
}
|
||||
/// The `vertical-align` value.
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, PartialEq, Copy)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
% for keyword in vertical_align_keywords:
|
||||
${to_rust_ident(keyword)},
|
||||
% endfor
|
||||
LengthOrPercentage(specified::LengthOrPercentage),
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
% for keyword in vertical_align_keywords:
|
||||
SpecifiedValue::${to_rust_ident(keyword)} => dest.write_str("${keyword}"),
|
||||
% endfor
|
||||
SpecifiedValue::LengthOrPercentage(value) => value.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
/// baseline | sub | super | top | text-top | middle | bottom | text-bottom
|
||||
/// | <percentage> | <length>
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
input.try(|i| specified::LengthOrPercentage::parse(context, i))
|
||||
.map(SpecifiedValue::LengthOrPercentage)
|
||||
.or_else(|()| {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
% for keyword in vertical_align_keywords:
|
||||
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
|
||||
% endfor
|
||||
_ => Err(())
|
||||
}
|
||||
})
|
||||
}
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::{CSSFloat, computed};
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum T {
|
||||
% for keyword in vertical_align_keywords:
|
||||
${to_rust_ident(keyword)},
|
||||
% endfor
|
||||
LengthOrPercentage(computed::LengthOrPercentage),
|
||||
}
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
% for keyword in vertical_align_keywords:
|
||||
T::${to_rust_ident(keyword)} => dest.write_str("${keyword}"),
|
||||
% endfor
|
||||
T::LengthOrPercentage(value) => value.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T { computed_value::T::baseline }
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
% for keyword in vertical_align_keywords:
|
||||
SpecifiedValue::${to_rust_ident(keyword)} => dest.write_str("${keyword}"),
|
||||
% endfor
|
||||
SpecifiedValue::LengthOrPercentage(value) => value.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
/// baseline | sub | super | top | text-top | middle | bottom | text-bottom
|
||||
/// | <percentage> | <length>
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
input.try(|i| specified::LengthOrPercentage::parse(context, i))
|
||||
.map(SpecifiedValue::LengthOrPercentage)
|
||||
.or_else(|_| {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
% for keyword in vertical_align_keywords:
|
||||
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
|
||||
% endfor
|
||||
_ => Err(())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
/// The computed value for `vertical-align`.
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::{CSSFloat, computed};
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
% for keyword in vertical_align_keywords:
|
||||
SpecifiedValue::${to_rust_ident(keyword)} => {
|
||||
computed_value::T::${to_rust_ident(keyword)}
|
||||
}
|
||||
% endfor
|
||||
SpecifiedValue::LengthOrPercentage(value) =>
|
||||
computed_value::T::LengthOrPercentage(value.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
match *computed {
|
||||
% for keyword in vertical_align_keywords:
|
||||
computed_value::T::${to_rust_ident(keyword)} => {
|
||||
SpecifiedValue::${to_rust_ident(keyword)}
|
||||
}
|
||||
% endfor
|
||||
computed_value::T::LengthOrPercentage(value) =>
|
||||
SpecifiedValue::LengthOrPercentage(
|
||||
ToComputedValue::from_computed_value(&value)
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The keywords are the same, and the `LengthOrPercentage` is computed
|
||||
/// here.
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum T {
|
||||
% for keyword in vertical_align_keywords:
|
||||
${to_rust_ident(keyword)},
|
||||
% endfor
|
||||
LengthOrPercentage(computed::LengthOrPercentage),
|
||||
}
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
% for keyword in vertical_align_keywords:
|
||||
T::${to_rust_ident(keyword)} => dest.write_str("${keyword}"),
|
||||
% endfor
|
||||
T::LengthOrPercentage(value) => value.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The initial computed value for `vertical-align`.
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::baseline
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
% for keyword in vertical_align_keywords:
|
||||
SpecifiedValue::${to_rust_ident(keyword)} => {
|
||||
computed_value::T::${to_rust_ident(keyword)}
|
||||
}
|
||||
% endfor
|
||||
SpecifiedValue::LengthOrPercentage(value) =>
|
||||
computed_value::T::LengthOrPercentage(value.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
match *computed {
|
||||
% for keyword in vertical_align_keywords:
|
||||
computed_value::T::${to_rust_ident(keyword)} => {
|
||||
SpecifiedValue::${to_rust_ident(keyword)}
|
||||
}
|
||||
% endfor
|
||||
computed_value::T::LengthOrPercentage(value) =>
|
||||
SpecifiedValue::LengthOrPercentage(
|
||||
ToComputedValue::from_computed_value(&value)
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
|
||||
|
@ -275,44 +290,51 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
gecko_constant_prefix="NS_STYLE_OVERFLOW")}
|
||||
|
||||
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
|
||||
<%helpers:longhand name="overflow-y"
|
||||
need_clone="True"
|
||||
animatable="False">
|
||||
use super::overflow_x;
|
||||
<%helpers:longhand name="overflow-y" need_clone="True" animatable="False">
|
||||
use super::overflow_x;
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::NoViewportPercentage;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::NoViewportPercentage;
|
||||
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub super::super::overflow_x::computed_value::T);
|
||||
}
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
/// 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 {
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct T(pub super::super::overflow_x::computed_value::T);
|
||||
}
|
||||
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(overflow_x::get_initial_value())
|
||||
}
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
overflow_x::parse(context, input).map(SpecifiedValue)
|
||||
}
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(overflow_x::get_initial_value())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
overflow_x::parse(context, input).map(SpecifiedValue)
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
// TODO(pcwalton): Multiple transitions.
|
||||
<%helpers:longhand name="transition-duration"
|
||||
need_index="True"
|
||||
animatable="False">
|
||||
|
@ -369,7 +391,6 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
|||
</%helpers:longhand>
|
||||
|
||||
// TODO(pcwalton): Lots more timing functions.
|
||||
// TODO(pcwalton): Multiple transitions.
|
||||
<%helpers:longhand name="transition-timing-function"
|
||||
need_index="True"
|
||||
animatable="False">
|
||||
|
|
|
@ -315,7 +315,10 @@ ${helpers.single_keyword("font-variant-caps",
|
|||
use app_units::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)
|
||||
}
|
||||
|
||||
|
|
|
@ -160,8 +160,8 @@ pub mod shorthands {
|
|||
|
||||
/// A module with all the code related to animated properties.
|
||||
///
|
||||
/// This needs to be loaded at least after all longhand modules, given they
|
||||
/// populate the global data.
|
||||
/// This needs to be "included" by mako at least after all longhand modules,
|
||||
/// given they populate the global data.
|
||||
pub mod animated_properties {
|
||||
#![deny(missing_docs)]
|
||||
|
||||
|
@ -467,15 +467,21 @@ impl ShorthandId {
|
|||
}
|
||||
}
|
||||
|
||||
/// Serializes possible shorthand name with value to input buffer given a list of longhand declarations.
|
||||
/// On success, returns true if shorthand value is written and false if no shorthand value is present.
|
||||
/// Serializes the possible shorthand name with value to input buffer given
|
||||
/// 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,
|
||||
dest: &mut W,
|
||||
declarations: I,
|
||||
is_first_serialization: &mut bool,
|
||||
importance: Importance)
|
||||
-> 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) {
|
||||
None => Ok(false),
|
||||
Some(appendable_value) => {
|
||||
|
@ -490,60 +496,73 @@ 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>>
|
||||
where I: IntoIterator<Item=&'a PropertyDeclaration>, I::IntoIter: Clone {
|
||||
let declarations = declarations.into_iter();
|
||||
where I: IntoIterator<Item=&'a PropertyDeclaration>,
|
||||
I::IntoIter: Clone,
|
||||
{
|
||||
let declarations = declarations.into_iter();
|
||||
|
||||
// Only cloning iterators (a few pointers each) not declarations.
|
||||
let mut declarations2 = declarations.clone();
|
||||
let mut declarations3 = declarations.clone();
|
||||
// Only cloning iterators (a few pointers each) not declarations.
|
||||
let mut declarations2 = declarations.clone();
|
||||
let mut declarations3 = declarations.clone();
|
||||
|
||||
let first_declaration = match declarations2.next() {
|
||||
Some(declaration) => declaration,
|
||||
None => return None
|
||||
};
|
||||
let first_declaration = match declarations2.next() {
|
||||
Some(declaration) => declaration,
|
||||
None => return None
|
||||
};
|
||||
|
||||
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
|
||||
if let Some(css) = first_declaration.with_variables_from_shorthand(self) {
|
||||
if declarations2.all(|d| d.with_variables_from_shorthand(self) == Some(css)) {
|
||||
return Some(AppendableValue::Css(css));
|
||||
}
|
||||
else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
|
||||
if let Some(css) = first_declaration.with_variables_from_shorthand(self) {
|
||||
if declarations2.all(|d| d.with_variables_from_shorthand(self) == Some(css)) {
|
||||
return Some(AppendableValue::Css(css));
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
if !declarations3.any(|d| d.with_variables()) {
|
||||
return Some(AppendableValue::DeclarationsForShorthand(self, declarations));
|
||||
}
|
||||
if !declarations3.any(|d| d.with_variables()) {
|
||||
return Some(AppendableValue::DeclarationsForShorthand(self, declarations));
|
||||
}
|
||||
|
||||
None
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Servo's representation of a declared value for a given `T`, which is the
|
||||
/// declared value for that property.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum DeclaredValue<T> {
|
||||
/// A known specified value from the stylesheet.
|
||||
Value(T),
|
||||
/// A value that contained any css variables.
|
||||
WithVariables {
|
||||
/// The css serialization for this value.
|
||||
css: String,
|
||||
/// The first token type for this serialization.
|
||||
first_token_type: TokenSerializationType,
|
||||
/// The base url.
|
||||
base_url: ServoUrl,
|
||||
/// The shorthand this came from.
|
||||
from_shorthand: Option<ShorthandId>,
|
||||
},
|
||||
/// The `initial` keyword.
|
||||
Initial,
|
||||
/// The `inherit` keyword.
|
||||
Inherit,
|
||||
/// The `unset` keyword.
|
||||
Unset,
|
||||
}
|
||||
|
||||
impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
DeclaredValue::Value(ref v)
|
||||
=> v.has_viewport_percentage(),
|
||||
DeclaredValue::WithVariables { .. }
|
||||
=> panic!("DeclaredValue::has_viewport_percentage without resolving variables!"),
|
||||
DeclaredValue::Value(ref v) => v.has_viewport_percentage(),
|
||||
DeclaredValue::WithVariables { .. } => {
|
||||
panic!("DeclaredValue::has_viewport_percentage without \
|
||||
resolving variables!")
|
||||
},
|
||||
DeclaredValue::Initial |
|
||||
DeclaredValue::Inherit |
|
||||
DeclaredValue::Unset => false,
|
||||
|
@ -621,7 +640,9 @@ impl fmt::Debug 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 {
|
||||
PropertyId::Longhand(id) => dest.write_str(id.name()),
|
||||
PropertyId::Shorthand(id) => dest.write_str(id.name()),
|
||||
|
@ -1156,19 +1177,22 @@ pub struct ComputedValues {
|
|||
% endfor
|
||||
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
shareable: bool,
|
||||
/// The writing mode of this computed values struct.
|
||||
pub writing_mode: WritingMode,
|
||||
/// The root element's computed font size.
|
||||
pub root_font_size: Au,
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl ComputedValues {
|
||||
/// Construct a `ComputedValues` instance.
|
||||
pub fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
shareable: bool,
|
||||
writing_mode: WritingMode,
|
||||
root_font_size: Au,
|
||||
% for style_struct in data.active_style_structs():
|
||||
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||
% endfor
|
||||
shareable: bool,
|
||||
writing_mode: WritingMode,
|
||||
root_font_size: Au,
|
||||
% for style_struct in data.active_style_structs():
|
||||
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||
% endfor
|
||||
) -> Self {
|
||||
ComputedValues {
|
||||
custom_properties: custom_properties,
|
||||
|
@ -1821,16 +1845,21 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>,
|
|||
}
|
||||
|
||||
if seen.get_font_style() || seen.get_font_weight() || seen.get_font_stretch() ||
|
||||
seen.get_font_family() {
|
||||
seen.get_font_family() {
|
||||
style.mutate_font().compute_font_hash();
|
||||
}
|
||||
|
||||
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")]
|
||||
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) {
|
||||
// The 'align-self' property needs some special treatment since
|
||||
// its value depends on the 'align-items' value of its parent.
|
||||
% if "align-items" in data.longhands_by_name:
|
||||
|
@ -1870,12 +1899,17 @@ pub fn modify_style_for_anonymous_flow(style: &mut Arc<ComputedValues>,
|
|||
outline.outline_width = Au(0);
|
||||
}
|
||||
|
||||
/// Alters the given style to accommodate replaced content. This is called in flow construction. It
|
||||
/// handles cases like `<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`).
|
||||
/// Alters the given style to accommodate replaced content. This is called in
|
||||
/// flow construction. It handles cases like:
|
||||
///
|
||||
/// 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")]
|
||||
#[inline]
|
||||
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
|
||||
/// within the range of an element.
|
||||
/// Adjusts borders as appropriate to account for a fragment's status as the
|
||||
/// 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
|
||||
/// not outermost.
|
||||
/// Specifically, this function sets border widths to zero on the sides for
|
||||
/// which the fragment is not outermost.
|
||||
#[cfg(feature = "servo")]
|
||||
#[inline]
|
||||
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")]
|
||||
#[inline]
|
||||
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_
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// itself relatively positioned.
|
||||
/// Text is never directly relatively positioned; it's always contained within
|
||||
/// an element that is itself relatively positioned.
|
||||
#[cfg(feature = "servo")]
|
||||
#[inline]
|
||||
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
|
||||
/// children.
|
||||
/// Adjusts the `clip` property so that an inline absolute hypothetical fragment
|
||||
/// doesn't clip its children.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn modify_style_for_inline_absolute_hypothetical_fragment(style: &mut Arc<ComputedValues>) {
|
||||
if style.get_effects().clip.0.is_some() {
|
||||
|
|
|
@ -7,8 +7,16 @@ use style_traits::ToCss;
|
|||
use values::specified::{BorderStyle, CSSColor};
|
||||
use std::fmt;
|
||||
|
||||
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 {
|
||||
#[allow(missing_docs)]
|
||||
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 {
|
||||
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
|
||||
where I: Iterator<Item=&'a PropertyDeclaration> {
|
||||
where I: Iterator<Item=&'a PropertyDeclaration>
|
||||
{
|
||||
if let AppendableValue::DeclarationsForShorthand(shorthand, _) = *appendable_value {
|
||||
if let ShorthandId::Overflow = shorthand {
|
||||
return true;
|
||||
|
|
|
@ -268,7 +268,8 @@ impl CssRule {
|
|||
/// Note that only some types of rules can contain rules. An empty slice is
|
||||
/// used for others.
|
||||
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 {
|
||||
CssRule::Import(ref lock) => {
|
||||
let rule = lock.read();
|
||||
|
|
|
@ -72,9 +72,13 @@ pub trait ToComputedValue {
|
|||
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 {}
|
||||
|
||||
impl<T> ToComputedValue for T where T: ComputedValueAsSpecified + Clone {
|
||||
impl<T> ToComputedValue for T
|
||||
where T: ComputedValueAsSpecified + Clone,
|
||||
{
|
||||
type ComputedValue = T;
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -34,7 +34,8 @@ macro_rules! define_numbered_css_keyword_enum {
|
|||
|
||||
impl ToCss for $name {
|
||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||
where W: ::std::fmt::Write {
|
||||
where W: ::std::fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
$( $name::$variant => dest.write_str($css) ),+
|
||||
}
|
||||
|
@ -46,17 +47,26 @@ macro_rules! define_numbered_css_keyword_enum {
|
|||
pub mod computed;
|
||||
pub mod specified;
|
||||
|
||||
/// A CSS float value.
|
||||
pub type CSSFloat = f32;
|
||||
|
||||
/// The default font size.
|
||||
pub const FONT_MEDIUM_PX: i32 = 16;
|
||||
|
||||
/// A trait used to represent whether this value has viewport units.
|
||||
pub trait HasViewportPercentage {
|
||||
/// Returns true if this value has viewport units.
|
||||
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 {}
|
||||
|
||||
impl<T> HasViewportPercentage for T where T: NoViewportPercentage {
|
||||
impl<T> HasViewportPercentage for T
|
||||
where T: NoViewportPercentage,
|
||||
{
|
||||
#[inline]
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -23,15 +23,22 @@ pub use super::image::{SizeKeyword, VerticalDirection};
|
|||
|
||||
#[derive(Clone, PartialEq, Copy, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
/// A font relative length.
|
||||
pub enum FontRelativeLength {
|
||||
/// A "em" value: https://drafts.csswg.org/css-values/#em
|
||||
Em(CSSFloat),
|
||||
/// A "ex" value: https://drafts.csswg.org/css-values/#ex
|
||||
Ex(CSSFloat),
|
||||
/// A "ch" value: https://drafts.csswg.org/css-values/#ch
|
||||
Ch(CSSFloat),
|
||||
/// A "rem" value: https://drafts.csswg.org/css-values/#rem
|
||||
Rem(CSSFloat)
|
||||
}
|
||||
|
||||
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 {
|
||||
FontRelativeLength::Em(length) => write!(dest, "{}em", length),
|
||||
FontRelativeLength::Ex(length) => write!(dest, "{}ex", length),
|
||||
|
|
|
@ -127,7 +127,7 @@ pub enum ViewportLength {
|
|||
|
||||
impl ToCss for ViewportLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write
|
||||
where W: fmt::Write,
|
||||
{
|
||||
match *self {
|
||||
ViewportLength::Specified(length) => length.to_css(dest),
|
||||
|
@ -545,7 +545,9 @@ impl Cascade {
|
|||
}
|
||||
|
||||
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();
|
||||
for stylesheet in stylesheets {
|
||||
stylesheet.as_ref().effective_viewport_rules(device, |rule| {
|
||||
|
@ -581,10 +583,13 @@ impl Cascade {
|
|||
}
|
||||
}
|
||||
|
||||
/// Just a helper trait to be able to implement methods on ViewportConstraints.
|
||||
pub trait MaybeNew {
|
||||
/// Create a ViewportConstraints from a viewport size and a `@viewport`
|
||||
/// rule.
|
||||
fn maybe_new(initial_viewport: TypedSize2D<f32, ViewportPx>,
|
||||
rule: &ViewportRule)
|
||||
-> Option<ViewportConstraints>;
|
||||
rule: &ViewportRule)
|
||||
-> Option<ViewportConstraints>;
|
||||
}
|
||||
|
||||
impl MaybeNew for ViewportConstraints {
|
||||
|
|
|
@ -95,11 +95,12 @@ macro_rules! __define_css_keyword_enum__actual {
|
|||
|
||||
impl ToCss for $name {
|
||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||
where W: ::std::fmt::Write {
|
||||
match *self {
|
||||
$( $name::$variant => dest.write_str($css) ),+
|
||||
}
|
||||
where W: ::std::fmt::Write
|
||||
{
|
||||
match *self {
|
||||
$( $name::$variant => dest.write_str($css) ),+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue