diff options
-rw-r--r-- | components/layout/fragment.rs | 38 | ||||
-rw-r--r-- | components/layout/inline.rs | 6 | ||||
-rw-r--r-- | components/layout/text.rs | 4 | ||||
-rw-r--r-- | components/layout/wrapper.rs | 10 | ||||
-rw-r--r-- | components/style/properties.mako.rs | 37 |
5 files changed, 47 insertions, 48 deletions
diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 1814e1ad664..70fcffffe3f 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1238,36 +1238,6 @@ impl Fragment { self.style().get_inheritedtext().white_space } - pub fn white_space_allow_wrap(&self) -> bool { - match self.white_space() { - white_space::T::nowrap | - white_space::T::pre => false, - white_space::T::normal | - white_space::T::pre_wrap | - white_space::T::pre_line => true, - } - } - - pub fn white_space_preserve_newlines(&self) -> bool { - match self.white_space() { - white_space::T::normal | - white_space::T::nowrap => false, - white_space::T::pre | - white_space::T::pre_wrap | - white_space::T::pre_line => true, - } - } - - pub fn white_space_preserve_spaces(&self) -> bool { - match self.white_space() { - white_space::T::normal | - white_space::T::nowrap | - white_space::T::pre_line => false, - white_space::T::pre | - white_space::T::pre_wrap => true, - } - } - /// Returns the text decoration of this fragment, according to the style of the nearest ancestor /// element. /// @@ -1297,7 +1267,7 @@ impl Fragment { /// Returns true if this element can be split. This is true for text fragments, unless /// `white-space: pre` or `white-space: nowrap` is set. pub fn can_split(&self) -> bool { - self.is_scanned_text_fragment() && self.white_space_allow_wrap() + self.is_scanned_text_fragment() && self.white_space().allow_wrap() } /// Returns true if and only if this fragment is a generated content fragment. @@ -1371,7 +1341,7 @@ impl Fragment { .metrics_for_range(range) .advance_width; - let min_line_inline_size = if self.white_space_allow_wrap() { + let min_line_inline_size = if self.white_space().allow_wrap() { text_fragment_info.run.min_width_for_range(range) } else { max_line_inline_size @@ -2224,7 +2194,7 @@ impl Fragment { } pub fn strip_leading_whitespace_if_necessary(&mut self) -> WhitespaceStrippingResult { - if self.white_space_preserve_spaces() { + if self.white_space().preserve_spaces() { return WhitespaceStrippingResult::RetainFragment } @@ -2287,7 +2257,7 @@ impl Fragment { /// Returns true if the entire fragment was stripped. pub fn strip_trailing_whitespace_if_necessary(&mut self) -> WhitespaceStrippingResult { - if self.white_space_preserve_spaces() { + if self.white_space().preserve_spaces() { return WhitespaceStrippingResult::RetainFragment } diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 4cee4454620..2ddefea0392 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -534,7 +534,7 @@ impl LineBreaker { self.pending_line.green_zone = line_bounds.size; false } else { - fragment.white_space_allow_wrap() + fragment.white_space().allow_wrap() }; debug!("LineBreaker: trying to append to line {} (fragment size: {:?}, green zone: {:?}): \ @@ -564,7 +564,7 @@ impl LineBreaker { // If we must flush the line after finishing this fragment due to `white-space: pre`, // detect that. - let line_flush_mode = if fragment.white_space_preserve_newlines() { + let line_flush_mode = if fragment.white_space().preserve_newlines() { if fragment.requires_line_break_afterward_if_wrapping_on_newlines() { LineFlushMode::Flush } else { @@ -588,7 +588,7 @@ impl LineBreaker { // If the wrapping mode prevents us from splitting, then back up and split at the last // known good split point. - if !fragment.white_space_allow_wrap() { + if !fragment.white_space().allow_wrap() { debug!("LineBreaker: fragment can't split; falling back to last known good split point"); if !self.split_line_at_last_known_good_position() { // No line breaking opportunity exists at all for this line. Overflow. diff --git a/components/layout/text.rs b/components/layout/text.rs index feab75efa65..b561b8d5da1 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -40,7 +40,7 @@ fn text(fragments: &LinkedList<Fragment>) -> String { for fragment in fragments { match fragment.specific { SpecificFragmentInfo::UnscannedText(ref info) => { - if fragment.white_space_preserve_newlines() { + if fragment.white_space().preserve_newlines() { text.push_str(&info.text); } else { text.push_str(&info.text.replace("\n", " ")); @@ -411,7 +411,7 @@ fn split_first_fragment_at_newline_if_necessary(fragments: &mut LinkedList<Fragm let string_before; let insertion_point_before; { - if !first_fragment.white_space_preserve_newlines() { + if !first_fragment.white_space().preserve_newlines() { return; } diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index a38009f7a52..f158dfb386d 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -63,7 +63,7 @@ use std::mem; use std::sync::Arc; use string_cache::{Atom, Namespace}; use style::computed_values::content::ContentItem; -use style::computed_values::{content, display, white_space}; +use style::computed_values::{content, display}; use style::node::TElementAttributes; use style::properties::ComputedValues; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; @@ -960,13 +960,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { // // If you implement other values for this property, you will almost certainly // want to update this check. - match self.style().get_inheritedtext().white_space { - white_space::T::normal | - white_space::T::nowrap => true, - white_space::T::pre | - white_space::T::pre_wrap | - white_space::T::pre_line => false, - } + !self.style().get_inheritedtext().white_space.preserve_newlines() } } diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 847155c8de8..453bf153a9e 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -2331,7 +2331,42 @@ pub mod longhands { } </%self:longhand> - ${single_keyword("white-space", "normal pre nowrap pre-wrap pre-line")} + <%self:single_keyword_computed name="white-space" values="normal pre nowrap pre-wrap pre-line"> + use values::computed::ComputedValueAsSpecified; + impl ComputedValueAsSpecified for SpecifiedValue {} + + impl SpecifiedValue { + pub fn allow_wrap(&self) -> bool { + match *self { + SpecifiedValue::nowrap | + SpecifiedValue::pre => false, + SpecifiedValue::normal | + SpecifiedValue::pre_wrap | + SpecifiedValue::pre_line => true, + } + } + + pub fn preserve_newlines(&self) -> bool { + match *self { + SpecifiedValue::normal | + SpecifiedValue::nowrap => false, + SpecifiedValue::pre | + SpecifiedValue::pre_wrap | + SpecifiedValue::pre_line => true, + } + } + + pub fn preserve_spaces(&self) -> bool { + match *self { + SpecifiedValue::normal | + SpecifiedValue::nowrap | + SpecifiedValue::pre_line => false, + SpecifiedValue::pre | + SpecifiedValue::pre_wrap => true, + } + } + } + </%self:single_keyword_computed> // TODO(pcwalton): `full-width` ${single_keyword("text-transform", "none capitalize uppercase lowercase")} |