|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | #include <LibWeb/CSS/ComputedProperties.h> |
| 10 | +#include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h> |
10 | 11 | #include <LibWeb/CSS/SystemColor.h> |
11 | 12 | #include <LibWeb/DOM/Document.h> |
12 | 13 | #include <LibWeb/DOM/Element.h> |
|
15 | 16 | #include <LibWeb/Layout/Node.h> |
16 | 17 | #include <LibWeb/Layout/TextNode.h> |
17 | 18 | #include <LibWeb/Layout/TextOffsetMapping.h> |
| 19 | +#include <LibWeb/Page/Page.h> |
18 | 20 | #include <LibWeb/Painting/DisplayListRecorder.h> |
19 | 21 | #include <LibWeb/Painting/DisplayListRecordingContext.h> |
20 | 22 | #include <LibWeb/Painting/Paintable.h> |
@@ -281,19 +283,40 @@ Painting::BorderRadiiData normalize_border_radii_data(Layout::Node const& node, |
281 | 283 | // fill-color, stroke-width, and CSS custom properties. |
282 | 284 | Paintable::SelectionStyle Paintable::selection_style() const |
283 | 285 | { |
284 | | - auto color_scheme = computed_values().color_scheme(); |
285 | | - SelectionStyle default_style { CSS::SystemColor::highlight(color_scheme), {}, {}, {} }; |
| 286 | + auto default_style_for_color_scheme = [&](CSS::PreferredColorScheme color_scheme, bool use_palette_for_normal_color_scheme = true) { |
| 287 | + auto palette = document().page().palette(); |
| 288 | + auto palette_color_scheme = palette.is_dark() ? CSS::PreferredColorScheme::Dark : CSS::PreferredColorScheme::Light; |
| 289 | + if (color_scheme == palette_color_scheme || use_palette_for_normal_color_scheme) { |
| 290 | + return SelectionStyle { |
| 291 | + CSS::SystemColor::transform_selection_background_color(palette.selection()), |
| 292 | + palette.selection_text(), |
| 293 | + {}, |
| 294 | + {}, |
| 295 | + }; |
| 296 | + } |
| 297 | + |
| 298 | + return SelectionStyle { |
| 299 | + CSS::SystemColor::transform_selection_background_color(CSS::SystemColor::highlight(color_scheme)), |
| 300 | + CSS::SystemColor::highlight_text(color_scheme), |
| 301 | + {}, |
| 302 | + {}, |
| 303 | + }; |
| 304 | + }; |
286 | 305 |
|
287 | 306 | // For text nodes, check the parent element since text nodes don't have computed properties. |
288 | 307 | auto node = dom_node(); |
289 | 308 | if (!node) |
290 | | - return default_style; |
| 309 | + return default_style_for_color_scheme(computed_values().color_scheme()); |
291 | 310 |
|
292 | 311 | DOM::Element const* element = as_if<DOM::Element>(*node); |
293 | 312 | if (!element) |
294 | 313 | element = node->parent_element(); |
295 | 314 | if (!element) |
296 | | - return default_style; |
| 315 | + return default_style_for_color_scheme(computed_values().color_scheme()); |
| 316 | + |
| 317 | + auto color_scheme_is_normal = element->computed_properties()->property(CSS::PropertyID::ColorScheme).as_color_scheme().schemes().is_empty(); |
| 318 | + auto use_palette_for_normal_color_scheme = color_scheme_is_normal && !document().supported_color_schemes().has_value(); |
| 319 | + auto default_style = default_style_for_color_scheme(computed_values().color_scheme(), use_palette_for_normal_color_scheme); |
297 | 320 |
|
298 | 321 | auto style_from_element = [&](DOM::Element const& element) -> Optional<SelectionStyle> { |
299 | 322 | auto element_layout_node = element.layout_node(); |
|
0 commit comments