mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Factor out a UrlOrNone value type and make -moz-binding use it.
MozReview-Commit-ID: L57QEf40e2m
This commit is contained in:
parent
333afb61f6
commit
75e97c02dc
5 changed files with 62 additions and 66 deletions
|
@ -893,7 +893,7 @@ fn static_assert() {
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) {
|
pub fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) {
|
||||||
use properties::longhands::_moz_binding::SpecifiedValue as BindingValue;
|
use properties::longhands::_moz_binding::computed_value::T as BindingValue;
|
||||||
match v {
|
match v {
|
||||||
BindingValue::None => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
|
BindingValue::None => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
|
||||||
BindingValue::Url(ref url, ref extra_data) => {
|
BindingValue::Url(ref url, ref extra_data) => {
|
||||||
|
|
|
@ -16,19 +16,24 @@
|
||||||
</%call>
|
</%call>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse', **kwargs)">
|
<%def name="predefined_type(name, type, initial_value, parse_method='parse', needs_context=False, **kwargs)">
|
||||||
<%call expr="longhand(name, predefined_type=type, **kwargs)">
|
<%call expr="longhand(name, predefined_type=type, **kwargs)">
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::{Color as CSSParserColor, RGBA};
|
use cssparser::{Color as CSSParserColor, RGBA};
|
||||||
pub type SpecifiedValue = specified::${type};
|
pub use values::specified::${type} as SpecifiedValue;
|
||||||
pub mod computed_value {
|
pub mod computed_value {
|
||||||
pub use values::computed::${type} as T;
|
pub use values::computed::${type} as T;
|
||||||
}
|
}
|
||||||
#[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} }
|
#[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} }
|
||||||
#[inline] pub fn parse(_context: &ParserContext, input: &mut Parser)
|
#[allow(unused_variables)]
|
||||||
|
#[inline] pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<SpecifiedValue, ()> {
|
-> Result<SpecifiedValue, ()> {
|
||||||
|
% if needs_context:
|
||||||
|
specified::${type}::${parse_method}(context, input)
|
||||||
|
% else:
|
||||||
specified::${type}::${parse_method}(input)
|
specified::${type}::${parse_method}(input)
|
||||||
|
% endif
|
||||||
}
|
}
|
||||||
</%call>
|
</%call>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -920,64 +920,8 @@ ${helpers.single_keyword("-moz-appearance",
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding
|
// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding
|
||||||
<%helpers:longhand name="-moz-binding" products="gecko" animatable="False" disable_when_testing="True">
|
${helpers.predefined_type("-moz-binding", "UrlOrNone", "computed_value::T::None",
|
||||||
use cssparser::{CssStringWriter, ToCss};
|
needs_context=True,
|
||||||
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
|
products="gecko",
|
||||||
use std::fmt::{self, Write};
|
animatable="False",
|
||||||
use url::Url;
|
disable_when_testing="True")}
|
||||||
use values::specified::UrlExtraData;
|
|
||||||
use values::computed::ComputedValueAsSpecified;
|
|
||||||
use values::NoViewportPercentage;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
||||||
pub enum SpecifiedValue {
|
|
||||||
Url(Url, UrlExtraData),
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
|
||||||
impl NoViewportPercentage for SpecifiedValue {}
|
|
||||||
|
|
||||||
impl ToCss for SpecifiedValue {
|
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
|
||||||
use values::LocalToCss;
|
|
||||||
match *self {
|
|
||||||
SpecifiedValue::Url(ref url, _) => {
|
|
||||||
url.to_css(dest)
|
|
||||||
}
|
|
||||||
SpecifiedValue::None => {
|
|
||||||
try!(dest.write_str("none"));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod computed_value {
|
|
||||||
pub type T = super::SpecifiedValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline] pub fn get_initial_value() -> SpecifiedValue {
|
|
||||||
SpecifiedValue::None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
|
||||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
|
||||||
return Ok(SpecifiedValue::None);
|
|
||||||
}
|
|
||||||
|
|
||||||
let url = context.parse_url(&*try!(input.expect_url()));
|
|
||||||
match UrlExtraData::make_from(context) {
|
|
||||||
Some(extra_data) => {
|
|
||||||
Ok(SpecifiedValue::Url(url, extra_data))
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
// FIXME(heycam) should ensure we always have a principal, etc., when parsing
|
|
||||||
// style attributes and re-parsing due to CSS Variables.
|
|
||||||
println!("stylo: skipping -moz-binding declaration without ParserContextExtraData");
|
|
||||||
Err(())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:longhand>
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use super::LocalToCss;
|
||||||
pub use cssparser::Color as CSSColor;
|
pub use cssparser::Color as CSSColor;
|
||||||
pub use self::image::{EndingShape as GradientShape, Gradient, GradientKind, Image};
|
pub use self::image::{EndingShape as GradientShape, Gradient, GradientKind, Image};
|
||||||
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||||
pub use super::specified::{Angle, BorderStyle, Time, UrlExtraData};
|
pub use super::specified::{Angle, BorderStyle, Time, UrlExtraData, UrlOrNone};
|
||||||
|
|
||||||
pub mod basic_shape;
|
pub mod basic_shape;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
|
|
|
@ -18,6 +18,7 @@ use std::ops::Mul;
|
||||||
use style_traits::values::specified::AllowedNumericType;
|
use style_traits::values::specified::AllowedNumericType;
|
||||||
use super::{CSSFloat, FONT_MEDIUM_PX, HasViewportPercentage, LocalToCss, NoViewportPercentage};
|
use super::{CSSFloat, FONT_MEDIUM_PX, HasViewportPercentage, LocalToCss, NoViewportPercentage};
|
||||||
use super::computed::{self, ComputedValueAsSpecified, Context, ToComputedValue};
|
use super::computed::{self, ComputedValueAsSpecified, Context, ToComputedValue};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||||
pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||||
|
@ -1452,3 +1453,49 @@ impl ToCss for Opacity {
|
||||||
self.0.to_css(dest)
|
self.0.to_css(dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Clone, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
pub enum UrlOrNone {
|
||||||
|
Url(Url, UrlExtraData),
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ComputedValueAsSpecified for UrlOrNone {}
|
||||||
|
impl NoViewportPercentage for UrlOrNone {}
|
||||||
|
|
||||||
|
impl ToCss for UrlOrNone {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
use values::LocalToCss;
|
||||||
|
match *self {
|
||||||
|
UrlOrNone::Url(ref url, _) => {
|
||||||
|
url.to_css(dest)
|
||||||
|
}
|
||||||
|
UrlOrNone::None => {
|
||||||
|
try!(dest.write_str("none"));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UrlOrNone {
|
||||||
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<UrlOrNone, ()> {
|
||||||
|
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||||
|
return Ok(UrlOrNone::None);
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = context.parse_url(&*try!(input.expect_url()));
|
||||||
|
match UrlExtraData::make_from(context) {
|
||||||
|
Some(extra_data) => {
|
||||||
|
Ok(UrlOrNone::Url(url, extra_data))
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
// FIXME(heycam) should ensure we always have a principal, etc., when parsing
|
||||||
|
// style attributes and re-parsing due to CSS Variables.
|
||||||
|
println!("stylo: skipping UrlOrNone declaration without ParserContextExtraData");
|
||||||
|
Err(())
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue