diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 07759121f4e..6cdac91368c 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -102,39 +102,38 @@ impl BlockFlowData { } } - // If not an anonymous block context, add in the block box's widths. These widths will not - // include child elements, just padding etc. - for self.box.each |&box| { - // Can compute border width here since it doesn't depend on anything. + /* if not an anonymous block context, add in block box's widths. + these widths will not include child elements, just padding etc. */ + self.box.map(|&box| { + //Can compute border width here since it doesn't depend on anything let style = box.style(); do box.with_model |model| { model.compute_borders(style) } min_width = min_width.add(&box.get_min_width(ctx)); pref_width = pref_width.add(&box.get_pref_width(ctx)); - } + }); self.common.min_width = min_width; self.common.pref_width = pref_width; } /// Computes left and right margins and width based on CSS 2.1 secion 10.3.3. - /// Requires borders and padding to already be computed. - fn compute_horiz(&self, - width: MaybeAuto, - left_margin: MaybeAuto, - right_margin: MaybeAuto, - available_width: Au) - -> (Au, Au, Au) { - // If width is not 'auto', and width + margins > available_width, all 'auto' margins are - // treated as '0'. - let (left_margin, right_margin) = match width { + /// Requires borders and padding to already be computed + priv fn compute_horiz( &self, + width: MaybeAuto, + left_margin: MaybeAuto, + right_margin: MaybeAuto, + available_width: Au) -> (Au, Au, Au) { + + //If width is not 'auto', and width + margins > available_width, all 'auto' margins are treated as '0' + let (left_margin, right_margin) = match width{ Auto => (left_margin, right_margin), Specified(width) => { let left = left_margin.spec_or_default(Au(0)); let right = right_margin.spec_or_default(Au(0)); - if (left + right + width) > available_width { + if((left + right + width) > available_width) { (Specified(left), Specified(right)) } else { (left_margin, right_margin) @@ -142,43 +141,31 @@ impl BlockFlowData { } }; - // Invariant: left_margin_Au + width_Au + right_margin_Au == available_width + //Invariant: left_margin_Au + width_Au + right_margin_Au == available_width let (left_margin_Au, width_Au, right_margin_Au) = match (left_margin, width, right_margin) { - // If all have a computed value other than 'auto', the system is over-constrained and - // we need to discard a margin. If direction is ltr, ignore the specified right margin - // and solve for it. If it is rtl, ignore the specified left margin. - // - // FIXME(eatkinson): this assumes the direction is ltr - (Specified(margin_l), Specified(width), Specified(_)) => { - (margin_l, width, available_width - (margin_l + width)) - } + //If all have a computed value other than 'auto', the system is over-constrained and we need to discard a margin. + //if direction is ltr, ignore the specified right margin and solve for it. If it is rtl, ignore the specified + //left margin. FIXME(eatkinson): this assumes the direction is ltr + (Specified(margin_l), Specified(width), Specified(margin_r)) => (margin_l, width, available_width - (margin_l + width )), - // If exactly one value is 'auto', solve for it - (Auto, Specified(width), Specified(margin_r)) => { - (available_width - (width + margin_r), width, margin_r) - } - (Specified(margin_l), Auto, Specified(margin_r)) => { - (margin_l, available_width - (margin_l + margin_r), margin_r) - } - (Specified(margin_l), Specified(width), Auto) => { - (margin_l, width, available_width - (margin_l + width)) - } + //If exactly one value is 'auto', solve for it + (Auto, Specified(width), Specified(margin_r)) => (available_width - (width + margin_r), width, margin_r), + (Specified(margin_l), Auto, Specified(margin_r)) => (margin_l, available_width - (margin_l + margin_r), margin_r), + (Specified(margin_l), Specified(width), Auto) => (margin_l, width, available_width - (margin_l + width)), - // If width is set to 'auto', any other 'auto' value becomes '0', and width is solved - // for. + //If width is set to 'auto', any other 'auto' value becomes '0', and width is solved for (Auto, Auto, Specified(margin_r)) => (Au(0), available_width - margin_r, margin_r), (Specified(margin_l), Auto, Auto) => (margin_l, available_width - margin_l, Au(0)), (Auto, Auto, Auto) => (Au(0), available_width, Au(0)), - // If left and right margins are auto, they become equal. + //If left and right margins are auto, they become equal (Auto, Specified(width), Auto) => { let margin = (available_width - width).scale_by(0.5); (margin, width, margin) } }; - - // Return values in same order as params. + //return values in same order as params (width_Au, left_margin_Au, right_margin_Au) } @@ -255,11 +242,11 @@ impl BlockFlowData { pub fn assign_height_block(@mut self, ctx: &LayoutContext) { let mut cur_y = Au(0); - self.box.map(|&box| { + for self.box.each |&box| { do box.with_model |model| { cur_y += model.margin.top + model.border.top + model.padding.top; } - }); + } for BlockFlow(self).each_child |kid| { do kid.with_mut_base |child_node| { diff --git a/src/components/main/layout/context.rs b/src/components/main/layout/context.rs index e0ad6bcad7e..8646b9faabc 100644 --- a/src/components/main/layout/context.rs +++ b/src/components/main/layout/context.rs @@ -8,10 +8,12 @@ use geom::rect::Rect; use gfx::font_context::FontContext; use gfx::geometry::Au; use servo_net::local_image_cache::LocalImageCache; +use std::net::url::Url; /// Data needed by the layout task. pub struct LayoutContext { font_ctx: @mut FontContext, image_cache: @mut LocalImageCache, - screen_size: Rect, + doc_url: Url, + screen_size: Rect } diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index 19580507eeb..82a3a214b9c 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -116,10 +116,12 @@ impl Layout { let image_cache = self.local_image_cache; let font_ctx = self.font_ctx; let screen_size = self.screen_size.unwrap(); + let doc_url = self.doc_url.clone(); LayoutContext { image_cache: image_cache, font_ctx: font_ctx, + doc_url: doc_url.unwrap(), screen_size: Rect(Point2D(Au(0), Au(0)), screen_size), } } @@ -347,12 +349,10 @@ impl Layout { let display_list = &display_list.take().list; for display_list.each_reverse |display_item| { let bounds = display_item.bounds(); - - // FIXME(pcwalton): Move this to be a method on Rect. if x <= bounds.origin.x + bounds.size.width && - x >= bounds.origin.x && - y < bounds.origin.y + bounds.size.height && - y >= bounds.origin.y { + bounds.origin.x <= x && + y < bounds.origin.y + bounds.size.height && + bounds.origin.y < y { resp = Ok(HitTestResponse(display_item.base().extra.node())); break; } diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index 8f222814dc1..0260fd346c7 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -22,14 +22,10 @@ use newcss::values::{CSSBorderWidthThick, CSSBorderWidthThin}; use newcss::values::{CSSWidth, CSSWidthLength, CSSWidthPercentage, CSSWidthAuto}; use newcss::values::{CSSMargin, CSSMarginLength, CSSMarginPercentage, CSSMarginAuto}; use newcss::values::{CSSPadding, CSSPaddingLength, CSSPaddingPercentage}; - /// Encapsulates the borders, padding, and margins, which we collectively call the "box model". pub struct BoxModel { - /// The size of the borders. border: SideOffsets2D, - /// The size of the padding. padding: SideOffsets2D, - /// The size of the margins. margin: SideOffsets2D, /// The width of the content box. content_box_width: Au, @@ -90,7 +86,7 @@ impl Zero for BoxModel { } impl BoxModel { - /// Populates the box model border parameters from the given computed style. + /// Populates the box model parameters from the given computed style. pub fn compute_borders(&mut self, style: CompleteStyle) { // Compute the borders. self.border.top = self.compute_border_width(style.border_top_width()); @@ -99,16 +95,11 @@ impl BoxModel { self.border.left = self.compute_border_width(style.border_left_width()); } - /// Populates the box model padding parameters from the given computed style. - pub fn compute_padding(&mut self, style: CompleteStyle, content_box_width: Au) { - self.padding.top = self.compute_padding_length(style.padding_top(), - content_box_width); - self.padding.right = self.compute_padding_length(style.padding_right(), - content_box_width); - self.padding.bottom = self.compute_padding_length(style.padding_bottom(), - content_box_width); - self.padding.left = self.compute_padding_length(style.padding_left(), - content_box_width); + pub fn compute_padding(&mut self, style: CompleteStyle, cb_width: Au){ + self.padding.top = self.compute_padding_length(style.padding_top(), cb_width); + self.padding.right = self.compute_padding_length(style.padding_right(), cb_width); + self.padding.bottom = self.compute_padding_length(style.padding_bottom(), cb_width); + self.padding.left = self.compute_padding_length(style.padding_left(), cb_width); } pub fn noncontent_width(&self) -> Au { @@ -122,7 +113,7 @@ impl BoxModel { } /// Helper function to compute the border width in app units from the CSS border width. - fn compute_border_width(&self, width: CSSBorderWidth) -> Au { + priv fn compute_border_width(&self, width: CSSBorderWidth) -> Au { match width { CSSBorderWidthLength(Px(v)) | CSSBorderWidthLength(Em(v)) |