From 74dde4dc0f23d7ff6748bf16c919a25b41ec35b1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 30 Jan 2025 15:47:09 +0100 Subject: [PATCH] LibWeb: Rename `is_scrollable()` to `could_be_scrolled_by_wheel_event()` Previous name for misleading because it checks if box could be scrolled by user input event which is diffent from checking if box is scrollable. For example box with `overflow: hidden` is scrollable but it can't be scrolled by user input event. --- Libraries/LibWeb/DOM/Node.cpp | 2 +- Libraries/LibWeb/Painting/PaintableBox.cpp | 12 ++++++------ Libraries/LibWeb/Painting/PaintableBox.h | 4 ++-- Libraries/LibWeb/Painting/ViewportPaintable.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index b5a624259d3..a3fc8105902 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -1651,7 +1651,7 @@ void Node::serialize_tree_as_json(JsonObjectSerializer& object) c } if (paintable_box()) { - if (paintable_box()->is_scrollable()) { + if (paintable_box()->could_be_scrolled_by_wheel_event()) { MUST(object.add("scrollable"sv, true)); } if (!paintable_box()->is_visible()) { diff --git a/Libraries/LibWeb/Painting/PaintableBox.cpp b/Libraries/LibWeb/Painting/PaintableBox.cpp index aa943dd4887..9055a09c5b1 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -335,7 +335,7 @@ void PaintableBox::after_paint(PaintContext& context, [[maybe_unused]] PaintPhas } } -bool PaintableBox::is_scrollable(ScrollDirection direction) const +bool PaintableBox::could_be_scrolled_by_wheel_event(ScrollDirection direction) const { auto overflow = direction == ScrollDirection::Horizontal ? computed_values().overflow_x() : computed_values().overflow_y(); auto scrollable_overflow_rect = this->scrollable_overflow_rect(); @@ -348,9 +348,9 @@ bool PaintableBox::is_scrollable(ScrollDirection direction) const return overflow == CSS::Overflow::Scroll; } -bool PaintableBox::is_scrollable() const +bool PaintableBox::could_be_scrolled_by_wheel_event() const { - return is_scrollable(ScrollDirection::Horizontal) || is_scrollable(ScrollDirection::Vertical); + return could_be_scrolled_by_wheel_event(ScrollDirection::Horizontal) || could_be_scrolled_by_wheel_event(ScrollDirection::Vertical); } static constexpr CSSPixels scrollbar_thumb_thickness = 8; @@ -375,7 +375,7 @@ Optional PaintableBox::scroll_thumb_rect(ScrollDirection direction Optional PaintableBox::compute_scrollbar_data(ScrollDirection direction) const { - if (!is_scrollable(direction)) { + if (!could_be_scrolled_by_wheel_event(direction)) { return {}; } @@ -907,7 +907,7 @@ Paintable::DispatchEventOfSameName PaintableBox::handle_mousemove(Badge, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) { - if (!is_scrollable()) { + if (!could_be_scrolled_by_wheel_event()) { return false; } @@ -1360,7 +1360,7 @@ PaintableBox const* PaintableBox::nearest_scrollable_ancestor() const { auto const* paintable = this->containing_block(); while (paintable) { - if (paintable->is_scrollable()) + if (paintable->could_be_scrolled_by_wheel_event()) return paintable; if (paintable->is_fixed_position()) return nullptr; diff --git a/Libraries/LibWeb/Painting/PaintableBox.h b/Libraries/LibWeb/Painting/PaintableBox.h index e67282fe460..6cc08a8754f 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.h +++ b/Libraries/LibWeb/Painting/PaintableBox.h @@ -232,7 +232,7 @@ public: StickyInsets const& sticky_insets() const { return *m_sticky_insets; } void set_sticky_insets(OwnPtr sticky_insets) { m_sticky_insets = move(sticky_insets); } - [[nodiscard]] bool is_scrollable() const; + [[nodiscard]] bool could_be_scrolled_by_wheel_event() const; void set_used_values_for_grid_template_columns(RefPtr style_value) { m_used_values_for_grid_template_columns = move(style_value); } RefPtr const& used_values_for_grid_template_columns() const { return m_used_values_for_grid_template_columns; } @@ -262,7 +262,7 @@ protected: }; Optional compute_scrollbar_data(ScrollDirection) const; [[nodiscard]] Optional scroll_thumb_rect(ScrollDirection) const; - [[nodiscard]] bool is_scrollable(ScrollDirection) const; + [[nodiscard]] bool could_be_scrolled_by_wheel_event(ScrollDirection) const; TraversalDecision hit_test_scrollbars(CSSPixelPoint position, Function const& callback) const; diff --git a/Libraries/LibWeb/Painting/ViewportPaintable.cpp b/Libraries/LibWeb/Painting/ViewportPaintable.cpp index 439071d52fe..8f0e7e2fd0c 100644 --- a/Libraries/LibWeb/Painting/ViewportPaintable.cpp +++ b/Libraries/LibWeb/Painting/ViewportPaintable.cpp @@ -194,7 +194,7 @@ void ViewportPaintable::refresh_scroll_state() CSSPixels min_x_offset_relative_to_nearest_scrollable_ancestor; CSSPixels max_x_offset_relative_to_nearest_scrollable_ancestor; auto const* containing_block_of_sticky_box = sticky_box.containing_block(); - if (containing_block_of_sticky_box->is_scrollable()) { + if (containing_block_of_sticky_box->could_be_scrolled_by_wheel_event()) { min_y_offset_relative_to_nearest_scrollable_ancestor = 0; max_y_offset_relative_to_nearest_scrollable_ancestor = containing_block_of_sticky_box->scrollable_overflow_rect()->height() - sticky_box.absolute_border_box_rect().height(); min_x_offset_relative_to_nearest_scrollable_ancestor = 0;