mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Add style adjustments for ruby.
This commit is contained in:
parent
f08c432b57
commit
6a12de1c1a
7 changed files with 158 additions and 8 deletions
|
@ -12,6 +12,8 @@ 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;
|
||||
#[cfg(feature = "gecko")]
|
||||
use properties::longhands::unicode_bidi::computed_value::T as unicode_bidi;
|
||||
|
||||
|
||||
/// An unsized struct that implements all the adjustment methods.
|
||||
|
@ -321,6 +323,83 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool {
|
||||
use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK;
|
||||
// Line break suppression should only be propagated to in-flow children.
|
||||
if self.style.floated() || self.style.out_of_flow_positioned() {
|
||||
return false;
|
||||
}
|
||||
let parent_display = layout_parent_style.get_box().clone_display();
|
||||
if layout_parent_style.flags.contains(SHOULD_SUPPRESS_LINEBREAK) {
|
||||
// Line break suppression is propagated to any children of
|
||||
// line participants.
|
||||
if parent_display.is_line_participant() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
match self.style.get_box().clone_display() {
|
||||
// Ruby base and text are always non-breakable.
|
||||
display::ruby_base | display::ruby_text => true,
|
||||
// Ruby base container and text container are breakable.
|
||||
// Note that, when certain HTML tags, e.g. form controls, have ruby
|
||||
// level container display type, they could also escape from the
|
||||
// line break suppression flag while they shouldn't. However, it is
|
||||
// generally fine since they themselves are non-breakable.
|
||||
display::ruby_base_container | display::ruby_text_container => false,
|
||||
// Anything else is non-breakable if and only if its layout parent
|
||||
// has a ruby display type, because any of the ruby boxes can be
|
||||
// anonymous.
|
||||
_ => parent_display.is_ruby_type(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Do ruby-related style adjustments, which include:
|
||||
/// * propagate the line break suppression flag,
|
||||
/// * inlinify block descendants,
|
||||
/// * suppress border and padding for ruby level containers,
|
||||
/// * correct unicode-bidi.
|
||||
#[cfg(feature = "gecko")]
|
||||
fn adjust_for_ruby(&mut self,
|
||||
layout_parent_style: &ComputedValues,
|
||||
default_computed_values: &'b ComputedValues,
|
||||
flags: CascadeFlags) {
|
||||
use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
||||
use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK;
|
||||
let self_display = self.style.get_box().clone_display();
|
||||
// Check whether line break should be suppressed for this element.
|
||||
if self.should_suppress_linebreak(layout_parent_style) {
|
||||
self.style.flags.insert(SHOULD_SUPPRESS_LINEBREAK);
|
||||
// Inlinify the display type if allowed.
|
||||
if !flags.contains(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) {
|
||||
let inline_display = self_display.inlinify();
|
||||
if self_display != inline_display {
|
||||
self.style.mutate_box().set_display(inline_display);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Suppress border and padding for ruby level containers.
|
||||
// This is actually not part of the spec. It is currently unspecified
|
||||
// how border and padding should be handled for ruby level container,
|
||||
// and suppressing them here make it easier for layout to handle.
|
||||
if self_display.is_ruby_level_container() {
|
||||
self.style.reset_border(default_computed_values);
|
||||
self.style.reset_padding(default_computed_values);
|
||||
}
|
||||
// Force bidi isolation on all internal ruby boxes and ruby container
|
||||
// per spec https://drafts.csswg.org/css-ruby-1/#bidi
|
||||
if self_display.is_ruby_type() {
|
||||
let new_value = match self.style.get_text().clone_unicode_bidi() {
|
||||
unicode_bidi::normal | unicode_bidi::embed => Some(unicode_bidi::isolate),
|
||||
unicode_bidi::bidi_override => Some(unicode_bidi::isolate_override),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(new_value) = new_value {
|
||||
self.style.mutate_text().set_unicode_bidi(new_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Adjusts the style to account for various fixups that don't fit naturally
|
||||
/// into the cascade.
|
||||
///
|
||||
|
@ -328,6 +407,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
|
|||
/// `nsStyleContext::ApplyStyleFixups`.
|
||||
pub fn adjust(&mut self,
|
||||
layout_parent_style: &ComputedValues,
|
||||
_default_computed_values: &'b ComputedValues,
|
||||
flags: CascadeFlags) {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
|
@ -351,5 +431,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
|
|||
self.adjust_for_outline();
|
||||
self.adjust_for_writing_mode(layout_parent_style);
|
||||
self.adjust_for_text_decoration_lines(layout_parent_style);
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
self.adjust_for_ruby(layout_parent_style,
|
||||
_default_computed_values, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue