From 2d232cecb283de486f3b3e4ac9eb1b2bf7d24869 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Mon, 10 Oct 2016 14:55:19 +0800 Subject: [PATCH] Support url() values in background-image and mask-image in stylo. r=manishearth MozReview-Commit-ID: 7IUzzVV9rOi --- components/style/properties/data.py | 4 ++- components/style/properties/gecko.mako.rs | 26 +++++++++++++------ components/style/properties/helpers.mako.rs | 5 ++++ .../properties/longhand/background.mako.rs | 3 ++- .../style/properties/longhand/svg.mako.rs | 3 ++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index e5c7778bfec..8ef12fd6cd4 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -67,7 +67,8 @@ class Longhand(object): def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None, predefined_type=None, custom_cascade=False, experimental=False, internal=False, need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False, - allowed_in_keyframe_block=True, complex_color=False, cast_type='u8'): + allowed_in_keyframe_block=True, complex_color=False, cast_type='u8', + has_uncacheable_values=False): self.name = name self.keyword = keyword self.predefined_type = predefined_type @@ -78,6 +79,7 @@ class Longhand(object): self.custom_cascade = custom_cascade self.internal = internal self.need_index = need_index + self.has_uncacheable_values = has_uncacheable_values self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case self.depend_on_viewport_size = depend_on_viewport_size self.derived_from = (derived_from or "").split() diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 7774c599e93..73676c23eb8 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -30,6 +30,7 @@ use gecko_bindings::bindings::Gecko_SetGradientImageValue; use gecko_bindings::bindings::Gecko_SetListStyleType; use gecko_bindings::bindings::Gecko_SetMozBinding; use gecko_bindings::bindings::Gecko_SetNullImageValue; +use gecko_bindings::bindings::Gecko_SetUrlImageValue; use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}; use gecko_bindings::structs; @@ -1196,8 +1197,10 @@ fn static_assert() { } } + #[allow(unused_variables)] pub fn set_${shorthand}_image(&mut self, - images: longhands::${shorthand}_image::computed_value::T) { + images: longhands::${shorthand}_image::computed_value::T, + cacheable: &mut bool) { use gecko_bindings::structs::nsStyleImage; use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType; use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SHAPE_CIRCULAR}; @@ -1385,13 +1388,20 @@ fn static_assert() { Image::Gradient(gradient) => { set_gradient(gradient, &mut geckoimage.mImage) }, - Image::Url(..) => { - // let utf8_bytes = url.as_bytes(); - // Gecko_SetUrlImageValue(&mut self.gecko.mImage.mLayers.mFirstElement, - // utf8_bytes.as_ptr() as *const _, - // utf8_bytes.len()); - warn!("stylo: imgRequestProxies are not threadsafe in gecko, \ - background-image: url() not yet implemented"); + Image::Url(ref url, ref extra_data) => { + unsafe { + Gecko_SetUrlImageValue(&mut geckoimage.mImage, + url.as_str().as_ptr(), + url.as_str().len() as u32, + extra_data.base.get(), + extra_data.referrer.get(), + extra_data.principal.get()); + } + // We unfortunately must make any url() value uncacheable, since + // the applicable declarations cache is not per document, but + // global, and the imgRequestProxy objects we store in the style + // structs don't like to be tracked by more than one document. + *cacheable = false; } } } diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 292f8fc66b6..d5e48f6970b 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -224,8 +224,13 @@ match *value { DeclaredValue::Value(ref specified_value) => { let computed = specified_value.to_computed_value(context); + % if property.has_uncacheable_values: + context.mutate_style().mutate_${data.current_style_struct.name_lower}() + .set_${property.ident}(computed, cacheable); + % else: context.mutate_style().mutate_${data.current_style_struct.name_lower}() .set_${property.ident}(computed); + % endif } DeclaredValue::WithVariables { .. } => unreachable!(), DeclaredValue::Initial => { diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index e30040fe8fd..4c0bee3dfe6 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -10,7 +10,8 @@ ${helpers.predefined_type("background-color", "CSSColor", "::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */", animatable=True)} -<%helpers:vector_longhand name="background-image" animatable="False"> +<%helpers:vector_longhand name="background-image" animatable="False" + has_uncacheable_values="${product == 'gecko'}"> use cssparser::ToCss; use std::fmt; use values::specified::Image; diff --git a/components/style/properties/longhand/svg.mako.rs b/components/style/properties/longhand/svg.mako.rs index cc9aadf4e02..cd7409cc1c7 100644 --- a/components/style/properties/longhand/svg.mako.rs +++ b/components/style/properties/longhand/svg.mako.rs @@ -146,7 +146,8 @@ ${helpers.single_keyword("mask-composite", products="gecko", animatable=False)} -<%helpers:vector_longhand name="mask-image" products="gecko" animatable="False"> +<%helpers:vector_longhand name="mask-image" products="gecko" animatable="False" + has_uncacheable_values="${product == 'gecko'}"> use cssparser::ToCss; use std::fmt; use url::Url;