mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement getComputedStyle
This commit is contained in:
parent
416931f4be
commit
e484d6b5e3
24 changed files with 886 additions and 152 deletions
|
@ -92,6 +92,14 @@ impl PropertyAnimation {
|
|||
new_style.$structname().$field)
|
||||
}
|
||||
)*
|
||||
TransitionProperty::Clip => {
|
||||
AnimatedProperty::Clip(old_style.get_effects().clip.0,
|
||||
new_style.get_effects().clip.0)
|
||||
}
|
||||
TransitionProperty::LetterSpacing => {
|
||||
AnimatedProperty::LetterSpacing(old_style.get_inheritedtext().letter_spacing.0,
|
||||
new_style.get_inheritedtext().letter_spacing.0)
|
||||
}
|
||||
TransitionProperty::TextShadow => {
|
||||
AnimatedProperty::TextShadow(old_style.get_effects().text_shadow.clone(),
|
||||
new_style.get_effects().text_shadow.clone())
|
||||
|
@ -100,6 +108,10 @@ impl PropertyAnimation {
|
|||
AnimatedProperty::Transform(old_style.get_effects().transform.clone(),
|
||||
new_style.get_effects().transform.clone())
|
||||
}
|
||||
TransitionProperty::WordSpacing => {
|
||||
AnimatedProperty::WordSpacing(old_style.get_inheritedtext().word_spacing.0,
|
||||
new_style.get_inheritedtext().word_spacing.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,12 +129,10 @@ impl PropertyAnimation {
|
|||
[BorderTopWidth; get_border; border_top_width],
|
||||
[Bottom; get_positionoffsets; bottom],
|
||||
[Color; get_color; color],
|
||||
[Clip; get_effects; clip],
|
||||
[FontSize; get_font; font_size],
|
||||
[FontWeight; get_font; font_weight],
|
||||
[Height; get_box; height],
|
||||
[Left; get_positionoffsets; bottom],
|
||||
[LetterSpacing; get_inheritedtext; letter_spacing],
|
||||
[LineHeight; get_inheritedbox; line_height],
|
||||
[MarginBottom; get_margin; margin_bottom],
|
||||
[MarginLeft; get_margin; margin_left],
|
||||
|
@ -145,7 +155,6 @@ impl PropertyAnimation {
|
|||
[VerticalAlign; get_box; vertical_align],
|
||||
[Visibility; get_inheritedbox; visibility],
|
||||
[Width; get_box; width],
|
||||
[WordSpacing; get_inheritedtext; word_spacing],
|
||||
[ZIndex; get_box; z_index]);
|
||||
|
||||
let property_animation = PropertyAnimation {
|
||||
|
@ -186,7 +195,22 @@ impl PropertyAnimation {
|
|||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
AnimatedProperty::Clip(ref start, ref end) => {
|
||||
if let Some(value) = start.interpolate(end, progress) {
|
||||
style.mutate_effects().clip.0 = value
|
||||
}
|
||||
}
|
||||
AnimatedProperty::LetterSpacing(ref start, ref end) => {
|
||||
if let Some(value) = start.interpolate(end, progress) {
|
||||
style.mutate_inheritedtext().letter_spacing.0 = value
|
||||
}
|
||||
}
|
||||
AnimatedProperty::WordSpacing(ref start, ref end) => {
|
||||
if let Some(value) = start.interpolate(end, progress) {
|
||||
style.mutate_inheritedtext().word_spacing.0 = value
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
match_property!(
|
||||
[BackgroundColor; mutate_background; background_color],
|
||||
|
@ -202,12 +226,10 @@ impl PropertyAnimation {
|
|||
[BorderTopWidth; mutate_border; border_top_width],
|
||||
[Bottom; mutate_positionoffsets; bottom],
|
||||
[Color; mutate_color; color],
|
||||
[Clip; mutate_effects; clip],
|
||||
[FontSize; mutate_font; font_size],
|
||||
[FontWeight; mutate_font; font_weight],
|
||||
[Height; mutate_box; height],
|
||||
[Left; mutate_positionoffsets; bottom],
|
||||
[LetterSpacing; mutate_inheritedtext; letter_spacing],
|
||||
[LineHeight; mutate_inheritedbox; line_height],
|
||||
[MarginBottom; mutate_margin; margin_bottom],
|
||||
[MarginLeft; mutate_margin; margin_left],
|
||||
|
@ -232,7 +254,6 @@ impl PropertyAnimation {
|
|||
[VerticalAlign; mutate_box; vertical_align],
|
||||
[Visibility; mutate_inheritedbox; visibility],
|
||||
[Width; mutate_box; width],
|
||||
[WordSpacing; mutate_inheritedtext; word_spacing],
|
||||
[ZIndex; mutate_box; z_index]);
|
||||
}
|
||||
|
||||
|
@ -765,7 +786,7 @@ fn interpolate_transform_list(from_list: &Vec<TransformOperation>,
|
|||
result.push_all(from_list);
|
||||
}
|
||||
|
||||
Some(result)
|
||||
TransformList(Some(result))
|
||||
}
|
||||
|
||||
/// Build an equivalent 'identity transform function list' based
|
||||
|
@ -809,7 +830,7 @@ impl Interpolate for TransformList {
|
|||
#[inline]
|
||||
fn interpolate(&self, other: &TransformList, time: f32) -> Option<TransformList> {
|
||||
// http://dev.w3.org/csswg/css-transforms/#interpolation-of-transforms
|
||||
let result = match (self, other) {
|
||||
let result = match (&self.0, &other.0) {
|
||||
(&Some(ref from_list), &Some(ref to_list)) => {
|
||||
// Two lists of transforms
|
||||
interpolate_transform_list(from_list, &to_list, time)
|
||||
|
@ -824,9 +845,9 @@ impl Interpolate for TransformList {
|
|||
let from_list = build_identity_transform_list(to_list);
|
||||
interpolate_transform_list(&from_list, to_list, time)
|
||||
}
|
||||
(&None, &None) => {
|
||||
_ => {
|
||||
// http://dev.w3.org/csswg/css-transforms/#none-none-animation
|
||||
None
|
||||
TransformList(None)
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -655,7 +655,16 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
computed_value::T::Normal => dest.write_str("normal"),
|
||||
computed_value::T::Length(length) => length.to_css(dest),
|
||||
computed_value::T::Number(number) => write!(dest, "{}", number),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T { computed_value::T::Normal }
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -749,6 +758,17 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl ::cssparser::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::Length(value) => value.to_css(dest),
|
||||
T::Percentage(percentage) => write!(dest, "{}%", percentage * 100.),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T { computed_value::T::baseline }
|
||||
|
@ -1067,7 +1087,20 @@ pub mod longhands {
|
|||
|
||||
pub mod computed_value {
|
||||
use url::Url;
|
||||
pub type T = Option<Url>;
|
||||
use cssparser::{ToCss, Token};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<Url>);
|
||||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("none"),
|
||||
Some(ref url) => Token::Url(url.to_string().into()).to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -1076,8 +1109,8 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::None => None,
|
||||
SpecifiedValue::Url(ref url) => Some(url.clone()),
|
||||
SpecifiedValue::None => computed_value::T(None),
|
||||
SpecifiedValue::Url(ref url) => computed_value::T(Some(url.clone())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1091,7 +1124,7 @@ pub mod longhands {
|
|||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
</%self:longhand>
|
||||
|
||||
|
@ -1249,7 +1282,20 @@ pub mod longhands {
|
|||
|
||||
pub mod computed_value {
|
||||
use values::computed;
|
||||
pub type T = Option<computed::Image>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<computed::Image>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("none"),
|
||||
Some(computed::Image::Url(ref url)) =>
|
||||
::cssparser::Token::Url(url.to_string().into()).to_css(dest),
|
||||
Some(computed::Image::LinearGradient(ref gradient)) =>
|
||||
gradient.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
@ -1266,7 +1312,7 @@ pub mod longhands {
|
|||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||
|
@ -1281,8 +1327,9 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue(None) => None,
|
||||
SpecifiedValue(Some(ref image)) => Some(image.to_computed_value(context)),
|
||||
SpecifiedValue(None) => computed_value::T(None),
|
||||
SpecifiedValue(Some(ref image)) =>
|
||||
computed_value::T(Some(image.to_computed_value(context))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1318,6 +1365,15 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.horizontal.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.vertical.to_css(dest));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl SpecifiedValue {
|
||||
fn new(first: specified::PositionComponent, second: specified::PositionComponent)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
|
@ -1424,6 +1480,16 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
computed_value::T::Explicit(ref size) => size.to_css(dest),
|
||||
computed_value::T::Cover => dest.write_str("cover"),
|
||||
computed_value::T::Contain => dest.write_str("contain"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct SpecifiedExplicitSize {
|
||||
pub width: specified::LengthOrPercentageOrAuto,
|
||||
|
@ -1438,6 +1504,15 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::ExplicitSize {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.width.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.height.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub enum SpecifiedValue {
|
||||
Explicit(SpecifiedExplicitSize),
|
||||
|
@ -1727,6 +1802,15 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
% for weight in range(100, 901, 100):
|
||||
computed_value::T::Weight${weight} => dest.write_str("${weight}"),
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::Weight400 // normal
|
||||
|
@ -1909,12 +1993,22 @@ pub mod longhands {
|
|||
|
||||
pub mod computed_value {
|
||||
use util::geometry::Au;
|
||||
pub type T = Option<Au>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<Au>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("normal"),
|
||||
Some(l) => l.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -1923,8 +2017,9 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::Normal => None,
|
||||
SpecifiedValue::Specified(l) => Some(l.to_computed_value(context))
|
||||
SpecifiedValue::Normal => computed_value::T(None),
|
||||
SpecifiedValue::Specified(l) =>
|
||||
computed_value::T(Some(l.to_computed_value(context)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1960,12 +2055,22 @@ pub mod longhands {
|
|||
|
||||
pub mod computed_value {
|
||||
use util::geometry::Au;
|
||||
pub type T = Option<Au>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<Au>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("normal"),
|
||||
Some(l) => l.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -1974,8 +2079,9 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::Normal => None,
|
||||
SpecifiedValue::Specified(l) => Some(l.to_computed_value(context))
|
||||
SpecifiedValue::Normal => computed_value::T(None),
|
||||
SpecifiedValue::Specified(l) =>
|
||||
computed_value::T(Some(l.to_computed_value(context)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2098,7 +2204,9 @@ pub mod longhands {
|
|||
|
||||
<%self:longhand name="-servo-text-decorations-in-effect"
|
||||
derived_from="display text-decoration">
|
||||
use cssparser::RGBA;
|
||||
use cssparser::{RGBA, ToCss};
|
||||
use std::fmt;
|
||||
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
|
@ -2114,6 +2222,13 @@ pub mod longhands {
|
|||
pub type T = super::SpecifiedValue;
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
// Web compat doesn't matter here.
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
SpecifiedValue {
|
||||
|
@ -2233,6 +2348,14 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.horizontal.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.vertical.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
|
@ -2370,12 +2493,22 @@ pub mod longhands {
|
|||
|
||||
pub mod computed_value {
|
||||
use util::geometry::Au;
|
||||
pub type T = Option<Au>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<Au>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("auto"),
|
||||
Some(l) => l.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -2384,8 +2517,9 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::Auto => None,
|
||||
SpecifiedValue::Specified(l) => Some(l.to_computed_value(context))
|
||||
SpecifiedValue::Auto => computed_value::T(None),
|
||||
SpecifiedValue::Specified(l) =>
|
||||
computed_value::T(Some(l.to_computed_value(context)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2420,12 +2554,22 @@ pub mod longhands {
|
|||
}
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = Option<u32>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<u32>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("auto"),
|
||||
Some(count) => write!(dest, "{}", count),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -2434,8 +2578,9 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::Auto => None,
|
||||
SpecifiedValue::Specified(count) => Some(count)
|
||||
SpecifiedValue::Auto => computed_value::T(None),
|
||||
SpecifiedValue::Specified(count) =>
|
||||
computed_value::T(Some(count))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2476,12 +2621,22 @@ pub mod longhands {
|
|||
|
||||
pub mod computed_value {
|
||||
use util::geometry::Au;
|
||||
pub type T = Option<Au>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<Au>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("normal"),
|
||||
Some(l) => l.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -2490,8 +2645,9 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::Normal => None,
|
||||
SpecifiedValue::Specified(l) => Some(l.to_computed_value(context))
|
||||
SpecifiedValue::Normal => computed_value::T(None),
|
||||
SpecifiedValue::Specified(l) =>
|
||||
computed_value::T(Some(l.to_computed_value(context)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2611,7 +2767,8 @@ pub mod longhands {
|
|||
use values::computed;
|
||||
use std::fmt;
|
||||
|
||||
pub type T = Vec<BoxShadow>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Vec<BoxShadow>);
|
||||
|
||||
#[derive(Clone, PartialEq, Copy)]
|
||||
pub struct BoxShadow {
|
||||
|
@ -2635,9 +2792,44 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let mut iter = self.0.iter();
|
||||
if let Some(shadow) = iter.next() {
|
||||
try!(shadow.to_css(dest));
|
||||
} else {
|
||||
try!(dest.write_str("none"));
|
||||
return Ok(())
|
||||
}
|
||||
for shadow in iter {
|
||||
try!(dest.write_str(", "));
|
||||
try!(shadow.to_css(dest));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::BoxShadow {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if self.inset {
|
||||
try!(dest.write_str("inset "));
|
||||
}
|
||||
try!(self.blur_radius.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.spread_radius.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.offset_x.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.offset_y.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.color.to_css(dest));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
Vec::new()
|
||||
computed_value::T(Vec::new())
|
||||
}
|
||||
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
|
@ -2653,7 +2845,7 @@ pub mod longhands {
|
|||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
self.0.iter().map(|value| compute_one_box_shadow(value, context)).collect()
|
||||
computed_value::T(self.0.iter().map(|value| compute_one_box_shadow(value, context)).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2752,7 +2944,38 @@ pub mod longhands {
|
|||
pub left: Au,
|
||||
}
|
||||
|
||||
pub type T = Option<ClipRect>;
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct T(pub Option<ClipRect>);
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("auto"),
|
||||
Some(rect) => {
|
||||
try!(dest.write_str("rect("));
|
||||
try!(rect.top.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
if let Some(right) = rect.right {
|
||||
try!(right.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
} else {
|
||||
try!(dest.write_str("auto, "));
|
||||
}
|
||||
|
||||
if let Some(bottom) = rect.bottom {
|
||||
try!(bottom.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
} else {
|
||||
try!(dest.write_str("auto, "));
|
||||
}
|
||||
|
||||
try!(rect.left.to_css(dest));
|
||||
try!(dest.write_str(")"));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Copy)]
|
||||
|
@ -2780,7 +3003,7 @@ pub mod longhands {
|
|||
try!(dest.write_str("auto, "));
|
||||
}
|
||||
|
||||
if let Some(bottom) = self.right {
|
||||
if let Some(bottom) = self.bottom {
|
||||
try!(bottom.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
} else {
|
||||
|
@ -2806,7 +3029,7 @@ pub mod longhands {
|
|||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
|
@ -2814,12 +3037,12 @@ pub mod longhands {
|
|||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
self.0.map(|value| computed_value::ClipRect {
|
||||
computed_value::T(self.0.map(|value| computed_value::ClipRect {
|
||||
top: value.top.to_computed_value(context),
|
||||
right: value.right.map(|right| right.to_computed_value(context)),
|
||||
bottom: value.bottom.map(|bottom| bottom.to_computed_value(context)),
|
||||
left: value.left.to_computed_value(context),
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2903,6 +3126,36 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let mut iter = self.0.iter();
|
||||
if let Some(shadow) = iter.next() {
|
||||
try!(shadow.to_css(dest));
|
||||
} else {
|
||||
try!(dest.write_str("none"));
|
||||
return Ok(())
|
||||
}
|
||||
for shadow in iter {
|
||||
try!(dest.write_str(", "));
|
||||
try!(shadow.to_css(dest));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::TextShadow {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.offset_x.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.offset_y.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.blur_radius.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.color.to_css(dest));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let mut iter = self.0.iter();
|
||||
|
@ -3103,6 +3356,23 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let mut iter = self.filters.iter();
|
||||
if let Some(filter) = iter.next() {
|
||||
try!(filter.to_css(dest));
|
||||
} else {
|
||||
try!(dest.write_str("none"));
|
||||
return Ok(())
|
||||
}
|
||||
for filter in iter {
|
||||
try!(dest.write_str(" "));
|
||||
try!(filter.to_css(dest));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let mut iter = self.0.iter();
|
||||
|
@ -3120,6 +3390,31 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::Filter {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
computed_value::Filter::Blur(value) => {
|
||||
try!(dest.write_str("blur("));
|
||||
try!(value.to_css(dest));
|
||||
try!(dest.write_str(")"));
|
||||
}
|
||||
computed_value::Filter::Brightness(value) => try!(write!(dest, "brightness({})", value)),
|
||||
computed_value::Filter::Contrast(value) => try!(write!(dest, "contrast({})", value)),
|
||||
computed_value::Filter::Grayscale(value) => try!(write!(dest, "grayscale({})", value)),
|
||||
computed_value::Filter::HueRotate(value) => {
|
||||
try!(dest.write_str("hue-rotate("));
|
||||
try!(value.to_css(dest));
|
||||
try!(dest.write_str(")"));
|
||||
}
|
||||
computed_value::Filter::Invert(value) => try!(write!(dest, "invert({})", value)),
|
||||
computed_value::Filter::Opacity(value) => try!(write!(dest, "opacity({})", value)),
|
||||
computed_value::Filter::Saturate(value) => try!(write!(dest, "saturate({})", value)),
|
||||
computed_value::Filter::Sepia(value) => try!(write!(dest, "sepia({})", value)),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedFilter {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
|
@ -3253,7 +3548,8 @@ pub mod longhands {
|
|||
Perspective(computed::Length),
|
||||
}
|
||||
|
||||
pub type T = Option<Vec<ComputedOperation>>;
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct T(pub Option<Vec<ComputedOperation>>);
|
||||
}
|
||||
|
||||
pub use self::computed_value::ComputedMatrix as SpecifiedMatrix;
|
||||
|
@ -3290,6 +3586,13 @@ pub mod longhands {
|
|||
Perspective(specified::Length),
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
// TODO(pcwalton)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedOperation {
|
||||
fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
// TODO(pcwalton)
|
||||
|
@ -3316,7 +3619,7 @@ pub mod longhands {
|
|||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
None
|
||||
computed_value::T(None)
|
||||
}
|
||||
|
||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
|
@ -3548,7 +3851,7 @@ pub mod longhands {
|
|||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
if self.0.is_empty() {
|
||||
return None
|
||||
return computed_value::T(None)
|
||||
}
|
||||
|
||||
let mut result = vec!();
|
||||
|
@ -3577,7 +3880,7 @@ pub mod longhands {
|
|||
};
|
||||
}
|
||||
|
||||
Some(result)
|
||||
computed_value::T(Some(result))
|
||||
}
|
||||
}
|
||||
</%self:longhand>
|
||||
|
@ -3612,6 +3915,16 @@ pub mod longhands {
|
|||
depth: Length,
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.horizontal.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
try!(self.vertical.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.depth.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.horizontal.to_css(dest));
|
||||
|
@ -3742,6 +4055,14 @@ pub mod longhands {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToCss for computed_value::T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.horizontal.to_css(dest));
|
||||
try!(dest.write_str(" "));
|
||||
self.vertical.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct SpecifiedValue {
|
||||
horizontal: LengthOrPercentage,
|
||||
|
@ -5542,7 +5863,7 @@ impl ComputedValues {
|
|||
#[inline]
|
||||
pub fn is_multicol(&self) -> bool {
|
||||
let style = self.get_column();
|
||||
style.column_count.is_some() || style.column_width.is_some()
|
||||
style.column_count.0.is_some() || style.column_width.0.is_some()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -5560,13 +5881,13 @@ impl ComputedValues {
|
|||
// TODO(gw): Add clip-path, isolation, mask-image, mask-border-source when supported.
|
||||
if effects.opacity < 1.0 ||
|
||||
!effects.filter.is_empty() ||
|
||||
effects.clip.is_some() {
|
||||
effects.clip.0.is_some() {
|
||||
effects.mix_blend_mode != mix_blend_mode::T::normal ||
|
||||
return transform_style::T::flat;
|
||||
}
|
||||
|
||||
if effects.transform_style == transform_style::T::auto {
|
||||
if effects.transform.is_some() {
|
||||
if effects.transform.0.is_some() {
|
||||
return transform_style::T::flat;
|
||||
}
|
||||
if effects.perspective != computed::LengthOrNone::None {
|
||||
|
@ -5579,17 +5900,28 @@ impl ComputedValues {
|
|||
}
|
||||
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
#[inline]
|
||||
pub fn get_${style_struct.name.lower()}
|
||||
<'a>(&'a self) -> &'a style_structs::${style_struct.name} {
|
||||
&*self.${style_struct.ident}
|
||||
}
|
||||
#[inline]
|
||||
pub fn mutate_${style_struct.name.lower()}
|
||||
<'a>(&'a mut self) -> &'a mut style_structs::${style_struct.name} {
|
||||
&mut *Arc::make_unique(&mut self.${style_struct.ident})
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_${style_struct.name.lower()}
|
||||
<'a>(&'a self) -> &'a style_structs::${style_struct.name} {
|
||||
&*self.${style_struct.ident}
|
||||
}
|
||||
#[inline]
|
||||
pub fn mutate_${style_struct.name.lower()}
|
||||
<'a>(&'a mut self) -> &'a mut style_structs::${style_struct.name} {
|
||||
&mut *Arc::make_unique(&mut self.${style_struct.ident})
|
||||
}
|
||||
% endfor
|
||||
|
||||
pub fn computed_value_to_string(&self, name: &str) -> Option<String> {
|
||||
match name {
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% for longhand in style_struct.longhands:
|
||||
"${longhand.name}" => Some(self.${style_struct.ident}.${longhand.ident}.to_css_string()),
|
||||
% endfor
|
||||
% endfor
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -975,6 +975,16 @@ pub mod computed {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for LengthOrPercentage {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self {
|
||||
&LengthOrPercentage::Length(length) => length.to_css(dest),
|
||||
&LengthOrPercentage::Percentage(percentage)
|
||||
=> write!(dest, "{}%", percentage * 100.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
pub enum LengthOrPercentageOrAuto {
|
||||
Length(Au),
|
||||
|
@ -1010,6 +1020,17 @@ pub mod computed {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for LengthOrPercentageOrAuto {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self {
|
||||
&LengthOrPercentageOrAuto::Length(length) => length.to_css(dest),
|
||||
&LengthOrPercentageOrAuto::Percentage(percentage)
|
||||
=> write!(dest, "{}%", percentage * 100.),
|
||||
&LengthOrPercentageOrAuto::Auto => dest.write_str("auto"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
pub enum LengthOrPercentageOrNone {
|
||||
Length(Au),
|
||||
|
@ -1045,6 +1066,17 @@ pub mod computed {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for LengthOrPercentageOrNone {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self {
|
||||
&LengthOrPercentageOrNone::Length(length) => length.to_css(dest),
|
||||
&LengthOrPercentageOrNone::Percentage(percentage) =>
|
||||
write!(dest, "{}%", percentage * 100.),
|
||||
&LengthOrPercentageOrNone::None => dest.write_str("none"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Copy)]
|
||||
pub enum LengthOrNone {
|
||||
Length(Au),
|
||||
|
@ -1075,6 +1107,15 @@ pub mod computed {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for LengthOrNone {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self {
|
||||
&LengthOrNone::Length(length) => length.to_css(dest),
|
||||
&LengthOrNone::None => dest.write_str("none"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::Image {
|
||||
type ComputedValue = Image;
|
||||
|
||||
|
@ -1116,6 +1157,19 @@ pub mod computed {
|
|||
pub stops: Vec<ColorStop>,
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for LinearGradient {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(dest.write_str("linear-gradient("));
|
||||
try!(self.angle_or_corner.to_css(dest));
|
||||
for stop in self.stops.iter() {
|
||||
try!(dest.write_str(", "));
|
||||
try!(stop.to_css(dest));
|
||||
}
|
||||
try!(dest.write_str(")"));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for LinearGradient {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let _ = write!(f, "{:?}", self.angle_or_corner);
|
||||
|
@ -1137,6 +1191,17 @@ pub mod computed {
|
|||
pub position: Option<LengthOrPercentage>,
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for ColorStop {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.color.to_css(dest));
|
||||
if let Some(position) = self.position {
|
||||
try!(dest.write_str(" "));
|
||||
try!(position.to_css(dest));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ColorStop {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let _ = write!(f, "{:?}", self.color);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue