From 9dd16e41ab5f63dedd6862df93814f3b87746460 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 23 May 2014 16:49:01 +0100 Subject: [PATCH] Make ComputedStyle fields private and add getters. This isolates layout code from upcoming refactoring in properties.rs.mako. --- src/components/main/layout/block.rs | 42 +++++----- src/components/main/layout/box_.rs | 81 ++++++++++---------- src/components/main/layout/construct.rs | 6 +- src/components/main/layout/incremental.rs | 26 ++++--- src/components/main/layout/inline.rs | 4 +- src/components/main/layout/layout_task.rs | 3 +- src/components/main/layout/model.rs | 8 +- src/components/main/layout/table.rs | 6 +- src/components/main/layout/table_cell.rs | 2 +- src/components/main/layout/table_colgroup.rs | 2 +- src/components/main/layout/table_row.rs | 6 +- src/components/main/layout/table_wrapper.rs | 14 ++-- src/components/main/layout/text.rs | 12 +-- src/components/main/layout/wrapper.rs | 10 +-- src/components/style/properties.rs.mako | 78 ++++++++++--------- 15 files changed, 154 insertions(+), 146 deletions(-) diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 6d97c96ad65..7d7415a941a 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -299,21 +299,21 @@ impl CandidateHeightIterator { // the containing block. If that is not determined yet by the time we need to resolve // `min-height` and `max-height`, percentage values are ignored. - let height = match (style.Box.get().height, block_container_height) { + let height = match (style.get_box().height, block_container_height) { (LPA_Percentage(percent), Some(block_container_height)) => { Specified(block_container_height.scale_by(percent)) } (LPA_Percentage(_), None) | (LPA_Auto, _) => Auto, (LPA_Length(length), _) => Specified(length), }; - let max_height = match (style.Box.get().max_height, block_container_height) { + let max_height = match (style.get_box().max_height, block_container_height) { (LPN_Percentage(percent), Some(block_container_height)) => { Some(block_container_height.scale_by(percent)) } (LPN_Percentage(_), None) | (LPN_None, _) => None, (LPN_Length(length), _) => Some(length), }; - let min_height = match (style.Box.get().min_height, block_container_height) { + let min_height = match (style.get_box().min_height, block_container_height) { (LP_Percentage(percent), Some(block_container_height)) => { block_container_height.scale_by(percent) } @@ -1183,11 +1183,11 @@ impl BlockFlow { { // Non-auto margin-top and margin-bottom values have already been // calculated during assign-width. - let margin_top = match self.box_.style().Margin.get().margin_top { + let margin_top = match self.box_.style().get_margin().margin_top { LPA_Auto => Auto, _ => Specified(self.box_.margin.top) }; - let margin_bottom = match self.box_.style().Margin.get().margin_bottom { + let margin_bottom = match self.box_.style().get_margin().margin_bottom { LPA_Auto => Auto, _ => Specified(self.box_.margin.bottom) }; @@ -1195,7 +1195,7 @@ impl BlockFlow { let top; let bottom; { - let position_style = self.box_.style().PositionOffsets.get(); + let position_style = self.box_.style().get_positionoffsets(); top = MaybeAuto::from_style(position_style.top, containing_block_height); bottom = MaybeAuto::from_style(position_style.bottom, containing_block_height); } @@ -1397,15 +1397,15 @@ impl BlockFlow { /// `FormattingContextType`. fn formatting_context_type(&self) -> FormattingContextType { let style = self.box_.style(); - if style.Box.get().float != float::none { + if style.get_box().float != float::none { return OtherFormattingContext } - match style.Box.get().display { + match style.get_box().display { display::table_cell | display::table_caption | display::inline_block => { OtherFormattingContext } - _ if style.Box.get().position == position::static_ && - style.Box.get().overflow != overflow::visible => { + _ if style.get_box().position == position::static_ && + style.get_box().overflow != overflow::visible => { BlockFormattingContext } _ => NonformattingContext, @@ -1424,7 +1424,7 @@ impl Flow for BlockFlow { /// Returns the direction that this flow clears floats in, if any. fn float_clearance(&self) -> clear::T { - self.box_.style().Box.get().clear + self.box_.style().get_box().clear } /// Pass 1 of reflow: computes minimum and preferred widths. @@ -1466,7 +1466,7 @@ impl Flow for BlockFlow { intrinsic_widths.surround_width = box_intrinsic_widths.surround_width; self.base.intrinsic_widths = intrinsic_widths; - match self.box_.style().Box.get().float { + match self.box_.style().get_box().float { float::none => {} float::left => flags.set_has_left_floated_descendants(true), float::right => flags.set_has_right_floated_descendants(true), @@ -1666,7 +1666,7 @@ impl Flow for BlockFlow { /// The 'position' property of this flow. fn positioning(&self) -> position::T { - self.box_.style.Box.get().position + self.box_.style.get_box().position } /// Return true if this is the root of an Absolute flow tree. @@ -1799,15 +1799,15 @@ pub trait WidthAndMarginsComputer { let style = block.box_.style(); // The text alignment of a block flow is the text alignment of its box's style. - block.base.flags.set_text_align(style.InheritedText.get().text_align); + block.base.flags.set_text_align(style.get_inheritedtext().text_align); let (margin_left, margin_right) = - (MaybeAuto::from_style(style.Margin.get().margin_left, containing_block_width), - MaybeAuto::from_style(style.Margin.get().margin_right, containing_block_width)); + (MaybeAuto::from_style(style.get_margin().margin_left, containing_block_width), + MaybeAuto::from_style(style.get_margin().margin_right, containing_block_width)); let (left, right) = - (MaybeAuto::from_style(style.PositionOffsets.get().left, containing_block_width), - MaybeAuto::from_style(style.PositionOffsets.get().right, containing_block_width)); + (MaybeAuto::from_style(style.get_positionoffsets().left, containing_block_width), + MaybeAuto::from_style(style.get_positionoffsets().right, containing_block_width)); let available_width = containing_block_width - block.box_.border_padding.horizontal(); return WidthConstraintInput::new(computed_width, margin_left, @@ -1854,7 +1854,7 @@ pub trait WidthAndMarginsComputer { parent_flow_width: Au, ctx: &mut LayoutContext) -> MaybeAuto { - MaybeAuto::from_style(block.box_().style().Box.get().width, + MaybeAuto::from_style(block.box_().style().get_box().width, self.containing_block_width(block, parent_flow_width, ctx)) } @@ -1881,7 +1881,7 @@ pub trait WidthAndMarginsComputer { // If the tentative used width is greater than 'max-width', width should be recalculated, // but this time using the computed value of 'max-width' as the computed value for 'width'. - match specified_or_none(block.box_().style().Box.get().max_width, containing_block_width) { + match specified_or_none(block.box_().style().get_box().max_width, containing_block_width) { Some(max_width) if max_width < solution.width => { input.computed_width = Specified(max_width); solution = self.solve_width_constraints(block, &input); @@ -1891,7 +1891,7 @@ pub trait WidthAndMarginsComputer { // If the resulting width is smaller than 'min-width', width should be recalculated, // but this time using the value of 'min-width' as the computed value for 'width'. - let computed_min_width = specified(block.box_().style().Box.get().min_width, + let computed_min_width = specified(block.box_().style().get_box().min_width, containing_block_width); if computed_min_width > solution.width { input.computed_width = Specified(computed_min_width); diff --git a/src/components/main/layout/box_.rs b/src/components/main/layout/box_.rs index 32f8d1dc001..f931968fe4e 100644 --- a/src/components/main/layout/box_.rs +++ b/src/components/main/layout/box_.rs @@ -409,18 +409,18 @@ impl Box { }; let style = self.style(); - let width = MaybeAuto::from_style(style.Box.get().width, Au::new(0)).specified_or_zero(); + let width = MaybeAuto::from_style(style.get_box().width, Au::new(0)).specified_or_zero(); let (margin_left, margin_right) = if use_margins { - (MaybeAuto::from_style(style.Margin.get().margin_left, Au(0)).specified_or_zero(), - MaybeAuto::from_style(style.Margin.get().margin_right, Au(0)).specified_or_zero()) + (MaybeAuto::from_style(style.get_margin().margin_left, Au(0)).specified_or_zero(), + MaybeAuto::from_style(style.get_margin().margin_right, Au(0)).specified_or_zero()) } else { (Au(0), Au(0)) }; let (padding_left, padding_right) = if use_padding { - (model::specified(style.Padding.get().padding_left, Au(0)), - model::specified(style.Padding.get().padding_right, Au(0))) + (model::specified(style.get_padding().padding_left, Au(0)), + model::specified(style.get_padding().padding_right, Au(0))) } else { (Au(0), Au(0)) }; @@ -471,10 +471,10 @@ impl Box { _ => { // NB: Percentages are relative to containing block width (not height) per CSS 2.1. self.margin.top = - MaybeAuto::from_style(self.style().Margin.get().margin_top, + MaybeAuto::from_style(self.style().get_margin().margin_top, containing_block_width).specified_or_zero(); self.margin.bottom = - MaybeAuto::from_style(self.style().Margin.get().margin_bottom, + MaybeAuto::from_style(self.style().get_margin().margin_bottom, containing_block_width).specified_or_zero() } } @@ -510,26 +510,26 @@ impl Box { -> Point2D { fn left_right(style: &ComputedValues, block_width: Au) -> Au { // TODO(ksh8281) : consider RTL(right-to-left) culture - match (style.PositionOffsets.get().left, style.PositionOffsets.get().right) { + match (style.get_positionoffsets().left, style.get_positionoffsets().right) { (LPA_Auto, _) => { - -MaybeAuto::from_style(style.PositionOffsets.get().right, block_width) + -MaybeAuto::from_style(style.get_positionoffsets().right, block_width) .specified_or_zero() } (_, _) => { - MaybeAuto::from_style(style.PositionOffsets.get().left, block_width) + MaybeAuto::from_style(style.get_positionoffsets().left, block_width) .specified_or_zero() } } } fn top_bottom(style: &ComputedValues,block_height: Au) -> Au { - match (style.PositionOffsets.get().top, style.PositionOffsets.get().bottom) { + match (style.get_positionoffsets().top, style.get_positionoffsets().bottom) { (LPA_Auto, _) => { - -MaybeAuto::from_style(style.PositionOffsets.get().bottom, block_height) + -MaybeAuto::from_style(style.get_positionoffsets().bottom, block_height) .specified_or_zero() } (_, _) => { - MaybeAuto::from_style(style.PositionOffsets.get().top, block_height) + MaybeAuto::from_style(style.get_positionoffsets().top, block_height) .specified_or_zero() } } @@ -539,14 +539,14 @@ impl Box { let mut rel_pos: Point2D = Zero::zero(); match inline_fragment_context { None => { - if self.style().Box.get().position == position::relative { + if self.style().get_box().position == position::relative { rel_pos.x = rel_pos.x + left_right(self.style(), container_block_size.width); rel_pos.y = rel_pos.y + top_bottom(self.style(), container_block_size.height); } } Some(inline_fragment_context) => { for range in inline_fragment_context.ranges() { - if range.style.Box.get().position == position::relative { + if range.style.get_box().position == position::relative { rel_pos.x = rel_pos.x + left_right(&*range.style, container_block_size.width); rel_pos.y = rel_pos.y + top_bottom(&*range.style, @@ -565,7 +565,7 @@ impl Box { #[inline(always)] pub fn clear(&self) -> Option { let style = self.style(); - match style.Box.get().clear { + match style.get_box().clear { clear::none => None, clear::left => Some(ClearLeft), clear::right => Some(ClearRight), @@ -586,15 +586,15 @@ impl Box { /// Returns the text alignment of the computed style of the nearest ancestor-or-self `Element` /// node. pub fn text_align(&self) -> text_align::T { - self.style().InheritedText.get().text_align + self.style().get_inheritedtext().text_align } pub fn vertical_align(&self) -> vertical_align::T { - self.style().Box.get().vertical_align + self.style().get_box().vertical_align } pub fn white_space(&self) -> white_space::T { - self.style().InheritedText.get().white_space + self.style().get_inheritedtext().white_space } /// Returns the text decoration of this box, according to the style of the nearest ancestor @@ -605,7 +605,7 @@ impl Box { /// model. Therefore, this is a best lower bound approximation, but the end result may actually /// have the various decoration flags turned on afterward. pub fn text_decoration(&self) -> text_decoration::T { - self.style().Text.get().text_decoration + self.style().get_text().text_decoration } /// Returns the left offset from margin edge to content edge. @@ -641,7 +641,7 @@ impl Box { // inefficient. What we really want is something like "nearest ancestor element that // doesn't have a box". let style = self.style(); - let background_color = style.resolve_color(style.Background.get().background_color); + let background_color = style.resolve_color(style.get_background().background_color); if !background_color.alpha.approx_eq(&0.0) { let display_item = box SolidColorDisplayItem { base: BaseDisplayItem::new(*absolute_bounds, self.node, level), @@ -654,7 +654,7 @@ impl Box { // 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 - let background = style.Background.get(); + let background = style.get_background(); let image_url = match background.background_image { None => return, Some(ref image_url) => image_url, @@ -750,10 +750,10 @@ impl Box { } let style = self.style(); - let top_color = style.resolve_color(style.Border.get().border_top_color); - let right_color = style.resolve_color(style.Border.get().border_right_color); - let bottom_color = style.resolve_color(style.Border.get().border_bottom_color); - let left_color = style.resolve_color(style.Border.get().border_left_color); + let top_color = style.resolve_color(style.get_border().border_top_color); + let right_color = style.resolve_color(style.get_border().border_right_color); + let bottom_color = style.resolve_color(style.get_border().border_bottom_color); + let left_color = style.resolve_color(style.get_border().border_left_color); // Append the border to the display list. let border_display_item = box BorderDisplayItem { @@ -763,10 +763,10 @@ impl Box { right_color.to_gfx_color(), bottom_color.to_gfx_color(), left_color.to_gfx_color()), - style: SideOffsets2D::new(style.Border.get().border_top_style, - style.Border.get().border_right_style, - style.Border.get().border_bottom_style, - style.Border.get().border_left_style) + style: SideOffsets2D::new(style.get_border().border_top_style, + style.get_border().border_right_style, + style.get_border().border_bottom_style, + style.get_border().border_left_style) }; list.push(BorderDisplayItemClass(border_display_item)) @@ -852,7 +852,7 @@ impl Box { absolute_box_bounds, self.node, ContentStackingLevel); - if self.style().InheritedBox.get().visibility != visibility::visible { + if self.style().get_inheritedbox().visibility != visibility::visible { return accumulator } @@ -892,12 +892,11 @@ impl Box { TableColumnBox(_) => fail!("Shouldn't see table column boxes here."), ScannedTextBox(ref text_box) => { // Compute text color. - let text_color = self.style().Color.get().color.to_gfx_color(); + let text_color = self.style().get_color().color.to_gfx_color(); // Compute text decorations. let text_decorations_in_effect = self.style() - .InheritedText - .get() + .get_inheritedtext() ._servo_text_decorations_in_effect; let text_decorations = TextDecorations { underline: text_decorations_in_effect.underline.map(|c| c.to_gfx_color()), @@ -1265,8 +1264,8 @@ impl Box { self.compute_border_padding_margins(container_width, inline_fragment_context); - let style_width = self.style().Box.get().width; - let style_height = self.style().Box.get().height; + let style_width = self.style().get_box().width; + let style_height = self.style().get_box().height; let noncontent_width = self.border_padding.horizontal(); match self.specific { @@ -1314,8 +1313,8 @@ impl Box { ImageBox(_) | ScannedTextBox(_) => {} } - let style_width = self.style().Box.get().width; - let style_height = self.style().Box.get().height; + let style_width = self.style().get_box().width; + let style_height = self.style().get_box().height; let noncontent_height = self.border_padding.vertical(); match self.specific { @@ -1368,7 +1367,7 @@ impl Box { } ScannedTextBox(ref text_box) => { // See CSS 2.1 ยง 10.8.1. - let font_size = self.style().Font.get().font_size; + let font_size = self.style().get_font().font_size; let line_height = self.calculate_line_height(font_size); InlineMetrics::from_font_metrics(&text_box.run.font_metrics, line_height) } @@ -1395,7 +1394,7 @@ impl Box { /// Returns true if the contents should be clipped (i.e. if `overflow` is `hidden`). pub fn needs_clip(&self) -> bool { - self.style().Box.get().overflow == overflow::hidden + self.style().get_box().overflow == overflow::hidden } /// A helper function to return a debug string describing the side offsets for one of the rect @@ -1472,7 +1471,7 @@ impl ChildDisplayListAccumulator { fn new(style: &ComputedValues, bounds: Rect, node: OpaqueNode, level: StackingLevel) -> ChildDisplayListAccumulator { ChildDisplayListAccumulator { - clip_display_item: match style.Box.get().overflow { + clip_display_item: match style.get_box().overflow { overflow::hidden => { Some(box ClipDisplayItem { base: BaseDisplayItem::new(bounds, node, level), diff --git a/src/components/main/layout/construct.rs b/src/components/main/layout/construct.rs index 0aa2acb1e94..902a86d288a 100644 --- a/src/components/main/layout/construct.rs +++ b/src/components/main/layout/construct.rs @@ -843,11 +843,11 @@ impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> { None => { // Pseudo-element. let style = node.style(); - (display::inline, style.Box.get().float, style.Box.get().position) + (display::inline, style.get_box().float, style.get_box().position) } Some(ElementNodeTypeId(_)) => { let style = node.style(); - (style.Box.get().display, style.Box.get().float, style.Box.get().position) + (style.get_box().display, style.get_box().float, style.get_box().position) } Some(TextNodeTypeId) => (display::inline, float::none, position::static_), Some(CommentNodeTypeId) | @@ -999,7 +999,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> { // // If you implement other values for this property, you will almost certainly // want to update this check. - match self.style().InheritedText.get().white_space { + match self.style().get_inheritedtext().white_space { white_space::normal => true, _ => false, } diff --git a/src/components/main/layout/incremental.rs b/src/components/main/layout/incremental.rs index c4e95875db8..e050418886e 100644 --- a/src/components/main/layout/incremental.rs +++ b/src/components/main/layout/incremental.rs @@ -106,8 +106,8 @@ impl RestyleDamage { // breakage on modifications. macro_rules! add_if_not_equal( ($old:ident, $new:ident, $damage:ident, - [ $($effect:ident),* ], [ $($style_struct:ident.$name:ident),* ]) => ({ - if $( ($old.$style_struct.get().$name != $new.$style_struct.get().$name) )||* { + [ $($effect:ident),* ], [ $($style_struct_getter:ident.$name:ident),* ]) => ({ + if $( ($old.$style_struct_getter().$name != $new.$style_struct_getter().$name) )||* { $damage.union_in_place( restyle_damage!( $($effect),* ) ); } }) @@ -123,18 +123,20 @@ pub fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> RestyleDama // FIXME: We can short-circuit more of this. add_if_not_equal!(old, new, damage, [ Repaint ], - [ Color.color, Background.background_color, - Border.border_top_color, Border.border_right_color, - Border.border_bottom_color, Border.border_left_color ]); + [ get_color.color, get_background.background_color, + get_border.border_top_color, get_border.border_right_color, + get_border.border_bottom_color, get_border.border_left_color ]); add_if_not_equal!(old, new, damage, [ Repaint, BubbleWidths, Reflow ], - [ Border.border_top_width, Border.border_right_width, - Border.border_bottom_width, Border.border_left_width, - Margin.margin_top, Margin.margin_right, Margin.margin_bottom, Margin.margin_left, - Padding.padding_top, Padding.padding_right, Padding.padding_bottom, Padding.padding_left, - Box.position, Box.width, Box.height, Box.float, Box.display, - Font.font_family, Font.font_size, Font.font_style, Font.font_weight, - InheritedText.text_align, Text.text_decoration, InheritedBox.line_height ]); + [ get_border.border_top_width, get_border.border_right_width, + get_border.border_bottom_width, get_border.border_left_width, + get_margin.margin_top, get_margin.margin_right, + get_margin.margin_bottom, get_margin.margin_left, + get_padding.padding_top, get_padding.padding_right, + get_padding.padding_bottom, get_padding.padding_left, + get_box.position, get_box.width, get_box.height, get_box.float, get_box.display, + get_font.font_family, get_font.font_size, get_font.font_style, get_font.font_weight, + get_inheritedtext.text_align, get_text.text_decoration, get_inheritedbox.line_height ]); // FIXME: test somehow that we checked every CSS property diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index 5b0557c2c4d..12f6640e82d 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -842,7 +842,7 @@ impl InlineFlow { style: &ComputedValues) { let font_style = text::computed_style_to_font_style(style); let font_metrics = text::font_metrics_for_style(font_context, &font_style); - let line_height = text::line_height_from_style(style, style.Font.get().font_size); + let line_height = text::line_height_from_style(style, style.get_font().font_size); let inline_metrics = InlineMetrics::from_font_metrics(&font_metrics, line_height); self.minimum_height_above_baseline = inline_metrics.height_above_baseline; self.minimum_depth_below_baseline = inline_metrics.depth_below_baseline; @@ -978,7 +978,7 @@ impl Flow for InlineFlow { // // CSS 2.1 does not state which font to use. Previous versions of the code used // the parent's font; this code uses the current font. - let parent_text_top = fragment.style().Font.get().font_size; + let parent_text_top = fragment.style().get_font().font_size; // We should calculate the distance from baseline to the bottom of the parent's // content area. But for now we assume it's zero. diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index e039bc7e506..daec55327ef 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -689,8 +689,7 @@ impl LayoutTask { let thread_safe_child = ThreadSafeLayoutNode::new(&child); thread_safe_child.style() .resolve_color(thread_safe_child.style() - .Background - .get() + .get_background() .background_color) .to_gfx_color() }; diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index 3fda7357fe7..084aa4df0c1 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -112,9 +112,9 @@ impl MarginCollapseInfo { -> (CollapsibleMargins, Au) { let state = match self.state { AccumulatingCollapsibleTopMargin => { - match fragment.style().Box.get().height { + match fragment.style().get_box().height { LPA_Auto | LPA_Length(Au(0)) | LPA_Percentage(0.) => { - match fragment.style().Box.get().min_height { + match fragment.style().get_box().min_height { LP_Length(Au(0)) | LP_Percentage(0.) => { MarginsCollapseThroughFinalMarginState }, @@ -315,7 +315,7 @@ pub fn specified(length: computed::LengthOrPercentage, containing_length: Au) -> #[inline] pub fn border_from_style(style: &ComputedValues) -> SideOffsets2D { - let border_style = style.Border.get(); + let border_style = style.get_border(); SideOffsets2D::new(border_style.border_top_width, border_style.border_right_width, border_style.border_bottom_width, @@ -325,7 +325,7 @@ pub fn border_from_style(style: &ComputedValues) -> SideOffsets2D { #[inline] pub fn padding_from_style(style: &ComputedValues, containing_block_width: Au) -> SideOffsets2D { - let padding_style = style.Padding.get(); + let padding_style = style.get_padding(); SideOffsets2D::new(specified(padding_style.padding_top, containing_block_width), specified(padding_style.padding_right, containing_block_width), specified(padding_style.padding_bottom, containing_block_width), diff --git a/src/components/main/layout/table.rs b/src/components/main/layout/table.rs index d3b67699073..5f5d8c8b343 100644 --- a/src/components/main/layout/table.rs +++ b/src/components/main/layout/table.rs @@ -43,7 +43,7 @@ impl TableFlow { box_: Box) -> TableFlow { let mut block_flow = BlockFlow::from_node_and_box(node, box_); - let table_layout = if block_flow.box_().style().Table.get().table_layout == + let table_layout = if block_flow.box_().style().get_table().table_layout == table_layout::fixed { FixedLayout } else { @@ -62,7 +62,7 @@ impl TableFlow { node: &ThreadSafeLayoutNode) -> TableFlow { let mut block_flow = BlockFlow::from_node(constructor, node); - let table_layout = if block_flow.box_().style().Table.get().table_layout == + let table_layout = if block_flow.box_().style().get_table().table_layout == table_layout::fixed { FixedLayout } else { @@ -82,7 +82,7 @@ impl TableFlow { float_kind: FloatKind) -> TableFlow { let mut block_flow = BlockFlow::float_from_node(constructor, node, float_kind); - let table_layout = if block_flow.box_().style().Table.get().table_layout == + let table_layout = if block_flow.box_().style().get_table().table_layout == table_layout::fixed { FixedLayout } else { diff --git a/src/components/main/layout/table_cell.rs b/src/components/main/layout/table_cell.rs index da1dd6ea6eb..1d8714f1831 100644 --- a/src/components/main/layout/table_cell.rs +++ b/src/components/main/layout/table_cell.rs @@ -69,7 +69,7 @@ impl Flow for TableCellFlow { /// Minimum/preferred widths set by this function are used in automatic table layout calculation. fn bubble_widths(&mut self, ctx: &mut LayoutContext) { self.block_flow.bubble_widths(ctx); - let specified_width = MaybeAuto::from_style(self.block_flow.box_.style().Box.get().width, + let specified_width = MaybeAuto::from_style(self.block_flow.box_.style().get_box().width, Au::new(0)).specified_or_zero(); if self.block_flow.base.intrinsic_widths.minimum_width < specified_width { self.block_flow.base.intrinsic_widths.minimum_width = specified_width; diff --git a/src/components/main/layout/table_colgroup.rs b/src/components/main/layout/table_colgroup.rs index 004d18d751f..99c0659d109 100644 --- a/src/components/main/layout/table_colgroup.rs +++ b/src/components/main/layout/table_colgroup.rs @@ -53,7 +53,7 @@ impl Flow for TableColGroupFlow { fn bubble_widths(&mut self, _: &mut LayoutContext) { for box_ in self.cols.iter() { // get the specified value from width property - let width = MaybeAuto::from_style(box_.style().Box.get().width, + let width = MaybeAuto::from_style(box_.style().get_box().width, Au::new(0)).specified_or_zero(); let span: int = match box_.specific { diff --git a/src/components/main/layout/table_row.rs b/src/components/main/layout/table_row.rs index 036f53e85cd..ab1e2d22134 100644 --- a/src/components/main/layout/table_row.rs +++ b/src/components/main/layout/table_row.rs @@ -86,7 +86,7 @@ impl TableRowFlow { { let child_box = kid.as_table_cell().box_(); // TODO: Percentage height - let child_specified_height = MaybeAuto::from_style(child_box.style().Box.get().height, + let child_specified_height = MaybeAuto::from_style(child_box.style().get_box().height, Au::new(0)).specified_or_zero(); max_y = geometry::max(max_y, @@ -99,7 +99,7 @@ impl TableRowFlow { let mut height = max_y; // TODO: Percentage height - height = match MaybeAuto::from_style(self.block_flow.box_.style().Box.get().height, Au(0)) { + height = match MaybeAuto::from_style(self.block_flow.box_.style().get_box().height, Au(0)) { Auto => height, Specified(value) => geometry::max(value, height) }; @@ -173,7 +173,7 @@ impl Flow for TableRowFlow { // collect the specified column widths of cells. These are used in fixed table layout calculation. { let child_box = kid.as_table_cell().box_(); - let child_specified_width = MaybeAuto::from_style(child_box.style().Box.get().width, + let child_specified_width = MaybeAuto::from_style(child_box.style().get_box().width, Au::new(0)).specified_or_zero(); self.col_widths.push(child_specified_width); } diff --git a/src/components/main/layout/table_wrapper.rs b/src/components/main/layout/table_wrapper.rs index 69ef004ede6..767b8afc8fd 100644 --- a/src/components/main/layout/table_wrapper.rs +++ b/src/components/main/layout/table_wrapper.rs @@ -40,7 +40,7 @@ impl TableWrapperFlow { box_: Box) -> TableWrapperFlow { let mut block_flow = BlockFlow::from_node_and_box(node, box_); - let table_layout = if block_flow.box_().style().Table.get().table_layout == + let table_layout = if block_flow.box_().style().get_table().table_layout == table_layout::fixed { FixedLayout } else { @@ -57,7 +57,7 @@ impl TableWrapperFlow { node: &ThreadSafeLayoutNode) -> TableWrapperFlow { let mut block_flow = BlockFlow::from_node(constructor, node); - let table_layout = if block_flow.box_().style().Table.get().table_layout == + let table_layout = if block_flow.box_().style().get_table().table_layout == table_layout::fixed { FixedLayout } else { @@ -75,7 +75,7 @@ impl TableWrapperFlow { float_kind: FloatKind) -> TableWrapperFlow { let mut block_flow = BlockFlow::float_from_node(constructor, node, float_kind); - let table_layout = if block_flow.box_().style().Table.get().table_layout == + let table_layout = if block_flow.box_().style().get_table().table_layout == table_layout::fixed { FixedLayout } else { @@ -237,12 +237,12 @@ impl TableWrapper { // Get left and right paddings, borders for table. // We get these values from the box's style since table_wrapper doesn't have it's own border or padding. // input.available_width is same as containing_block_width in table_wrapper. - let padding_left = specified(style.Padding.get().padding_left, + let padding_left = specified(style.get_padding().padding_left, input.available_width); - let padding_right = specified(style.Padding.get().padding_right, + let padding_right = specified(style.get_padding().padding_right, input.available_width); - let border_left = style.Border.get().border_left_width; - let border_right = style.Border.get().border_right_width; + let border_left = style.get_border().border_left_width; + let border_right = style.get_border().border_right_width; let padding_and_borders = padding_left + padding_right + border_left + border_right; // Compare border-edge widths. Because fixed_cells_width indicates content-width, // padding and border values are added to fixed_cells_width. diff --git a/src/components/main/layout/text.rs b/src/components/main/layout/text.rs index 2d08bf38019..11f92d8d61b 100644 --- a/src/components/main/layout/text.rs +++ b/src/components/main/layout/text.rs @@ -278,20 +278,20 @@ pub fn computed_style_to_font_style(style: &ComputedValues) -> FontStyle { debug!("(font style) start"); // FIXME: Too much allocation here. - let mut font_families = style.Font.get().font_family.iter().map(|family| { + let mut font_families = style.get_font().font_family.iter().map(|family| { match *family { font_family::FamilyName(ref name) => (*name).clone(), } }); debug!("(font style) font families: `{:?}`", font_families); - let font_size = style.Font.get().font_size.to_f64().unwrap() / 60.0; + let font_size = style.get_font().font_size.to_f64().unwrap() / 60.0; debug!("(font style) font size: `{:f}px`", font_size); FontStyle { pt_size: font_size, - weight: style.Font.get().font_weight, - style: style.Font.get().font_style, + weight: style.get_font().font_weight, + style: style.get_font().font_style, families: font_families.collect(), } } @@ -300,12 +300,12 @@ pub fn computed_style_to_font_style(style: &ComputedValues) -> FontStyle { /// /// FIXME(pcwalton): I believe this should not take a separate `font-size` parameter. pub fn line_height_from_style(style: &ComputedValues, font_size: Au) -> Au { - let from_inline = match style.InheritedBox.get().line_height { + let from_inline = match style.get_inheritedbox().line_height { line_height::Normal => font_size.scale_by(1.14), line_height::Number(l) => font_size.scale_by(l), line_height::Length(l) => l }; - let minimum = style.InheritedBox.get()._servo_minimum_line_height; + let minimum = style.get_inheritedbox()._servo_minimum_line_height; Au::max(from_inline, minimum) } diff --git a/src/components/main/layout/wrapper.rs b/src/components/main/layout/wrapper.rs index 49cfafe9fe1..f2d8f094f8d 100644 --- a/src/components/main/layout/wrapper.rs +++ b/src/components/main/layout/wrapper.rs @@ -474,10 +474,10 @@ impl<'ln> TLayoutNode for ThreadSafeLayoutNode<'ln> { if self.pseudo == Before { let before_style = node_layout_data_wrapper.data.before_style.get_ref(); - return get_content(&before_style.Box.get().content) + return get_content(&before_style.get_box().content) } else { let after_style = node_layout_data_wrapper.data.after_style.get_ref(); - return get_content(&after_style.Box.get().content) + return get_content(&after_style.get_box().content) } } @@ -553,15 +553,15 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { let display = match kind { Before | BeforeBlock => { let before_style = node_layout_data_wrapper.data.before_style.get_ref(); - before_style.Box.get().display + before_style.get_box().display } After | AfterBlock => { let after_style = node_layout_data_wrapper.data.after_style.get_ref(); - after_style.Box.get().display + after_style.get_box().display } Normal => { let after_style = node_layout_data_wrapper.shared_data.style.get_ref(); - after_style.Box.get().display + after_style.get_box().display } }; diff --git a/src/components/style/properties.rs.mako b/src/components/style/properties.rs.mako index 8e2a176af51..0376878a11c 100644 --- a/src/components/style/properties.rs.mako +++ b/src/components/style/properties.rs.mako @@ -31,7 +31,7 @@ pub mod common_types; def to_rust_ident(name): name = name.replace("-", "_") - if name in ["static", "super"]: # Rust keywords + if name in ["static", "super", "box"]: # Rust keywords name += "_" return name @@ -54,6 +54,7 @@ class Shorthand(object): class StyleStruct(object): def __init__(self, name, inherited): self.name = name + self.ident = to_rust_ident(name.lower()) self.longhands = [] self.inherited = inherited @@ -1571,7 +1572,7 @@ pub mod style_structs { #[deriving(Eq, Clone)] pub struct ComputedValues { % for style_struct in STYLE_STRUCTS: - pub ${style_struct.name}: CowArc, + ${style_struct.ident}: CowArc, % endfor shareable: bool, } @@ -1587,16 +1588,23 @@ impl ComputedValues { pub fn resolve_color(&self, color: computed::CSSColor) -> RGBA { match color { RGBA(rgba) => rgba, - CurrentColor => self.Color.get().color, + CurrentColor => self.get_color().color, } } + + % for style_struct in STYLE_STRUCTS: + pub fn get_${style_struct.name.lower()} + <'a>(&'a self) -> &'a style_structs::${style_struct.name} { + self.${style_struct.ident}.get() + } + % endfor } /// The initial values for all style structs as defined by the specification. lazy_init! { static ref INITIAL_VALUES: ComputedValues = ComputedValues { % for style_struct in STYLE_STRUCTS: - ${style_struct.name}: CowArc::new(style_structs::${style_struct.name} { + ${style_struct.ident}: CowArc::new(style_structs::${style_struct.name} { % for longhand in style_struct.longhands: ${longhand.ident}: longhands::${longhand.ident}::get_initial_value(), % endfor @@ -1615,9 +1623,9 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty], -> ComputedValues { % for style_struct in STYLE_STRUCTS: % if style_struct.inherited: - let mut style_${style_struct.name} = parent_style.${style_struct.name}.clone(); + let mut style_${style_struct.ident} = parent_style.${style_struct.ident}.clone(); % else: - let style_${style_struct.name} = cached_style.${style_struct.name}.clone(); + let style_${style_struct.ident} = cached_style.${style_struct.ident}.clone(); % endif % endfor @@ -1650,18 +1658,18 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty], // matter. // // FIXME: is it still? - parent_style.${style_struct.name} + parent_style.${style_struct.ident} .get() .${property.ident} .clone() } }; - style_${style_struct.name}.get_mut().${property.ident} = + style_${style_struct.ident}.get_mut().${property.ident} = computed_value; % if property.name in DERIVED_LONGHANDS: % for derived in DERIVED_LONGHANDS[property.name]: - style_${derived.style_struct.name}.get_mut() + style_${derived.style_struct.ident}.get_mut() .${derived.ident} = longhands::${derived.ident} ::derive_from_${property.ident}( @@ -1685,7 +1693,7 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty], ComputedValues { % for style_struct in STYLE_STRUCTS: - ${style_struct.name}: style_${style_struct.name}, + ${style_struct.ident}: style_${style_struct.ident}, % endfor shareable: shareable, } @@ -1719,21 +1727,20 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], }; let mut context = { - let inherited_font_style = inherited_style.Font.get(); + let inherited_font_style = inherited_style.get_font(); computed::Context { is_root_element: is_root_element, inherited_font_weight: inherited_font_style.font_weight, inherited_font_size: inherited_font_style.font_size, - inherited_height: inherited_style.Box.get().height, - inherited_minimum_line_height: inherited_style.InheritedBox - .get() + inherited_height: inherited_style.get_box().height, + inherited_minimum_line_height: inherited_style.get_inheritedbox() ._servo_minimum_line_height, inherited_text_decorations_in_effect: - inherited_style.InheritedText.get()._servo_text_decorations_in_effect, + inherited_style.get_inheritedtext()._servo_text_decorations_in_effect, // To be overridden by applicable declarations: font_size: inherited_font_style.font_size, display: longhands::display::get_initial_value(), - color: inherited_style.Color.get().color, + color: inherited_style.get_color().color, text_decoration: longhands::text_decoration::get_initial_value(), positioned: false, floated: false, @@ -1746,11 +1753,11 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], // This assumes that the computed and specified values have the same Rust type. macro_rules! get_specified( - ($style_struct: ident, $property: ident, $declared_value: expr) => { + ($style_struct_getter: ident, $property: ident, $declared_value: expr) => { match *$declared_value { SpecifiedValue(specified_value) => specified_value, CSSWideKeyword(Initial) => longhands::$property::get_initial_value(), - CSSWideKeyword(Inherit) => inherited_style.$style_struct.get().$property.clone(), + CSSWideKeyword(Inherit) => inherited_style.$style_struct_getter().$property.clone(), } }; ) @@ -1770,27 +1777,28 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], } } color_declaration(ref value) => { - context.color = get_specified!(Color, color, value); + context.color = get_specified!(get_color, color, value); } display_declaration(ref value) => { - context.display = get_specified!(Box, display, value); + context.display = get_specified!(get_box, display, value); } position_declaration(ref value) => { - context.positioned = match get_specified!(Box, position, value) { + context.positioned = match get_specified!(get_box, position, value) { longhands::position::absolute | longhands::position::fixed => true, _ => false, } } float_declaration(ref value) => { - context.floated = get_specified!(Box, float, value) != longhands::float::none; + context.floated = get_specified!(get_box, float, value) + != longhands::float::none; } text_decoration_declaration(ref value) => { - context.text_decoration = get_specified!(Text, text_decoration, value); + context.text_decoration = get_specified!(get_text, text_decoration, value); } % for side in ["top", "right", "bottom", "left"]: border_${side}_style_declaration(ref value) => { context.border_${side}_present = - match get_specified!(Border, border_${side}_style, value) { + match get_specified!(get_border, border_${side}_style, value) { longhands::border_top_style::none | longhands::border_top_style::hidden => false, _ => true, @@ -1815,13 +1823,13 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], // Set computed values, overwriting earlier declarations for the same property. % for style_struct in STYLE_STRUCTS: - let mut style_${style_struct.name} = + let mut style_${style_struct.ident} = % if style_struct.inherited: inherited_style % else: initial_values % endif - .${style_struct.name}.clone(); + .${style_struct.ident}.clone(); % endfor let mut cacheable = true; let mut seen = PropertyBitField::new(); @@ -1853,18 +1861,18 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], // // FIXME: is it still? cacheable = false; - inherited_style.${style_struct.name} + inherited_style.${style_struct.ident} .get() .${property.ident} .clone() } }; - style_${style_struct.name}.get_mut().${property.ident} = + style_${style_struct.ident}.get_mut().${property.ident} = computed_value; % if property.name in DERIVED_LONGHANDS: % for derived in DERIVED_LONGHANDS[property.name]: - style_${derived.style_struct.name}.get_mut() + style_${derived.style_struct.ident}.get_mut() .${derived.ident} = longhands::${derived.ident} ::derive_from_${property.ident}( @@ -1886,7 +1894,7 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], // The initial value of border-*-width may be changed at computed value time. { - let border = style_Border.get_mut(); + let border = style_border.get_mut(); % for side in ["top", "right", "bottom", "left"]: // Like calling to_computed_value, which wouldn't type check. if !context.border_${side}_present { @@ -1897,13 +1905,13 @@ pub fn cascade(applicable_declarations: &[MatchedProperty], // The initial value of display may be changed at computed value time. if !seen.get_display() { - let box_ = style_Box.get_mut(); + let box_ = style_box_.get_mut(); box_.display = longhands::display::to_computed_value(box_.display, &context); } (ComputedValues { % for style_struct in STYLE_STRUCTS: - ${style_struct.name}: style_${style_struct.name}, + ${style_struct.ident}: style_${style_struct.ident}, % endfor shareable: shareable, }, cacheable) @@ -1918,18 +1926,18 @@ pub fn cascade_anonymous(parent_style: &ComputedValues) -> ComputedValues { let initial_values = &*INITIAL_VALUES; let mut result = ComputedValues { % for style_struct in STYLE_STRUCTS: - ${style_struct.name}: + ${style_struct.ident}: % if style_struct.inherited: parent_style % else: initial_values % endif - .${style_struct.name}.clone(), + .${style_struct.ident}.clone(), % endfor shareable: false, }; { - let border = result.Border.get_mut(); + let border = result.border.get_mut(); % for side in ["top", "right", "bottom", "left"]: // Like calling to_computed_value, which wouldn't type check. border.border_${side}_width = Au(0);