mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Remove angle values from image-orientation.
Bug: 1473450 Reviewed-by: emilio MozReview-Commit-ID: FB74ILJM6Fm
This commit is contained in:
parent
4e8d3fce38
commit
f526af7f01
7 changed files with 10 additions and 310 deletions
|
@ -285,7 +285,6 @@ class Longhand(object):
|
||||||
"FontSynthesis",
|
"FontSynthesis",
|
||||||
"FontWeight",
|
"FontWeight",
|
||||||
"GridAutoFlow",
|
"GridAutoFlow",
|
||||||
"ImageOrientation",
|
|
||||||
"InitialLetter",
|
"InitialLetter",
|
||||||
"Integer",
|
"Integer",
|
||||||
"JustifyContent",
|
"JustifyContent",
|
||||||
|
|
|
@ -4533,64 +4533,7 @@ fn static_assert() {
|
||||||
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="InheritedBox"
|
<%self:impl_trait style_struct_name="InheritedBox">
|
||||||
skip_longhands="image-orientation">
|
|
||||||
// FIXME: Gecko uses a tricky way to store computed value of image-orientation
|
|
||||||
// within an u8. We could inline following glue codes by implementing all
|
|
||||||
// those tricky parts for Servo as well. But, it's not done yet just for
|
|
||||||
// convenience.
|
|
||||||
pub fn set_image_orientation(&mut self, v: longhands::image_orientation::computed_value::T) {
|
|
||||||
use properties::longhands::image_orientation::computed_value::T;
|
|
||||||
match v {
|
|
||||||
T::FromImage => {
|
|
||||||
unsafe {
|
|
||||||
bindings::Gecko_SetImageOrientationAsFromImage(&mut self.gecko);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
T::AngleWithFlipped(ref orientation, flipped) => {
|
|
||||||
unsafe {
|
|
||||||
bindings::Gecko_SetImageOrientation(&mut self.gecko, *orientation as u8, flipped);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_image_orientation_from(&mut self, other: &Self) {
|
|
||||||
unsafe {
|
|
||||||
bindings::Gecko_CopyImageOrientationFrom(&mut self.gecko, &other.gecko);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset_image_orientation(&mut self, other: &Self) {
|
|
||||||
self.copy_image_orientation_from(other)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clone_image_orientation(&self) -> longhands::image_orientation::computed_value::T {
|
|
||||||
use gecko_bindings::structs::nsStyleImageOrientation_Angles;
|
|
||||||
use properties::longhands::image_orientation::computed_value::T;
|
|
||||||
use values::computed::Orientation;
|
|
||||||
|
|
||||||
let gecko_orientation = self.gecko.mImageOrientation.mOrientation;
|
|
||||||
if gecko_orientation & structs::nsStyleImageOrientation_Bits_FROM_IMAGE_MASK as u8 != 0 {
|
|
||||||
T::FromImage
|
|
||||||
} else {
|
|
||||||
const ANGLE0: u8 = nsStyleImageOrientation_Angles::ANGLE_0 as u8;
|
|
||||||
const ANGLE90: u8 = nsStyleImageOrientation_Angles::ANGLE_90 as u8;
|
|
||||||
const ANGLE180: u8 = nsStyleImageOrientation_Angles::ANGLE_180 as u8;
|
|
||||||
const ANGLE270: u8 = nsStyleImageOrientation_Angles::ANGLE_270 as u8;
|
|
||||||
|
|
||||||
let flip = gecko_orientation & structs::nsStyleImageOrientation_Bits_FLIP_MASK as u8 != 0;
|
|
||||||
let orientation =
|
|
||||||
match gecko_orientation & structs::nsStyleImageOrientation_Bits_ORIENTATION_MASK as u8 {
|
|
||||||
ANGLE0 => Orientation::Angle0,
|
|
||||||
ANGLE90 => Orientation::Angle90,
|
|
||||||
ANGLE180 => Orientation::Angle180,
|
|
||||||
ANGLE270 => Orientation::Angle270,
|
|
||||||
_ => unreachable!()
|
|
||||||
};
|
|
||||||
T::AngleWithFlipped(orientation, flip)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="InheritedTable"
|
<%self:impl_trait style_struct_name="InheritedTable"
|
||||||
|
|
|
@ -76,11 +76,12 @@ ${helpers.single_keyword(
|
||||||
spec="https://drafts.csswg.org/css-images/#propdef-image-rendering",
|
spec="https://drafts.csswg.org/css-images/#propdef-image-rendering",
|
||||||
)}
|
)}
|
||||||
|
|
||||||
${helpers.predefined_type("image-orientation",
|
${helpers.single_keyword(
|
||||||
"ImageOrientation",
|
"image-orientation",
|
||||||
"computed::ImageOrientation::zero()",
|
"none from-image",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
animation_value_type="discrete",
|
gecko_enum_prefix="StyleImageOrientation",
|
||||||
gecko_pref="layout.css.image-orientation.enabled",
|
animation_value_type="discrete",
|
||||||
spec="https://drafts.csswg.org/css-images/#propdef-image-orientation, \
|
gecko_pref="layout.css.image-orientation.enabled",
|
||||||
/// additional values in https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation")}
|
spec="https://drafts.csswg.org/css-images/#propdef-image-orientation",
|
||||||
|
)}
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
//! Computed values for inherited box
|
|
||||||
|
|
||||||
use std::fmt::{self, Write};
|
|
||||||
use style_traits::{CssWriter, ToCss};
|
|
||||||
use values::specified::Angle;
|
|
||||||
|
|
||||||
/// An angle rounded and normalized per https://drafts.csswg.org/css-images/#propdef-image-orientation
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq)]
|
|
||||||
pub enum Orientation {
|
|
||||||
Angle0 = 0,
|
|
||||||
Angle90,
|
|
||||||
Angle180,
|
|
||||||
Angle270,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Orientation {
|
|
||||||
/// Get the actual angle that this orientation value represents.
|
|
||||||
pub fn angle(&self) -> Angle {
|
|
||||||
match *self {
|
|
||||||
Orientation::Angle0 => Angle::from_degrees(0.0, false),
|
|
||||||
Orientation::Angle90 => Angle::from_degrees(90.0, false),
|
|
||||||
Orientation::Angle180 => Angle::from_degrees(180.0, false),
|
|
||||||
Orientation::Angle270 => Angle::from_degrees(270.0, false),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for Orientation {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
// Should agree with Angle::to_css.
|
|
||||||
match *self {
|
|
||||||
Orientation::Angle0 => dest.write_str("0deg"),
|
|
||||||
Orientation::Angle90 => dest.write_str("90deg"),
|
|
||||||
Orientation::Angle180 => dest.write_str("180deg"),
|
|
||||||
Orientation::Angle270 => dest.write_str("270deg"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-images/#propdef-image-orientation
|
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
|
|
||||||
pub enum ImageOrientation {
|
|
||||||
/// 'from-image'
|
|
||||||
FromImage,
|
|
||||||
|
|
||||||
/// '<angle>' | '<angle>? flip'
|
|
||||||
AngleWithFlipped(Orientation, bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImageOrientation {
|
|
||||||
#[allow(missing_docs)]
|
|
||||||
pub fn zero() -> Self {
|
|
||||||
ImageOrientation::AngleWithFlipped(Orientation::Angle0, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for ImageOrientation {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
match *self {
|
|
||||||
ImageOrientation::FromImage => dest.write_str("from-image"),
|
|
||||||
ImageOrientation::AngleWithFlipped(angle, flipped) => {
|
|
||||||
angle.to_css(dest)?;
|
|
||||||
if flipped {
|
|
||||||
dest.write_str(" flip")?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -52,7 +52,6 @@ pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
|
||||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||||
pub use self::flex::FlexBasis;
|
pub use self::flex::FlexBasis;
|
||||||
pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
|
pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect};
|
||||||
pub use self::inherited_box::{ImageOrientation, Orientation};
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::gecko::ScrollSnapPoint;
|
pub use self::gecko::ScrollSnapPoint;
|
||||||
pub use self::rect::LengthOrNumberRect;
|
pub use self::rect::LengthOrNumberRect;
|
||||||
|
@ -99,7 +98,6 @@ pub mod font;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub mod gecko;
|
pub mod gecko;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
pub mod inherited_box;
|
|
||||||
pub mod length;
|
pub mod length;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
pub mod outline;
|
pub mod outline;
|
||||||
|
|
|
@ -1,158 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
//! Specified values for inherited box
|
|
||||||
|
|
||||||
use cssparser::Parser;
|
|
||||||
use parser::{Parse, ParserContext};
|
|
||||||
use std::f64::consts::PI;
|
|
||||||
use std::fmt::{self, Write};
|
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
|
||||||
use values::computed;
|
|
||||||
use values::computed::{Context, Orientation, ToComputedValue};
|
|
||||||
use values::specified::Angle;
|
|
||||||
|
|
||||||
/// The specified value of the `image-orientation` property.
|
|
||||||
/// https://drafts.csswg.org/css-images/#propdef-image-orientation
|
|
||||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo)]
|
|
||||||
pub struct ImageOrientation {
|
|
||||||
/// The angle specified, if any
|
|
||||||
pub angle: Option<Angle>,
|
|
||||||
|
|
||||||
/// Whether or not "flip" was specified
|
|
||||||
#[value_info(other_values = "flip,from-image")]
|
|
||||||
pub flipped: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCss for ImageOrientation {
|
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
||||||
where
|
|
||||||
W: Write,
|
|
||||||
{
|
|
||||||
if let Some(angle) = self.angle {
|
|
||||||
angle.to_css(dest)?;
|
|
||||||
if self.flipped {
|
|
||||||
dest.write_str(" flip")
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if self.flipped {
|
|
||||||
dest.write_str("flip")
|
|
||||||
} else {
|
|
||||||
dest.write_str("from-image")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const TWO_PI: f64 = 2.0 * PI;
|
|
||||||
|
|
||||||
// According to CSS Content Module Level 3:
|
|
||||||
// The computed value of the property is calculated by rounding the specified angle
|
|
||||||
// to the nearest quarter-turn, rounding away from 0, then moduloing the value by 1 turn.
|
|
||||||
// This mirrors the Gecko implementation in
|
|
||||||
// nsStyleImageOrientation::CreateAsAngleAndFlip.
|
|
||||||
#[inline]
|
|
||||||
fn orientation_of_angle(angle: &computed::Angle) -> Orientation {
|
|
||||||
// Note that `angle` can be negative.
|
|
||||||
let mut rounded_angle = angle.radians64() % TWO_PI;
|
|
||||||
if rounded_angle < 0.0 {
|
|
||||||
// This computation introduces rounding error. Gecko previously
|
|
||||||
// didn't handle the negative case correctly; by branching we can
|
|
||||||
// match Gecko's behavior when it was correct.
|
|
||||||
rounded_angle += TWO_PI;
|
|
||||||
}
|
|
||||||
if rounded_angle < 0.25 * PI {
|
|
||||||
return Orientation::Angle0;
|
|
||||||
}
|
|
||||||
if rounded_angle < 0.75 * PI {
|
|
||||||
return Orientation::Angle90;
|
|
||||||
}
|
|
||||||
if rounded_angle < 1.25 * PI {
|
|
||||||
return Orientation::Angle180;
|
|
||||||
}
|
|
||||||
if rounded_angle < 1.75 * PI {
|
|
||||||
return Orientation::Angle270;
|
|
||||||
}
|
|
||||||
Orientation::Angle0
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToComputedValue for ImageOrientation {
|
|
||||||
type ComputedValue = computed::ImageOrientation;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, context: &Context) -> computed::ImageOrientation {
|
|
||||||
if let Some(ref angle) = self.angle {
|
|
||||||
let angle = angle.to_computed_value(context);
|
|
||||||
let orientation = orientation_of_angle(&angle);
|
|
||||||
computed::ImageOrientation::AngleWithFlipped(orientation, self.flipped)
|
|
||||||
} else {
|
|
||||||
if self.flipped {
|
|
||||||
computed::ImageOrientation::zero()
|
|
||||||
} else {
|
|
||||||
computed::ImageOrientation::FromImage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &computed::ImageOrientation) -> Self {
|
|
||||||
match *computed {
|
|
||||||
computed::ImageOrientation::FromImage => ImageOrientation {
|
|
||||||
angle: None,
|
|
||||||
flipped: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
computed::ImageOrientation::AngleWithFlipped(ref orientation, flipped) => {
|
|
||||||
ImageOrientation {
|
|
||||||
angle: Some(orientation.angle()),
|
|
||||||
flipped: flipped,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for ImageOrientation {
|
|
||||||
// from-image | <angle> | [<angle>? flip]
|
|
||||||
fn parse<'i, 't>(
|
|
||||||
context: &ParserContext,
|
|
||||||
input: &mut Parser<'i, 't>,
|
|
||||||
) -> Result<Self, ParseError<'i>> {
|
|
||||||
if input
|
|
||||||
.try(|input| input.expect_ident_matching("from-image"))
|
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
// Handle from-image
|
|
||||||
Ok(ImageOrientation {
|
|
||||||
angle: None,
|
|
||||||
flipped: false,
|
|
||||||
})
|
|
||||||
} else if input
|
|
||||||
.try(|input| input.expect_ident_matching("flip"))
|
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
// Handle flip
|
|
||||||
Ok(ImageOrientation {
|
|
||||||
angle: Some(Angle::zero()),
|
|
||||||
flipped: true,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// Handle <angle> | <angle> flip
|
|
||||||
let angle = input.try(|input| Angle::parse(context, input)).ok();
|
|
||||||
if angle.is_none() {
|
|
||||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
|
||||||
}
|
|
||||||
|
|
||||||
let flipped = input
|
|
||||||
.try(|input| input.expect_ident_matching("flip"))
|
|
||||||
.is_ok();
|
|
||||||
Ok(ImageOrientation {
|
|
||||||
angle: angle,
|
|
||||||
flipped: flipped,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -49,7 +49,6 @@ pub use self::flex::FlexBasis;
|
||||||
pub use self::gecko::ScrollSnapPoint;
|
pub use self::gecko::ScrollSnapPoint;
|
||||||
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||||
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
|
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
|
||||||
pub use self::inherited_box::ImageOrientation;
|
|
||||||
pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};
|
pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};
|
||||||
pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
|
pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
|
||||||
pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
|
@ -99,7 +98,6 @@ pub mod font;
|
||||||
pub mod gecko;
|
pub mod gecko;
|
||||||
pub mod grid;
|
pub mod grid;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
pub mod inherited_box;
|
|
||||||
pub mod length;
|
pub mod length;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
pub mod outline;
|
pub mod outline;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue