diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index a57a625097d..364991d2061 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -531,6 +531,18 @@ pub trait FragmentDisplayListBuilding { absolute_bounds: &Rect, ); + /// Same as build_display_list_for_background_if_applicable, but lets you + /// override the actual background used + fn build_display_list_for_background_if_applicable_with_background( + &self, + state: &mut DisplayListBuildState, + style: &ComputedValues, + background: &style_structs::Background, + background_color: RGBA, + display_list_section: DisplayListSection, + absolute_bounds: &Rect, + ); + /// Determines where to place an element background image or gradient. /// /// Photos have their resolution as intrinsic size while gradients have @@ -929,13 +941,28 @@ impl FragmentDisplayListBuilding for Fragment { style: &ComputedValues, display_list_section: DisplayListSection, absolute_bounds: &Rect, + ) { + let background = style.get_background(); + let background_color = style.resolve_color(background.background_color); + // XXXManishearth the below method should ideally use an iterator over + // backgrounds + self.build_display_list_for_background_if_applicable_with_background( + state, style, background, background_color, display_list_section, absolute_bounds) + } + + fn build_display_list_for_background_if_applicable_with_background( + &self, + state: &mut DisplayListBuildState, + style: &ComputedValues, + background: &style_structs::Background, + background_color: RGBA, + display_list_section: DisplayListSection, + absolute_bounds: &Rect, ) { // FIXME: This causes a lot of background colors to be displayed when they are clearly not // needed. We could use display list optimization to clean this up, but it still seems // inefficient. What we really want is something like "nearest ancestor element that // doesn't have a fragment". - let background = style.get_background(); - let background_color = style.resolve_color(background.background_color); // 'background-clip' determines the area within which the background is painted. // http://dev.w3.org/csswg/css-backgrounds-3/#the-background-clip