Use generics for the vertical-align property

This commit is contained in:
Anthony Ramine 2017-08-30 00:31:39 +02:00
parent 19cbea23a8
commit 542a9337a4
13 changed files with 202 additions and 178 deletions

View file

@ -42,7 +42,7 @@ use std::collections::LinkedList;
use std::sync::{Arc, Mutex};
use style::computed_values::{border_collapse, box_sizing, clear, color, display, mix_blend_mode};
use style::computed_values::{overflow_wrap, overflow_x, position, text_decoration_line};
use style::computed_values::{transform_style, vertical_align, white_space, word_break};
use style::computed_values::{transform_style, white_space, word_break};
use style::computed_values::content::ContentItem;
use style::logical_geometry::{Direction, LogicalMargin, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues;
@ -52,6 +52,7 @@ use style::servo::restyle_damage::RECONSTRUCT_FLOW;
use style::str::char_is_whitespace;
use style::values::{self, Either, Auto};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::generics::box_::VerticalAlign;
use text;
use text::TextRunScanner;
use webrender_api;
@ -2222,8 +2223,8 @@ impl Fragment {
// FIXME(#5624, pcwalton): This passes our current reftests but isn't the right thing
// to do.
match style.get_box().vertical_align {
vertical_align::T::baseline => {}
vertical_align::T::middle => {
VerticalAlign::Baseline => {}
VerticalAlign::Middle => {
let font_metrics = with_thread_local_font_context(layout_context, |font_context| {
text::font_metrics_for_style(font_context, self.style.clone_font())
});
@ -2231,42 +2232,41 @@ impl Fragment {
content_inline_metrics.space_below_baseline -
font_metrics.x_height).scale_by(0.5)
}
vertical_align::T::sub => {
VerticalAlign::Sub => {
offset += minimum_line_metrics.space_needed()
.scale_by(FONT_SUBSCRIPT_OFFSET_RATIO)
}
vertical_align::T::super_ => {
VerticalAlign::Super => {
offset -= minimum_line_metrics.space_needed()
.scale_by(FONT_SUPERSCRIPT_OFFSET_RATIO)
}
vertical_align::T::text_top => {
VerticalAlign::TextTop => {
offset = self.content_inline_metrics(layout_context).ascent -
minimum_line_metrics.space_above_baseline
}
vertical_align::T::text_bottom => {
VerticalAlign::TextBottom => {
offset = minimum_line_metrics.space_below_baseline -
self.content_inline_metrics(layout_context).space_below_baseline
}
vertical_align::T::top => {
VerticalAlign::Top => {
if let Some(actual_line_metrics) = actual_line_metrics {
offset = content_inline_metrics.ascent -
actual_line_metrics.space_above_baseline
}
}
vertical_align::T::bottom => {
VerticalAlign::Bottom => {
if let Some(actual_line_metrics) = actual_line_metrics {
offset = actual_line_metrics.space_below_baseline -
content_inline_metrics.space_below_baseline
}
}
vertical_align::T::LengthOrPercentage(LengthOrPercentage::Length(length)) => {
VerticalAlign::Length(LengthOrPercentage::Length(length)) => {
offset -= length
}
vertical_align::T::LengthOrPercentage(LengthOrPercentage::Percentage(
percentage)) => {
VerticalAlign::Length(LengthOrPercentage::Percentage(percentage)) => {
offset -= minimum_line_metrics.space_needed().scale_by(percentage.0)
}
vertical_align::T::LengthOrPercentage(LengthOrPercentage::Calc(formula)) => {
VerticalAlign::Length(LengthOrPercentage::Calc(formula)) => {
offset -= formula.to_used_value(Some(minimum_line_metrics.space_needed())).unwrap()
}
}
@ -2824,13 +2824,13 @@ impl Fragment {
/// `vertical-align` set to `top` or `bottom`.
pub fn is_vertically_aligned_to_top_or_bottom(&self) -> bool {
match self.style.get_box().vertical_align {
vertical_align::T::top | vertical_align::T::bottom => return true,
VerticalAlign::Top | VerticalAlign::Bottom => return true,
_ => {}
}
if let Some(ref inline_context) = self.inline_context {
for node in &inline_context.nodes {
match node.style.get_box().vertical_align {
vertical_align::T::top | vertical_align::T::bottom => return true,
VerticalAlign::Top | VerticalAlign::Bottom => return true,
_ => {}
}
}

View file

@ -34,6 +34,7 @@ use style::computed_values::{vertical_align, white_space};
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::properties::{longhands, ComputedValues};
use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, RESOLVE_GENERATED_CONTENT};
use style::values::generics::box_::VerticalAlign;
use text;
use traversal::PreorderFlowTraversal;
use unicode_bidi as bidi;
@ -1136,12 +1137,12 @@ impl InlineFlow {
let mut largest_block_size_for_top_fragments = Au(0);
let mut largest_block_size_for_bottom_fragments = Au(0);
// We use `vertical_align::T::baseline` here because `vertical-align` must not apply to
// the inside of inline blocks.
// We use `VerticalAlign::Baseline` here because `vertical-align` must
// not apply to the inside of inline blocks.
update_line_metrics_for_fragment(&mut line_metrics,
&inline_metrics,
style.get_box().display,
vertical_align::T::baseline,
VerticalAlign::Baseline,
&mut largest_block_size_for_top_fragments,
&mut largest_block_size_for_bottom_fragments);
@ -1182,19 +1183,19 @@ impl InlineFlow {
largest_block_size_for_top_fragments: &mut Au,
largest_block_size_for_bottom_fragments: &mut Au) {
match (display_value, vertical_align_value) {
(display::T::inline, vertical_align::T::top) |
(display::T::block, vertical_align::T::top) |
(display::T::inline_flex, vertical_align::T::top) |
(display::T::inline_block, vertical_align::T::top) if
(display::T::inline, VerticalAlign::Top) |
(display::T::block, VerticalAlign::Top) |
(display::T::inline_flex, VerticalAlign::Top) |
(display::T::inline_block, VerticalAlign::Top) if
inline_metrics.space_above_baseline >= Au(0) => {
*largest_block_size_for_top_fragments = max(
*largest_block_size_for_top_fragments,
inline_metrics.space_above_baseline + inline_metrics.space_below_baseline)
}
(display::T::inline, vertical_align::T::bottom) |
(display::T::block, vertical_align::T::bottom) |
(display::T::inline_flex, vertical_align::T::bottom) |
(display::T::inline_block, vertical_align::T::bottom) if
(display::T::inline, VerticalAlign::Bottom) |
(display::T::block, VerticalAlign::Bottom) |
(display::T::inline_flex, VerticalAlign::Bottom) |
(display::T::inline_block, VerticalAlign::Bottom) if
inline_metrics.space_below_baseline >= Au(0) => {
*largest_block_size_for_bottom_fragments = max(
*largest_block_size_for_bottom_fragments,

View file

@ -18,10 +18,11 @@ use layout_debug;
use model::MaybeAuto;
use script_layout_interface::wrapper_traits::ThreadSafeLayoutNode;
use std::fmt;
use style::computed_values::{border_collapse, border_top_style, vertical_align};
use style::computed_values::{border_collapse, border_top_style};
use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues;
use style::values::computed::Color;
use style::values::generics::box_::VerticalAlign;
use table::InternalTable;
use table_row::{CollapsedBorder, CollapsedBorderProvenance};
@ -124,11 +125,11 @@ impl TableCellFlow {
self.block_flow.fragment.border_padding.block_start_end();
let kids_self_gap = self_size - kids_size;
// This offset should also account for vertical_align::T::baseline.
// This offset should also account for VerticalAlign::Baseline.
// Need max cell ascent from the first row of this cell.
let offset = match self.block_flow.fragment.style().get_box().vertical_align {
vertical_align::T::middle => kids_self_gap / 2,
vertical_align::T::bottom => kids_self_gap,
VerticalAlign::Middle => kids_self_gap / 2,
VerticalAlign::Bottom => kids_self_gap,
_ => Au(0),
};
if offset == Au(0) {