mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Factor out opacity property to use an Opacity type.
This commit is contained in:
parent
d69763b0c1
commit
0f2dc53b0a
3 changed files with 35 additions and 41 deletions
|
@ -7,46 +7,9 @@
|
|||
// Box-shadow, etc.
|
||||
<% data.new_style_struct("Effects", inherited=False) %>
|
||||
|
||||
<%helpers:longhand name="opacity">
|
||||
use cssparser::ToCss;
|
||||
use std::fmt;
|
||||
use values::CSSFloat;
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, HeapSizeOf)]
|
||||
pub struct SpecifiedValue(pub CSSFloat);
|
||||
pub mod computed_value {
|
||||
use values::CSSFloat;
|
||||
pub type T = CSSFloat;
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
1.0
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> computed_value::T {
|
||||
if self.0 < 0.0 {
|
||||
0.0
|
||||
} else if self.0 > 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
specified::parse_number(input).map(SpecifiedValue)
|
||||
}
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type("opacity",
|
||||
"Opacity",
|
||||
"1.0")}
|
||||
|
||||
<%helpers:longhand name="box-shadow">
|
||||
use cssparser::{self, ToCss};
|
||||
|
|
|
@ -1475,6 +1475,36 @@ pub mod specified {
|
|||
write!(dest, "{}s", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, HeapSizeOf)]
|
||||
pub struct Opacity(pub CSSFloat);
|
||||
|
||||
impl Opacity {
|
||||
pub fn parse(input: &mut Parser) -> Result<Opacity, ()> {
|
||||
parse_number(input).map(Opacity)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for Opacity {
|
||||
type ComputedValue = CSSFloat;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> CSSFloat {
|
||||
if self.0 < 0.0 {
|
||||
0.0
|
||||
} else if self.0 > 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for Opacity {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed {
|
||||
|
@ -2087,4 +2117,5 @@ pub mod computed {
|
|||
}
|
||||
}
|
||||
pub type Length = Au;
|
||||
pub type Opacity = CSSFloat;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue