From 6304186f4feb41dd079aa29116de68ced165ed6a Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Mon, 28 Sep 2015 14:57:44 -0700 Subject: [PATCH] Fix text-transform:capitalize across text runs --- components/layout/text.rs | 13 ++++++++----- tests/ref/text_transform_capitalize_a.html | 1 + tests/ref/text_transform_capitalize_ref.html | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/layout/text.rs b/components/layout/text.rs index 4fd7b0f9e36..fbcd1dc7e7e 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -524,9 +524,12 @@ impl RunMapping { // Account for `text-transform`. (Confusingly, this is not handled in "text // transformation" above, but we follow Gecko in the naming.) + let is_first_run = *start_position == 0; let character_count = apply_style_transform_if_necessary(&mut run_info.text, old_byte_length, - text_transform); + text_transform, + *last_whitespace, + is_first_run); // Record the position of the insertion point if necessary. if let Some(insertion_point) = insertion_point { @@ -557,7 +560,9 @@ impl RunMapping { /// use graphemes instead of characters. fn apply_style_transform_if_necessary(string: &mut String, first_character_position: usize, - text_transform: text_transform::T) + text_transform: text_transform::T, + last_whitespace: bool, + is_first_run: bool) -> usize { match text_transform { text_transform::T::none => string[first_character_position..].chars().count(), @@ -585,9 +590,7 @@ fn apply_style_transform_if_necessary(string: &mut String, let original = string[first_character_position..].to_owned(); string.truncate(first_character_position); - // FIXME(pcwalton): This may not always be correct in the case of something like - // `foo`. - let mut capitalize_next_letter = true; + let mut capitalize_next_letter = is_first_run || last_whitespace; let mut count = 0; for character in original.chars() { count += 1; diff --git a/tests/ref/text_transform_capitalize_a.html b/tests/ref/text_transform_capitalize_a.html index b4ad9c2ff46..4e040ef9370 100644 --- a/tests/ref/text_transform_capitalize_a.html +++ b/tests/ref/text_transform_capitalize_a.html @@ -1,5 +1,6 @@ +

ュゥゥゥゥ can do ányThing at ゾムボ.cOm

diff --git a/tests/ref/text_transform_capitalize_ref.html b/tests/ref/text_transform_capitalize_ref.html index a585003eb9a..1fd4ceb1b30 100644 --- a/tests/ref/text_transform_capitalize_ref.html +++ b/tests/ref/text_transform_capitalize_ref.html @@ -1,5 +1,6 @@ +

ュゥゥゥゥ Can Do ÁnyThing At ゾムボ.cOm