Repository navigation
script: Stringify selections according to the flat tree / user-select - #48242
Conversation
| } | ||
|
|
||
| pub(crate) fn text_content(&self) -> &str { | ||
| self.text_content.get().unwrap_or_default() |
There was a problem hiding this comment.
untested fix for the compile error:
| self.text_content.get().unwrap_or_default() | |
| self.text_content.get().as_deref().unwrap_or_default() |
|
|
||
| /// A slot used to share the full text string of the [`InlineFormattingContext`] this | ||
| /// builder will ultimately build. | ||
| pub text_content_slot: Arc<OnceLock<String>>, |
There was a problem hiding this comment.
It’s an Arc<OnceLock<_>> because it’s shared with text fragments created before the full string is available, right?
There was a problem hiding this comment.
Yep, that's exactly right.
| (range_in_text_run.start + start_in_ifc).to_utf8_code_units_in(AssumeUnder4GB, string); | ||
| let end = | ||
| (range_in_text_run.end + start_in_ifc).to_utf8_code_units_in(AssumeUnder4GB, string); | ||
| Some(string[start.0 as usize..end.0 as usize].to_owned()) |
There was a problem hiding this comment.
Didn’t we add a helper for this? (slicing &str with a Range<Utf8CodeUnits>) Or do I only wish we did?
At some point I tried adding an Index impl but the orphan rule didn’t allow it. (std::ops::Range<Utf8CodeUnits> is not considered "local" even if Utf8CodeUnits is.) So I’m not sure where a good place for it would be. An associated function on Utf8CodeUnits sounds verbose
So unless we come up with something good I’m ok with leaving this as-is
There was a problem hiding this comment.
I took another look and couldn't find a helper unfortunately.
There was a problem hiding this comment.
Ah I didn’t just imagine it! Utf8CodeUnits::to_usize_range(&Range<Self>) -> Range<usize> added in #47742
Though it’s almost as verbose as not using it, so I don’t mind if we don’t use it
| // Flush all layout before stringifying so that rendered text is up-to-date. | ||
| self.document.window().layout_reflow(QueryMsg::StyleQuery); |
There was a problem hiding this comment.
Does StyleQuery include box construction?
There was a problem hiding this comment.
Yes, at least for the moment StyleQuery does a box / fragment tree rebuild. Once we split style and layout into two passes this probably won't be the case any longer.
| pub(crate) fn rendered_text(&self, range: RangeAny<Utf32CodeUnits>) -> Option<String> { | ||
| self.upcast::<Node>() | ||
| .layout_data() | ||
| .borrow() | ||
| .as_ref() | ||
| .and_then(|layout_data| layout_data.rendered_text(range)) |
There was a problem hiding this comment.
I guess not having rendered text for display: none comes indirectly from not having layout_data?
Is layout_data actively removed if display used to be something else and later changed to none?
There was a problem hiding this comment.
Yes, setting a box have have display: none should clear its layout data and clear the style and layout data of all descendants.
mrobinson
left a comment
There was a problem hiding this comment.
Thank you for the review!
|
|
||
| /// A slot used to share the full text string of the [`InlineFormattingContext`] this | ||
| /// builder will ultimately build. | ||
| pub text_content_slot: Arc<OnceLock<String>>, |
There was a problem hiding this comment.
Yep, that's exactly right.
| (range_in_text_run.start + start_in_ifc).to_utf8_code_units_in(AssumeUnder4GB, string); | ||
| let end = | ||
| (range_in_text_run.end + start_in_ifc).to_utf8_code_units_in(AssumeUnder4GB, string); | ||
| Some(string[start.0 as usize..end.0 as usize].to_owned()) |
There was a problem hiding this comment.
I took another look and couldn't find a helper unfortunately.
| pub(crate) fn rendered_text(&self, range: RangeAny<Utf32CodeUnits>) -> Option<String> { | ||
| self.upcast::<Node>() | ||
| .layout_data() | ||
| .borrow() | ||
| .as_ref() | ||
| .and_then(|layout_data| layout_data.rendered_text(range)) |
There was a problem hiding this comment.
Yes, setting a box have have display: none should clear its layout data and clear the style and layout data of all descendants.
| // Flush all layout before stringifying so that rendered text is up-to-date. | ||
| self.document.window().layout_reflow(QueryMsg::StyleQuery); |
There was a problem hiding this comment.
Yes, at least for the moment StyleQuery does a box / fragment tree rebuild. Once we split style and layout into two passes this probably won't be the case any longer.
c0a5c82 to
5129932
Compare
This change makes it so that Servo produces selection text according to the flat tree and respecting the box tree and `user-select` values. There are still some issues around white space handling at the end of lines and also block elements are no inserting a newline as they should, but this is an improvement. Signed-off-by: Martin Robinson <[email protected]>
5129932 to
adc49ea
Compare
…t` (servo#48242) This change makes it so that Servo produces selection text according to the flat tree and respecting the box tree and `user-select` values. There are still some issues around white space handling at the end of lines and also block elements are no inserting a newline as they should, but this is an improvement. Testing: This causes a WPT subtest to pass (more waiting on improvements to handling whitespace trimming in the rendered text query). In addition, since stringification behavior is not well specified, two Servo-specific tests are added for flat tree / `display: none` behavior. Fixes: servo#48242 Signed-off-by: Martin Robinson <[email protected]>
…t` (servo#48242) This change makes it so that Servo produces selection text according to the flat tree and respecting the box tree and `user-select` values. There are still some issues around white space handling at the end of lines and also block elements are no inserting a newline as they should, but this is an improvement. Testing: This causes a WPT subtest to pass (more waiting on improvements to handling whitespace trimming in the rendered text query). In addition, since stringification behavior is not well specified, two Servo-specific tests are added for flat tree / `display: none` behavior. Fixes: servo#48242 Signed-off-by: Martin Robinson <[email protected]>
This change makes it so that Servo produces selection text according to
the flat tree and respecting the box tree and
user-selectvalues.There are still some issues around white space handling at the end of
lines and also block elements are no inserting a newline as they should,
but this is an improvement.
Testing: This causes a WPT subtest to pass (more waiting on improvements
to handling whitespace trimming in the rendered text query). In addition,
since stringification behavior is not well specified, two Servo-specific
tests are added for flat tree /
display: nonebehavior.Fixes: #48242