Move to_bidi_level method from Stylo to Servo (#37343)

This method is only used in Servo and is the only reason that `stylo`
depends on `unicode-bidi`.

Stylo PR: https://github.com/servo/stylo/pull/196
This commit is contained in:
Nico Burns 2025-06-11 15:44:13 +01:00 committed by GitHub
parent c1ee354c38
commit 7427ea4aed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 17 deletions

25
Cargo.lock generated
View file

@ -6653,7 +6653,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.28.0" version = "0.28.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"cssparser", "cssparser",
@ -6948,7 +6948,7 @@ dependencies = [
[[package]] [[package]]
name = "servo_arc" name = "servo_arc"
version = "0.4.1" version = "0.4.1"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"serde", "serde",
"stable_deref_trait", "stable_deref_trait",
@ -7409,7 +7409,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo" name = "stylo"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"app_units", "app_units",
"arrayvec", "arrayvec",
@ -7457,7 +7457,6 @@ dependencies = [
"to_shmem", "to_shmem",
"to_shmem_derive", "to_shmem_derive",
"uluru", "uluru",
"unicode-bidi",
"url", "url",
"void", "void",
"walkdir", "walkdir",
@ -7467,7 +7466,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo_atoms" name = "stylo_atoms"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"string_cache", "string_cache",
"string_cache_codegen", "string_cache_codegen",
@ -7476,12 +7475,12 @@ dependencies = [
[[package]] [[package]]
name = "stylo_config" name = "stylo_config"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
[[package]] [[package]]
name = "stylo_derive" name = "stylo_derive"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@ -7493,7 +7492,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo_dom" name = "stylo_dom"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"stylo_malloc_size_of", "stylo_malloc_size_of",
@ -7502,7 +7501,7 @@ dependencies = [
[[package]] [[package]]
name = "stylo_malloc_size_of" name = "stylo_malloc_size_of"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"app_units", "app_units",
"cssparser", "cssparser",
@ -7519,12 +7518,12 @@ dependencies = [
[[package]] [[package]]
name = "stylo_static_prefs" name = "stylo_static_prefs"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
[[package]] [[package]]
name = "stylo_traits" name = "stylo_traits"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"app_units", "app_units",
"bitflags 2.9.1", "bitflags 2.9.1",
@ -7933,7 +7932,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "to_shmem" name = "to_shmem"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"cssparser", "cssparser",
"servo_arc", "servo_arc",
@ -7946,7 +7945,7 @@ dependencies = [
[[package]] [[package]]
name = "to_shmem_derive" name = "to_shmem_derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2025-05-01#47c2a67d4cf4441d46274b8298915ad745099168" source = "git+https://github.com/servo/stylo?branch=2025-05-01#15596275d9bdfcbfc584bdb6618fa2006ac38f29"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",

View file

@ -21,7 +21,7 @@ use crate::formatting_contexts::{
IndependentNonReplacedContents, IndependentNonReplacedContents,
}; };
use crate::layout_box_base::LayoutBoxBase; use crate::layout_box_base::LayoutBoxBase;
use crate::style_ext::DisplayGeneratingBox; use crate::style_ext::{ComputedValuesExt, DisplayGeneratingBox};
/// A builder used for both flex and grid containers. /// A builder used for both flex and grid containers.
pub(crate) struct ModernContainerBuilder<'a, 'dom> { pub(crate) struct ModernContainerBuilder<'a, 'dom> {
@ -152,7 +152,7 @@ impl<'a, 'dom> ModernContainerBuilder<'a, 'dom> {
self.context, self.context,
true, /* has_first_formatted_line */ true, /* has_first_formatted_line */
false, /* is_single_line_text_box */ false, /* is_single_line_text_box */
self.info.style.writing_mode.to_bidi_level(), self.info.style.to_bidi_level(),
)?; )?;
let block_formatting_context = BlockFormattingContext::from_block_container( let block_formatting_context = BlockFormattingContext::from_block_container(

View file

@ -230,7 +230,7 @@ impl<'dom, 'style> BlockContainerBuilder<'dom, 'style> {
self.context, self.context,
!self.have_already_seen_first_line_for_text_indent, !self.have_already_seen_first_line_for_text_indent,
self.info.is_single_line_text_input(), self.info.is_single_line_text_input(),
self.info.style.writing_mode.to_bidi_level(), self.info.style.to_bidi_level(),
) )
} }
@ -539,7 +539,7 @@ impl<'dom> BlockContainerBuilder<'dom, '_> {
builder.split_around_block_and_finish( builder.split_around_block_and_finish(
self.context, self.context,
!self.have_already_seen_first_line_for_text_indent, !self.have_already_seen_first_line_for_text_indent,
self.info.style.writing_mode.to_bidi_level(), self.info.style.to_bidi_level(),
) )
}) })
{ {

View file

@ -28,6 +28,7 @@ use style::values::generics::position::{GenericAspectRatio, PreferredRatio};
use style::values::generics::transform::{GenericRotate, GenericScale, GenericTranslate}; use style::values::generics::transform::{GenericRotate, GenericScale, GenericTranslate};
use style::values::specified::align::AlignFlags; use style::values::specified::align::AlignFlags;
use style::values::specified::{Overflow, WillChangeBits, box_ as stylo}; use style::values::specified::{Overflow, WillChangeBits, box_ as stylo};
use unicode_bidi::Level;
use webrender_api as wr; use webrender_api as wr;
use webrender_api::units::LayoutTransform; use webrender_api::units::LayoutTransform;
@ -365,6 +366,7 @@ pub(crate) trait ComputedValuesExt {
) -> bool; ) -> bool;
fn is_inline_box(&self, fragment_flags: FragmentFlags) -> bool; fn is_inline_box(&self, fragment_flags: FragmentFlags) -> bool;
fn overflow_direction(&self) -> OverflowDirection; fn overflow_direction(&self) -> OverflowDirection;
fn to_bidi_level(&self) -> Level;
} }
impl ComputedValuesExt for ComputedValues { impl ComputedValuesExt for ComputedValues {
@ -1017,6 +1019,17 @@ impl ComputedValuesExt for ComputedValues {
downward, downward,
} }
} }
/// The default bidirectional embedding level for the writing mode of this style.
///
/// Returns bidi level 0 if the mode is LTR, or 1 otherwise.
fn to_bidi_level(&self) -> Level {
if self.writing_mode.is_bidi_ltr() {
Level::ltr()
} else {
Level::rtl()
}
}
} }
pub(crate) enum LayoutStyle<'a> { pub(crate) enum LayoutStyle<'a> {