style: simplify -servo-text-decorations-in-effect.

It's stupid.

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-09-17 00:30:25 +02:00
parent 2c88248b87
commit 15a76b01c1
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 34 additions and 51 deletions

View file

@ -2230,13 +2230,10 @@ impl FragmentDisplayListBuilding for Fragment {
// Create display items for text decorations. // Create display items for text decorations.
let mut text_decorations = self.style() let text_decorations =
self.style()
.get_inheritedtext() .get_inheritedtext()
._servo_text_decorations_in_effect; ._servo_text_decorations_in_effect;
// Note that the text decoration colors are always the same as the text color.
text_decorations.underline = text_decorations.underline.map(|_| text_color);
text_decorations.overline = text_decorations.overline.map(|_| text_color);
text_decorations.line_through = text_decorations.line_through.map(|_| text_color);
let stacking_relative_content_box = let stacking_relative_content_box =
LogicalRect::from_physical(self.style.writing_mode, LogicalRect::from_physical(self.style.writing_mode,
@ -2244,25 +2241,29 @@ impl FragmentDisplayListBuilding for Fragment {
container_size); container_size);
// Underline // Underline
if let Some(ref underline_color) = text_decorations.underline { if text_decorations.underline {
let mut stacking_relative_box = stacking_relative_content_box; let mut stacking_relative_box = stacking_relative_content_box;
stacking_relative_box.start.b = stacking_relative_content_box.start.b + stacking_relative_box.start.b = stacking_relative_content_box.start.b +
metrics.ascent - metrics.underline_offset; metrics.ascent - metrics.underline_offset;
stacking_relative_box.size.block = metrics.underline_size; stacking_relative_box.size.block = metrics.underline_size;
self.build_display_list_for_text_decoration(state, self.build_display_list_for_text_decoration(
underline_color, state,
&text_color,
&stacking_relative_box, &stacking_relative_box,
clip); clip,
);
} }
// Overline // Overline
if let Some(ref overline_color) = text_decorations.overline { if text_decorations.overline {
let mut stacking_relative_box = stacking_relative_content_box; let mut stacking_relative_box = stacking_relative_content_box;
stacking_relative_box.size.block = metrics.underline_size; stacking_relative_box.size.block = metrics.underline_size;
self.build_display_list_for_text_decoration(state, self.build_display_list_for_text_decoration(
overline_color, state,
&text_color,
&stacking_relative_box, &stacking_relative_box,
clip); clip,
);
} }
// Text // Text
@ -2281,15 +2282,17 @@ impl FragmentDisplayListBuilding for Fragment {
// Line-Through // Line-Through
if let Some(ref line_through_color) = text_decorations.line_through { if text_decorations.line_through {
let mut stacking_relative_box = stacking_relative_content_box; let mut stacking_relative_box = stacking_relative_content_box;
stacking_relative_box.start.b = stacking_relative_box.start.b + metrics.ascent - stacking_relative_box.start.b = stacking_relative_box.start.b + metrics.ascent -
metrics.strikeout_offset; metrics.strikeout_offset;
stacking_relative_box.size.block = metrics.strikeout_size; stacking_relative_box.size.block = metrics.strikeout_size;
self.build_display_list_for_text_decoration(state, self.build_display_list_for_text_decoration(
line_through_color, state,
&text_color,
&stacking_relative_box, &stacking_relative_box,
clip); clip,
);
} }
// Pair all the PushTextShadows // Pair all the PushTextShadows

View file

@ -282,17 +282,16 @@ ${helpers.predefined_type("word-spacing",
need_clone="True" products="servo" need_clone="True" products="servo"
animation_value_type="none" animation_value_type="none"
spec="Nonstandard (Internal property used by Servo)"> spec="Nonstandard (Internal property used by Servo)">
use cssparser::RGBA;
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue { pub struct SpecifiedValue {
pub underline: Option<RGBA>, pub underline: bool,
pub overline: Option<RGBA>, pub overline: bool,
pub line_through: Option<RGBA>, pub line_through: bool,
} }
trivial_to_computed_value!(SpecifiedValue); trivial_to_computed_value!(SpecifiedValue);
@ -310,19 +309,7 @@ ${helpers.predefined_type("word-spacing",
#[inline] #[inline]
pub fn get_initial_value() -> computed_value::T { pub fn get_initial_value() -> computed_value::T {
SpecifiedValue { SpecifiedValue::default()
underline: None,
overline: None,
line_through: None,
}
}
fn maybe(flag: bool, context: &Context) -> Option<RGBA> {
if flag {
Some(context.style().get_color().clone_color())
} else {
None
}
} }
fn derive(context: &Context) -> computed_value::T { fn derive(context: &Context) -> computed_value::T {
@ -330,20 +317,13 @@ ${helpers.predefined_type("word-spacing",
// declarations in effect and add in the text decorations that this block specifies. // declarations in effect and add in the text decorations that this block specifies.
let mut result = match context.style().get_box().clone_display() { let mut result = match context.style().get_box().clone_display() {
super::display::computed_value::T::inline_block | super::display::computed_value::T::inline_block |
super::display::computed_value::T::inline_table => SpecifiedValue { super::display::computed_value::T::inline_table => get_initial_value(),
underline: None,
overline: None,
line_through: None,
},
_ => context.builder.get_parent_inheritedtext().clone__servo_text_decorations_in_effect() _ => context.builder.get_parent_inheritedtext().clone__servo_text_decorations_in_effect()
}; };
result.underline = maybe(context.style().get_text().has_underline() result.underline |= context.style().get_text().has_underline();
|| result.underline.is_some(), context); result.overline |= context.style().get_text().has_overline();
result.overline = maybe(context.style().get_text().has_overline() result.line_through |= context.style().get_text().has_line_through();
|| result.overline.is_some(), context);
result.line_through = maybe(context.style().get_text().has_line_through()
|| result.line_through.is_some(), context);
result result
} }