From 80388242117f7580d7eb3db7f3e01fb01bb98bb8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 26 Mar 2023 11:56:12 +0200 Subject: [PATCH] LibWeb: Add Layout::Box::is_scroll_container() The computed `overflow` property values determine whether a box is a scroll container or not, so let's have a simple helper for asking this. --- Userland/Libraries/LibWeb/Layout/Box.cpp | 21 +++++++++++++++++++++ Userland/Libraries/LibWeb/Layout/Box.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 0ed952b402..f35239c95f 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -29,6 +29,27 @@ Box::~Box() { } +// https://www.w3.org/TR/css-overflow-3/#overflow-control +bool overflow_value_makes_box_a_scroll_container(CSS::Overflow overflow) +{ + switch (overflow) { + case CSS::Overflow::Clip: + case CSS::Overflow::Visible: + return false; + case CSS::Overflow::Auto: + case CSS::Overflow::Hidden: + case CSS::Overflow::Scroll: + return true; + } +} + +// https://www.w3.org/TR/css-overflow-3/#scroll-container +bool Box::is_scroll_container() const +{ + return overflow_value_makes_box_a_scroll_container(computed_values().overflow_x()) + || overflow_value_makes_box_a_scroll_container(computed_values().overflow_y()); +} + bool Box::is_scrollable() const { // FIXME: Support horizontal scroll as well (overflow-x) diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 7bca93cdef..be73293e23 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -42,6 +42,8 @@ public: virtual JS::GCPtr create_paintable() const override; + bool is_scroll_container() const; + bool is_scrollable() const; CSSPixelPoint scroll_offset() const { return m_scroll_offset; } void set_scroll_offset(CSSPixelPoint);