From 0021c70c0867498e6e38627aadaffb6c36a0844f Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Sun, 29 Apr 2018 09:03:31 +1000 Subject: [PATCH] style: Handle keywords for color values. Bug: 1434130 Reviewed-by: emilio MozReview-Commit-ID: 5GvIHSeQuCX --- components/style/values/specified/color.rs | 11 ++++++++++- ports/geckolib/glue.rs | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 32e0316f654..3066c5b8c2a 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -14,7 +14,7 @@ use parser::{Parse, ParserContext}; use properties::longhands::system_colors::SystemColor; use std::fmt::{self, Write}; use std::io::Write as IoWrite; -use style_traits::{CssType, CssWriter, ParseError, StyleParseErrorKind}; +use style_traits::{CssType, CssWriter, KeywordsCollectFn, ParseError, StyleParseErrorKind}; use style_traits::{SpecifiedValueInfo, ToCss, ValueParseErrorKind}; use super::AllowQuirks; use values::computed::{Color as ComputedColor, Context, ToComputedValue}; @@ -429,6 +429,15 @@ impl From for RGBAColor { impl SpecifiedValueInfo for Color { const SUPPORTED_TYPES: u8 = CssType::COLOR; + + fn collect_completion_keywords(f: KeywordsCollectFn) { + // We are not going to insert all the color names here. Caller and + // devtools should take care of them. XXX Actually, transparent + // should probably be handled that way as well. + // XXX `currentColor` should really be `currentcolor`. But let's + // keep it consistent with the old system for now. + f(&["rgb", "rgba", "hsl", "hsla", "currentColor", "transparent"]); + } } /// Specified value for the "color" property, which resolves the `currentcolor` diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 07d3615d13d..e602401c954 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1012,9 +1012,18 @@ pub unsafe extern "C" fn Servo_Property_GetCSSValuesForProperty( let mut values = BTreeSet::<&'static str>::new(); prop_id.collect_property_completion_keywords(&mut |list| values.extend(list.iter())); + let mut extras = vec![]; + if values.contains("transparent") { + // This is a special value devtools use to avoid inserting the + // long list of color keywords. We need to prepend it to values. + extras.push("COLOR"); + } + let result = result.as_mut().unwrap(); - bindings::Gecko_ResizeTArrayForStrings(result, values.len() as u32); - for (src, dest) in values.iter().zip(result.iter_mut()) { + let len = extras.len() + values.len(); + bindings::Gecko_ResizeTArrayForStrings(result, len as u32); + + for (src, dest) in extras.iter().chain(values.iter()).zip(result.iter_mut()) { dest.write_str(src).unwrap(); } }