Auto merge of #21787 - emilio:gecko-sync, r=emilio

style: Sync changes from mozilla-central.

See each individual commit for details.

https://bugzilla.mozilla.org/show_bug.cgi?id=1493435

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21787)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-09-22 15:11:25 -04:00 committed by GitHub
commit d2a79b39c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 160 additions and 39 deletions

View file

@ -5304,7 +5304,7 @@ clip-path
</%self:impl_trait>
<%self:impl_trait style_struct_name="InheritedUI"
skip_longhands="cursor">
skip_longhands="cursor scrollbar-color">
pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) {
use style_traits::cursor::CursorKind;
@ -5450,6 +5450,48 @@ clip-path
longhands::cursor::computed_value::T { images, keyword }
}
pub fn set_scrollbar_color(&mut self, v: longhands::scrollbar_color::computed_value::T) {
use gecko_bindings::structs::StyleComplexColor;
use values::generics::ui::ScrollbarColor;
match v {
ScrollbarColor::Auto => {
self.gecko.mScrollbarFaceColor = StyleComplexColor::auto();
self.gecko.mScrollbarTrackColor = StyleComplexColor::auto();
}
ScrollbarColor::Colors { thumb, track } => {
self.gecko.mScrollbarFaceColor = thumb.into();
self.gecko.mScrollbarTrackColor = track.into();
}
}
}
pub fn copy_scrollbar_color_from(&mut self, other: &Self) {
self.gecko.mScrollbarFaceColor = other.gecko.mScrollbarFaceColor;
self.gecko.mScrollbarTrackColor = other.gecko.mScrollbarTrackColor;
}
pub fn reset_scrollbar_color(&mut self, other: &Self) {
self.copy_scrollbar_color_from(other);
}
pub fn clone_scrollbar_color(&self) -> longhands::scrollbar_color::computed_value::T {
use gecko_bindings::structs::StyleComplexColor_Tag as Tag;
use values::generics::ui::ScrollbarColor;
debug_assert!(
(self.gecko.mScrollbarFaceColor.mTag == Tag::eAuto) ==
(self.gecko.mScrollbarTrackColor.mTag == Tag::eAuto),
"Whether the two colors are `auto` should match",
);
if self.gecko.mScrollbarFaceColor.mTag == Tag::eAuto {
ScrollbarColor::Auto
} else {
ScrollbarColor::Colors {
thumb: self.gecko.mScrollbarFaceColor.into(),
track: self.gecko.mScrollbarTrackColor.into(),
}
}
}
</%self:impl_trait>
<%self:impl_trait style_struct_name="Column"

View file

@ -67,24 +67,15 @@ ${helpers.predefined_type(
products="gecko",
)}
// Only scrollbar-face-color and scrollbar-track-color are added here.
// These two are the only common parts of scrollbar among Windows and
// macOS. We may or may not want to provide other properties to allow
// finer-grain control.
//
// NOTE The syntax in spec is currently `normal | <color>`, but I think
// reusing `auto | <color>` as `caret-color` makes more sense. See
// https://github.com/w3c/csswg-drafts/issues/2660
% for part in ["face", "track"]:
${helpers.predefined_type(
"scrollbar-%s-color" % part,
"ColorOrAuto",
"Either::Second(Auto)",
spec="https://drafts.csswg.org/css-scrollbars-1/#scrollbar-color-properties",
"scrollbar-color",
"ui::ScrollbarColor",
"Default::default()",
spec="https://drafts.csswg.org/css-scrollbars-1/#scrollbar-color",
gecko_pref="layout.css.scrollbar-colors.enabled",
animation_value_type="ColorOrAuto",
animation_value_type="ScrollbarColor",
boxed=True,
ignored_when_colors_disabled=True,
enabled_in="chrome",
products="gecko",
)}
% endfor

View file

