/* * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include namespace Web::Painting { NonnullRefPtr TextPaintable::create(Layout::TextNode const& layout_node) { return adopt_ref(*new TextPaintable(layout_node)); } TextPaintable::TextPaintable(Layout::TextNode const& layout_node) : Paintable(layout_node) { } bool TextPaintable::wants_mouse_events() const { return layout_node().first_ancestor_of_type(); } void TextPaintable::handle_mousedown(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) { auto* label = layout_node().first_ancestor_of_type(); if (!label) return; const_cast(label)->handle_mousedown_on_label({}, position, button); const_cast(browsing_context()).event_handler().set_mouse_event_tracking_layout_node(&const_cast(layout_node())); } void TextPaintable::handle_mouseup(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) { auto* label = layout_node().first_ancestor_of_type(); if (!label) return; // NOTE: Changing the state of the DOM node may run arbitrary JS, which could disappear this node. NonnullRefPtr protect = *this; const_cast(label)->handle_mouseup_on_label({}, position, button); const_cast(browsing_context()).event_handler().set_mouse_event_tracking_layout_node(nullptr); } void TextPaintable::handle_mousemove(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) { auto* label = layout_node().first_ancestor_of_type(); if (!label) return; const_cast(label)->handle_mousemove_on_label({}, position, button); } }