Port text-combine-upright writing mode fixup to Servo

Ports the Gecko fixup for text-combine-upright writing mode to Servo.  In
addition, this passes the current pseudo element (if any) down to the cascade
for use during the fixup process.

MozReview-Commit-ID: BkHd4AvSsOt
This commit is contained in:
J. Ryan Stinnett 2017-04-24 16:04:15 -05:00
parent 78a2e3be51
commit 978239927d
7 changed files with 57 additions and 12 deletions

View file

@ -11,20 +11,23 @@ use properties::longhands::display::computed_value::T as display;
use properties::longhands::float::computed_value::T as float;
use properties::longhands::overflow_x::computed_value::T as overflow;
use properties::longhands::position::computed_value::T as position;
use selector_parser::PseudoElement;
/// An unsized struct that implements all the adjustment methods.
#[allow(dead_code)] // `pseudo` field is currently unused by Servo
pub struct StyleAdjuster<'a> {
style: &'a mut ComputedValues,
is_root_element: bool,
pseudo: Option<&'a PseudoElement>,
}
impl<'a> StyleAdjuster<'a> {
/// Trivially constructs a new StyleAdjuster.
pub fn new(style: &'a mut ComputedValues, is_root_element: bool) -> Self {
pub fn new(style: &'a mut ComputedValues, is_root_element: bool, pseudo: Option<&'a PseudoElement>) -> Self {
StyleAdjuster {
style: style,
is_root_element: is_root_element,
pseudo: pseudo,
}
}
@ -85,6 +88,26 @@ impl<'a> StyleAdjuster<'a> {
}
}
/// Change writing mode of text frame for text-combine-upright.
/// It is safe to look at the parent's style because we are looking at
/// inherited properties, and ::-moz-text never matches any rules.
#[cfg(feature = "gecko")]
fn adjust_for_text_combine_upright(&mut self,
layout_parent_style: &ComputedValues) {
if let Some(p) = self.pseudo {
if *p.as_atom() == atom!(":-moz-text") {
use computed_values::text_combine_upright::T as text_combine_upright;
use computed_values::writing_mode::T as writing_mode;
let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode();
let parent_text_combine_upright = layout_parent_style.get_inheritedtext().clone_text_combine_upright();
if parent_writing_mode != writing_mode::horizontal_tb &&
parent_text_combine_upright == text_combine_upright::all {
self.style.mutate_inheritedbox().set_writing_mode(writing_mode::horizontal_tb);
}
}
}
}
/// https://drafts.csswg.org/css-writing-modes-3/#block-flow:
///
/// If a box has a different writing-mode value than its containing
@ -223,10 +246,14 @@ impl<'a> StyleAdjuster<'a> {
}
}
/// Adjusts the style to account for display fixups.
/// Adjusts the style to account for various fixups that don't fit naturally into the cascade.
pub fn adjust(mut self,
layout_parent_style: &ComputedValues,
skip_root_and_element_display_fixup: bool) {
#[cfg(feature = "gecko")]
{
self.adjust_for_text_combine_upright(layout_parent_style);
}
self.adjust_for_top_layer();
self.blockify_if_necessary(layout_parent_style,
skip_root_and_element_display_fixup);