1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 07:44:59 +00:00
serenity/Userland/Libraries/LibWebView/OutOfProcessWebView.h
Timothy Flynn ea682207d0 LibWeb+LibWebView: Migrate Browser's input event handling to LibWebView
The Serenity chrome is the only chrome thus far that sends all input key
and mouse events to WebContent, including shortcut activations. This is
necessary for all chromes - we must give web pages a chance to intercept
input events before handling them ourselves.

To make this easier for other chromes, this patch moves Serenity's input
event handling to LibWebView. To do so, we add the Web::InputEvent type,
which models the event data we need within LibWeb. Chromes will then be
responsible for converting between this type and their native events.

This class lives in LibWeb (rather than LibWebView) because the plan is
to use it wholesale throughout the Page's event handler and across IPC.
Right now, we still send the individual fields of the event over IPC,
but it will be an easy refactor to send the event itself. We just can't
do this until all chromes have been ported to this event queueing.

Also note that we now only handle key input events back in the chrome.
WebContent handles all mouse events that it possibly can. If it was not
able to handle a mouse event, there's nothing for the chrome to do (i.e.
there is no clicking, scrolling, etc. the chrome is able to do if the
WebContent couldn't).
2024-03-06 07:46:18 +01:00

94 lines
3.3 KiB
C++

/*
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/URL.h>
#include <LibGUI/AbstractScrollableWidget.h>
#include <LibGUI/Widget.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/Page/Page.h>
#include <LibWebView/ViewImplementation.h>
namespace Messages::WebContentServer {
class WebdriverExecuteScriptResponse;
}
namespace WebView {
class WebContentClient;
class OutOfProcessWebView final
: public GUI::AbstractScrollableWidget
, public ViewImplementation {
C_OBJECT(OutOfProcessWebView);
using Super = GUI::AbstractScrollableWidget;
public:
virtual ~OutOfProcessWebView() override;
ByteString dump_layout_tree();
OrderedHashMap<String, String> get_local_storage_entries();
OrderedHashMap<String, String> get_session_storage_entries();
void set_content_filters(Vector<String>);
void set_autoplay_allowed_on_all_websites();
void set_autoplay_allowlist(Vector<String>);
void set_proxy_mappings(Vector<ByteString> proxies, HashMap<ByteString, size_t> mappings);
void connect_to_webdriver(ByteString const& webdriver_ipc_path);
void set_window_position(Gfx::IntPoint);
void set_window_size(Gfx::IntSize);
void set_system_visibility_state(bool visible);
// This is a hint that tells OOPWV that the content will scale to the viewport size.
// In practice, this means that OOPWV may render scaled stale versions of the content while resizing.
void set_content_scales_to_viewport(bool);
private:
OutOfProcessWebView();
// ^Widget
virtual void paint_event(GUI::PaintEvent&) override;
virtual void resize_event(GUI::ResizeEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void mousewheel_event(GUI::MouseEvent&) override;
virtual void doubleclick_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void keyup_event(GUI::KeyEvent&) override;
virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
virtual void focusin_event(GUI::FocusEvent&) override;
virtual void focusout_event(GUI::FocusEvent&) override;
virtual void show_event(GUI::ShowEvent&) override;
virtual void hide_event(GUI::HideEvent&) override;
// ^AbstractScrollableWidget
virtual void did_scroll() override;
// ^WebView::ViewImplementation
virtual void initialize_client(CreateNewClient) override;
virtual void update_zoom() override;
virtual Web::DevicePixelRect viewport_rect() const override;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
void enqueue_native_event(Web::MouseEvent::Type, GUI::MouseEvent const& event);
void enqueue_native_event(Web::KeyEvent::Type, GUI::KeyEvent const& event);
void finish_handling_key_event(Web::KeyEvent const&);
bool m_content_scales_to_viewport { false };
};
}