diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index bcbb0ccebd1..d50d76ccb0a 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -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; @@ -937,6 +938,7 @@ impl Box { /// necessary. pub fn paint_background_if_applicable( &self, + builder: &DisplayListBuilder, index: uint, lists: &RefCell>, absolute_bounds: &Rect) { @@ -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 @@ -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."), @@ -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. diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 9ffb17c3254..2eb0553f2f6 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -221,7 +221,9 @@ impl Element { match local_name.as_slice() { "style" => { - self.style_attribute = Some(style::parse_style_attribute(value)) + let doc = self.node.owner_doc(); + let base_url = doc.document().url.clone(); + self.style_attribute = Some(style::parse_style_attribute(value, &base_url)) } "id" if abstract_self.is_in_doc() => { // XXX: this dual declaration are workaround to avoid the compile error: diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 4ba46343817..9b66e4ecb1a 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -26,7 +26,6 @@ use servo_util::url::parse_url; use std::cast; use std::cell::RefCell; use std::comm::{Port, SharedChan}; -use std::from_str::FromStr; use std::str; use style::Stylesheet; @@ -277,7 +276,8 @@ pub fn parse_html(cx: *JSContext, debug!("Fetched page; metadata is {:?}", load_response.metadata); - let url2 = load_response.metadata.final_url.clone(); + let base_url = load_response.metadata.final_url.clone(); + let url2 = base_url.clone(); let url3 = url2.clone(); // Store the final URL before we start parsing, so that DOM routines @@ -485,7 +485,6 @@ pub fn parse_html(cx: *JSContext, // We've reached the end of a + +
+ background: url(rust-0.png) gray; width:200px; height:200px; +
+
+ background-image: url(rust-45.png); width:200px; height:200px; +
+
+ background: url(rust-90.png) yellow; width:200px; height:200px; border: 5px solid #000; +
+ + diff --git a/src/test/ref/background_a.html b/src/test/ref/background_a.html new file mode 100644 index 00000000000..28bc8f6b21d --- /dev/null +++ b/src/test/ref/background_a.html @@ -0,0 +1,9 @@ + + + + + + +
+ + diff --git a/src/test/ref/background_b.html b/src/test/ref/background_b.html new file mode 100644 index 00000000000..11faa177fb7 --- /dev/null +++ b/src/test/ref/background_b.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/test/ref/basic.list b/src/test/ref/basic.list index 290a00741ca..bfd262afecb 100644 --- a/src/test/ref/basic.list +++ b/src/test/ref/basic.list @@ -29,3 +29,4 @@ == position_relative_a.html position_relative_b.html == attr_exists_selector.html attr_exists_selector_ref.html == data_img_a.html data_img_b.html +== background_a.html background_b.html diff --git a/src/test/ref/rust-0.png b/src/test/ref/rust-0.png new file mode 100644 index 00000000000..20d93badf5e Binary files /dev/null and b/src/test/ref/rust-0.png differ