From 4b2737606d25ab19d6ddbf17c14eaa4f6edf093d Mon Sep 17 00:00:00 2001 From: Nikhil Shagrithaya Date: Wed, 19 Oct 2016 00:06:19 +0530 Subject: [PATCH] implemented string-valued text-overflow --- components/layout/fragment.rs | 7 ++- components/layout/inline.rs | 37 +++++++----- .../style/properties/longhand/text.mako.rs | 4 -- tests/wpt/mozilla/meta/MANIFEST.json | 56 +++++++++++++------ ...low_a.html => text_overflow_ellipsis.html} | 5 +- .../mozilla/tests/css/text_overflow_ref.html | 2 - .../tests/css/text_overflow_string.html | 20 +++++++ 7 files changed, 91 insertions(+), 40 deletions(-) rename tests/wpt/mozilla/tests/css/{text_overflow_a.html => text_overflow_ellipsis.html} (77%) create mode 100644 tests/wpt/mozilla/tests/css/text_overflow_string.html diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 1fa3ae0612a0..2842eb755eff 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1029,12 +1029,15 @@ impl Fragment { } /// Transforms this fragment into an ellipsis fragment, preserving all the other data. - pub fn transform_into_ellipsis(&self, layout_context: &LayoutContext) -> Fragment { + pub fn transform_into_ellipsis(&self, + layout_context: &LayoutContext, + text_overflow_string: String) + -> Fragment { let mut unscanned_ellipsis_fragments = LinkedList::new(); unscanned_ellipsis_fragments.push_back(self.transform( self.border_box.size, SpecificFragmentInfo::UnscannedText( - box UnscannedTextFragmentInfo::new("…".to_owned(), None)))); + box UnscannedTextFragmentInfo::new(text_overflow_string, None)))); let ellipsis_fragments = TextRunScanner::new().scan_for_runs(&mut layout_context.font_context(), unscanned_ellipsis_fragments); debug_assert!(ellipsis_fragments.len() == 1); diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 735ee0acf90a..57eb16f1b841 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -31,10 +31,10 @@ use std::collections::VecDeque; use std::sync::Arc; use style::arc_ptr_eq; use style::computed_values::{display, overflow_x, position, text_align, text_justify}; -use style::computed_values::{text_overflow, vertical_align, white_space}; +use style::computed_values::{vertical_align, white_space}; use style::context::{SharedStyleContext, StyleContext}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; -use style::properties::ServoComputedValues; +use style::properties::{longhands, ServoComputedValues}; use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPOSITION, RESOLVE_GENERATED_CONTENT}; use text; use unicode_bidi; @@ -684,21 +684,30 @@ impl LineBreaker { } // Determine if an ellipsis will be necessary to account for `text-overflow`. - let mut need_ellipsis = false; let available_inline_size = self.pending_line.green_zone.inline - self.pending_line.bounds.size.inline - indentation; - match (fragment.style().get_text().text_overflow, - fragment.style().get_box().overflow_x) { - (text_overflow::T::clip, _) | (_, overflow_x::T::visible) => {} - (text_overflow::T::ellipsis, _) => { - need_ellipsis = fragment.margin_box_inline_size() > available_inline_size; + + let ellipsis = match (&fragment.style().get_text().text_overflow.first, + fragment.style().get_box().overflow_x) { + (&longhands::text_overflow::Side::Clip, _) | (_, overflow_x::T::visible) => None, + (&longhands::text_overflow::Side::Ellipsis, _) => { + if fragment.margin_box_inline_size() > available_inline_size { + Some("…".to_string()) + } else { + None + } + }, + (&longhands::text_overflow::Side::String(ref string), _) => { + if fragment.margin_box_inline_size() > available_inline_size { + Some(string.to_string()) + } else { + None + } } - } + }; - if !need_ellipsis { - self.push_fragment_to_line_ignoring_text_overflow(fragment, layout_context); - } else { - let ellipsis = fragment.transform_into_ellipsis(layout_context); + if let Some(string) = ellipsis { + let ellipsis = fragment.transform_into_ellipsis(layout_context, string); if let Some(truncation_info) = fragment.truncate_to_inline_size(available_inline_size - ellipsis.margin_box_inline_size()) { @@ -707,6 +716,8 @@ impl LineBreaker { self.push_fragment_to_line_ignoring_text_overflow(fragment, layout_context); } self.push_fragment_to_line_ignoring_text_overflow(ellipsis, layout_context); + } else { + self.push_fragment_to_line_ignoring_text_overflow(fragment, layout_context); } if line_flush_mode == LineFlushMode::Flush { diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index d10850400fac..2923948ed1c7 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -12,9 +12,6 @@ Method("has_overline", "bool"), Method("has_line_through", "bool")]) %> -% if product == "servo": - ${helpers.single_keyword("text-overflow", "clip ellipsis", animatable=False)} -% else: <%helpers:longhand name="text-overflow" animatable="False"> use std::fmt; use style_traits::ToCss; @@ -93,7 +90,6 @@ } } -% endif ${helpers.single_keyword("unicode-bidi", "normal embed isolate bidi-override isolate-override plaintext", diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index b0b62309839c..4752ad4381fe 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -5496,28 +5496,40 @@ "url": "/_mozilla/css/text_node_opacity.html" } ], - "css/text_overflow_a.html": [ + "css/text_overflow_basic_a.html": [ { - "path": "css/text_overflow_a.html", + "path": "css/text_overflow_basic_a.html", + "references": [ + [ + "/_mozilla/css/text_overflow_basic_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/text_overflow_basic_a.html" + } + ], + "css/text_overflow_ellipsis.html": [ + { + "path": "css/text_overflow_ellipsis.html", "references": [ [ "/_mozilla/css/text_overflow_ref.html", "!=" ] ], - "url": "/_mozilla/css/text_overflow_a.html" + "url": "/_mozilla/css/text_overflow_ellipsis.html" } ], - "css/text_overflow_basic_a.html": [ + "css/text_overflow_string.html": [ { - "path": "css/text_overflow_basic_a.html", + "path": "css/text_overflow_string.html", "references": [ [ - "/_mozilla/css/text_overflow_basic_ref.html", - "==" + "/_mozilla/css/text_overflow_ref.html", + "!=" ] ], - "url": "/_mozilla/css/text_overflow_basic_a.html" + "url": "/_mozilla/css/text_overflow_string.html" } ], "css/text_shadow_blur_a.html": [ @@ -20364,28 +20376,40 @@ "url": "/_mozilla/css/text_node_opacity.html" } ], - "css/text_overflow_a.html": [ + "css/text_overflow_basic_a.html": [ { - "path": "css/text_overflow_a.html", + "path": "css/text_overflow_basic_a.html", + "references": [ + [ + "/_mozilla/css/text_overflow_basic_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/text_overflow_basic_a.html" + } + ], + "css/text_overflow_ellipsis.html": [ + { + "path": "css/text_overflow_ellipsis.html", "references": [ [ "/_mozilla/css/text_overflow_ref.html", "!=" ] ], - "url": "/_mozilla/css/text_overflow_a.html" + "url": "/_mozilla/css/text_overflow_ellipsis.html" } ], - "css/text_overflow_basic_a.html": [ + "css/text_overflow_string.html": [ { - "path": "css/text_overflow_basic_a.html", + "path": "css/text_overflow_string.html", "references": [ [ - "/_mozilla/css/text_overflow_basic_ref.html", - "==" + "/_mozilla/css/text_overflow_ref.html", + "!=" ] ], - "url": "/_mozilla/css/text_overflow_basic_a.html" + "url": "/_mozilla/css/text_overflow_string.html" } ], "css/text_shadow_blur_a.html": [ diff --git a/tests/wpt/mozilla/tests/css/text_overflow_a.html b/tests/wpt/mozilla/tests/css/text_overflow_ellipsis.html similarity index 77% rename from tests/wpt/mozilla/tests/css/text_overflow_a.html rename to tests/wpt/mozilla/tests/css/text_overflow_ellipsis.html index 2a3ca5be0f7b..70de0992fee1 100644 --- a/tests/wpt/mozilla/tests/css/text_overflow_a.html +++ b/tests/wpt/mozilla/tests/css/text_overflow_ellipsis.html @@ -8,14 +8,13 @@ background: gold; text-overflow: ellipsis; } -#hideme { +p.hidden { overflow: hidden; } -

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

+ - diff --git a/tests/wpt/mozilla/tests/css/text_overflow_ref.html b/tests/wpt/mozilla/tests/css/text_overflow_ref.html index 19adf5d91041..0e19e6e3f071 100644 --- a/tests/wpt/mozilla/tests/css/text_overflow_ref.html +++ b/tests/wpt/mozilla/tests/css/text_overflow_ref.html @@ -13,5 +13,3 @@

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

- - diff --git a/tests/wpt/mozilla/tests/css/text_overflow_string.html b/tests/wpt/mozilla/tests/css/text_overflow_string.html new file mode 100644 index 000000000000..3249b8b224f0 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/text_overflow_string.html @@ -0,0 +1,20 @@ + + + + + + + +

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

+ + +