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. #22641

Merged
merged 27 commits into from Jan 7, 2019
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4799e83
style: Enable CSS containment for frontend code.
dholbert Dec 15, 2018
31838b1
style: The 'all' property is not animatable.
emilio Dec 15, 2018
b59ec2e
style: Make <use> shadow trees lookup keyframe rules in the containin…
emilio Dec 17, 2018
1903559
style: Cleanup some conversion code dealing with NonNegative.
emilio Dec 16, 2018
ca1ad00
style: Use NonNegative more in the border code.
emilio Dec 17, 2018
3ed525f
style: Use cbindgen for ExtremumLength.
BorisChiou Dec 18, 2018
b7e728a
style: Support unprefixed min-content and max-content.
BorisChiou Dec 18, 2018
6275595
style: Let logical height, block-size, accept keywords.
BorisChiou Dec 18, 2018
f0f3eb3
style: Clamp to non-negative value after doing interpolation for circ…
BorisChiou Dec 19, 2018
7b44418
style: Bump smallvec and smallbitvec.
heycam Dec 20, 2018
8a6230e
style: changes to implement enum class for #define NS_STYLE_COLOR_ADJ…
sharath29 Dec 24, 2018
8929087
style: Update the Rust target version for bindgen.
emilio Dec 25, 2018
81a07b4
style: Implement the 'overflow-block' media query.
quasicomputational Dec 27, 2018
274845f
style: Implement the 'overflow-inline' media query.
quasicomputational Dec 22, 2018
a454f62
Rename nsIDocument to mozilla::dom::Document.
emilio Jan 2, 2019
d5bee57
style: Drop layout.css.box-decoration-break.enabled pref.
Jan 4, 2019
529ff36
style: Drop layout.css.color-adjust.enabled pref.
Jan 4, 2019
d862dae
style: Drop layout.css.image-orientation.enabled pref.
Jan 4, 2019
0488f81
style: Drop layout.css.isolation.enabled pref.
Jan 4, 2019
a0d1a03
style: Drop layout.css.mix-blend-mode.enabled pref.
Jan 4, 2019
48e4433
style: Drop layout.css.scroll-behavior.property-enabled pref.
Jan 4, 2019
152ef2e
style: Drop layout.css.background-blend-mode.enabled pref.
Jan 4, 2019
5f173c4
style: Rustfmt recent changes.
emilio Jan 6, 2019
d0eb20c
Update lockfile.
emilio Jan 6, 2019
4c1076a
style: Fix gecko build.
emilio Jan 6, 2019
97bd8fc
Fix Servo build.
emilio Jan 6, 2019
ecd9794
style: Remove a bunch of unit tests that are not very useful.
emilio Jan 7, 2019
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

style: Use NonNegative more in the border code.

This ended up not being so small of a patch as I'd have thought, since it
propagated a bit. But most of it is mechanical. Interesting part is
NonNegativeNumberOrPercentage and the actual uses of the NonNegative stuff and
during parsing.

This looks like it'd fix a few correctness issues during interpolation for all
the types except for BorderRadius and co (which handled it manually).

I should write tests for those in a different patch.

Differential Revision: https://phabricator.services.mozilla.com/D14673
  • Loading branch information
emilio committed Jan 6, 2019
commit ca1ad003bdb7dc8d2ae97d9bd0d15a7971847947
@@ -5,6 +5,8 @@
//! This module contains conversion helpers between Servo and Gecko types
//! Ideally, it would be in geckolib itself, but coherence
//! forces us to keep the traits and implementations here
//!
//! FIXME(emilio): This file should generally just die.

#![allow(unsafe_code)]

