layout: fix Servo build.

This commit is contained in:
Emilio Cobos Álvarez 2019-05-06 10:17:08 +02:00
parent 561018da7d
commit 0000e4cec2
7 changed files with 112 additions and 72 deletions

View file

@ -12,7 +12,7 @@ use style::values::computed::image::{EndingShape, LineDirection};
use style::values::computed::{Angle, GradientItem, LengthPercentage, Percentage, Position}; use style::values::computed::{Angle, GradientItem, LengthPercentage, Percentage, Position};
use style::values::generics::image::EndingShape as GenericEndingShape; use style::values::generics::image::EndingShape as GenericEndingShape;
use style::values::generics::image::GradientItem as GenericGradientItem; use style::values::generics::image::GradientItem as GenericGradientItem;
use style::values::generics::image::{Circle, Ellipse, ShapeExtent}; use style::values::generics::image::{Circle, ColorStop, Ellipse, ShapeExtent};
use style::values::specified::position::{X, Y}; use style::values::specified::position::{X, Y};
use webrender_api::{ExtendMode, Gradient, GradientBuilder, GradientStop, RadialGradient}; use webrender_api::{ExtendMode, Gradient, GradientBuilder, GradientStop, RadialGradient};
@ -92,7 +92,14 @@ fn convert_gradient_stops(
let mut stop_items = gradient_items let mut stop_items = gradient_items
.iter() .iter()
.filter_map(|item| match *item { .filter_map(|item| match *item {
GenericGradientItem::ColorStop(ref stop) => Some(*stop), GenericGradientItem::SimpleColorStop(color) => Some(ColorStop {
color,
position: None,
}),
GenericGradientItem::ComplexColorStop { color, position } => Some(ColorStop {
color,
position: Some(position),
}),
_ => None, _ => None,
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -61,8 +61,8 @@ use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::str::char_is_whitespace; use style::str::char_is_whitespace;
use style::values::computed::counters::ContentItem; use style::values::computed::counters::ContentItem;
use style::values::computed::{LengthPercentage, LengthPercentageOrAuto, Size}; use style::values::computed::{LengthPercentage, LengthPercentageOrAuto, Size, VerticalAlign};
use style::values::generics::box_::{Perspective, VerticalAlign}; use style::values::generics::box_::{Perspective, VerticalAlignKeyword};
use style::values::generics::transform; use style::values::generics::transform;
use style::Zero; use style::Zero;
use webrender_api::{self, LayoutTransform}; use webrender_api::{self, LayoutTransform};
@ -2397,47 +2397,49 @@ impl Fragment {
// FIXME(#5624, pcwalton): This passes our current reftests but isn't the right thing // FIXME(#5624, pcwalton): This passes our current reftests but isn't the right thing
// to do. // to do.
match style.get_box().vertical_align { match style.get_box().vertical_align {
VerticalAlign::Baseline => {}, VerticalAlign::Keyword(kw) => match kw {
VerticalAlign::Middle => { VerticalAlignKeyword::Baseline => {},
let font_metrics = VerticalAlignKeyword::Middle => {
with_thread_local_font_context(layout_context, |font_context| { let font_metrics =
text::font_metrics_for_style(font_context, self.style.clone_font()) with_thread_local_font_context(layout_context, |font_context| {
}); text::font_metrics_for_style(font_context, self.style.clone_font())
offset += (content_inline_metrics.ascent - });
content_inline_metrics.space_below_baseline - offset += (content_inline_metrics.ascent -
font_metrics.x_height) content_inline_metrics.space_below_baseline -
.scale_by(0.5) font_metrics.x_height)
}, .scale_by(0.5)
VerticalAlign::Sub => { },
offset += minimum_line_metrics VerticalAlignKeyword::Sub => {
.space_needed() offset += minimum_line_metrics
.scale_by(FONT_SUBSCRIPT_OFFSET_RATIO) .space_needed()
}, .scale_by(FONT_SUBSCRIPT_OFFSET_RATIO)
VerticalAlign::Super => { },
offset -= minimum_line_metrics VerticalAlignKeyword::Super => {
.space_needed() offset -= minimum_line_metrics
.scale_by(FONT_SUPERSCRIPT_OFFSET_RATIO) .space_needed()
}, .scale_by(FONT_SUPERSCRIPT_OFFSET_RATIO)
VerticalAlign::TextTop => { },
offset = self.content_inline_metrics(layout_context).ascent - VerticalAlignKeyword::TextTop => {
minimum_line_metrics.space_above_baseline offset = self.content_inline_metrics(layout_context).ascent -
}, minimum_line_metrics.space_above_baseline
VerticalAlign::TextBottom => { },
offset = minimum_line_metrics.space_below_baseline - VerticalAlignKeyword::TextBottom => {
self.content_inline_metrics(layout_context) offset = minimum_line_metrics.space_below_baseline -
.space_below_baseline self.content_inline_metrics(layout_context)
}, .space_below_baseline
VerticalAlign::Top => { },
if let Some(actual_line_metrics) = actual_line_metrics { VerticalAlignKeyword::Top => {
offset = if let Some(actual_line_metrics) = actual_line_metrics {
content_inline_metrics.ascent - actual_line_metrics.space_above_baseline offset = content_inline_metrics.ascent -
} actual_line_metrics.space_above_baseline
}, }
VerticalAlign::Bottom => { },
if let Some(actual_line_metrics) = actual_line_metrics { VerticalAlignKeyword::Bottom => {
offset = actual_line_metrics.space_below_baseline - if let Some(actual_line_metrics) = actual_line_metrics {
content_inline_metrics.space_below_baseline offset = actual_line_metrics.space_below_baseline -
} content_inline_metrics.space_below_baseline
}
},
}, },
VerticalAlign::Length(ref lp) => { VerticalAlign::Length(ref lp) => {
offset -= lp.to_used_value(minimum_line_metrics.space_needed()); offset -= lp.to_used_value(minimum_line_metrics.space_needed());
@ -3087,15 +3089,22 @@ impl Fragment {
/// Returns true if any of the inline styles associated with this fragment have /// Returns true if any of the inline styles associated with this fragment have
/// `vertical-align` set to `top` or `bottom`. /// `vertical-align` set to `top` or `bottom`.
pub fn is_vertically_aligned_to_top_or_bottom(&self) -> bool { pub fn is_vertically_aligned_to_top_or_bottom(&self) -> bool {
match self.style.get_box().vertical_align { fn is_top_or_bottom(v: &VerticalAlign) -> bool {
VerticalAlign::Top | VerticalAlign::Bottom => return true, match *v {
_ => {}, VerticalAlign::Keyword(VerticalAlignKeyword::Top) |
VerticalAlign::Keyword(VerticalAlignKeyword::Bottom) => true,
_ => false,
}
} }
if is_top_or_bottom(&self.style.get_box().vertical_align) {
return true;
}
if let Some(ref inline_context) = self.inline_context { if let Some(ref inline_context) = self.inline_context {
for node in &inline_context.nodes { for node in &inline_context.nodes {
match node.style.get_box().vertical_align { if is_top_or_bottom(&node.style.get_box().vertical_align) {
VerticalAlign::Top | VerticalAlign::Bottom => return true, return true;
_ => {},
} }
} }
} }

View file

@ -41,7 +41,7 @@ use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::servo::restyle_damage::ServoRestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::computed::box_::VerticalAlign; use style::values::computed::box_::VerticalAlign;
use style::values::generics::box_::VerticalAlign as GenericVerticalAlign; use style::values::generics::box_::VerticalAlignKeyword;
use style::values::specified::text::TextOverflowSide; use style::values::specified::text::TextOverflowSide;
use unicode_bidi as bidi; use unicode_bidi as bidi;
@ -1269,13 +1269,13 @@ impl InlineFlow {
let mut largest_block_size_for_top_fragments = Au(0); let mut largest_block_size_for_top_fragments = Au(0);
let mut largest_block_size_for_bottom_fragments = Au(0); let mut largest_block_size_for_bottom_fragments = Au(0);
// We use `VerticalAlign::Baseline` here because `vertical-align` must // We use `VerticalAlign::baseline()` here because `vertical-align` must
// not apply to the inside of inline blocks. // not apply to the inside of inline blocks.
update_line_metrics_for_fragment( update_line_metrics_for_fragment(
&mut line_metrics, &mut line_metrics,
&inline_metrics, &inline_metrics,
style.get_box().display, style.get_box().display,
GenericVerticalAlign::Baseline, VerticalAlign::baseline(),
&mut largest_block_size_for_top_fragments, &mut largest_block_size_for_top_fragments,
&mut largest_block_size_for_bottom_fragments, &mut largest_block_size_for_bottom_fragments,
); );
@ -1322,11 +1322,20 @@ impl InlineFlow {
largest_block_size_for_top_fragments: &mut Au, largest_block_size_for_top_fragments: &mut Au,
largest_block_size_for_bottom_fragments: &mut Au, largest_block_size_for_bottom_fragments: &mut Au,
) { ) {
// FIXME(emilio): This should probably be handled.
let vertical_align_value = match vertical_align_value {
VerticalAlign::Keyword(kw) => kw,
VerticalAlign::Length(..) => {
*line_metrics = line_metrics.new_metrics_for_fragment(inline_metrics);
return;
},
};
match (display_value, vertical_align_value) { match (display_value, vertical_align_value) {
(Display::Inline, GenericVerticalAlign::Top) | (Display::Inline, VerticalAlignKeyword::Top) |
(Display::Block, GenericVerticalAlign::Top) | (Display::Block, VerticalAlignKeyword::Top) |
(Display::InlineFlex, GenericVerticalAlign::Top) | (Display::InlineFlex, VerticalAlignKeyword::Top) |
(Display::InlineBlock, GenericVerticalAlign::Top) (Display::InlineBlock, VerticalAlignKeyword::Top)
if inline_metrics.space_above_baseline >= Au(0) => if inline_metrics.space_above_baseline >= Au(0) =>
{ {
*largest_block_size_for_top_fragments = max( *largest_block_size_for_top_fragments = max(
@ -1334,10 +1343,10 @@ impl InlineFlow {
inline_metrics.space_above_baseline + inline_metrics.space_below_baseline, inline_metrics.space_above_baseline + inline_metrics.space_below_baseline,
) )
}, },
(Display::Inline, GenericVerticalAlign::Bottom) | (Display::Inline, VerticalAlignKeyword::Bottom) |
(Display::Block, GenericVerticalAlign::Bottom) | (Display::Block, VerticalAlignKeyword::Bottom) |
(Display::InlineFlex, GenericVerticalAlign::Bottom) | (Display::InlineFlex, VerticalAlignKeyword::Bottom) |
(Display::InlineBlock, GenericVerticalAlign::Bottom) (Display::InlineBlock, VerticalAlignKeyword::Bottom)
if inline_metrics.space_below_baseline >= Au(0) => if inline_metrics.space_below_baseline >= Au(0) =>
{ {
*largest_block_size_for_bottom_fragments = max( *largest_block_size_for_bottom_fragments = max(

View file

@ -23,7 +23,7 @@ use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMo
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::computed::length::Size; use style::values::computed::length::Size;
use style::values::computed::Color; use style::values::computed::Color;
use style::values::generics::box_::VerticalAlign; use style::values::generics::box_::{VerticalAlign, VerticalAlignKeyword};
use style::values::specified::BorderStyle; use style::values::specified::BorderStyle;
#[allow(unsafe_code)] #[allow(unsafe_code)]
@ -138,11 +138,11 @@ impl TableCellFlow {
self.block_flow.fragment.border_padding.block_start_end(); self.block_flow.fragment.border_padding.block_start_end();
let kids_self_gap = self_size - kids_size; let kids_self_gap = self_size - kids_size;
// This offset should also account for VerticalAlign::Baseline. // This offset should also account for VerticalAlign::baseline.
// Need max cell ascent from the first row of this cell. // Need max cell ascent from the first row of this cell.
let offset = match self.block_flow.fragment.style().get_box().vertical_align { let offset = match self.block_flow.fragment.style().get_box().vertical_align {
VerticalAlign::Middle => kids_self_gap / 2, VerticalAlign::Keyword(VerticalAlignKeyword::Middle) => kids_self_gap / 2,
VerticalAlign::Bottom => kids_self_gap, VerticalAlign::Keyword(VerticalAlignKeyword::Bottom) => kids_self_gap,
_ => Au(0), _ => Au(0),
}; };
if offset == Au(0) { if offset == Au(0) {

View file

@ -21,13 +21,13 @@ use std::collections::LinkedList;
use std::mem; use std::mem;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::text_rendering::T as TextRendering; use style::computed_values::text_rendering::T as TextRendering;
use style::computed_values::text_transform::T as TextTransform;
use style::computed_values::white_space::T as WhiteSpace; use style::computed_values::white_space::T as WhiteSpace;
use style::computed_values::word_break::T as WordBreak; use style::computed_values::word_break::T as WordBreak;
use style::logical_geometry::{LogicalSize, WritingMode}; use style::logical_geometry::{LogicalSize, WritingMode};
use style::properties::style_structs::Font as FontStyleStruct; use style::properties::style_structs::Font as FontStyleStruct;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::values::generics::text::LineHeight; use style::values::generics::text::LineHeight;
use style::values::specified::text::{TextTransform, TextTransformCase};
use unicode_bidi as bidi; use unicode_bidi as bidi;
use unicode_script::{get_script, Script}; use unicode_script::{get_script, Script};
use xi_unicode::LineBreakLeafIter; use xi_unicode::LineBreakLeafIter;
@ -738,23 +738,23 @@ fn apply_style_transform_if_necessary(
last_whitespace: bool, last_whitespace: bool,
is_first_run: bool, is_first_run: bool,
) { ) {
match text_transform { match text_transform.case_ {
TextTransform::None => {}, TextTransformCase::None => {},
TextTransform::Uppercase => { TextTransformCase::Uppercase => {
let original = string[first_character_position..].to_owned(); let original = string[first_character_position..].to_owned();
string.truncate(first_character_position); string.truncate(first_character_position);
for ch in original.chars().flat_map(|ch| ch.to_uppercase()) { for ch in original.chars().flat_map(|ch| ch.to_uppercase()) {
string.push(ch); string.push(ch);
} }
}, },
TextTransform::Lowercase => { TextTransformCase::Lowercase => {
let original = string[first_character_position..].to_owned(); let original = string[first_character_position..].to_owned();
string.truncate(first_character_position); string.truncate(first_character_position);
for ch in original.chars().flat_map(|ch| ch.to_lowercase()) { for ch in original.chars().flat_map(|ch| ch.to_lowercase()) {
string.push(ch); string.push(ch);
} }
}, },
TextTransform::Capitalize => { TextTransformCase::Capitalize => {
let original = string[first_character_position..].to_owned(); let original = string[first_character_position..].to_owned();
string.truncate(first_character_position); string.truncate(first_character_position);

View file

@ -972,6 +972,11 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
} }
} }
#[inline]
fn is_part(&self, _name: &Atom) -> bool {
false
}
#[inline] #[inline]
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool { fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
unsafe { self.element.has_class_for_layout(name, case_sensitivity) } unsafe { self.element.has_class_for_layout(name, case_sensitivity) }
@ -1484,6 +1489,12 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
false false
} }
#[inline]
fn is_part(&self, _name: &Atom) -> bool {
debug!("ServoThreadSafeLayoutElement::is_part called");
false
}
fn has_class(&self, _name: &Atom, _case_sensitivity: CaseSensitivity) -> bool { fn has_class(&self, _name: &Atom, _case_sensitivity: CaseSensitivity) -> bool {
debug!("ServoThreadSafeLayoutElement::has_class called"); debug!("ServoThreadSafeLayoutElement::has_class called");
false false

View file

@ -3075,6 +3075,10 @@ impl<'a> SelectorsElement for DomRoot<Element> {
.map_or(false, |atom| case_sensitivity.eq_atom(id, atom)) .map_or(false, |atom| case_sensitivity.eq_atom(id, atom))
} }
fn is_part(&self, _name: &Atom) -> bool {
false
}
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool { fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
Element::has_class(&**self, name, case_sensitivity) Element::has_class(&**self, name, case_sensitivity)
} }