From 8912df8a5bbd24e9bce034112fe34863ccc2acc9 Mon Sep 17 00:00:00 2001 From: patrick kim Date: Thu, 16 Jan 2014 09:19:23 +0900 Subject: [PATCH 1/3] some refactor & fix image size compute --- src/components/main/layout/box_.rs | 145 ++++++++++++++++++++------- src/components/main/layout/inline.rs | 10 +- 2 files changed, 113 insertions(+), 42 deletions(-) diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 39cb0004df1..6c4f0664e88 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -37,7 +37,7 @@ use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData, ToG use layout::float_context::{ClearType, ClearLeft, ClearRight, ClearBoth}; use layout::flow::Flow; use layout::flow; -use layout::model::{MaybeAuto, Auto, specified}; +use layout::model::{MaybeAuto, specified, Auto, Specified}; use layout::util::OpaqueNode; use layout::wrapper::LayoutNode; @@ -108,9 +108,8 @@ pub enum SpecificBoxInfo { pub struct ImageBoxInfo { /// The image held within this box. image: RefCell, - /// The width attribute supplied by the DOM, if any. + computed_size: RefCell>>, dom_width: Option, - /// The height attribute supplied by the DOM, if any. dom_height: Option, } @@ -121,6 +120,7 @@ impl ImageBoxInfo { /// me. pub fn new(node: &LayoutNode, image_url: Url, local_image_cache: MutexArc) -> ImageBoxInfo { + fn convert_length(node: &LayoutNode, name: &str) -> Option { node.with_element(|element| { element.get_attr(None, name).and_then(|string| { @@ -132,27 +132,45 @@ impl ImageBoxInfo { ImageBoxInfo { image: RefCell::new(ImageHolder::new(image_url, local_image_cache)), - dom_width: convert_length(node, "width"), - dom_height: convert_length(node, "height"), + computed_size: RefCell::new(None), + dom_width: convert_length(node,"width"), + dom_height: convert_length(node,"height"), } } - // Calculates the width of an image, accounting for the width attribute. - fn image_width(&self) -> Au { - // TODO(brson): Consult margins and borders? - self.dom_width.unwrap_or_else(|| { - let mut image_ref = self.image.borrow_mut(); - Au::from_px(image_ref.get().get_size().unwrap_or(Size2D(0, 0)).width) - }) + /// Returns Calculated the width of an image, accounting for the height attribute. + pub fn computed_width(&self) -> Au { + match self.computed_size.borrow().get() { + &Some(size) => { + size.width + }, + &None => { + fail!("image size is not computed yet!"); + } + } + } + /// Returns width of image(just original width) + pub fn image_width(&self) -> Au { + let mut image_ref = self.image.borrow_mut(); + Au::from_px(image_ref.get().get_size().unwrap_or(Size2D(0,0)).width) } - // Calculate the height of an image, accounting for the height attribute. + /// Returns Calculated the height of an image, accounting for the height attribute. + pub fn computed_height(&self) -> Au { + match self.computed_size.borrow().get() { + &Some(size) => { + size.height + }, + &None => { + fail!("image size is not computed yet!"); + } + } + } + + /// Returns height of image(just original height) pub fn image_height(&self) -> Au { - // TODO(brson): Consult margins and borders? - self.dom_height.unwrap_or_else(|| { - let mut image_ref = self.image.borrow_mut(); - Au::from_px(image_ref.get().get_size().unwrap_or(Size2D(0, 0)).height) - }) + let mut image_ref = self.image.borrow_mut(); + Au::from_px(image_ref.get().get_size().unwrap_or(Size2D(0,0)).height) } } @@ -939,23 +957,28 @@ impl Box { (guessed_width + additional_minimum, guessed_width + additional_preferred) } - /// Returns, and computes, the height of this box. - /// - /// FIXME(pcwalton): Rename to just `height`? - /// FIXME(pcwalton): This function *mutates* the height? Gross! Refactor please. - pub fn box_height(&self) -> Au { + + pub fn content_width(&self) -> Au { match self.specific { GenericBox | IframeBox(_) => Au(0), ImageBox(ref image_box_info) => { - let mut image_ref = image_box_info.image.borrow_mut(); - let size = image_ref.get().get_size(); - let height = Au::from_px(size.unwrap_or(Size2D(0, 0)).height); - - // Eww. Refactor this. - self.position.borrow_mut().get().size.height = height; - debug!("box_height: found image height: {}", height); - - height + image_box_info.computed_width() + } + ScannedTextBox(ref text_box_info) => { + let (range, run) = (&text_box_info.range, &text_box_info.run); + let text_bounds = run.get().metrics_for_range(range).bounding_box; + text_bounds.size.width + } + UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), + } + } + /// Returns, and computes, the height of this box. + /// + pub fn content_height(&self) -> Au { + match self.specific { + GenericBox | IframeBox(_) => Au(0), + ImageBox(ref image_box_info) => { + image_box_info.computed_height() } ScannedTextBox(ref text_box_info) => { // Compute the height based on the line-height and font size. @@ -1077,15 +1100,63 @@ impl Box { } /// Assigns the appropriate width to this box. - pub fn assign_width(&self) { + pub fn assign_width(&self,container_width: Au) { match self.specific { GenericBox | IframeBox(_) => { - // FIXME(pcwalton): This seems clownshoes; can we remove? - self.position.borrow_mut().get().size.width = Au::from_px(45) } ImageBox(ref image_box_info) => { - let image_width = image_box_info.image_width(); - self.position.borrow_mut().get().size.width = image_width + // TODO(ksh8281): compute border,margin,padding + let width = match (MaybeAuto::from_style(self.style().Box.width,container_width), + image_box_info.dom_width) { + (Specified(width),_) => { + Specified(width) + }, + (Auto,Some(width)) => { + Specified(width) + }, + (Auto,None) => { + Auto + } + }; + + + let height = match (MaybeAuto::from_style(self.style().Box.height,container_width), + image_box_info.dom_height) { + (Specified(height),_) => { + Specified(height) + }, + (Auto,Some(height)) => { + Specified(height) + }, + (Auto,None) => { + Auto + } + }; + + let (width,height) = match (width,height) { + (Auto,Auto) => { + (image_box_info.image_width(),image_box_info.image_height()) + }, + (Auto,Specified(h)) => { + let scale = image_box_info. + image_height().to_f32().unwrap() / h.to_f32().unwrap(); + (Au::new((image_box_info.image_width().to_f32().unwrap() / scale) as i32),h) + }, + (Specified(w),Auto) => { + let scale = image_box_info. + image_width().to_f32().unwrap() / w.to_f32().unwrap(); + (w,Au::new((image_box_info.image_height().to_f32().unwrap() / scale) as i32)) + + }, + (Specified(w),Specified(h)) => { + (w,h) + } + }; + + let mut position = self.position.borrow_mut(); + position.get().size.width = width; + position.get().size.height = height; + image_box_info.computed_size.set(Some(Size2D(width,height))); } ScannedTextBox(_) => { // Scanned text boxes will have already had their widths assigned by this point. diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index 28da9b58a26..c41bc4e35c0 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -160,7 +160,7 @@ impl LineboxScanner { // FIXME(eatkinson): this assumes that the tallest box in the line determines the line height // This might not be the case with some weird text fonts. fn new_height_for_line(&self, new_box: &Box) -> Au { - let box_height = new_box.box_height(); + let box_height = new_box.content_height(); if box_height > self.pending_line.bounds.size.height { box_height } else { @@ -508,7 +508,7 @@ impl InlineFlow { vertical_align::middle => { // TODO: x-height value should be used from font info. let xheight = Au::new(0); - (-(xheight + cur_box.box_height()).scale_by(0.5), false) + (-(xheight + cur_box.content_height()).scale_by(0.5), false) }, vertical_align::sub => { // TODO: The proper position for subscripts should be used. @@ -636,7 +636,7 @@ impl Flow for InlineFlow { { let this = &mut *self; for box_ in this.boxes.iter() { - box_.assign_width(); + box_.assign_width(self.base.position.size.width); } } @@ -707,8 +707,8 @@ impl Flow for InlineFlow { // FIXME(pcwalton): Move into `box.rs` like the rest of box-specific layout code? let (top_from_base, bottom_from_base, ascent) = match cur_box.specific { - ImageBox(ref image_box) => { - let mut height = image_box.image_height(); + ImageBox(_) => { + let mut height = cur_box.content_height(); // TODO: margin, border, padding's top and bottom should be calculated in // advance, since baseline of image is bottom margin edge. From ef122f8fbfc79e71b953f0d449cbf2bc56e01018 Mon Sep 17 00:00:00 2001 From: patrick kim Date: Tue, 21 Jan 2014 11:13:26 +0900 Subject: [PATCH 2/3] add comment & add ref test --- src/components/main/layout/box_.rs | 3 +++ src/test/ref/basic.list | 1 + src/test/ref/img_size.png | Bin 0 -> 4399 bytes src/test/ref/img_size_a.html | 18 ++++++++++++++++++ src/test/ref/img_size_b.html | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 src/test/ref/img_size.png create mode 100644 src/test/ref/img_size_a.html create mode 100644 src/test/ref/img_size_b.html diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 6c4f0664e88..7351986c1dd 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -1120,6 +1120,9 @@ impl Box { }; + // FIXME(ksh8281): we shouldn't assign height this way + // we need box.assign_height + // now, we can't know about size of parent's height let height = match (MaybeAuto::from_style(self.style().Box.height,container_width), image_box_info.dom_height) { (Specified(height),_) => { diff --git a/src/test/ref/basic.list b/src/test/ref/basic.list index 3ce729e74dc..37de5b3e00f 100644 --- a/src/test/ref/basic.list +++ b/src/test/ref/basic.list @@ -22,3 +22,4 @@ == font_size_em.html font_size_em_ref.html == font_size_percentage.html font_size_em_ref.html == position_fixed_a.html position_fixed_b.html +== img_size_a.html img_size_b.html diff --git a/src/test/ref/img_size.png b/src/test/ref/img_size.png new file mode 100644 index 0000000000000000000000000000000000000000..20d93badf5e2290baba400611b888d31dc03b5af GIT binary patch literal 4399 zcmZ`-Wl$6V(>_WX={`d7Kn~<+IS@QJLg^5s8w8{e2`Q;Nln{{aj*~{Z8>G8afup-5 zUf!SI%=_)k?laHEzulSL4OLT-CnaJe0ssJ{ZxrAf4>DO z@<`$vQ@jU`<*Fes4Ja96#yk)pP!$eo_2M0(bCdlVPRQW zS^fL>Pf1CMf`VdeYb!rL|MBC;czAe0K|wEGyf85_xx2e7EiE-LFeoW0!N$g(nVISB z?fvlK!@gnm#)z$Iv@X*oG0f9gX2?+}ei;$2IYHI4AKYuDKE5CX3W@u;#fk2Rwl3H3?c6WC# zEG*R2)TpVcVK5jD4vwc!pUTS08X6jojg7UnwULpLrKhL+`}+q31YBQV@9pg=Dk|#e z=!l4ju(PvYTwHwn_N}9%BO@b&h=?dDDapgbgNlmE(b18Cfq|Ksd2(`6MMdT7*RQW$ zy~@nY|E-@kvqd-rZ)VgdvL zEiNt!3JO9X5HT^aGSo}QjRfBqySB)ok25+5HwB_*Z3y*)QK7Y2iE zZf-_JMa9L%85*4DP6p+Q4KLtI?EtgLKqZZ0x1l7@!H*Vp&cr%&?o z^2No)Sy@@0o}L8-1X|%3vAo|y!I>p?jvn- zIzu&6I``Q{N$cx^B+Pb6+7j#8t=Frw?WT*|1~l3Ti1pvL`Jd8G{^SXcOYvM-w#te? zQORPPX|_?7AV|9&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mn?GxM`oz8 z59x=ao`#sZhkdsCkPgki%e;~dG38896ee5%c_St?g=U#%K3B>nAeiS~yO*>mya(5y z=J9?MC35O!PlxGNO`d)hY%c6QF{U2c&*|tLG$+m_O0@IYJe~k0;z7g6zf?JfVP<2# ztp6#;g7Gdi`esn7PfA6>y^!>jMh*aPx5dKprJFNU2K}bcGRq|cFXpU16`n^(=^g-% zxgSg&`JwQkE}pE)XA>zNKrJM-lagSlxw(Il^CBnT3o~j?CzU|+v;Q^h><%P;CQ;Vu z960&~{g>Hx=cROtt|NXZAZaHv@C*8UObnKwlGKD480ssGGUZF92*NCsn0ZSic4p?J>Dd-U z2J)0voH#+eds5XErsC~)p79|enA7h{IaDeX$zLLPn6cw5#|Bm+=nc$Dd0y?fSM=;h zM|^{{sJCNxY9E&iugRIelCF4Dg!ekf^M|N*E}yZCy#|4;^E^#DkSHd}eJa6L-Ru)LmHyg3oEM zU6dykqF~a(-zkZdR59sx@RUg@`kKemg6`pt9{8v$<<$|YRr-`SpYT!m2k%5S_SVV= z+s~u-*6`C=k9@4${S!`Nlg64TcP2qK$4T?*Q4^E zclSh-x)H8(adxV84!V+rkV)+070SLb! zFF%AABB;eL426h7ALxUHK<3lV{QpmZy`zPVmFNFoP}HIP@VEc~-pH!JOQcN#{sa1U BUCRIf literal 0 HcmV?d00001 diff --git a/src/test/ref/img_size_a.html b/src/test/ref/img_size_a.html new file mode 100644 index 00000000000..bcfa30137d0 --- /dev/null +++ b/src/test/ref/img_size_a.html @@ -0,0 +1,18 @@ + + + + The winter is too cold for me... + + + +
+ +
+
+ +
+
+ +
+ + diff --git a/src/test/ref/img_size_b.html b/src/test/ref/img_size_b.html new file mode 100644 index 00000000000..d0cf3da554d --- /dev/null +++ b/src/test/ref/img_size_b.html @@ -0,0 +1,18 @@ + + + + The winter is too cold for me... + + + +
+ +
+
+ +
+
+ +
+ + From 5ce3bae160bc15ed5d972439e4e8d4245e009618 Mon Sep 17 00:00:00 2001 From: patrick kim Date: Wed, 22 Jan 2014 14:29:54 +0900 Subject: [PATCH 3/3] add assign_height in box_ --- src/components/main/layout/box_.rs | 138 ++++++++++++++++----------- src/components/main/layout/inline.rs | 4 + 2 files changed, 88 insertions(+), 54 deletions(-) diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 7351986c1dd..1763c9d46fa 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -27,7 +27,7 @@ use std::cell::RefCell; use std::cmp::ApproxEq; use std::num::Zero; use style::{ComputedValues, TElement, TNode, cascade}; -use style::computed_values::{LengthOrPercentage, overflow}; +use style::computed_values::{LengthOrPercentage, LengthOrPercentageOrAuto, overflow, LPA_Auto}; use style::computed_values::{border_style, clear, font_family, line_height}; use style::computed_values::{text_align, text_decoration, vertical_align, visibility}; @@ -108,7 +108,8 @@ pub enum SpecificBoxInfo { pub struct ImageBoxInfo { /// The image held within this box. image: RefCell, - computed_size: RefCell>>, + computed_width: RefCell>, + computed_height: RefCell>, dom_width: Option, dom_height: Option, } @@ -132,20 +133,21 @@ impl ImageBoxInfo { ImageBoxInfo { image: RefCell::new(ImageHolder::new(image_url, local_image_cache)), - computed_size: RefCell::new(None), + computed_width: RefCell::new(None), + computed_height: RefCell::new(None), dom_width: convert_length(node,"width"), dom_height: convert_length(node,"height"), } } - /// Returns Calculated the width of an image, accounting for the height attribute. + /// Returns the calculated width of the image, accounting for the width attribute. pub fn computed_width(&self) -> Au { - match self.computed_size.borrow().get() { - &Some(size) => { - size.width + match self.computed_width.borrow().get() { + &Some(width) => { + width }, &None => { - fail!("image size is not computed yet!"); + fail!("width is not computed yet!"); } } } @@ -155,11 +157,26 @@ impl ImageBoxInfo { Au::from_px(image_ref.get().get_size().unwrap_or(Size2D(0,0)).width) } - /// Returns Calculated the height of an image, accounting for the height attribute. + pub fn style_length(style_length: LengthOrPercentageOrAuto, + dom_length: Option, + container_width: Au) -> MaybeAuto { + match (MaybeAuto::from_style(style_length,container_width),dom_length) { + (Specified(length),_) => { + Specified(length) + }, + (Auto,Some(length)) => { + Specified(length) + }, + (Auto,None) => { + Auto + } + } + } + /// Returns the calculated height of the image, accounting for the height attribute. pub fn computed_height(&self) -> Au { - match self.computed_size.borrow().get() { - &Some(size) => { - size.height + match self.computed_height.borrow().get() { + &Some(height) => { + height }, &None => { fail!("image size is not computed yet!"); @@ -957,7 +974,7 @@ impl Box { (guessed_width + additional_minimum, guessed_width + additional_preferred) } - + pub fn content_width(&self) -> Au { match self.specific { GenericBox | IframeBox(_) => Au(0), @@ -970,7 +987,7 @@ impl Box { text_bounds.size.width } UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), - } + } } /// Returns, and computes, the height of this box. /// @@ -1106,60 +1123,73 @@ impl Box { } ImageBox(ref image_box_info) => { // TODO(ksh8281): compute border,margin,padding - let width = match (MaybeAuto::from_style(self.style().Box.width,container_width), - image_box_info.dom_width) { - (Specified(width),_) => { - Specified(width) - }, - (Auto,Some(width)) => { - Specified(width) - }, - (Auto,None) => { - Auto - } - }; + let width = ImageBoxInfo::style_length(self.style().Box.width, + image_box_info.dom_width, + container_width); + // FIXME(ksh8281): we shouldn't figure height this way + // now, we don't know about size of parent's height + let height = ImageBoxInfo::style_length(self.style().Box.height, + image_box_info.dom_height, + Au::new(0)); - // FIXME(ksh8281): we shouldn't assign height this way - // we need box.assign_height - // now, we can't know about size of parent's height - let height = match (MaybeAuto::from_style(self.style().Box.height,container_width), - image_box_info.dom_height) { - (Specified(height),_) => { - Specified(height) - }, - (Auto,Some(height)) => { - Specified(height) - }, - (Auto,None) => { - Auto - } - }; - - let (width,height) = match (width,height) { + let width = match (width,height) { (Auto,Auto) => { - (image_box_info.image_width(),image_box_info.image_height()) + image_box_info.image_width() }, (Auto,Specified(h)) => { let scale = image_box_info. image_height().to_f32().unwrap() / h.to_f32().unwrap(); - (Au::new((image_box_info.image_width().to_f32().unwrap() / scale) as i32),h) + Au::new((image_box_info.image_width().to_f32().unwrap() / scale) as i32) }, - (Specified(w),Auto) => { - let scale = image_box_info. - image_width().to_f32().unwrap() / w.to_f32().unwrap(); - (w,Au::new((image_box_info.image_height().to_f32().unwrap() / scale) as i32)) - - }, - (Specified(w),Specified(h)) => { - (w,h) + (Specified(w),_) => { + w } }; let mut position = self.position.borrow_mut(); position.get().size.width = width; + image_box_info.computed_width.set(Some(width)); + } + ScannedTextBox(_) => { + // Scanned text boxes will have already had their widths assigned by this point. + } + UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), + } + } + + pub fn assign_height(&self) { + match self.specific { + GenericBox | IframeBox(_) => { + } + ImageBox(ref image_box_info) => { + // TODO(ksh8281): compute border,margin,padding + let width = image_box_info.computed_width(); + // FIXME(ksh8281): we shouldn't assign height this way + // we don't know about size of parent's height + let height = ImageBoxInfo::style_length(self.style().Box.height, + image_box_info.dom_height, + Au::new(0)); + + let height = match (self.style().Box.width, + image_box_info.dom_width, + height) { + (LPA_Auto, None, Auto) => { + image_box_info.image_height() + }, + (_,_,Auto) => { + let scale = image_box_info.image_width().to_f32().unwrap() + / width.to_f32().unwrap(); + Au::new((image_box_info.image_height().to_f32().unwrap() / scale) as i32) + }, + (_,_,Specified(h)) => { + h + } + }; + + let mut position = self.position.borrow_mut(); position.get().size.height = height; - image_box_info.computed_size.set(Some(Size2D(width,height))); + image_box_info.computed_height.set(Some(height)); } ScannedTextBox(_) => { // Scanned text boxes will have already had their widths assigned by this point. diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index c41bc4e35c0..74857cb38bf 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -676,6 +676,10 @@ impl Flow for InlineFlow { // TODO(pcwalton): Cache the linebox scanner? debug!("assign_height_inline: floats_in: {:?}", self.base.floats_in); + // assign height for inline boxes + for box_ in self.boxes.iter() { + box_.assign_height(); + } let scanner_floats = self.base.floats_in.clone(); let mut scanner = LineboxScanner::new(scanner_floats);