Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Sync changes from mozilla-central. #21036

Merged
merged 40 commits into from Jun 12, 2018
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ea5417b
style: Make contain:paint trigger clipping independent of the overflo…
muhammedyusuf-sermet May 30, 2018
35a1a30
style: Remove invalid assertion.
emilio Jun 4, 2018
6940787
style: Make the transition-property code make more sense.
emilio Jun 1, 2018
f6f421f
style: Hide multiple -moz-window-* properties from content.
emilio Jun 1, 2018
90ef560
style: Move TransitionProperty where it belongs.
emilio Jun 1, 2018
ce5a85d
style: Use custom_properties::Name in TransitionProperty.
emilio Jun 4, 2018
1da798e
style: Introduce css(parse_condition).
emilio Jun 2, 2018
cf7b10a
style: Hide -moz- display values from content behind a pref.
emilio Jun 2, 2018
618eef7
style: Don't hide -moz-box / -moz-inline-box yet.
emilio Jun 2, 2018
0f1b793
style: Minor indentation cleanup.
emilio Jun 4, 2018
4b10b2a
style: Update smallbitvec to v2.1.1.
emilio Jun 4, 2018
2baa794
style: Sprinkle some inline in methods that are just pointer-chasing …
emilio Jun 4, 2018
710184b
style: Sprinkle some #[inline] on methods that have inline fast-paths.
emilio Jun 4, 2018
f829300
style: Don't look at the rule type from value parsing.
emilio Jun 1, 2018
8d069d1
style: Work around a bindgen bug on Android.
emilio Jun 4, 2018
8821ad7
style: Make pseudo-elements work with :host.
emilio Jun 4, 2018
2c0a19e
style: Move some parsing-only attributes to use #[parse(..)] instead …
emilio Jun 4, 2018
d461a7d
style: Make the threadsafe refcounting macros more reusable.
emilio Jun 4, 2018
63ca2a8
style: Make clearing atoms slightly more ergonomic.
emilio Jun 4, 2018
c6e43c0
style: Avoid useless allocations in custom property name serialization.
emilio Jun 5, 2018
7529788
style: Make getting a property name explicitly an indexing operation.
emilio Jun 4, 2018
915c872
style: Remove PropertyId::name.
emilio Jun 4, 2018
3816143
style: Use Atomic<bool> for the staticpref version of layout.css.font…
bzbarsky Jun 6, 2018
255fe05
style: Extend StyleComplexColor to support additive blending.
djg May 23, 2018
9c51d31
style: Inline some trivial bits.
emilio Jun 4, 2018
e052666
style: Fix a typo.
emilio Jun 5, 2018
6ca324f
style: Remove unused PropertyDeclarationBlock::set_importance.
emilio Jun 5, 2018
3c7fb2a
style: Add a before-change callback to remove_property.
emilio Jun 5, 2018
cdbc409
style: Trivially simplify a condition.
emilio Jun 5, 2018
314b14d
style: Fix nsStyleBorder::mBorderColor for GCC.
djg Jun 5, 2018
5f74a15
style: Extract {animated,computed}::Color common parts.
djg Jun 5, 2018
011cad2
style: Add a Servo API to get the serialized style of a property.
emilio Jun 7, 2018
d65b29d
style: Add CssPropFlags::SerializedByServo and use it on some simple …
emilio Jun 7, 2018
572a931
style: Add diagnostics.
emilio Jun 9, 2018
078df23
style: Update cssparser.
emilio Jun 11, 2018
e94395b
style_derive: Fix tidy lint.
emilio Jun 11, 2018
ab76003
style: Fix servo build.
emilio Jun 11, 2018
4cd16ee
style: Derive Animate for ComplexColorRatios.
emilio Jun 11, 2018
0d0b0e0
Update WPT expectations.
emilio Jun 12, 2018
2106cc4
style: Update cssparser again to avoid intermittent stack overflows o…
emilio Jun 12, 2018
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

style: Extract {animated,computed}::Color common parts.

