Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/Page/EventHandler.cpp (C++)

Code before:

        if (node) {
            if (auto* navigable_container = as_if<HTML::NavigableContainer>(*node)) {
                auto position_in_navigable_container = viewport_position.translated(compute_mouse_event_offset({}, *paintable));
                auto result = navigable_container->content_navigable()->event_handler().handle_mousewheel(position_in_navigable_container, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y);
                if (result == EventResult::Handled)
                    return EventResult::Handled;
            }

            // Search for the first parent of the hit target that's an element.
            GC::Ptr<Layout::Node> layout_node;
            if (!parent_element_for_event_dispatch(*paintable, node, layout_node))
                return EventResult::Dropped;

            auto page_offset = compute_mouse_event_page_offset(viewport_position);
            auto const& offset_paintable = layout_node->first_paintable() ? layout_node->first_paintable() : paintable.ptr();
            auto offset = compute_mouse_event_offset(page_offset, *offset_paintable);
            if (node->dispatch_event(UIEvents::WheelEvent::create_from_platform_event(node->realm(), m_navigable->active_window_proxy(), UIEvents::EventNames::wheel, screen_position, page_offset, viewport_position, offset, wheel_delta_x, wheel_delta_y, button, buttons, modifiers).release_value_but_fixme_should_propagate_errors())) {
                m_navigable->scroll_viewport_by_delta({ wheel_delta_x, wheel_delta_y });
            }

            handled_event = EventResult::Handled;
        }
    }

    return handled_event;
}

EventResult EventHandler::handle_mouseup(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers)
{
    if (should_ignore_device_input_event())
        return EventResult::Dropped;

    auto document = m_navigable->active_document();
    if (!document)
        return EventResult::Dropped;
    if (!document->is_fully_active())
        return EventResult::Dropped;

    auto viewport_position = document->visual_viewport()->map_to_layout_viewport(visual_viewport_position);

    m_navigable->active_document()->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseUp);

    if (!paint_root())
        return EventResult::Dropped;

    GC::Ptr<Painting::Paintable> paintable;
    if (auto result = target_for_mouse_position(viewport_position); result.has_value())
        paintable = result->paintable;

    if (paintable && paintable->wants_mouse_events()) {

Review comment (suggestion):
Shouldn't such a logic live in `parent_element_for_event_dispatch` instead? I think we should skip over any parent element that has `display: contents`.

Code after:
                return EventResult::Handled;

            containing_block = containing_block->containing_block();
        }

        if (paintable->handle_mousewheel({}, viewport_position, buttons, modifiers, wheel_delta_x, wheel_delta_y))
            return EventResult::Handled;

        auto node = dom_node_for_event_dispatch(*paintable);

        if (node) {
            if (auto* navigable_container = as_if<HTML::NavigableContainer>(*node)) {
                auto position_in_navigable_container = viewport_position.translated(compute_mouse_event_offset({}, *paintable));
                auto result = navigable_container->content_navigable()->event_handler().handle_mousewheel(position_in_navigable_container, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y);
                if (result == EventResult::Handled)
                    return EventResult::Handled;
            }

            // Search for the first parent of the hit target that's an element.
            GC::Ptr<Layout::Node> layout_node;
            if (!parent_element_for_event_dispatch(*paintable, node, layout_node))
                return EventResult::Dropped;

            auto page_offset = compute_mouse_event_page_offset(viewport_position);
            auto const& offset_paintable = layout_node->first_paintable() ? layout_node->first_paintable() : paintable.ptr();
            auto offset = compute_mouse_event_offset(page_offset, *offset_paintable);
            if (node->dispatch_event(UIEvents::WheelEvent::create_from_platform_event(node->realm(), m_navigable->active_window_proxy(), UIEvents::EventNames::wheel, screen_position, page_offset, viewport_position, offset, wheel_delta_x, wheel_delta_y, button, buttons, modifiers).release_value_but_fixme_should_propagate_errors())) {
                m_navigable->scroll_viewport_by_delta({ wheel_delta_x, wheel_delta_y });
            }

            handled_event = EventResult::Handled;
        }
    }

    return handled_event;
}

EventResult EventHandler::handle_mouseup(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers)
{
    if (should_ignore_device_input_event())
        return EventResult::Dropped;

    auto document = m_navigable->active_document();
    if (!document)
        return EventResult::Dropped;
    if (!document->is_fully_active())
        return EventResult::Dropped;

    auto viewport_position = document->visual_viewport()->map_to_layout_viewport(visual_viewport_position);

    m_navigable->active_document()->update_layout(DOM::UpdateLayoutReason::EventHandlerHandleMouseUp);