Kill side keywords from style::values::specified::image

This commit is contained in:
Anthony Ramine 2017-05-11 17:39:09 +02:00
parent 1c54758ad6
commit f2aaba685b
6 changed files with 31 additions and 33 deletions

View file

@ -63,7 +63,7 @@ use style::values::computed::{LengthOrPercentageOrAuto, LengthOrKeyword, LengthO
use style::values::computed::{NumberOrPercentage, Position};
use style::values::computed::image::{EndingShape, SizeKeyword};
use style::values::generics::image::{GradientItem as GenericGradientItem, Image};
use style::values::specified::{HorizontalDirection, VerticalDirection};
use style::values::specified::position::{X, Y};
use style_traits::CSSPixel;
use style_traits::cursor::Cursor;
use table_cell::CollapsedBordersForCell;
@ -1111,13 +1111,13 @@ impl FragmentDisplayListBuilding for Fragment {
let atan = (bounds.size.height.to_f32_px() /
bounds.size.width.to_f32_px()).atan();
match (horizontal, vertical) {
(HorizontalDirection::Right, VerticalDirection::Bottom)
(X::Right, Y::Bottom)
=> f32::consts::PI - atan,
(HorizontalDirection::Left, VerticalDirection::Bottom)
(X::Left, Y::Bottom)
=> f32::consts::PI + atan,
(HorizontalDirection::Right, VerticalDirection::Top)
(X::Right, Y::Top)
=> atan,
(HorizontalDirection::Left, VerticalDirection::Top)
(X::Left, Y::Top)
=> -atan,
}
}

View file

@ -194,7 +194,8 @@ impl nsStyleImage {
use gecko_bindings::structs::nsStyleCoord;
use values::computed::{AngleOrCorner, GradientKind, GradientShape, LengthOrKeyword};
use values::computed::LengthOrPercentageOrKeyword;
use values::specified::{HorizontalDirection, SizeKeyword, VerticalDirection};
use values::specified::SizeKeyword;
use values::specified::position::{X, Y};
let stop_count = gradient.items.len();
if stop_count >= ::std::u32::MAX as usize {
@ -222,12 +223,12 @@ impl nsStyleImage {
},
AngleOrCorner::Corner(horiz, vert) => {
let percent_x = match horiz {
HorizontalDirection::Left => 0.0,
HorizontalDirection::Right => 1.0,
X::Left => 0.0,
X::Right => 1.0,
};
let percent_y = match vert {
VerticalDirection::Top => 0.0,
VerticalDirection::Bottom => 1.0,
Y::Top => 0.0,
Y::Bottom => 1.0,
};
unsafe {

View file

@ -16,7 +16,8 @@ use values::generics::image::{Gradient as GenericGradient, GradientItem as Gener
use values::generics::image::{Image as GenericImage, ImageRect as GenericImageRect};
use values::computed::{Angle, Context, Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue};
use values::computed::position::Position;
use values::specified::{self, HorizontalDirection, VerticalDirection};
use values::specified;
use values::specified::position::{X, Y};
pub use values::specified::SizeKeyword;
@ -320,7 +321,7 @@ impl ToComputedValue for specified::LengthOrPercentageOrKeyword {
#[allow(missing_docs)]
pub enum AngleOrCorner {
Angle(Angle),
Corner(HorizontalDirection, VerticalDirection)
Corner(X, Y)
}
impl ToComputedValue for specified::AngleOrCorner {
@ -337,16 +338,16 @@ impl ToComputedValue for specified::AngleOrCorner {
},
specified::AngleOrCorner::Corner(horizontal, vertical) => {
match (horizontal, vertical) {
(None, Some(VerticalDirection::Top)) => {
(None, Some(Y::Top)) => {
AngleOrCorner::Angle(Angle::from_radians(0.0))
},
(Some(HorizontalDirection::Right), None) => {
(Some(X::Right), None) => {
AngleOrCorner::Angle(Angle::from_radians(PI * 0.5))
},
(None, Some(VerticalDirection::Bottom)) => {
(None, Some(Y::Bottom)) => {
AngleOrCorner::Angle(Angle::from_radians(PI))
},
(Some(HorizontalDirection::Left), None) => {
(Some(X::Left), None) => {
AngleOrCorner::Angle(Angle::from_radians(PI * 1.5))
},
(Some(horizontal), Some(vertical)) => {

View file

@ -18,7 +18,7 @@ use values::generics::image::{CompatMode, ColorStop as GenericColorStop};
use values::generics::image::{Gradient as GenericGradient, GradientItem as GenericGradientItem};
use values::generics::image::{Image as GenericImage, ImageRect as GenericImageRect};
use values::specified::{Angle, CSSColor, Length, LengthOrPercentage, NumberOrPercentage};
use values::specified::position::Position;
use values::specified::position::{Position, X, Y};
use values::specified::url::SpecifiedUrl;
/// Specified values for an image according to CSS-IMAGES.
@ -222,11 +222,11 @@ impl GradientKind {
} else {
if input.try(|i| i.expect_ident_matching("to")).is_ok() {
let (horizontal, vertical) =
if let Ok(value) = input.try(HorizontalDirection::parse) {
(Some(value), input.try(VerticalDirection::parse).ok())
if let Ok(value) = input.try(X::parse) {
(Some(value), input.try(Y::parse).ok())
} else {
let value = try!(VerticalDirection::parse(input));
(input.try(HorizontalDirection::parse).ok(), Some(value))
let value = try!(Y::parse(input));
(input.try(X::parse).ok(), Some(value))
};
try!(input.expect_comma());
AngleOrCorner::Corner(horizontal, vertical)
@ -241,11 +241,11 @@ impl GradientKind {
let direction = if let Ok(angle) = input.try(|i| Angle::parse_with_unitless(context, i)) {
AngleOrCorner::Angle(angle)
} else {
if let Ok(value) = input.try(HorizontalDirection::parse) {
AngleOrCorner::Corner(Some(value), input.try(VerticalDirection::parse).ok())
if let Ok(value) = input.try(X::parse) {
AngleOrCorner::Corner(Some(value), input.try(Y::parse).ok())
} else {
if let Ok(value) = input.try(VerticalDirection::parse) {
AngleOrCorner::Corner(input.try(HorizontalDirection::parse).ok(), Some(value))
if let Ok(value) = input.try(Y::parse) {
AngleOrCorner::Corner(input.try(X::parse).ok(), Some(value))
} else {
AngleOrCorner::None
}
@ -408,7 +408,7 @@ fn parse_position(context: &ParserContext, input: &mut Parser) -> Result<Positio
#[allow(missing_docs)]
pub enum AngleOrCorner {
Angle(Angle),
Corner(Option<HorizontalDirection>, Option<VerticalDirection>),
Corner(Option<X>, Option<Y>),
None,
}
@ -438,9 +438,6 @@ impl AngleOrCorner {
}
}
define_css_keyword_enum!(HorizontalDirection: "left" => Left, "right" => Right);
define_css_keyword_enum!(VerticalDirection: "top" => Top, "bottom" => Bottom);
impl Parse for ColorStop {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
Ok(ColorStop {

View file

@ -25,8 +25,7 @@ use values::specified::calc::CalcNode;
pub use values::specified::calc::CalcLengthOrPercentage;
pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
pub use super::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
pub use super::image::{SizeKeyword, VerticalDirection};
pub use super::image::{GradientKind, Image, LengthOrKeyword, LengthOrPercentageOrKeyword, SizeKeyword};
/// Number of app units per pixel
pub const AU_PER_PX: CSSFloat = 60.;

View file

@ -29,8 +29,8 @@ pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, Justify
pub use self::color::Color;
pub use self::grid::{GridLine, TrackKeyword};
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
pub use self::image::{GradientItem, GradientKind, HorizontalDirection, Image, ImageRect, LayerImage};
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword, SizeKeyword, VerticalDirection};
pub use self::image::{GradientItem, GradientKind, Image, ImageRect, LayerImage};
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword, SizeKeyword};
pub use self::length::AbsoluteLength;
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};