diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index c1b2a1ad07b..efc08803405 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -1867,7 +1867,7 @@ void Element::set_scroll_left(double x) // FIXME: Implement this in terms of calling "scroll the element". auto scroll_offset = paintable_box()->scroll_offset(); scroll_offset.set_x(CSSPixels::nearest_value_for(x)); - paintable_box()->set_scroll_offset(scroll_offset); + (void)paintable_box()->set_scroll_offset(scroll_offset); } void Element::set_scroll_top(double y) @@ -1924,7 +1924,7 @@ void Element::set_scroll_top(double y) // FIXME: Implement this in terms of calling "scroll the element". auto scroll_offset = paintable_box()->scroll_offset(); scroll_offset.set_y(CSSPixels::nearest_value_for(y)); - paintable_box()->set_scroll_offset(scroll_offset); + (void)paintable_box()->set_scroll_offset(scroll_offset); } // https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth @@ -3144,7 +3144,7 @@ void Element::scroll(double x, double y) auto scroll_offset = paintable_box()->scroll_offset(); scroll_offset.set_x(CSSPixels::nearest_value_for(x)); scroll_offset.set_y(CSSPixels::nearest_value_for(y)); - paintable_box()->set_scroll_offset(scroll_offset); + (void)paintable_box()->set_scroll_offset(scroll_offset); } // https://drafts.csswg.org/cssom-view/#dom-element-scroll diff --git a/Libraries/LibWeb/Layout/LayoutState.cpp b/Libraries/LibWeb/Layout/LayoutState.cpp index 453ea1ced74..4fb2291f79c 100644 --- a/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Libraries/LibWeb/Layout/LayoutState.cpp @@ -433,7 +433,7 @@ void LayoutState::commit(Box& root) // (scrollable overflow rect become smaller), the scroll offset would be out of bounds. auto& paintable_box = const_cast(*box->paintable_box()); if (!paintable_box.scroll_offset().is_zero()) - paintable_box.set_scroll_offset(paintable_box.scroll_offset()); + (void)paintable_box.set_scroll_offset(paintable_box.scroll_offset()); } for (auto& it : used_values_per_layout_node) { diff --git a/Libraries/LibWeb/Painting/PaintableBox.cpp b/Libraries/LibWeb/Painting/PaintableBox.cpp index 1df4f4391fc..32af45c4b1b 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -111,11 +111,11 @@ CSSPixelPoint PaintableBox::scroll_offset() const return static_cast(dom_node())->scroll_offset({}); } -void PaintableBox::set_scroll_offset(CSSPixelPoint offset) +PaintableBox::ScrollHandled PaintableBox::set_scroll_offset(CSSPixelPoint offset) { auto scrollable_overflow_rect = this->scrollable_overflow_rect(); if (!scrollable_overflow_rect.has_value()) - return; + return ScrollHandled::No; document().set_needs_to_refresh_scroll_state(true); @@ -128,7 +128,7 @@ void PaintableBox::set_scroll_offset(CSSPixelPoint offset) // FIXME: If there is horizontal and vertical scroll ignore only part of the new offset if (offset.y() < 0 || scroll_offset() == offset) - return; + return ScrollHandled::No; auto& node = layout_node(); if (auto pseudo_element = node.generated_for_pseudo_element(); pseudo_element.has_value()) { @@ -136,7 +136,7 @@ void PaintableBox::set_scroll_offset(CSSPixelPoint offset) } else if (auto* element = as_if(dom_node())) { element->set_scroll_offset({}, offset); } else { - return; + return ScrollHandled::No; } // https://drafts.csswg.org/cssom-view-1/#scrolling-events @@ -154,17 +154,18 @@ void PaintableBox::set_scroll_offset(CSSPixelPoint offset) // 3. If the element is already in doc’s pending scroll event targets, abort these steps. if (document.pending_scroll_event_targets().contains_slow(event_target)) - return; + return ScrollHandled::Yes; // 4. Append the element to doc’s pending scroll event targets. document.pending_scroll_event_targets().append(*layout_node_with_style_and_box_metrics().dom_node()); set_needs_display(InvalidateDisplayList::No); + return ScrollHandled::Yes; } -void PaintableBox::scroll_by(int delta_x, int delta_y) +PaintableBox::ScrollHandled PaintableBox::scroll_by(int delta_x, int delta_y) { - set_scroll_offset(scroll_offset().translated(delta_x, delta_y)); + return set_scroll_offset(scroll_offset().translated(delta_x, delta_y)); } void PaintableBox::set_offset(CSSPixelPoint offset) @@ -1163,7 +1164,7 @@ void PaintableBox::scroll_to_mouse_position(CSSPixelPoint position) if (is_viewport()) document().navigable()->perform_scroll_of_viewport(new_scroll_offset); else - set_scroll_offset(new_scroll_offset); + (void)set_scroll_offset(new_scroll_offset); } bool PaintableBox::handle_mousewheel(Badge, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) @@ -1173,8 +1174,8 @@ bool PaintableBox::handle_mousewheel(Badge, CSSPixelPoint, unsigne return false; } - scroll_by(wheel_delta_x, wheel_delta_y); - return true; + auto scroll_handled = scroll_by(wheel_delta_x, wheel_delta_y); + return scroll_handled == ScrollHandled::Yes; } TraversalDecision PaintableBox::hit_test_scrollbars(CSSPixelPoint position, Function const& callback) const diff --git a/Libraries/LibWeb/Painting/PaintableBox.h b/Libraries/LibWeb/Painting/PaintableBox.h index a6cbb0ecbd9..06ecc8e2517 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.h +++ b/Libraries/LibWeb/Painting/PaintableBox.h @@ -63,9 +63,14 @@ public: // Offset from the top left of the containing block's content edge. [[nodiscard]] CSSPixelPoint offset() const; + enum class ScrollHandled { + No, + Yes, + }; + CSSPixelPoint scroll_offset() const; - void set_scroll_offset(CSSPixelPoint); - void scroll_by(int delta_x, int delta_y); + [[nodiscard]] ScrollHandled set_scroll_offset(CSSPixelPoint); + [[nodiscard]] ScrollHandled scroll_by(int delta_x, int delta_y); void set_offset(CSSPixelPoint); void set_offset(float x, float y) { set_offset({ x, y }); }