@@ -22,6 +24,7 @@ use crate::values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image};
use crate::values::computed::{Integer, LengthOrPercentage};
use crate::values::computed::{LengthOrPercentageOrAuto, NonNegativeLengthOrPercentageOrAuto};
use crate::values::computed::{Percentage, TextAlign};
use crate::values::generics::NonNegative;
use crate::values::generics::box_::VerticalAlign;
use crate::values::generics::grid::{TrackListValue, TrackSize};
use crate::values::generics::image::{CompatMode, GradientItem, Image as GenericImage};
@@ -113,7 +116,6 @@ impl From<nsStyleCoord_CalcValue> for LengthOrPercentageOrAuto {
// disappear as we move more stuff to cbindgen.
impl From<nsStyleCoord_CalcValue> for NonNegativeLengthOrPercentageOrAuto {
fn from(other: nsStyleCoord_CalcValue) -> Self {
use crate::values::generics::NonNegative;
use style_traits::values::specified::AllowedNumericType;
NonNegative(if other.mLength < 0 || other.mPercent < 0. {
LengthOrPercentageOrAuto::Calc(CalcLengthOrPercentage::with_clamping_mode(
@@ -675,6 +677,7 @@ pub mod basic_shape {
use crate::values::generics::basic_shape::{
BasicShape as GenericBasicShape, InsetRect, Polygon,
};
use crate::values::generics::NonNegative;
use crate::values::generics::basic_shape::{Circle, Ellipse, Path, PolygonCoord};
use crate::values::generics::basic_shape::{GeometryBox, ShapeBox, ShapeSource};
use crate::values::generics::border::BorderRadius as GenericBorderRadius;
@@ -838,10 +841,10 @@ pub mod basic_shape {
fn from(other: &'a nsStyleCorners) -> Self {
let get_corner = |index| {
BorderCornerRadius::new(
LengthOrPercentage::from_gecko_style_coord(&other.data_at(index))
.expect("<border-radius> should be a length, percentage, or calc value"),
LengthOrPercentage::from_gecko_style_coord(&other.data_at(index + 1))
.expect("<border-radius> should be a length, percentage, or calc value"),
NonNegative(LengthOrPercentage::from_gecko_style_coord(&other.data_at(index))
.expect("<border-radius> should be a length, percentage, or calc value")),
NonNegative(LengthOrPercentage::from_gecko_style_coord(&other.data_at(index + 1))
.expect("<border-radius> should be a length, percentage, or calc value")),
)
};

@@ -1687,8 +1687,8 @@ fn static_assert() {

pub fn clone_border_image_slice(&self) -> longhands::border_image_slice::computed_value::T {
use crate::gecko_bindings::structs::NS_STYLE_BORDER_IMAGE_SLICE_FILL;
use crate::values::computed::{BorderImageSlice, NumberOrPercentage};
type NumberOrPercentageRect = crate::values::generics::rect::Rect<NumberOrPercentage>;
use crate::values::computed::{BorderImageSlice, NonNegativeNumberOrPercentage};
type NumberOrPercentageRect = crate::values::generics::rect::Rect<NonNegativeNumberOrPercentage>;

BorderImageSlice {
offsets:
@@ -153,14 +153,15 @@ ${helpers.predefined_type(
${helpers.predefined_type(
"border-image-slice",
"BorderImageSlice",
initial_value="computed::NumberOrPercentage::Percentage(computed::Percentage(1.)).into()",
initial_specified_value="specified::NumberOrPercentage::Percentage(specified::Percentage::new(1.)).into()",
initial_value="computed::BorderImageSlice::hundred_percent()",
initial_specified_value="specified::BorderImageSlice::hundred_percent()",
spec="https://drafts.csswg.org/css-backgrounds/#border-image-slice",
animation_value_type="discrete",
flags="APPLIES_TO_FIRST_LETTER",
boxed=True,
)}

// FIXME(emilio): Why does this live here? ;_;
#[cfg(feature = "gecko")]
impl crate::values::computed::BorderImageWidth {
pub fn to_gecko_rect(&self, sides: &mut crate::gecko_bindings::structs::nsStyleSides) {
@@ -177,7 +178,7 @@ impl crate::values::computed::BorderImageWidth {
l.to_gecko_style_coord(&mut sides.data_at_mut(${i}))
},
BorderImageSideWidth::Number(n) => {
sides.data_at_mut(${i}).set_value(CoordDataValue::Factor(n))
sides.data_at_mut(${i}).set_value(CoordDataValue::Factor(n.0))
},
}
% endfor
@@ -191,6 +192,7 @@ impl crate::values::computed::BorderImageWidth {
use crate::gecko::values::GeckoStyleCoordConvertible;
use crate::values::computed::{LengthOrPercentage, Number};
use crate::values::generics::border::BorderImageSideWidth;
use crate::values::generics::NonNegative;

Some(
crate::values::computed::BorderImageWidth::new(
@@ -201,13 +203,13 @@ impl crate::values::computed::BorderImageWidth {
},
eStyleUnit_Factor => {
BorderImageSideWidth::Number(
Number::from_gecko_style_coord(&sides.data_at(${i}))
.expect("sides[${i}] could not convert to Number"))
NonNegative(Number::from_gecko_style_coord(&sides.data_at(${i}))
.expect("sides[${i}] could not convert to Number")))
},
_ => {
BorderImageSideWidth::Length(
LengthOrPercentage::from_gecko_style_coord(&sides.data_at(${i}))
.expect("sides[${i}] could not convert to LengthOrPercentager"))
NonNegative(LengthOrPercentage::from_gecko_style_coord(&sides.data_at(${i}))
.expect("sides[${i}] could not convert to LengthOrPercentage")))
},
},
% endfor
@@ -295,7 +295,7 @@ ${helpers.predefined_type(
"-webkit-text-stroke-width",
"BorderSideWidth",
"crate::values::computed::NonNegativeLength::new(0.)",
initial_specified_value="specified::BorderSideWidth::Length(specified::Length::zero())",
initial_specified_value="specified::BorderSideWidth::zero()",
computed_type="crate::values::computed::NonNegativeLength",
products="gecko",
gecko_pref="layout.css.prefixes.webkit",
@@ -12,7 +12,6 @@ use crate::properties::PropertyId;
use crate::values::computed::length::CalcLengthOrPercentage;
use crate::values::computed::url::ComputedUrl;
use crate::values::computed::Angle as ComputedAngle;
use crate::values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
use crate::values::CSSFloat;
use app_units::Au;
use euclid::{Point2D, Size2D};
@@ -340,23 +339,6 @@ trivial_to_animated_value!(ComputedUrl);
trivial_to_animated_value!(bool);
trivial_to_animated_value!(f32);

impl ToAnimatedValue for ComputedBorderCornerRadius {
type AnimatedValue = Self;

#[inline]
fn to_animated_value(self) -> Self {
self
}

#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
ComputedBorderCornerRadius::new(
(animated.0).0.width.clamp_to_non_negative(),
(animated.0).0.height.clamp_to_non_negative(),
)
}
}

impl ToAnimatedZero for Au {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
@@ -8,7 +8,7 @@
//! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape

use crate::values::computed::url::ComputedUrl;
use crate::values::computed::{Image, LengthOrPercentage};
use crate::values::computed::{Image, LengthOrPercentage, NonNegativeLengthOrPercentage};
use crate::values::generics::basic_shape as generic;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
@@ -24,10 +24,10 @@ pub type FloatAreaShape = generic::FloatAreaShape<BasicShape, Image>;

/// A computed basic shape.
pub type BasicShape =
generic::BasicShape<LengthOrPercentage, LengthOrPercentage, LengthOrPercentage>;
generic::BasicShape<LengthOrPercentage, LengthOrPercentage, LengthOrPercentage, NonNegativeLengthOrPercentage>;

/// The computed value of `inset()`
pub type InsetRect = generic::InsetRect<LengthOrPercentage>;
pub type InsetRect = generic::InsetRect<LengthOrPercentage, NonNegativeLengthOrPercentage>;

/// A computed circle.
pub type Circle = generic::Circle<LengthOrPercentage, LengthOrPercentage, LengthOrPercentage>;
@@ -4,9 +4,9 @@

//! Computed types for CSS values related to borders.

use crate::values::animated::ToAnimatedZero;
use crate::values::computed::length::{LengthOrPercentage, NonNegativeLength};
use crate::values::computed::{Number, NumberOrPercentage};
use crate::values::generics::NonNegative;
use crate::values::computed::length::{NonNegativeLengthOrPercentage, NonNegativeLength};
use crate::values::computed::{NonNegativeNumber, NonNegativeNumberOrPercentage};
use crate::values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
use crate::values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
use crate::values::generics::border::BorderImageSlice as GenericBorderImageSlice;
@@ -22,16 +22,16 @@ pub use crate::values::specified::border::BorderImageRepeat;
pub type BorderImageWidth = Rect<BorderImageSideWidth>;

/// A computed value for a single side of a `border-image-width` property.
pub type BorderImageSideWidth = GenericBorderImageSideWidth<LengthOrPercentage, Number>;
pub type BorderImageSideWidth = GenericBorderImageSideWidth<NonNegativeLengthOrPercentage, NonNegativeNumber>;

/// A computed value for the `border-image-slice` property.
pub type BorderImageSlice = GenericBorderImageSlice<NumberOrPercentage>;
pub type BorderImageSlice = GenericBorderImageSlice<NonNegativeNumberOrPercentage>;

/// A computed value for the `border-radius` property.
pub type BorderRadius = GenericBorderRadius<LengthOrPercentage>;
pub type BorderRadius = GenericBorderRadius<NonNegativeLengthOrPercentage>;

/// A computed value for the `border-*-radius` longhand properties.
pub type BorderCornerRadius = GenericBorderCornerRadius<LengthOrPercentage>;
pub type BorderCornerRadius = GenericBorderCornerRadius<NonNegativeLengthOrPercentage>;

/// A computed value for the `border-spacing` longhand property.
pub type BorderSpacing = GenericBorderSpacing<NonNegativeLength>;
@@ -40,7 +40,18 @@ impl BorderImageSideWidth {
/// Returns `1`.
#[inline]
pub fn one() -> Self {
GenericBorderImageSideWidth::Number(1.)
GenericBorderImageSideWidth::Number(NonNegative(1.))
}
}

impl BorderImageSlice {
/// Returns the `100%` value.
#[inline]
pub fn hundred_percent() -> Self {
GenericBorderImageSlice {
offsets: Rect::all(NonNegativeNumberOrPercentage::hundred_percent()),
fill: false,
}
}
}

@@ -68,26 +79,18 @@ impl BorderCornerRadius {
/// Returns `0 0`.
pub fn zero() -> Self {
GenericBorderCornerRadius(Size::new(
LengthOrPercentage::zero(),
LengthOrPercentage::zero(),
NonNegativeLengthOrPercentage::zero(),
NonNegativeLengthOrPercentage::zero(),
))
}
}

impl ToAnimatedZero for BorderCornerRadius {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
// FIXME(nox): Why?
Err(())
}
}

impl BorderRadius {
/// Returns whether all the values are `0px`.
pub fn all_zero(&self) -> bool {
fn all(corner: &BorderCornerRadius) -> bool {
fn is_zero(l: &LengthOrPercentage) -> bool {
*l == LengthOrPercentage::zero()
fn is_zero(l: &NonNegativeLengthOrPercentage) -> bool {
*l == NonNegativeLengthOrPercentage::zero()
}
is_zero(corner.0.width()) && is_zero(corner.0.height())
}
@@ -543,6 +543,15 @@ pub enum NumberOrPercentage {
Number(Number),
}

impl NumberOrPercentage {
fn clamp_to_non_negative(self) -> Self {
match self {
NumberOrPercentage::Percentage(p) => NumberOrPercentage::Percentage(p.clamp_to_non_negative()),
NumberOrPercentage::Number(n) => NumberOrPercentage::Number(n.max(0.)),
}
}
}

impl ToComputedValue for specified::NumberOrPercentage {
type ComputedValue = NumberOrPercentage;

@@ -572,6 +581,31 @@ impl ToComputedValue for specified::NumberOrPercentage {
}
}

/// A non-negative <number-percentage>.
pub type NonNegativeNumberOrPercentage = NonNegative<NumberOrPercentage>;

impl NonNegativeNumberOrPercentage {
/// Returns the `100%` value.
#[inline]
pub fn hundred_percent() -> Self {
NonNegative(NumberOrPercentage::Percentage(Percentage::hundred()))
}
}

impl ToAnimatedValue for NonNegativeNumberOrPercentage {
type AnimatedValue = NumberOrPercentage;

#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
self.0
}

#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
NonNegative(animated.clamp_to_non_negative())
}
}

/// A type used for opacity.
pub type Opacity = CSSFloat;

@@ -85,8 +85,8 @@ pub enum ShapeSource<BasicShape, ReferenceBox, ImageOrUrl> {
ToComputedValue,
ToCss,
)]
pub enum BasicShape<H, V, LengthOrPercentage> {
Inset(#[css(field_bound)] InsetRect<LengthOrPercentage>),
pub enum BasicShape<H, V, LengthOrPercentage, NonNegativeLengthOrPercentage> {
Inset(#[css(field_bound)] InsetRect<LengthOrPercentage, NonNegativeLengthOrPercentage>),
Circle(#[css(field_bound)] Circle<H, V, LengthOrPercentage>),
Ellipse(#[css(field_bound)] Ellipse<H, V, LengthOrPercentage>),
Polygon(Polygon<LengthOrPercentage>),
@@ -105,9 +105,9 @@ pub enum BasicShape<H, V, LengthOrPercentage> {
SpecifiedValueInfo,
ToComputedValue,
)]
pub struct InsetRect<LengthOrPercentage> {
pub struct InsetRect<LengthOrPercentage, NonNegativeLengthOrPercentage> {
pub rect: Rect<LengthOrPercentage>,
pub round: Option<BorderRadius<LengthOrPercentage>>,
pub round: Option<BorderRadius<NonNegativeLengthOrPercentage>>,
}

/// <https://drafts.csswg.org/css-shapes/#funcdef-circle>
@@ -258,9 +258,10 @@ impl<B, T, U> ToAnimatedZero for ShapeSource<B, T, U> {
}
}

impl<L> ToCss for InsetRect<L>
impl<Length, NonNegativeLength> ToCss for InsetRect<Length, NonNegativeLength>
where
L: ToCss + PartialEq,
Length: ToCss + PartialEq,
NonNegativeLength: ToCss + PartialEq,
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
@@ -45,6 +45,8 @@ pub struct BorderImageSlice<NumberOrPercentage> {
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
)]
@@ -106,19 +108,6 @@ pub struct BorderRadius<LengthOrPercentage> {
pub bottom_left: BorderCornerRadius<LengthOrPercentage>,
}

impl<N> From<N> for BorderImageSlice<N>
where
N: Clone,
{
#[inline]
fn from(value: N) -> Self {
Self {
offsets: Rect::all(value),
fill: false,
}
}
}

impl<L> BorderRadius<L> {
/// Returns a new `BorderRadius<L>`.
#[inline]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.