@ -183,6 +183,7 @@ ${helpers.predefined_type(
"ImageLayer",
"Either::First(None_)",
initial_specified_value="Either::First(None_)",
parse_method="parse_with_cors_anonymous",
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-image",
vector=True,
products="gecko",

View file

@ -7,7 +7,7 @@
<%helpers:shorthand
name="overflow"
flags="SHORTHAND_IN_GETCS"
sub_properties="overflow-y overflow-x"
sub_properties="overflow-x overflow-y"
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow"
>
use properties::longhands::overflow_x::parse as parse_overflow;
@ -52,9 +52,9 @@
}
}
% endif
let overflow_y = parse_overflow(context, input)?;
let overflow_x =
input.try(|i| parse_overflow(context, i)).unwrap_or(overflow_y);
let overflow_x = parse_overflow(context, input)?;
let overflow_y =
input.try(|i| parse_overflow(context, i)).unwrap_or(overflow_x);
Ok(expanded! {
overflow_x: overflow_x,
overflow_y: overflow_y,
@ -63,10 +63,10 @@
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.overflow_y.to_css(dest)?;
self.overflow_x.to_css(dest)?;
if self.overflow_x != self.overflow_y {
dest.write_char(' ')?;
self.overflow_x.to_css(dest)?;
self.overflow_y.to_css(dest)?;
}
Ok(())
}

View file

@ -483,16 +483,19 @@ impl SingleFontFamily {
FontFamilyType::eFamily_fantasy => SingleFontFamily::Generic(atom!("fantasy")),
FontFamilyType::eFamily_moz_fixed => SingleFontFamily::Generic(atom!("-moz-fixed")),
FontFamilyType::eFamily_named => {
let name = Atom::from(&*family.mName);
let name = unsafe { Atom::from_raw(family.mName.mRawPtr) };
SingleFontFamily::FamilyName(FamilyName {
name,
syntax: FamilyNameSyntax::Identifiers,
})
},
FontFamilyType::eFamily_named_quoted => SingleFontFamily::FamilyName(FamilyName {
name: (&*family.mName).into(),
syntax: FamilyNameSyntax::Quoted,
}),
FontFamilyType::eFamily_named_quoted => {
let name = unsafe { Atom::from_raw(family.mName.mRawPtr) };
SingleFontFamily::FamilyName(FamilyName {
name,
syntax: FamilyNameSyntax::Quoted,
})
},
_ => panic!("Found unexpected font FontFamilyType"),
}
}
@ -538,9 +541,15 @@ impl Hash for FontFamilyList {
where
H: Hasher,
{
use string_cache::WeakAtom;
for name in self.0.mNames.iter() {
name.mType.hash(state);
name.mName.hash(state);
if !name.mName.mRawPtr.is_null() {
unsafe {
WeakAtom::new(name.mName.mRawPtr).hash(state);
}
}
}
}
}
@ -552,7 +561,7 @@ impl PartialEq for FontFamilyList {
return false;
}
for (a, b) in self.0.mNames.iter().zip(other.0.mNames.iter()) {
if a.mType != b.mType || &*a.mName != &*b.mName {
if a.mType != b.mType || a.mName.mRawPtr != b.mName.mRawPtr {
return false;
}
}

View file

@ -20,3 +20,6 @@ pub type Cursor = generics::Cursor<CursorImage>;
/// A computed value for item of `image cursors`.
pub type CursorImage = generics::CursorImage<ComputedImageUrl, Number>;
/// A computed value for `scrollbar-color` property.
pub type ScrollbarColor = generics::ScrollbarColor<Color>;

View file

@ -67,3 +67,27 @@ impl<ImageUrl: ToCss, Number: ToCss> ToCss for CursorImage<ImageUrl, Number> {
Ok(())
}
}
/// A generic value for `scrollbar-color` property.
///
/// https://drafts.csswg.org/css-scrollbars-1/#scrollbar-color
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf, PartialEq,
SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)]
pub enum ScrollbarColor<Color> {
/// `auto`
Auto,
/// `<color>{2}`
Colors {
/// First `<color>`, for color of the scrollbar thumb.
thumb: Color,
/// Second `<color>`, for color of the scrollbar track.
track: Color,
}
}
impl<Color> Default for ScrollbarColor<Color> {
#[inline]
fn default() -> Self {
ScrollbarColor::Auto
}
}

View file

@ -33,6 +33,20 @@ use values::specified::url::SpecifiedImageUrl;
/// A specified image layer.
pub type ImageLayer = Either<None_, Image>;
impl ImageLayer {
/// This is a specialization of Either with an alternative parse
/// method to provide anonymous CORS headers for the Image url fetch.
pub fn parse_with_cors_anonymous<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(v) = input.try(|i| None_::parse(context, i)) {
return Ok(Either::First(v));
}
Image::parse_with_cors_anonymous(context, input).map(Either::Second)
}
}
/// Specified values for an image according to CSS-IMAGES.
/// <https://drafts.csswg.org/css-images/#image-values>
pub type Image = generic::Image<Gradient, MozImageRect, SpecifiedImageUrl>;

View file

@ -13,7 +13,7 @@ use std::slice;
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use style_traits::values::SequenceWriter;
use values::CSSFloat;
use values::animated::{Animate, Procedure};
use values::animated::{Animate, Procedure, ToAnimatedZero};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
/// The SVG path data.
@ -198,9 +198,7 @@ pub enum PathCommand {
rx: CSSFloat,
ry: CSSFloat,
angle: CSSFloat,
#[animation(constant)]
large_arc_flag: ArcFlag,
#[animation(constant)]
sweep_flag: ArcFlag,
point: CoordPair,
absolute: IsAbsolute,
@ -538,6 +536,34 @@ impl ToCss for ArcFlag {
}
}
impl Animate for ArcFlag {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
(self.0 as i32)
.animate(&(other.0 as i32), procedure)
.map(|v| ArcFlag(v > 0))
}
}
impl ComputeSquaredDistance for ArcFlag {
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
(self.0 as i32).compute_squared_distance(&(other.0 as i32))
}
}
impl ToAnimatedZero for ArcFlag {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
// The 2 ArcFlags in EllipticalArc determine which one of the 4 different arcs will be
// used. (i.e. From 4 combinations). In other words, if we change the flag, we get a
// different arc. Therefore, we return *self.
// https://svgwg.org/svg2-draft/paths.html#PathDataEllipticalArcCommands
Ok(*self)
}
}
/// SVG Path parser.
struct PathParser<'a> {
chars: Peekable<Cloned<slice::Iter<'a, u8>>>,

View file

@ -122,3 +122,21 @@ impl From<MozForceBrokenImageIcon> for u8 {
}
}
}
/// A specified value for `scrollbar-color` property
pub type ScrollbarColor = generics::ScrollbarColor<Color>;
impl Parse for ScrollbarColor {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(generics::ScrollbarColor::Auto);
}
Ok(generics::ScrollbarColor::Colors {
thumb: Color::parse(context, input)?,
track: Color::parse(context, input)?,
})
}
}

View file

@ -1,4 +0,0 @@
[overflow-serialization.html]
[CSSOM - Overflow shorthand serialization]
expected: FAIL

View file

@ -29,6 +29,3 @@
[The serialization of list-style-type: circle; list-style-position: inside; list-style-image: initial; should be canonical.]
expected: FAIL
[The serialization of overflow-x: scroll; overflow-y: hidden; should be canonical.]
expected: FAIL