Extract the common parts of `animated::Color` and `computed::Color` out
into `generics::color::Color<T>` that is generic over the type of
RGBA color.

Bug: 1465307
Reviewed-by: xidorn
MozReview-Commit-ID: EymSr7aqnAP
  • Loading branch information
djg authored and emilio committed Jun 12, 2018
commit 5f74a15f385b4777549513a4d59bf01803ef2470
@@ -9,8 +9,8 @@ use gecko_bindings::structs::StyleComplexColor;
use gecko_bindings::structs::StyleComplexColor_Tag as Tag;
use values::{Auto, Either};
use values::computed::{Color as ComputedColor, RGBAColor as ComputedRGBA};
use values::computed::ComplexColorRatios;
use values::computed::ui::ColorOrAuto;
use values::generics::color::{Color as GenericColor, ComplexColorRatios};

impl StyleComplexColor {
/// Create a `StyleComplexColor` value that represents `currentColor`.
@@ -48,9 +48,9 @@ impl From<ComputedRGBA> for StyleComplexColor {
impl From<ComputedColor> for StyleComplexColor {
fn from(other: ComputedColor) -> Self {
match other {
ComputedColor::Numeric(color) => color.into(),
ComputedColor::Foreground => Self::current_color(),
ComputedColor::Complex(color, ratios) => {
GenericColor::Numeric(color) => color.into(),
GenericColor::Foreground => Self::current_color(),
GenericColor::Complex(color, ratios) => {
debug_assert!(ratios != ComplexColorRatios::NUMERIC);
debug_assert!(ratios != ComplexColorRatios::FOREGROUND);
StyleComplexColor {
@@ -69,16 +69,16 @@ impl From<StyleComplexColor> for ComputedColor {
match other.mTag {
Tag::eNumeric => {
debug_assert!(other.mBgRatio == 1. && other.mFgRatio == 0.);
ComputedColor::Numeric(convert_nscolor_to_rgba(other.mColor))
GenericColor::Numeric(convert_nscolor_to_rgba(other.mColor))
}
Tag::eForeground => {
debug_assert!(other.mBgRatio == 0. && other.mFgRatio == 1.);
ComputedColor::Foreground
GenericColor::Foreground
}
Tag::eComplex => {
debug_assert!(other.mBgRatio != 1. || other.mFgRatio != 0.);
debug_assert!(other.mBgRatio != 0. || other.mFgRatio != 1.);
ComputedColor::Complex(
GenericColor::Complex(
convert_nscolor_to_rgba(other.mColor),
ComplexColorRatios {
bg: other.mBgRatio,
@@ -6,7 +6,7 @@

use values::animated::{Animate, Procedure, ToAnimatedZero};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::computed::ComplexColorRatios;
use values::generics::color::{Color as GenericColor, ComplexColorRatios};

/// An animated RGBA color.
///
@@ -102,30 +102,15 @@ impl Animate for ComplexColorRatios {
}
}

#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Color {
Numeric(RGBA),
Foreground,
Complex(RGBA, ComplexColorRatios),
}
/// An animated value for `<color>`.
pub type Color = GenericColor<RGBA>;

impl Color {
fn currentcolor() -> Self {
Color::Foreground
}

/// Returns a transparent intermediate color.
pub fn transparent() -> Self {
Color::Numeric(RGBA::transparent())
}

fn effective_intermediate_rgba(&self) -> RGBA {
match *self {
Color::Numeric(color) => color,
Color::Foreground => RGBA::transparent(),
Color::Complex(color, ratios) => RGBA {
GenericColor::Numeric(color) => color,
GenericColor::Foreground => RGBA::transparent(),
GenericColor::Complex(color, ratios) => RGBA {
alpha: color.alpha * ratios.bg,
..color.clone()
},
@@ -134,47 +119,45 @@ impl Color {

fn effective_ratios(&self) -> ComplexColorRatios {
match *self {
Color::Numeric(..) => ComplexColorRatios::NUMERIC,
Color::Foreground => ComplexColorRatios::FOREGROUND,
Color::Complex(.., ratios) => ratios,
GenericColor::Numeric(..) => ComplexColorRatios::NUMERIC,
GenericColor::Foreground => ComplexColorRatios::FOREGROUND,
GenericColor::Complex(.., ratios) => ratios,
}
}
}

impl Animate for Color {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
use self::GenericColor::*;

// Common cases are interpolating between two numeric colors,
// two currentcolors, and a numeric color and a currentcolor.
let (this_weight, other_weight) = procedure.weights();

Ok(match (*self, *other, procedure) {
// Any interpolation of currentColor with currentColor returns currentColor.
(Color::Foreground, Color::Foreground, Procedure::Interpolate { .. }) => {
Color::currentcolor()
}
(Foreground, Foreground, Procedure::Interpolate { .. }) => Color::currentcolor(),
// Animating two numeric colors.
(Color::Numeric(c1), Color::Numeric(c2), _) => {
Color::Numeric(c1.animate(&c2, procedure)?)
}
(Numeric(c1), Numeric(c2), _) => Numeric(c1.animate(&c2, procedure)?),
// Combinations of numeric color and currentColor
(Color::Foreground, Color::Numeric(color), _) => Color::Complex(
(Foreground, Numeric(color), _) => Self::with_ratios(
color,
ComplexColorRatios {
bg: other_weight as f32,
fg: this_weight as f32,
},
),
(Color::Numeric(color), Color::Foreground, _) => Color::Complex(
(Numeric(color), Foreground, _) => Self::with_ratios(
color,
ComplexColorRatios {
bg: this_weight as f32,
fg: other_weight as f32,
},
),

// Any other animation of currentColor with currentColor is complex.
(Color::Foreground, Color::Foreground, _) => Color::Complex(
// Any other animation of currentColor with currentColor.
(Foreground, Foreground, _) => Self::with_ratios(
RGBA::transparent(),
ComplexColorRatios {
bg: 0.,
@@ -197,13 +180,7 @@ impl Animate for Color {
let alpha = color.alpha / ratios.bg;
let color = RGBA { alpha, ..color };

if ratios == ComplexColorRatios::NUMERIC {
Color::Numeric(color)
} else if ratios == ComplexColorRatios::FOREGROUND {
Color::Foreground
} else {
Color::Complex(color, ratios)
}
Self::with_ratios(color, ratios)
}
})
}
@@ -212,12 +189,13 @@ impl Animate for Color {
impl ComputeSquaredDistance for Color {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
use self::GenericColor::*;

// All comments from the Animate impl also applies here.
Ok(match (*self, *other) {
(Color::Foreground, Color::Foreground) => SquaredDistance::from_sqrt(0.),
(Color::Numeric(c1), Color::Numeric(c2)) => c1.compute_squared_distance(&c2)?,
(Color::Foreground, Color::Numeric(color))
| (Color::Numeric(color), Color::Foreground) => {
(Foreground, Foreground) => SquaredDistance::from_sqrt(0.),
(Numeric(c1), Numeric(c2)) => c1.compute_squared_distance(&c2)?,
(Foreground, Numeric(color)) | (Numeric(color), Foreground) => {
// `computed_squared_distance` is symmetic.
color.compute_squared_distance(&RGBA::transparent())?
+ SquaredDistance::from_sqrt(1.)
@@ -8,81 +8,33 @@ use cssparser::{Color as CSSParserColor, RGBA};
use std::fmt;
use style_traits::{CssWriter, ToCss};
use values::animated::ToAnimatedValue;
use values::animated::color::{Color as AnimatedColor, RGBA as AnimatedRGBA};

/// Ratios representing the contribution of color and currentcolor to
/// the final color value.
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
pub struct ComplexColorRatios {
/// Numeric color contribution.
pub bg: f32,
/// Foreground color, aka currentcolor, contribution.
pub fg: f32,
}

impl ComplexColorRatios {
/// Ratios representing pure numeric color.
pub const NUMERIC: ComplexColorRatios = ComplexColorRatios { bg: 1., fg: 0. };
/// Ratios representing pure foreground color.
pub const FOREGROUND: ComplexColorRatios = ComplexColorRatios { bg: 0., fg: 1. };
}

/// This enum represents a combined color from a numeric color and
/// the current foreground color (currentColor keyword).
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
pub enum Color {
/// Numeric RGBA color.
Numeric(RGBA),

/// The current foreground color.
Foreground,

/// A linear combination of numeric color and currentColor.
/// The formula is: `color * bg_ratio + currentColor * fg_ratio`.
Complex(RGBA, ComplexColorRatios),
}
use values::animated::color::RGBA as AnimatedRGBA;
use values::generics::color::Color as GenericColor;

/// Computed value type for the specified RGBAColor.
pub type RGBAColor = RGBA;

/// The computed value of the `color` property.
pub type ColorPropertyValue = RGBA;

impl Color {
/// Returns a numeric color representing the given RGBA value.
pub fn rgba(color: RGBA) -> Color {
Color::Numeric(color)
}
/// A computed value for `<color>`.
pub type Color = GenericColor<RGBAColor>;

impl Color {
/// Returns a complex color value representing transparent.
pub fn transparent() -> Color {
Color::rgba(RGBA::transparent())
}

/// Returns a complex color value representing currentcolor.
pub fn currentcolor() -> Color {
Color::Foreground
}

/// Whether it is a numeric color (no currentcolor component).
pub fn is_numeric(&self) -> bool {
matches!(*self, Color::Numeric { .. })
}

/// Whether it is a currentcolor value (no numeric color component).
pub fn is_currentcolor(&self) -> bool {
matches!(*self, Color::Foreground)
}

/// Combine this complex color with the given foreground color into
/// a numeric RGBA color. It currently uses linear blending.
pub fn to_rgba(&self, fg_color: RGBA) -> RGBA {
let (color, ratios) = match *self {
// Common cases that the complex color is either pure numeric
// color or pure currentcolor.
Color::Numeric(color) => return color,
Color::Foreground => return fg_color,
Color::Complex(color, ratios) => (color, ratios),
GenericColor::Numeric(color) => return color,
GenericColor::Foreground => return fg_color,
GenericColor::Complex(color, ratios) => (color, ratios),
};

// For the more complicated case that the alpha value differs,
@@ -117,51 +69,19 @@ impl Color {
}
}

impl From<RGBA> for Color {
fn from(color: RGBA) -> Color {
Color::Numeric(color)
}
}

impl ToCss for Color {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
match *self {
Color::Numeric(color) => color.to_css(dest),
Color::Foreground => CSSParserColor::CurrentColor.to_css(dest),
GenericColor::Numeric(color) => color.to_css(dest),
GenericColor::Foreground => CSSParserColor::CurrentColor.to_css(dest),
_ => Ok(()),
}
}
}

impl ToAnimatedValue for Color {
type AnimatedValue = AnimatedColor;

#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
match self {
Color::Numeric(color) => AnimatedColor::Numeric(color.to_animated_value()),
Color::Foreground => AnimatedColor::Foreground,
Color::Complex(color, ratios) => {
AnimatedColor::Complex(color.to_animated_value(), ratios)
}
}
}

#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
match animated {
AnimatedColor::Numeric(color) => Color::Numeric(RGBA::from_animated_value(color)),
AnimatedColor::Foreground => Color::Foreground,
AnimatedColor::Complex(color, ratios) => {
Color::Complex(RGBA::from_animated_value(color), ratios)
}
}
}
}

impl ToAnimatedValue for RGBA {
type AnimatedValue = AnimatedRGBA;

@@ -45,7 +45,7 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier,
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display, TransitionProperty};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective};
pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, ComplexColorRatios, RGBAColor};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
pub use self::column::ColumnCount;
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.