Skip to content

Commit

Permalink
Impl background-image support.
Browse files Browse the repository at this point in the history
  • Loading branch information
recrack committed Feb 19, 2014
1 parent 3b55a5f commit 7eabcbb
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/components/main/layout/box_.rs
Expand Up @@ -22,6 +22,7 @@ use servo_util::geometry::Au;
use servo_util::geometry;
use servo_util::range::*;
use servo_util::namespace;

use std::cast;
use std::cell::RefCell;
use std::cmp::ApproxEq;
Expand Down Expand Up @@ -937,6 +938,7 @@ impl Box {
/// necessary.
pub fn paint_background_if_applicable<E:ExtraDisplayListData>(
&self,
builder: &DisplayListBuilder,
index: uint,
lists: &RefCell<DisplayListCollection<E>>,
absolute_bounds: &Rect<Au>) {
Expand All @@ -959,6 +961,39 @@ impl Box {
lists.lists[index].append_item(SolidColorDisplayItemClass(solid_color_display_item))
});
}

// The background image is painted on top of the background color.
// Implements background image, per spec:
// http://www.w3.org/TR/CSS21/colors.html#background
match style.Background.get().background_image {
Some(ref image_url) => {
let mut holder = ImageHolder::new(image_url.clone(), builder.ctx.image_cache.clone());
match holder.get_image() {
Some(image) => {
debug!("(building display list) building background image");

// Place the image into the display list.
lists.with_mut(|lists| {
let image_display_item = ~ImageDisplayItem {
base: BaseDisplayItem {
bounds: *absolute_bounds,
extra: ExtraDisplayListData::new(self),
},
image: image.clone(),
};
lists.lists[index].append_item(ImageDisplayItemClass(image_display_item));
});
}
None => {
// No image data at all? Do nothing.
//
// TODO: Add some kind of placeholder background image.
debug!("(building display list) no background image :(");
}
}
}
None => {}
}
}

/// Adds the display items necessary to paint the borders of this box to a display list if
Expand Down Expand Up @@ -1052,7 +1087,7 @@ impl Box {

self.paint_inline_background_border_if_applicable(index, lists, &absolute_box_bounds, &offset);
// Add the background to the list, if applicable.
self.paint_background_if_applicable(index, lists, &absolute_box_bounds);
self.paint_background_if_applicable(builder, index, lists, &absolute_box_bounds);

match self.specific {
UnscannedTextBox(_) => fail!("Shouldn't see unscanned boxes here."),
Expand Down Expand Up @@ -1259,7 +1294,6 @@ impl Box {
//
// TODO: Outlines.
self.paint_borders_if_applicable(index, lists, &absolute_box_bounds);

}

/// Returns the *minimum width* and *preferred width* of this box as defined by CSS 2.1.
Expand Down

0 comments on commit 7eabcbb

Please sign in to comment.