Convert ScannedTextFragment fields into bitflags

This commit is contained in:
Matt Brubeck 2016-03-24 16:06:12 -07:00
parent 6171000875
commit 08caf7412f
4 changed files with 45 additions and 25 deletions

View file

@ -930,7 +930,7 @@ impl FragmentDisplayListBuilding for Fragment {
// Draw a highlighted background if the text is selected. // Draw a highlighted background if the text is selected.
// //
// TODO: Allow non-text fragments to be selected too. // TODO: Allow non-text fragments to be selected too.
if scanned_text_fragment_info.selected { if scanned_text_fragment_info.selected() {
state.add_display_item( state.add_display_item(
DisplayItem::SolidColorClass(box SolidColorDisplayItem { DisplayItem::SolidColorClass(box SolidColorDisplayItem {
base: BaseDisplayItem::new(stacking_relative_border_box, base: BaseDisplayItem::new(stacking_relative_border_box,
@ -1116,7 +1116,7 @@ impl FragmentDisplayListBuilding for Fragment {
// //
// NB: According to CSS-BACKGROUNDS, text shadows render in *reverse* order (front // NB: According to CSS-BACKGROUNDS, text shadows render in *reverse* order (front
// to back). // to back).
let text_color = if text_fragment.selected { let text_color = if text_fragment.selected() {
SELECTION_FOREGROUND_COLOR SELECTION_FOREGROUND_COLOR
} else { } else {
self.style().get_color().color self.style().get_color().color

View file

@ -657,9 +657,6 @@ pub struct ScannedTextFragmentInfo {
/// The position of the insertion point in characters, if any. /// The position of the insertion point in characters, if any.
pub insertion_point: Option<CharIndex>, pub insertion_point: Option<CharIndex>,
/// Is this fragment selected?
pub selected: bool,
/// The range within the above text run that this represents. /// The range within the above text run that this represents.
pub range: Range<CharIndex>, pub range: Range<CharIndex>,
@ -668,9 +665,18 @@ pub struct ScannedTextFragmentInfo {
/// performing incremental reflow. /// performing incremental reflow.
pub range_end_including_stripped_whitespace: CharIndex, pub range_end_including_stripped_whitespace: CharIndex,
/// Whether a line break is required after this fragment if wrapping on newlines (e.g. if pub flags: ScannedTextFlags,
/// `white-space: pre` is in effect). }
pub requires_line_break_afterward_if_wrapping_on_newlines: bool,
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 { impl ScannedTextFragmentInfo {
@ -679,20 +685,25 @@ impl ScannedTextFragmentInfo {
range: Range<CharIndex>, range: Range<CharIndex>,
content_size: LogicalSize<Au>, content_size: LogicalSize<Au>,
insertion_point: Option<CharIndex>, insertion_point: Option<CharIndex>,
selected: bool, flags: ScannedTextFlags)
requires_line_break_afterward_if_wrapping_on_newlines: bool)
-> ScannedTextFragmentInfo { -> ScannedTextFragmentInfo {
ScannedTextFragmentInfo { ScannedTextFragmentInfo {
run: run, run: run,
range: range, range: range,
insertion_point: insertion_point, insertion_point: insertion_point,
selected: selected,
content_size: content_size, content_size: content_size,
range_end_including_stripped_whitespace: range.end(), range_end_including_stripped_whitespace: range.end(),
requires_line_break_afterward_if_wrapping_on_newlines: flags: flags,
requires_line_break_afterward_if_wrapping_on_newlines,
} }
} }
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 /// 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, let size = LogicalSize::new(self.style.writing_mode,
split.inline_size, split.inline_size,
self.border_box.size.block); self.border_box.size.block);
let requires_line_break_afterward_if_wrapping_on_newlines = let flags = match self.specific {
self.requires_line_break_afterward_if_wrapping_on_newlines(); SpecificFragmentInfo::ScannedText(ref info) => info.flags,
_ => ScannedTextFlags::empty()
};
// FIXME(pcwalton): This should modify the insertion point as necessary. // FIXME(pcwalton): This should modify the insertion point as necessary.
let info = box ScannedTextFragmentInfo::new( let info = box ScannedTextFragmentInfo::new(
text_run, text_run,
split.range, split.range,
size, size,
None, None,
false, flags);
requires_line_break_afterward_if_wrapping_on_newlines);
self.transform(size, SpecificFragmentInfo::ScannedText(info)) 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.range.extend_to(other_info.range_end_including_stripped_whitespace);
this_info.content_size.inline = this_info.content_size.inline =
this_info.run.metrics_for_range(&this_info.range).advance_width; this_info.run.metrics_for_range(&this_info.range).advance_width;
this_info.requires_line_break_afterward_if_wrapping_on_newlines = if other_info.requires_line_break_afterward_if_wrapping_on_newlines() {
this_info.requires_line_break_afterward_if_wrapping_on_newlines || this_info.flags.insert(REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES);
other_info.requires_line_break_afterward_if_wrapping_on_newlines; }
self.border_padding.inline_end = next_fragment.border_padding.inline_end; self.border_padding.inline_end = next_fragment.border_padding.inline_end;
self.border_box.size.inline = this_info.content_size.inline + self.border_box.size.inline = this_info.content_size.inline +
self.border_padding.inline_start_end(); self.border_padding.inline_start_end();
@ -2231,7 +2243,7 @@ impl Fragment {
pub fn requires_line_break_afterward_if_wrapping_on_newlines(&self) -> bool { pub fn requires_line_break_afterward_if_wrapping_on_newlines(&self) -> bool {
match self.specific { match self.specific {
SpecificFragmentInfo::ScannedText(ref scanned_text) => { 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, _ => false,
} }

View file

@ -354,7 +354,7 @@ impl LineBreaker {
let need_to_merge = match (&mut result.specific, &candidate.specific) { let need_to_merge = match (&mut result.specific, &candidate.specific) {
(&mut SpecificFragmentInfo::ScannedText(ref mut result_info), (&mut SpecificFragmentInfo::ScannedText(ref mut result_info),
&SpecificFragmentInfo::ScannedText(ref candidate_info)) => { &SpecificFragmentInfo::ScannedText(ref candidate_info)) => {
result_info.selected == candidate_info.selected && result_info.selected() == candidate_info.selected() &&
util::arc_ptr_eq(&result_info.run, &candidate_info.run) && util::arc_ptr_eq(&result_info.run, &candidate_info.run) &&
inline_contexts_are_equal(&result.inline_context, inline_contexts_are_equal(&result.inline_context,
&candidate.inline_context) &candidate.inline_context)

View file

@ -7,7 +7,8 @@
#![deny(unsafe_code)] #![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use fragment::{Fragment, ScannedTextFragmentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo}; use fragment::{Fragment, REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES, ScannedTextFlags};
use fragment::{ScannedTextFragmentInfo, SELECTED, SpecificFragmentInfo, UnscannedTextFragmentInfo};
use gfx::font::{DISABLE_KERNING_SHAPING_FLAG, FontMetrics, IGNORE_LIGATURES_SHAPING_FLAG}; use gfx::font::{DISABLE_KERNING_SHAPING_FLAG, FontMetrics, IGNORE_LIGATURES_SHAPING_FLAG};
use gfx::font::{RTL_FLAG, RunMetrics, ShapingFlags, ShapingOptions}; use gfx::font::{RTL_FLAG, RunMetrics, ShapingFlags, ShapingOptions};
use gfx::font_context::FontContext; use gfx::font_context::FontContext;
@ -344,13 +345,20 @@ impl TextRunScanner {
} }
let text_size = old_fragment.border_box.size; let text_size = old_fragment.border_box.size;
let mut flags = ScannedTextFlags::empty();
if mapping.selected {
flags.insert(SELECTED);
}
if requires_line_break_afterward_if_wrapping_on_newlines {
flags.insert(REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES);
}
let mut new_text_fragment_info = box ScannedTextFragmentInfo::new( let mut new_text_fragment_info = box ScannedTextFragmentInfo::new(
scanned_run.run, scanned_run.run,
mapping.char_range, mapping.char_range,
text_size, text_size,
scanned_run.insertion_point, scanned_run.insertion_point,
mapping.selected, flags);
requires_line_break_afterward_if_wrapping_on_newlines);
let new_metrics = new_text_fragment_info.run.metrics_for_range(&mapping.char_range); let new_metrics = new_text_fragment_info.run.metrics_for_range(&mapping.char_range);
let writing_mode = old_fragment.style.writing_mode; let writing_mode = old_fragment.style.writing_mode;