diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-21 11:16:02 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-21 13:03:33 +0100 |
commit | b64b5fa8bdb70dd95342660464d9a861abef1e6a (patch) | |
tree | c34a2674e2dda99b5f5ccc024a8f435ac45b7e31 /Userland/Libraries/LibWeb | |
parent | 0ba785894c80286c9d0374a585c2cb534b81bc55 (diff) | |
download | serenity-b64b5fa8bdb70dd95342660464d9a861abef1e6a.zip |
LibWeb: Add Painting::HitTestResult::dom_node()
This is a convenience accessor to avoid having to say this everywhere:
result.paintable->layout_node().dom_node()
Instead, you can now do:
result.dom_node()
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Page/EventHandler.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/Paintable.h | 13 |
2 files changed, 17 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 2fa1606f9a..298efdb3e4 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -301,7 +301,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt } else { if (button == GUI::MouseButton::Primary) { auto result = paint_root()->hit_test(position.to_type<float>(), Painting::HitTestType::TextCursor); - if (result.has_value() && result->paintable->layout_node().dom_node()) { + if (result.has_value() && result->dom_node()) { // See if we want to focus something. bool did_focus_something = false; @@ -316,7 +316,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt // If we didn't focus anything, place the document text cursor at the mouse position. // FIXME: This is all rather strange. Find a better solution. if (!did_focus_something) { - m_browsing_context.set_cursor_position(DOM::Position(*result->paintable->layout_node().dom_node(), result->index_in_node)); + m_browsing_context.set_cursor_position(DOM::Position(*result->dom_node(), result->index_in_node)); layout_root()->set_selection({ { result->paintable->layout_node(), result->index_in_node }, {} }); m_in_mouse_selection = true; } @@ -410,8 +410,8 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt } if (m_in_mouse_selection) { auto hit = paint_root()->hit_test(position.to_type<float>(), Painting::HitTestType::TextCursor); - if (start_index.has_value() && hit.has_value() && hit->paintable->layout_node().dom_node()) { - m_browsing_context.set_cursor_position(DOM::Position(*hit->paintable->layout_node().dom_node(), *start_index)); + if (start_index.has_value() && hit.has_value() && hit->dom_node()) { + m_browsing_context.set_cursor_position(DOM::Position(*hit->dom_node(), *start_index)); layout_root()->set_selection_end({ hit->paintable->layout_node(), hit->index_in_node }); } if (auto* page = m_browsing_context.page()) diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h index 3140c68c26..75c471d684 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.h +++ b/Userland/Libraries/LibWeb/Painting/Paintable.h @@ -32,6 +32,9 @@ struct HitTestResult { After, }; InternalPosition internal_position { None }; + + DOM::Node* dom_node(); + DOM::Node const* dom_node() const; }; enum class HitTestType { @@ -96,4 +99,14 @@ private: Optional<Layout::BlockContainer*> mutable m_containing_block; }; +inline DOM::Node* HitTestResult::dom_node() +{ + return paintable->layout_node().dom_node(); +} + +inline DOM::Node const* HitTestResult::dom_node() const +{ + return paintable->layout_node().dom_node(); +} + } |