servo/components/layout_2020
DK Liao e62aecb103
feat: Implement display for text selection and caret (#35830)
This PR introduces an initial, straightforward implementation for
displaying text selection and the caret.

This is achieved by passing the selection range and insertion point
index down to `TextFragment`, along with the starting offset of each
`TextFragment` to determine the proper range for displaying the caret
and text selection. Additionally, the `selected_style` was passed into
`TextFragment` to specify the background color.

During the final build phase, although whitespace is typically ignored
when constructing glyphs, we still need to retrieve it to render both
the caret and text selection at the correct location. This ensures that
whitespace is not overlooked when the `TextFragment` contains an
insertion point or selection range.

There are several improvements yet to be made, including:

- The caret is static and does not flash.
- The caret is not rendered when the input field is empty. (I suppose
there should be an easy fix somewhere but I haven't found it yet)

**Working Examples**

macOS


https://github.com/user-attachments/assets/f3622cbe-9fa6-40c0-b2d8-b3a8f9842c28

Windows


https://github.com/user-attachments/assets/9b008a0d-0011-4c76-a2e2-0e35869a216c

Linux

[Screencast from 03-07-2025 11_05_41
AM.webm](https://github.com/user-attachments/assets/09a311ad-f975-4450-a66c-b20be525a5ed)



---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix part of #33237 (But the cursor isn't blinking
yet)
- [x] These changes do not require tests because there's no behavior
change

Signed-off-by: DK Liao <dklassic@gmail.com>
2025-04-10 14:40:38 +00:00
..
display_list feat: Implement display for text selection and caret (#35830) 2025-04-10 14:40:38 +00:00
flexbox refactor: use is_zero() instead of comparing with Au::Zero() (#36347) 2025-04-09 22:57:55 +00:00
flow feat: Implement display for text selection and caret (#35830) 2025-04-10 14:40:38 +00:00
fragment_tree feat: Implement display for text selection and caret (#35830) 2025-04-10 14:40:38 +00:00
table refactor: use is_zero() instead of comparing with Au::Zero() (#36347) 2025-04-09 22:57:55 +00:00
taffy layout: Enable using cached fragments when there is a BoxTree update point (#36404) 2025-04-09 13:32:07 +00:00
tests refactor: use is_zero() instead of comparing with Au::Zero() (#36347) 2025-04-09 22:57:55 +00:00
Cargo.toml refactor: use is_zero() instead of comparing with Au::Zero() (#36347) 2025-04-09 22:57:55 +00:00
cell.rs layout: Remove the obsolete layout tracing functionality (#35001) 2025-01-15 13:24:14 +00:00
construct_modern.rs layout: Simplify and generalize the usage of pseudo-elements (#36202) 2025-03-29 12:41:04 +00:00
context.rs layout: Scale images in image_set by their specified resolution (#36374) 2025-04-07 13:54:29 +00:00
dom.rs layout: Enable using cached fragments when there is a BoxTree update point (#36404) 2025-04-09 13:32:07 +00:00
dom_traversal.rs feat: Implement display for text selection and caret (#35830) 2025-04-10 14:40:38 +00:00
formatting_contexts.rs layout: Enable using cached fragments when there is a BoxTree update point (#36404) 2025-04-09 13:32:07 +00:00
geom.rs layout: Implement the fit-content() sizing function (#36056) 2025-03-23 14:26:44 +00:00
layout_box_base.rs layout: Enable using cached fragments when there is a BoxTree update point (#36404) 2025-04-09 13:32:07 +00:00
lib.rs layout: Cache IndependentNonReplacedContents::layout() (#36082) 2025-03-24 12:33:44 +00:00
lists.rs layout: Add initial support for the ::marker pseudo-element (#36317) 2025-04-07 17:49:05 +00:00
positioned.rs layout: Enable using cached fragments when there is a BoxTree update point (#36404) 2025-04-09 13:32:07 +00:00
query.rs layout: Add initial support for the ::marker pseudo-element (#36317) 2025-04-07 17:49:05 +00:00
quotes.rs layout: Implement a non-recursive version of CSS quotes (#34770) 2025-02-27 16:00:21 +00:00
replaced.rs constellation: Stop assuming that the viewport is shared by all WebViews (#36312) 2025-04-04 17:06:34 +00:00
sizing.rs layout: Restrict stretch alignment to flex items with computed auto size (#36288) 2025-04-04 10:15:40 +00:00
style_ext.rs layout: Restrict stretch alignment to flex items with computed auto size (#36288) 2025-04-04 10:15:40 +00:00
traversal.rs Update rustfmt to the 2024 style edition (#35764) 2025-03-03 11:26:53 +00:00