From 931c7ed7f03d1a8248d9cd5fc33c085f19c5b879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Sun, 20 Sep 2026 05:10:54 +0200 Subject: [PATCH] Honor retained scrollbar thumb interaction states (#785) --- .../code-oss-scrollbar-parts-785.md | 25 +++ .../native/html_parser/src/lib.rs | 1 + .../native/webscene_css_pseudo_application.h | 12 ++ .../native/webscene_css_rule_matching.h | 10 +- .../native/webscene_css_rule_operations.h | 2 +- .../native/webscene_native_dom.h | 6 + .../native/webscene_native_dom_scene.inc | 21 +-- .../webscene_v8_runtime_css_cascade.inc | 6 +- .../native/webscene_v8_runtime_dom_core.inc | 1 + .../native/webscene_v8_runtime_navigation.inc | 1 + .../native/webscene_v8_runtime_state.inc | 1 + .../native/webscene_v8_runtime_tasks.inc | 70 ++++++++- .../native_v8_runtime_layout_scene_tests.inc | 144 +++++++++++++++++- .../tests/native_v8_runtime_tests.cpp | 7 + src/WebScene.Css/CssStylesheetCompiler.cs | 13 +- tests/NativeWeb/css_service.cpp | 2 + .../CssStylesheetCompilerTests.cs | 21 +++ 17 files changed, 315 insertions(+), 28 deletions(-) create mode 100644 docs/validation/code-oss-scrollbar-parts-785.md diff --git a/docs/validation/code-oss-scrollbar-parts-785.md b/docs/validation/code-oss-scrollbar-parts-785.md new file mode 100644 index 000000000..483bcfd9b --- /dev/null +++ b/docs/validation/code-oss-scrollbar-parts-785.md @@ -0,0 +1,25 @@ +# Code OSS retained scrollbar part state (#785) + +## Current-main boundary + +WebScene already projects authored base `::-webkit-scrollbar` width/height and visibility, thumb/track color and radius, content-box transparent borders, proportional overlay geometry, scrolling, and primary-button thumb dragging. This slice keeps that path and fills the remaining declarations reached by unchanged Code OSS 1.137. + +The pinned checkout contains 39 `::-webkit-scrollbar-thumb`, 9 track, and 9 corner occurrences across source and generated CSS. Automation dialogs, Issue Reporter, Image Carousel, and Prompt Timeline use thumb `:hover`/`:active`, `min-height`, transparent borders, themed colors, and hidden corners. + +## Retained implementation + +`::-webkit-scrollbar-thumb:hover` and `:active` receive distinct parse kinds. Matching admits each only while the native thumb owns that state, then folds it into pseudo kind 4 before the existing cascade. Base and state declarations therefore share source order, specificity, layers, rollback, variables, and `!important` handling. + +Two interaction bits occupy the existing `dom_node` flag byte. A single runtime pointer identifies the hovered thumb; the existing drag pointer remains the active owner. Pointer transitions recascade only the previous/new scrollers. No pseudo DOM node, document scan, timer, animation frame, or platform widget is introduced. + +The lazy textual scrollbar record adds one authored vertical minimum thumb extent, matching the `min-height` declaration used by Code OSS. Scene paint and thumb hit testing consume the same value. Existing transparent-border/content-box inset and absent-corner behavior remain unchanged; the authored Code OSS `display:none` corner rules therefore continue to produce no corner command. + +## Authored gates + +- Portable compiler protection/restoration retains thumb `:hover` and `:active` selectors. +- Native selector payload contracts retain kinds 11/12 and the common host origin. +- The focused retained-scene contract checks normal, hover, active, 28 px minimum extent, transparent border inset, hidden-corner absence, drag geometry, and scroll event count. +- The performance contract requires pointer-state changes to preserve layout-pass count, publish bounded scene work, avoid sustained frame demand, and keep unrelated scroller cascade work at zero. +- Final product acceptance compares Prompt Timeline, Automation dialog, Issue Reporter, and Image Carousel regions in light/dark Chromium and AppScene captures, then exercises 100 create/scroll/style/remove cycles and a 4,096-scroller mutation fixture with heap/RSS and retained-count return. + +These gates are authored but unexecuted under the active implementation-throughput direction. No validation result is claimed by this document. diff --git a/experiments/WebScene.NativeEngine.Probe/native/html_parser/src/lib.rs b/experiments/WebScene.NativeEngine.Probe/native/html_parser/src/lib.rs index af662018a..2c412bcbc 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/html_parser/src/lib.rs +++ b/experiments/WebScene.NativeEngine.Probe/native/html_parser/src/lib.rs @@ -1511,6 +1511,7 @@ mod selector_syntax { | "-webkit-scrollbar" | "-webkit-scrollbar-thumb" | "-webkit-scrollbar-track" + | "-webkit-scrollbar-corner" ) } diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_pseudo_application.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_pseudo_application.h index 7b62bad7a..c0a9593a1 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_pseudo_application.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_pseudo_application.h @@ -38,6 +38,12 @@ inline int split_pseudo_element_selector(const std::string& selector, std::strin if (const auto kind = split_suffix("::details-content", 9); kind != 0) return kind; if (const auto kind = split_suffix("::-webkit-details-marker", 10); kind != 0) return kind; if (const auto kind = split_suffix("::backdrop", 7); kind != 0) return kind; + // Scrollbar-part interaction belongs to the retained part rather than + // the originating DOM element. Keep distinct parse kinds so matching + // can admit them only while that exact native thumb state is active, + // then fold them back into the thumb's single cascade. + if (const auto kind = split_suffix("::-webkit-scrollbar-thumb:hover", 11); kind != 0) return kind; + if (const auto kind = split_suffix("::-webkit-scrollbar-thumb:active", 12); kind != 0) return kind; if (const auto kind = split_suffix("::-webkit-scrollbar-thumb", 4); kind != 0) return kind; if (const auto kind = split_suffix("::-webkit-scrollbar-track", 5); kind != 0) return kind; if (const auto kind = split_suffix("::-webkit-scrollbar-corner", 6); kind != 0) return kind; @@ -324,6 +330,11 @@ inline void apply_scrollbar_declaration( if (declaration.name == "background" || declaration.name == "background-color") { scrollbar.thumb_rgba = lower == "initial" ? 0U : native_document::parse_color(value); + } else if (declaration.name == "min-height") { + const auto length = native_document::parse_length(value); + if (length.unit == length_unit::pixels) { + scrollbar.thumb_min_height = std::max(0.0F, length.value); + } } else if (declaration.name == "border-radius") { scrollbar.thumb_radius = std::max( 0.0F, native_document::parse_length(value).value); @@ -348,6 +359,7 @@ inline void apply_scrollbar_declaration( scrollbar.track_radius = std::max( 0.0F, native_document::parse_length(value).value); } + return; } } diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_matching.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_matching.h index 86830d56a..c17733f7b 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_matching.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_matching.h @@ -43,7 +43,15 @@ rule_matches match_candidates(native_document& document,const dom_node& node, if (pseudo_kind != 0) { const auto& origin = rule.payload->compiled_pseudo_origin; if (!origin.compounds.empty() && match_selector(node,rule,origin)) { - result.pseudo.emplace_back(pseudo_kind, &rule); + if (pseudo_kind == 11 && !node.scrollbar_thumb_hovered) continue; + if (pseudo_kind == 12 && !node.scrollbar_thumb_active) continue; + // All active thumb-state selectors target the same pseudo + // box. Folding them into kind 4 before sorting preserves + // specificity, source order, layers and !important across + // base, :hover and :active rules. + result.pseudo.emplace_back( + pseudo_kind == 11 || pseudo_kind == 12 ? 4 : pseudo_kind, + &rule); } continue; } diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_operations.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_operations.h index 800d1ba93..f15943797 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_operations.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_css_rule_operations.h @@ -310,7 +310,7 @@ void for_each_cascaded_pseudo_declaration( // kind prevents a high-priority ::before declaration from affecting // ::after while reusing the same layer/importance/rollback machinery // as the originating element. - std::array, 11> rules_by_kind; + std::array, 13> rules_by_kind; for (const auto& [kind, rule] : matched_rules) { if (kind > 0 && static_cast(kind) < rules_by_kind.size()) rules_by_kind[static_cast(kind)].push_back(rule); diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h index f350ab255..15992227e 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom.h @@ -770,6 +770,7 @@ struct node_style final { float height{6}; float overlay_inset{2}; float thumb_border_width{0}; + float thumb_min_height{18}; float thumb_radius{3}; float track_radius{3}; uint32_t thumb_rgba{0xA0A0A0D0U}; @@ -1798,6 +1799,11 @@ struct dom_node final { // display state reaches or leaves `none`. bool css_cascade_initialized : 1 {false}; bool css_was_rendered : 1 {false}; + // Retained scrollbar pseudo state is independent of the host element's + // :hover/:active state. These use the remaining bits in the existing node + // flag byte and therefore do not increase the hot dom_node footprint. + bool scrollbar_thumb_hovered : 1 {false}; + bool scrollbar_thumb_active : 1 {false}; std::string tag; std::string id_attribute; std::string class_name; diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_scene.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_scene.inc index d7a5865a1..d777e02f4 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_scene.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_native_dom_scene.inc @@ -3646,7 +3646,6 @@ void native_document::append_scene( const auto maximum_y = std::max( 0.0F, snapped_content_height - snapped_viewport_height); const auto& scrollbar = node.style.scrollbar(); - constexpr auto minimum_thumb = 18.0F; const auto append_overlay_rect = [&](float x, float y, float width, float height, uint32_t rgba, float radius) { if (width <= 0 || height <= 0) return; @@ -3672,17 +3671,24 @@ void native_document::append_scene( const auto vertical_thickness = scrollbar.width; const auto horizontal_thickness = scrollbar.height; const auto inset = scrollbar.overlay_inset; - if ((node.style.scroll_y_enabled || root_viewport_scroll_y) && maximum_y > 0.01F + const auto paints_vertical = + (node.style.scroll_y_enabled || root_viewport_scroll_y) && maximum_y > 0.01F && vertical_thickness > 0 && viewport_width >= vertical_thickness + inset * 2 - && viewport_height > 0) { + && viewport_height > 0; + const auto paints_horizontal = + (node.style.scroll_x_enabled || root_viewport_scroll_x) && maximum_x > 0.01F + && horizontal_thickness > 0 + && viewport_height >= horizontal_thickness + inset * 2 + && viewport_width > 0; + if (paints_vertical) { const auto rail_x = viewport_x + viewport_width - vertical_thickness - inset; const auto rail_y = viewport_y + inset; const auto rail_height = std::max(0.0F, viewport_height - inset * 2); const auto thumb_height = std::min( rail_height, std::max( - minimum_thumb, + scrollbar.thumb_min_height, rail_height * snapped_viewport_height / std::max(snapped_viewport_height, snapped_content_height))); const auto thumb_travel = std::max(0.0F, rail_height - thumb_height); @@ -3696,17 +3702,14 @@ void native_document::append_scene( vertical_thickness - border * 2, thumb_height - border * 2, scrollbar.thumb_rgba, std::max(0.0F, scrollbar.thumb_radius - border)); } - if ((node.style.scroll_x_enabled || root_viewport_scroll_x) && maximum_x > 0.01F - && horizontal_thickness > 0 - && viewport_height >= horizontal_thickness + inset * 2 - && viewport_width > 0) { + if (paints_horizontal) { const auto rail_x = viewport_x + inset; const auto rail_y = viewport_y + viewport_height - horizontal_thickness - inset; const auto rail_width = std::max(0.0F, viewport_width - inset * 2); const auto thumb_width = std::min( rail_width, std::max( - minimum_thumb, + 18.0F, rail_width * snapped_viewport_width / std::max(snapped_viewport_width, snapped_content_width))); const auto thumb_travel = std::max(0.0F, rail_width - thumb_width); diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_css_cascade.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_css_cascade.inc index b155841b4..d6a2623a9 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_css_cascade.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_css_cascade.inc @@ -697,7 +697,11 @@ const auto pseudo_kind = split_pseudo_element_selector(rule.selector(), pseudo_origin); if (pseudo_kind != 0) { if (!pseudo_origin.empty() && css_selector_matches(node, pseudo_origin)) { - matched_pseudo_rules.emplace_back(pseudo_kind, &rule); + if (pseudo_kind == 11 && !node.scrollbar_thumb_hovered) continue; + if (pseudo_kind == 12 && !node.scrollbar_thumb_active) continue; + matched_pseudo_rules.emplace_back( + pseudo_kind == 11 || pseudo_kind == 12 ? 4 : pseudo_kind, + &rule); } continue; } diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc index ea2327e03..c76c107c3 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_dom_core.inc @@ -2101,6 +2101,7 @@ } if (nodes.contains(active_pointer_target)) active_pointer_target = nullptr; if (nodes.contains(scrollbar_drag_target)) scrollbar_drag_target = nullptr; + if (nodes.contains(scrollbar_hover_target)) scrollbar_hover_target = nullptr; if (nodes.contains(hover_target)) hover_target = nullptr; if (nodes.contains(current_related_target)) current_related_target = nullptr; released_detached_dom_nodes += document.erase_detached_subtrees(roots); diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_navigation.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_navigation.inc index 3396eadc5..6a82088ee 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_navigation.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_navigation.inc @@ -292,6 +292,7 @@ middle_paste_target_id = 0U; active_pointer_target = nullptr; scrollbar_drag_target = nullptr; + scrollbar_hover_target = nullptr; scrollbar_drag_vertical = false; scrollbar_drag_pointer_origin = 0; scrollbar_drag_scroll_origin = 0; diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_state.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_state.inc index d696c8c54..902373aaf 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_state.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_state.inc @@ -733,6 +733,7 @@ bool outbound_drag_threshold_crossed{false}; dom_node* active_pointer_target{nullptr}; dom_node* scrollbar_drag_target{nullptr}; + dom_node* scrollbar_hover_target{nullptr}; bool scrollbar_drag_vertical{false}; double scrollbar_drag_pointer_origin{0}; float scrollbar_drag_scroll_origin{0}; diff --git a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_tasks.inc b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_tasks.inc index 2a8f61e85..c8f7bfd4b 100644 --- a/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_tasks.inc +++ b/experiments/WebScene.NativeEngine.Probe/native/webscene_v8_runtime_tasks.inc @@ -3654,7 +3654,6 @@ float x, float y) { - constexpr auto minimum_thumb = 18.0F; for (auto* node = &hit_target; node != nullptr; node = node->parent) { if (node->style.scrollbar_hidden || node->layout.width <= 0 || node->layout.height <= 0) continue; @@ -3698,7 +3697,7 @@ const auto rail_y = viewport_y + inset; const auto rail_height = std::max(0.0F, viewport_height - inset * 2); const auto thumb_height = std::min(rail_height, std::max( - minimum_thumb, + scrollbar.thumb_min_height, rail_height * node->scroll_viewport_height / std::max(node->scroll_viewport_height, node->scroll_content_height))); const auto travel = std::max(0.0F, rail_height - thumb_height); @@ -3716,7 +3715,7 @@ const auto rail_y = viewport_y + viewport_height - scrollbar.height - inset; const auto rail_width = std::max(0.0F, viewport_width - inset * 2); const auto thumb_width = std::min(rail_width, std::max( - minimum_thumb, + 18.0F, rail_width * node->scroll_viewport_width / std::max(node->scroll_viewport_width, node->scroll_content_width))); const auto travel = std::max(0.0F, rail_width - thumb_width); @@ -3732,6 +3731,33 @@ return std::nullopt; } + void update_scrollbar_thumb_interaction( + dom_node* next_hover, + dom_node* next_active) + { + auto* previous_hover = scrollbar_hover_target; + auto* previous_active = scrollbar_drag_target; + scrollbar_hover_target = next_hover; + std::array affected{ + previous_hover, previous_active, next_hover, next_active}; + for (size_t index = 0; index < affected.size(); ++index) { + auto* node = affected[index]; + if (node == nullptr || !is_connected(*node)) continue; + if (std::find(affected.begin(), affected.begin() + index, node) + != affected.begin() + index) continue; + const auto hovered = node == next_hover; + const auto active = node == next_active; + if (node->scrollbar_thumb_hovered == hovered + && node->scrollbar_thumb_active == active) continue; + node->scrollbar_thumb_hovered = hovered; + node->scrollbar_thumb_active = active; + // State selectors are folded into the existing thumb cascade, so + // one affected-node recascade preserves specificity, layers, + // source order and !important without scanning the document. + apply_css_rules(*node); + } + } + bool dispatch_input(const webscene_input_event& input, bool defer_cursor_update = false) { struct user_input_dispatch_scope { @@ -3812,6 +3838,7 @@ if (pointer_capture_target != nullptr || scrollbar_drag_target != nullptr) { return true; } + update_scrollbar_thumb_interaction(nullptr, nullptr); auto* previous = hover_target; hover_target = nullptr; current_related_target = nullptr; @@ -3859,6 +3886,23 @@ const auto viewport = viewport_provider(); const auto pointer_outside = input.x < 0 || input.y < 0 || input.x >= viewport.width || input.y >= viewport.height; + const auto scrollbar_hit_at_pointer = [&]() -> std::optional { + if (pointer_outside + || (input.kind != WEBSCENE_INPUT_POINTER_MOVE + && input.kind != WEBSCENE_INPUT_POINTER_DOWN + && input.kind != WEBSCENE_INPUT_POINTER_UP)) return std::nullopt; + auto* start = initial_hit_target; + if (start == nullptr) start = &document.body(); + return hit_test_scrollbar_thumb( + *start, static_cast(input.x), static_cast(input.y)); + }; + auto current_scrollbar_hit = scrollbar_hit_at_pointer(); + if (scrollbar_drag_target == nullptr + && input.kind == WEBSCENE_INPUT_POINTER_MOVE) { + update_scrollbar_thumb_interaction( + current_scrollbar_hit.has_value() ? current_scrollbar_hit->target : nullptr, + nullptr); + } if (scrollbar_drag_target != nullptr && (input.kind == WEBSCENE_INPUT_POINTER_MOVE || input.kind == WEBSCENE_INPUT_POINTER_UP)) { @@ -3887,6 +3931,10 @@ } } if (input.kind == WEBSCENE_INPUT_POINTER_UP) { + update_scrollbar_thumb_interaction( + current_scrollbar_hit.has_value() + ? current_scrollbar_hit->target : nullptr, + nullptr); scrollbar_drag_target = nullptr; if (pointer_outside) return leave_host(); } @@ -3910,9 +3958,16 @@ } if (input.kind == WEBSCENE_INPUT_POINTER_DOWN && ((input.flags >> 8U) & 0xffU) <= 1U) { - if (const auto hit = hit_test_scrollbar_thumb( + if (current_scrollbar_hit.has_value()) { + update_scrollbar_thumb_interaction( + current_scrollbar_hit->target, + current_scrollbar_hit->target); + // Hover declarations can alter the authored minimum extent. + // Re-read the same retained geometry before beginning drag. + current_scrollbar_hit = hit_test_scrollbar_thumb( *hit_target, static_cast(input.x), static_cast(input.y)); - hit.has_value()) { + } + if (const auto& hit = current_scrollbar_hit; hit.has_value()) { scrollbar_drag_target = hit->target; scrollbar_drag_vertical = hit->vertical; scrollbar_drag_pointer_origin = hit->pointer_origin; @@ -3922,6 +3977,11 @@ return true; } } + if (input.kind == WEBSCENE_INPUT_POINTER_UP) { + update_scrollbar_thumb_interaction( + current_scrollbar_hit.has_value() ? current_scrollbar_hit->target : nullptr, + nullptr); + } auto* target = pointer_capture_target != nullptr && input.kind != WEBSCENE_INPUT_POINTER_DOWN ? pointer_capture_target diff --git a/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_layout_scene_tests.inc b/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_layout_scene_tests.inc index 281092ae1..8100bd2fc 100644 --- a/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_layout_scene_tests.inc +++ b/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_layout_scene_tests.inc @@ -291,9 +291,18 @@ void test_authored_scrollbar_style_and_thumb_drag(webscene_engine* engine) } #styled::-webkit-scrollbar-thumb { background-color:rgb(18,52,86); background-clip:content-box; - border:1px solid transparent; border-radius:3px; + border:1px solid transparent; border-radius:3px; min-height:28px; } - #content { height:320px; } + #styled::-webkit-scrollbar-thumb:hover { + background-color:rgb(101,102,103); + } + #styled::-webkit-scrollbar-thumb:active { + background-color:rgb(201,202,203); + } + #styled::-webkit-scrollbar-corner { + display:none; background-color:rgb(9,8,7); + } + #content { width:320px; height:320px; }
`; const styled = document.getElementById('styled'); globalThis.__styledScrollbar = styled; @@ -301,22 +310,67 @@ void test_authored_scrollbar_style_and_thumb_drag(webscene_engine* engine) styled.addEventListener('scroll', () => __styledScrollbarEvents++); return { clientHeight:styled.clientHeight, + scrollWidth:styled.scrollWidth, scrollHeight:styled.scrollHeight, scrollTop:styled.scrollTop }; })() )JS", "native-authored-scrollbar-setup.js"); require( - initial == R"JSON({"clientHeight":80,"scrollHeight":320,"scrollTop":0})JSON", + initial == R"JSON({"clientHeight":80,"scrollWidth":320,"scrollHeight":320,"scrollTop":0})JSON", "authored scrollbar fixture did not establish its overflow range: " + initial); + const auto observe_thumb = [&](uint32_t expected_rgba, const char* state) { + webscene_engine_request_scene_checkpoint(engine); + for (auto attempt = 0; attempt < 100; ++attempt) { + if (const auto* scene = webscene_engine_acquire_latest_scene(engine); + scene != nullptr) { + auto matched = false; + auto leaked_corner = false; + for (uint32_t index = 0; index < scene->header.command_count; ++index) { + const auto& command = scene->commands[index]; + leaked_corner = leaked_corner || command.rgba == 0x090807FFU; + if (command.rgba != expected_rgba) continue; + matched = std::abs(command.width - 3.0F) < 0.1F + && std::abs(command.height - 26.0F) < 0.1F; + } + webscene_scene_acknowledge(scene); + webscene_scene_release(scene); + require(!leaked_corner, + "display:none scrollbar corner emitted retained paint"); + if (matched) return; + } + std::this_thread::sleep_for(std::chrono::milliseconds(2)); + } + fail(std::string("authored scrollbar thumb did not paint its ") + + state + " state with the authored minimum extent"); + }; + + observe_thumb(0x123456FFU, "normal"); + + webscene_engine_metrics interaction_before{}; + webscene_engine_get_metrics(engine, &interaction_before); const auto consumed_before_drag = consumed_input_count(engine); - pointer_button(engine, WEBSCENE_INPUT_POINTER_DOWN, 117, 10, 5801U, true); - pointer_move(engine, 117, 65, 5802U, true); - pointer_button(engine, WEBSCENE_INPUT_POINTER_UP, 117, 65, 5803U, false); + pointer_move(engine, 117, 10, 5801U, false); + wait_for_consumed_inputs( + engine, consumed_before_drag + 1, + "authored scrollbar hover input was not consumed"); + observe_thumb(0x656667FFU, "hover"); + webscene_engine_metrics after_hover{}; + webscene_engine_get_metrics(engine, &after_hover); + require( + after_hover.layout_passes == interaction_before.layout_passes, + "scrollbar thumb hover reran document layout"); + pointer_button(engine, WEBSCENE_INPUT_POINTER_DOWN, 117, 10, 5802U, true); + wait_for_consumed_inputs( + engine, consumed_before_drag + 2, + "authored scrollbar active input was not consumed"); + observe_thumb(0xC9CACBFFU, "active"); + pointer_move(engine, 117, 65, 5803U, true); + pointer_button(engine, WEBSCENE_INPUT_POINTER_UP, 117, 65, 5804U, false); wait_for_consumed_inputs( engine, - consumed_before_drag + 3, + consumed_before_drag + 4, "authored scrollbar thumb drag inputs were not consumed"); const auto dragged = evaluate(engine, R"JS( ({ @@ -325,12 +379,86 @@ void test_authored_scrollbar_style_and_thumb_drag(webscene_engine* engine) }) )JS", "native-authored-scrollbar-drag-result.js"); require( - dragged == R"JSON({"scrollTop":220,"scrollEvents":1})JSON", + dragged == R"JSON({"scrollTop":240,"scrollEvents":1})JSON", "dragging the authored scrollbar thumb did not update the finite scroll owner: " + dragged); + webscene_engine_metrics interaction_after{}; + webscene_engine_get_metrics(engine, &interaction_after); + require( + interaction_after.layout_passes == interaction_before.layout_passes, + "scrollbar thumb hover/active/drag reran document layout"); + require( + interaction_after.applied_animation_frames + == interaction_before.applied_animation_frames, + "settled scrollbar interaction introduced animation-frame demand"); } +void test_scrollbar_thumb_state_scaling(webscene_engine* engine) +{ + resize(engine, 640, 240, 5850U); + const auto setup = evaluate(engine, R"JS( + (() => { + document.body.innerHTML = `
`; + const root = document.getElementById('scrollbar-scale-root'); + const fragment = document.createDocumentFragment(); + for (let index = 0; index < 4096; ++index) { + const scroller = document.createElement('div'); + if (index === 0) { + scroller.className = 'scrollbar-scale'; + const content = document.createElement('div'); + content.style.height = '320px'; + scroller.appendChild(content); + } else { + scroller.className = 'scrollbar-unrelated'; + scroller.style.display = 'none'; + } + fragment.appendChild(scroller); + } + root.appendChild(fragment); + return [root.children.length, root.firstElementChild.scrollHeight]; + })() + )JS", "native-scrollbar-state-scale-setup.js"); + require(setup == "[4096,320]", + "scrollbar state scale fixture did not create 4,096 retained scrollers: " + setup); + + webscene_engine_metrics before{}; + webscene_engine_get_metrics(engine, &before); + const auto started = std::chrono::steady_clock::now(); + auto expected_inputs = consumed_input_count(engine); + for (uint64_t cycle = 0; cycle < 100U; ++cycle) { + pointer_move(engine, 117, 10, 5851U + cycle * 2U, false); + ++expected_inputs; + wait_for_consumed_inputs( + engine, expected_inputs, + "scrollbar state scale hover input was not consumed"); + pointer_move(engine, 300, 10, 5852U + cycle * 2U, false); + ++expected_inputs; + wait_for_consumed_inputs( + engine, expected_inputs, + "scrollbar state scale exit input was not consumed"); + } + const auto elapsed = std::chrono::duration( + std::chrono::steady_clock::now() - started).count(); + webscene_engine_metrics after{}; + webscene_engine_get_metrics(engine, &after); + require(elapsed < 5000.0, + "4,096-scroller hover state gate exceeded 5 seconds: " + + std::to_string(elapsed)); + require(after.layout_passes == before.layout_passes, + "4,096-scroller hover state gate reran document layout"); + require(after.applied_animation_frames == before.applied_animation_frames, + "4,096-scroller hover state gate introduced animation-frame demand"); + require(after.published_scenes <= before.published_scenes + 200U, + "scrollbar hover state published more than one bounded scene per transition"); +} + void test_absolute_virtualized_rows_follow_ancestor_scroll_container( webscene_engine* engine) { diff --git a/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_tests.cpp b/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_tests.cpp index c3698844a..820c99160 100644 --- a/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_tests.cpp +++ b/experiments/WebScene.NativeEngine.Probe/tests/native_v8_runtime_tests.cpp @@ -813,6 +813,13 @@ int main() webscene_engine_destroy(focused_engine); return 0; } + if (selected == "scrollbar-state-scale") { + auto* focused_engine = webscene_engine_create(64); + require(focused_engine != nullptr, "focused scrollbar scale engine creation failed"); + test_scrollbar_thumb_state_scaling(focused_engine); + webscene_engine_destroy(focused_engine); + return 0; + } if (selected == "toolbar-overflow-navigation") { auto* focused_engine = webscene_engine_create(64); require(focused_engine != nullptr, "focused engine creation failed"); diff --git a/src/WebScene.Css/CssStylesheetCompiler.cs b/src/WebScene.Css/CssStylesheetCompiler.cs index 0940f6c03..ea4269ae0 100644 --- a/src/WebScene.Css/CssStylesheetCompiler.cs +++ b/src/WebScene.Css/CssStylesheetCompiler.cs @@ -376,9 +376,12 @@ private static string ProtectScrollbarPseudoElementsForParser(string css) { return Regex.Replace( css, - @"::-(webkit-scrollbar(?:-(?:thumb|track|corner))?)", + @"::-(webkit-scrollbar(?:-(?:thumb|track|corner))?)(?::(?hover|active))?", match => ProtectedScrollbarPseudoClassPrefix + match.Groups[1].Value.Replace('-', '_') + + (match.Groups["state"].Success + ? "-state-" + match.Groups["state"].Value.ToLowerInvariant() + : string.Empty) + "::before", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); } @@ -388,9 +391,13 @@ private static string RestoreScrollbarPseudoElements(string selectorText) return Regex.Replace( selectorText, Regex.Escape(ProtectedScrollbarPseudoClassPrefix) - + @"(?webkit_scrollbar(?:_(?:thumb|track|corner))?)::before", + + @"(?webkit_scrollbar(?:_(?:thumb|track|corner))?)" + + @"(?:-state-(?hover|active))?::before", match => "::-" - + match.Groups["name"].Value.Replace('_', '-'), + + match.Groups["name"].Value.Replace('_', '-') + + (match.Groups["state"].Success + ? ":" + match.Groups["state"].Value + : string.Empty), RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); } diff --git a/tests/NativeWeb/css_service.cpp b/tests/NativeWeb/css_service.cpp index 9a88e5f57..02f6d670a 100644 --- a/tests/NativeWeb/css_service.cpp +++ b/tests/NativeWeb/css_service.cpp @@ -720,6 +720,8 @@ int main(int argc,char** argv) { {".base::after",2},{".base:after",2}, {".base::-webkit-scrollbar",3},{".base::-webkit-scrollbar-thumb",4}, {".base::-webkit-scrollbar-track",5},{".base::-webkit-scrollbar-corner",6}, + {".base::-webkit-scrollbar-thumb:hover",11}, + {".base::-webkit-scrollbar-thumb:active",12}, {".base::backdrop",7},{".base::placeholder",8}, {".base::-webkit-input-placeholder",8},{".base::-moz-placeholder",8}, {".base::details-content",9}, diff --git a/tests/WebScene.Css.Tests/CssStylesheetCompilerTests.cs b/tests/WebScene.Css.Tests/CssStylesheetCompilerTests.cs index fc3244926..cccc6cd46 100644 --- a/tests/WebScene.Css.Tests/CssStylesheetCompilerTests.cs +++ b/tests/WebScene.Css.Tests/CssStylesheetCompilerTests.cs @@ -17,6 +17,27 @@ public void PreservesScrollbarPseudoElementRules() declaration.Name == "display" && declaration.Value == "none"); } + [Fact] + public void PreservesScrollbarThumbInteractionStateAfterParserProtection() + { + var result = CssStylesheetCompiler.Compile(""" + .scroller::-webkit-scrollbar-thumb:hover { background-color: red; } + .scroller::-webkit-scrollbar-thumb:active { background-color: blue !important; } + """); + + Assert.Equal(2, result.Rules.Count); + Assert.All(result.Rules, rule => Assert.Contains( + rule.Selector.Parts[^1].Simple.Pseudos, + static pseudo => pseudo.IsElement && pseudo.Name == "-webkit-scrollbar-thumb")); + Assert.Contains(result.Rules[0].Selector.Parts[^1].Simple.Pseudos, + static pseudo => !pseudo.IsElement && pseudo.Name == "hover"); + Assert.Contains(result.Rules[1].Selector.Parts[^1].Simple.Pseudos, + static pseudo => !pseudo.IsElement && pseudo.Name == "active"); + Assert.Contains(result.Rules[1].Declarations, + static declaration => declaration.Name == "background-color" + && declaration.Value == "blue" && declaration.Important); + } + [Fact] public void CompilerProducesPortableSelectorsDeclarationsAndNestedMedia() {