mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Convert ScannedTextFragment fields into bitflags
This commit is contained in:
parent
6171000875
commit
08caf7412f
4 changed files with 45 additions and 25 deletions
|
@ -657,9 +657,6 @@ pub struct ScannedTextFragmentInfo {
|
|||
/// The position of the insertion point in characters, if any.
|
||||
pub insertion_point: Option<CharIndex>,
|
||||
|
||||
/// Is this fragment selected?
|
||||
pub selected: bool,
|
||||
|
||||
/// The range within the above text run that this represents.
|
||||
pub range: Range<CharIndex>,
|
||||
|
||||
|
@ -668,9 +665,18 @@ pub struct ScannedTextFragmentInfo {
|
|||
/// performing incremental reflow.
|
||||
pub range_end_including_stripped_whitespace: CharIndex,
|
||||
|
||||
/// Whether a line break is required after this fragment if wrapping on newlines (e.g. if
|
||||
/// `white-space: pre` is in effect).
|
||||
pub requires_line_break_afterward_if_wrapping_on_newlines: bool,
|
||||
pub flags: ScannedTextFlags,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
flags ScannedTextFlags: u8 {
|
||||
/// Whether a line break is required after this fragment if wrapping on newlines (e.g. if
|
||||
/// `white-space: pre` is in effect).
|
||||
const REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES = 0x01,
|
||||
|
||||
/// Is this fragment selected?
|
||||
const SELECTED = 0x02,
|
||||
}
|
||||
}
|
||||
|
||||
impl ScannedTextFragmentInfo {
|
||||
|
@ -679,20 +685,25 @@ impl ScannedTextFragmentInfo {
|
|||
range: Range<CharIndex>,
|
||||
content_size: LogicalSize<Au>,
|
||||
insertion_point: Option<CharIndex>,
|
||||
selected: bool,
|
||||
requires_line_break_afterward_if_wrapping_on_newlines: bool)
|
||||
flags: ScannedTextFlags)
|
||||
-> ScannedTextFragmentInfo {
|
||||
ScannedTextFragmentInfo {
|
||||
run: run,
|
||||
range: range,
|
||||
insertion_point: insertion_point,
|
||||
selected: selected,
|
||||
content_size: content_size,
|
||||
range_end_including_stripped_whitespace: range.end(),
|
||||
requires_line_break_afterward_if_wrapping_on_newlines:
|
||||
requires_line_break_afterward_if_wrapping_on_newlines,
|
||||
flags: flags,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn requires_line_break_afterward_if_wrapping_on_newlines(&self) -> bool {
|
||||
self.flags.contains(REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES)
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> bool {
|
||||
self.flags.contains(SELECTED)
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes how to split a fragment. This is used during line breaking as part of the return
|
||||
|
@ -866,16 +877,17 @@ impl Fragment {
|
|||
let size = LogicalSize::new(self.style.writing_mode,
|
||||
split.inline_size,
|
||||
self.border_box.size.block);
|
||||
let requires_line_break_afterward_if_wrapping_on_newlines =
|
||||
self.requires_line_break_afterward_if_wrapping_on_newlines();
|
||||
let flags = match self.specific {
|
||||
SpecificFragmentInfo::ScannedText(ref info) => info.flags,
|
||||
_ => ScannedTextFlags::empty()
|
||||
};
|
||||
// FIXME(pcwalton): This should modify the insertion point as necessary.
|
||||
let info = box ScannedTextFragmentInfo::new(
|
||||
text_run,
|
||||
split.range,
|
||||
size,
|
||||
None,
|
||||
false,
|
||||
requires_line_break_afterward_if_wrapping_on_newlines);
|
||||
flags);
|
||||
self.transform(size, SpecificFragmentInfo::ScannedText(info))
|
||||
}
|
||||
|
||||
|
@ -1665,9 +1677,9 @@ impl Fragment {
|
|||
this_info.range.extend_to(other_info.range_end_including_stripped_whitespace);
|
||||
this_info.content_size.inline =
|
||||
this_info.run.metrics_for_range(&this_info.range).advance_width;
|
||||
this_info.requires_line_break_afterward_if_wrapping_on_newlines =
|
||||
this_info.requires_line_break_afterward_if_wrapping_on_newlines ||
|
||||
other_info.requires_line_break_afterward_if_wrapping_on_newlines;
|
||||
if other_info.requires_line_break_afterward_if_wrapping_on_newlines() {
|
||||
this_info.flags.insert(REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES);
|
||||
}
|
||||
self.border_padding.inline_end = next_fragment.border_padding.inline_end;
|
||||
self.border_box.size.inline = this_info.content_size.inline +
|
||||
self.border_padding.inline_start_end();
|
||||
|
@ -2231,7 +2243,7 @@ impl Fragment {
|
|||
pub fn requires_line_break_afterward_if_wrapping_on_newlines(&self) -> bool {
|
||||
match self.specific {
|
||||
SpecificFragmentInfo::ScannedText(ref scanned_text) => {
|
||||
scanned_text.requires_line_break_afterward_if_wrapping_on_newlines
|
||||
scanned_text.requires_line_break_afterward_if_wrapping_on_newlines()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue