Skip to content

Commit

Permalink
style: Make structs uncacheable if currentcolor is used on properties…
Browse files Browse the repository at this point in the history
… not using ComplexColor storage.
  • Loading branch information
heycam committed Sep 14, 2017
1 parent 1346be5 commit 73ae5ff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
30 changes: 30 additions & 0 deletions components/style/properties/properties.mako.rs
Expand Up @@ -626,6 +626,36 @@ impl LonghandId {
LonghandId::Direction
)
}

/// Whether computed values of this property lossily convert any complex
/// colors into RGBA colors.
///
/// In Gecko, there are some properties still that compute currentcolor
/// down to an RGBA color at computed value time, instead of as
/// `StyleComplexColor`s. For these properties, we must return `false`,
/// so that we correctly avoid caching style data in the rule tree.
pub fn stores_complex_colors_lossily(&self) -> bool {
% if product == "gecko":
matches!(*self,
% for property in data.longhands:
% if property.predefined_type == "RGBAColor":
LonghandId::${property.camel_case} |
% endif
% endfor
LonghandId::BackgroundImage |
LonghandId::BorderImageSource |
LonghandId::BoxShadow |
LonghandId::MaskImage |
LonghandId::MozBorderBottomColors |
LonghandId::MozBorderLeftColors |
LonghandId::MozBorderRightColors |
LonghandId::MozBorderTopColors |
LonghandId::TextShadow
)
% else:
false
% endif
}
}

/// An identifier for a given shorthand property.
Expand Down
30 changes: 24 additions & 6 deletions components/style/values/specified/color.rs
Expand Up @@ -248,18 +248,36 @@ fn convert_nscolor_to_computedcolor(color: nscolor) -> ComputedColor {
impl ToComputedValue for Color {
type ComputedValue = ComputedColor;

fn to_computed_value(&self, _context: &Context) -> ComputedColor {
fn to_computed_value(&self, context: &Context) -> ComputedColor {
match *self {
Color::CurrentColor => ComputedColor::currentcolor(),
Color::CurrentColor => {
if let Some(longhand) = context.for_non_inherited_property {
if longhand.stores_complex_colors_lossily() {
context.rule_cache_conditions.borrow_mut()
.set_uncacheable();
}
}
ComputedColor::currentcolor()
}
Color::Numeric { ref parsed, .. } => ComputedColor::rgba(*parsed),
Color::Complex(ref complex) => *complex,
Color::Complex(ref complex) => {
if complex.foreground_ratio != 0 {
if let Some(longhand) = context.for_non_inherited_property {
if longhand.stores_complex_colors_lossily() {
context.rule_cache_conditions.borrow_mut()
.set_uncacheable();
}
}
}
*complex
}
#[cfg(feature = "gecko")]
Color::System(system) =>
convert_nscolor_to_computedcolor(system.to_computed_value(_context)),
convert_nscolor_to_computedcolor(system.to_computed_value(context)),
#[cfg(feature = "gecko")]
Color::Special(special) => {
use self::gecko::SpecialColorKeyword as Keyword;
let pres_context = _context.device().pres_context();
let pres_context = context.device().pres_context();
convert_nscolor_to_computedcolor(match special {
Keyword::MozDefaultColor => pres_context.mDefaultColor,
Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor,
Expand All @@ -273,7 +291,7 @@ impl ToComputedValue for Color {
use dom::TElement;
use gecko::wrapper::GeckoElement;
use gecko_bindings::bindings::Gecko_GetBody;
let pres_context = _context.device().pres_context();
let pres_context = context.device().pres_context();
let body = unsafe { Gecko_GetBody(pres_context) }.map(GeckoElement);
let data = body.as_ref().and_then(|wrap| wrap.borrow_data());
if let Some(data) = data {
Expand Down

0 comments on commit 73ae5ff

Please sign in to comment.