diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-28 17:08:42 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-28 17:09:51 +0200 |
commit | ec49c8fefd594e4c1393f5026896828634b86cf0 (patch) | |
tree | 1d16f9b61f7f6a03a31c089298dc87e282e8b10d /Userland/Libraries | |
parent | df3cd2fd569a880d918bb52dd850846f8fca539a (diff) | |
download | serenity-ec49c8fefd594e4c1393f5026896828634b86cf0.zip |
LibWeb: Clip descendants of boxes with overflow:hidden
This is a very limited implementation of overflow:hidden, but since it's
easy to cover this common scenario, let's do it.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.h | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 066386af5f..2423679d72 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -234,4 +234,22 @@ StackingContext* Box::enclosing_stacking_context() VERIFY_NOT_REACHED(); } +void Box::before_children_paint(PaintContext& context, PaintPhase phase) +{ + NodeWithStyleAndBoxModelMetrics::before_children_paint(context, phase); + // FIXME: Support more overflow variations. + if (computed_values().overflow_x() == CSS::Overflow::Hidden && computed_values().overflow_y() == CSS::Overflow::Hidden) { + context.painter().save(); + context.painter().add_clip_rect(enclosing_int_rect(bordered_rect())); + } +} + +void Box::after_children_paint(PaintContext& context, PaintPhase phase) +{ + NodeWithStyleAndBoxModelMetrics::after_children_paint(context, phase); + // FIXME: Support more overflow variations. + if (computed_values().overflow_x() == CSS::Overflow::Hidden && computed_values().overflow_y() == CSS::Overflow::Hidden) + context.painter().restore(); +} + } diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 1dc913aac4..dc7ecee20b 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -150,6 +150,9 @@ public: void clear_overflow_data() { m_overflow_data = nullptr; } + virtual void before_children_paint(PaintContext&, PaintPhase); + virtual void after_children_paint(PaintContext&, PaintPhase); + protected: Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style) : NodeWithStyleAndBoxModelMetrics(document, node, move(style)) |