From 6ae95b4532aa9ce6335d802b73b59e091ae53a28 Mon Sep 17 00:00:00 2001 From: KuoE0 Date: Tue, 5 Sep 2017 21:43:02 -0500 Subject: [PATCH] servo: Merge #18376 - Support None and NotSet for the fallback type of SVGPaint (from kuoe0:set-fallbacktype-to-none-when-the-fallback-color-of-context-property-is-none); r=xidorn We didn't set None and NotSet for the fallback type of SVGPaint, and it caused the fallback color is wrong when fallback color is empty or keyword `none`. So, we add the None and NotSet support for it. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix [Bug 1380590](https://bugzilla.mozilla.org/show_bug.cgi?id=1380590) - [ ] There are tests for these changes OR - [X] These changes do not require tests because of the test cases already in Gecko. Source-Repo: https://github.com/servo/servo Source-Revision: 1cf87a243a60cefd35bfea694ad442a6a9ab9d14 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 664b4c31496a280ab537bd1de4c5a3a765e3ff21 --- .../components/style/properties/gecko.mako.rs | 30 +++++++++++++------ servo/components/style/values/generics/svg.rs | 17 +++++++---- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index de1503ad5faf..a4d941608457 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -60,7 +60,7 @@ use selector_parser::PseudoElement; use servo_arc::{Arc, RawOffsetArc}; use std::mem::{forget, uninitialized, transmute, zeroed}; use std::{cmp, ops, ptr}; -use values::{self, Auto, CustomIdent, Either, KeyframesName}; +use values::{self, Auto, CustomIdent, Either, KeyframesName, None_}; use values::computed::{NonNegativeAu, ToComputedValue, Percentage}; use values::computed::effects::{BoxShadow, Filter, SimpleShadow}; use computed_values::border_style; @@ -743,10 +743,16 @@ def set_gecko_property(ffi_name, expr): } } - if let Some(fallback) = fallback { - paint.mFallbackType = nsStyleSVGFallbackType::eStyleSVGFallbackType_Color; - paint.mFallbackColor = convert_rgba_to_nscolor(&fallback); - } + paint.mFallbackType = match fallback { + Some(Either::First(color)) => { + paint.mFallbackColor = convert_rgba_to_nscolor(&color); + nsStyleSVGFallbackType::eStyleSVGFallbackType_Color + }, + Some(Either::Second(_)) => { + nsStyleSVGFallbackType::eStyleSVGFallbackType_None + }, + None => nsStyleSVGFallbackType::eStyleSVGFallbackType_NotSet + }; } #[allow(non_snake_case)] @@ -771,11 +777,17 @@ def set_gecko_property(ffi_name, expr): use self::structs::nsStyleSVGPaintType; use self::structs::nsStyleSVGFallbackType; let ref paint = ${get_gecko_property(gecko_ffi_name)}; - let fallback = if let nsStyleSVGFallbackType::eStyleSVGFallbackType_Color = paint.mFallbackType { - Some(convert_nscolor_to_rgba(paint.mFallbackColor)) - } else { - None + + let fallback = match paint.mFallbackType { + nsStyleSVGFallbackType::eStyleSVGFallbackType_Color => { + Some(Either::First(convert_nscolor_to_rgba(paint.mFallbackColor))) + }, + nsStyleSVGFallbackType::eStyleSVGFallbackType_None => { + Some(Either::Second(None_)) + }, + nsStyleSVGFallbackType::eStyleSVGFallbackType_NotSet => None, }; + let kind = match paint.mType { nsStyleSVGPaintType::eStyleSVGPaintType_None => SVGPaintKind::None, nsStyleSVGPaintType::eStyleSVGPaintType_ContextFill => SVGPaintKind::ContextFill, diff --git a/servo/components/style/values/generics/svg.rs b/servo/components/style/values/generics/svg.rs index 2d743100dc18..b48455ab1823 100644 --- a/servo/components/style/values/generics/svg.rs +++ b/servo/components/style/values/generics/svg.rs @@ -8,6 +8,7 @@ use cssparser::Parser; use parser::{Parse, ParserContext}; use std::fmt; use style_traits::{ParseError, StyleParseError, ToCss}; +use values::{Either, None_}; use values::computed::NumberOrPercentage; use values::computed::length::LengthOrPercentage; use values::distance::{ComputeSquaredDistance, SquaredDistance}; @@ -21,8 +22,8 @@ use values::distance::{ComputeSquaredDistance, SquaredDistance}; pub struct SVGPaint { /// The paint source pub kind: SVGPaintKind, - /// The fallback color - pub fallback: Option, + /// The fallback color. It would be empty, the `none` keyword or . + pub fallback: Option>, } /// An SVG paint value without the fallback @@ -60,15 +61,19 @@ impl SVGPaintKind { } /// Parse SVGPaint's fallback. -/// fallback is keyword(none) or Color. +/// fallback is keyword(none), Color or empty. /// https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint fn parse_fallback<'i, 't, ColorType: Parse>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Option { + -> Option> { if input.try(|i| i.expect_ident_matching("none")).is_ok() { - None + Some(Either::Second(None_)) } else { - input.try(|i| ColorType::parse(context, i)).ok() + if let Ok(color) = input.try(|i| ColorType::parse(context, i)) { + Some(Either::First(color)) + } else { + None + } } }