From ce44d9a32f4ad714d87e8680bad149b2807b9fae Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 17 Sep 2019 20:58:13 +0200 Subject: [PATCH] GWidget: Add a flag to ignore greediness in GWidget::hit_test() Normally if a GWidget has the is_greedy_for_hits() flag set, all hit tests will hit the widget itself instead of its descendants. Sometimes it may be desirable to override this behavior, and so this flag now allows you to do that. --- Libraries/LibGUI/GWidget.cpp | 4 ++-- Libraries/LibGUI/GWidget.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Libraries/LibGUI/GWidget.cpp b/Libraries/LibGUI/GWidget.cpp index ff67d00b09..6d84f2f12e 100644 --- a/Libraries/LibGUI/GWidget.cpp +++ b/Libraries/LibGUI/GWidget.cpp @@ -333,9 +333,9 @@ GWidget* GWidget::child_at(const Point& point) const return nullptr; } -GWidget::HitTestResult GWidget::hit_test(const Point& position) +GWidget::HitTestResult GWidget::hit_test(const Point& position, ShouldRespectGreediness should_respect_greediness) { - if (is_greedy_for_hits()) + if (should_respect_greediness == ShouldRespectGreediness::Yes && is_greedy_for_hits()) return { this, position }; if (auto* child = child_at(position)) return child->hit_test(position - child->relative_position()); diff --git a/Libraries/LibGUI/GWidget.h b/Libraries/LibGUI/GWidget.h index 0016990040..ef489af01b 100644 --- a/Libraries/LibGUI/GWidget.h +++ b/Libraries/LibGUI/GWidget.h @@ -119,11 +119,12 @@ public: bool is_focused() const; void set_focus(bool); + enum class ShouldRespectGreediness { No = 0, Yes }; struct HitTestResult { GWidget* widget { nullptr }; Point local_position; }; - HitTestResult hit_test(const Point&); + HitTestResult hit_test(const Point&, ShouldRespectGreediness = ShouldRespectGreediness::Yes); GWidget* child_at(const Point&) const; void set_relative_rect(const Rect&);