diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-22 23:44:51 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-22 23:44:51 +0100 |
commit | 82278d632f4305da9867c37c2101bf99565e7172 (patch) | |
tree | 98fec7c2257edb07a4e33e6c09cabf8a1c867b34 | |
parent | c9cd96894b7cb1aae19914e848bb5884e6ebbe92 (diff) | |
download | serenity-82278d632f4305da9867c37c2101bf99565e7172.zip |
LibWeb: Only scroll BlockBox on wheel event if overflow==scroll
We implement this by adding a BlockBox::is_scrollable() helper,
and then ignoring wheel events for non-scrollable boxes.
Thanks to FireFox317 for pointing this out! :^)
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockBox.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockBox.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 2 |
3 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp index a23d33d1e2..d46b743721 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp @@ -142,6 +142,12 @@ void BlockBox::split_into_lines(InlineFormattingContext& context, LayoutMode lay line_box->add_fragment(*this, 0, 0, border_box_width(), height()); } +bool BlockBox::is_scrollable() const +{ + // FIXME: Support horizontal scroll as well (overflow-x) + return computed_values().overflow_y() == CSS::Overflow::Scroll; +} + void BlockBox::set_scroll_offset(const Gfx::FloatPoint& offset) { if (m_scroll_offset == offset) @@ -152,6 +158,8 @@ void BlockBox::set_scroll_offset(const Gfx::FloatPoint& offset) void BlockBox::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta) { + if (!is_scrollable()) + return; auto new_offset = m_scroll_offset; new_offset.move_by(0, wheel_delta); set_scroll_offset(new_offset); diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.h b/Userland/Libraries/LibWeb/Layout/BlockBox.h index 470b78ad64..5d6951a0e0 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockBox.h +++ b/Userland/Libraries/LibWeb/Layout/BlockBox.h @@ -53,6 +53,7 @@ public: virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override; + bool is_scrollable() const; const Gfx::FloatPoint& scroll_offset() const { return m_scroll_offset; } void set_scroll_offset(const Gfx::FloatPoint&); diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 0893fb3416..e62a688513 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -321,6 +321,8 @@ void Node::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, void Node::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned, int wheel_delta) { if (auto* containing_block = this->containing_block()) { + if (!containing_block->is_scrollable()) + return; auto new_offset = containing_block->scroll_offset(); new_offset.move_by(0, wheel_delta); containing_block->set_scroll_offset(new_offset); |