mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #8542 - KiChjang:style-whitespace-methods, r=SimonSapin
Extend whitespace::T with additional helper methods Fixes #8128. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8542) <!-- Reviewable:end -->
This commit is contained in:
commit
6449cd09eb
5 changed files with 47 additions and 48 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue