2022-10-05 13:23:41 +00:00
|
|
|
/*
|
2023-05-14 16:57:14 +00:00
|
|
|
* Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
|
2023-01-12 14:39:05 +00:00
|
|
|
* Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
|
2022-10-05 13:23:41 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2022-10-05 13:23:41 +00:00
|
|
|
#include <AK/Function.h>
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/URL.h>
|
2023-08-05 16:42:26 +00:00
|
|
|
#include <Ladybird/Types.h>
|
2022-10-05 13:23:41 +00:00
|
|
|
#include <LibGfx/Forward.h>
|
|
|
|
#include <LibGfx/Rect.h>
|
|
|
|
#include <LibGfx/StandardCursor.h>
|
2023-01-12 18:27:34 +00:00
|
|
|
#include <LibWeb/CSS/PreferredColorScheme.h>
|
2022-12-18 00:50:53 +00:00
|
|
|
#include <LibWeb/CSS/Selector.h>
|
2022-10-05 13:23:41 +00:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-03-20 22:39:20 +00:00
|
|
|
#include <LibWeb/HTML/ActivateTab.h>
|
2023-01-31 13:45:11 +00:00
|
|
|
#include <LibWebView/ViewImplementation.h>
|
2022-10-05 13:23:41 +00:00
|
|
|
#include <QAbstractScrollArea>
|
2023-04-29 14:49:18 +00:00
|
|
|
#include <QUrl>
|
2022-10-05 13:23:41 +00:00
|
|
|
|
2024-03-05 12:53:57 +00:00
|
|
|
class QKeyEvent;
|
2022-10-05 13:23:41 +00:00
|
|
|
class QLineEdit;
|
2024-03-05 12:53:57 +00:00
|
|
|
class QSinglePointEvent;
|
|
|
|
class QTextEdit;
|
2022-10-05 13:23:41 +00:00
|
|
|
|
|
|
|
namespace WebView {
|
|
|
|
class WebContentClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
using WebView::WebContentClient;
|
|
|
|
|
2023-08-02 17:52:59 +00:00
|
|
|
namespace Ladybird {
|
|
|
|
|
2022-10-05 13:23:41 +00:00
|
|
|
class Tab;
|
|
|
|
|
|
|
|
class WebContentView final
|
|
|
|
: public QAbstractScrollArea
|
|
|
|
, public WebView::ViewImplementation {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-01-27 04:14:41 +00:00
|
|
|
WebContentView(QWidget* window, WebContentOptions const&, StringView webdriver_content_ipc_path, RefPtr<WebView::WebContentClient> parent_client = nullptr, size_t page_index = 0);
|
2022-10-05 13:23:41 +00:00
|
|
|
virtual ~WebContentView() override;
|
|
|
|
|
2024-02-11 07:15:39 +00:00
|
|
|
Function<String(const URL&, Web::HTML::ActivateTab)> on_tab_open_request;
|
2022-10-05 13:23:41 +00:00
|
|
|
|
|
|
|
virtual void paintEvent(QPaintEvent*) override;
|
|
|
|
virtual void resizeEvent(QResizeEvent*) override;
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent*) override;
|
|
|
|
virtual void mousePressEvent(QMouseEvent*) override;
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent*) override;
|
2023-12-15 16:46:09 +00:00
|
|
|
virtual void wheelEvent(QWheelEvent*) override;
|
2023-05-13 14:55:10 +00:00
|
|
|
virtual void mouseDoubleClickEvent(QMouseEvent*) override;
|
2023-01-07 16:40:04 +00:00
|
|
|
virtual void dragEnterEvent(QDragEnterEvent*) override;
|
|
|
|
virtual void dropEvent(QDropEvent*) override;
|
2022-10-05 13:23:41 +00:00
|
|
|
virtual void keyPressEvent(QKeyEvent* event) override;
|
|
|
|
virtual void keyReleaseEvent(QKeyEvent* event) override;
|
|
|
|
virtual void showEvent(QShowEvent*) override;
|
|
|
|
virtual void hideEvent(QHideEvent*) override;
|
2022-10-11 09:38:03 +00:00
|
|
|
virtual void focusInEvent(QFocusEvent*) override;
|
|
|
|
virtual void focusOutEvent(QFocusEvent*) override;
|
2022-10-11 15:17:49 +00:00
|
|
|
virtual bool event(QEvent*) override;
|
2022-10-05 13:23:41 +00:00
|
|
|
|
2023-01-27 09:41:24 +00:00
|
|
|
ErrorOr<String> dump_layout_tree();
|
|
|
|
|
2023-01-30 20:38:19 +00:00
|
|
|
void set_viewport_rect(Gfx::IntRect);
|
2023-03-08 20:57:24 +00:00
|
|
|
void set_window_size(Gfx::IntSize);
|
|
|
|
void set_window_position(Gfx::IntPoint);
|
2023-12-13 18:10:05 +00:00
|
|
|
void set_device_pixel_ratio(double);
|
2023-01-30 20:38:19 +00:00
|
|
|
|
2023-04-23 01:57:08 +00:00
|
|
|
enum class PaletteMode {
|
|
|
|
Default,
|
|
|
|
Dark,
|
|
|
|
};
|
|
|
|
void update_palette(PaletteMode = PaletteMode::Default);
|
|
|
|
|
2024-01-31 03:05:00 +00:00
|
|
|
using ViewImplementation::client;
|
|
|
|
|
2024-03-11 02:15:06 +00:00
|
|
|
QPoint map_point_to_global_position(Gfx::IntPoint) const;
|
|
|
|
|
2022-10-05 13:23:41 +00:00
|
|
|
signals:
|
2023-01-07 16:40:04 +00:00
|
|
|
void urls_dropped(QList<QUrl> const&);
|
2022-10-05 13:23:41 +00:00
|
|
|
|
|
|
|
private:
|
2023-01-12 19:27:17 +00:00
|
|
|
// ^WebView::ViewImplementation
|
2024-01-30 16:12:14 +00:00
|
|
|
virtual void initialize_client(CreateNewClient) override;
|
2023-01-12 19:49:49 +00:00
|
|
|
virtual void update_zoom() override;
|
2023-12-14 06:17:00 +00:00
|
|
|
virtual Web::DevicePixelRect viewport_rect() const override;
|
2023-05-17 14:12:13 +00:00
|
|
|
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
|
|
|
|
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
|
2023-01-12 19:27:17 +00:00
|
|
|
|
2022-10-05 13:23:41 +00:00
|
|
|
void update_viewport_rect();
|
2023-08-23 14:43:27 +00:00
|
|
|
void update_cursor(Gfx::StandardCursor cursor);
|
2023-05-14 16:57:14 +00:00
|
|
|
|
2024-03-05 12:53:57 +00:00
|
|
|
void enqueue_native_event(Web::MouseEvent::Type, QSinglePointEvent const& event);
|
|
|
|
void enqueue_native_event(Web::KeyEvent::Type, QKeyEvent const& event);
|
|
|
|
void finish_handling_key_event(Web::KeyEvent const&);
|
|
|
|
|
2022-10-05 13:23:41 +00:00
|
|
|
bool m_should_show_line_box_borders { false };
|
|
|
|
|
|
|
|
Gfx::IntRect m_viewport_rect;
|
|
|
|
|
2023-12-01 17:18:40 +00:00
|
|
|
WebContentOptions m_web_content_options;
|
2022-12-15 14:18:52 +00:00
|
|
|
StringView m_webdriver_content_ipc_path;
|
2022-10-05 13:23:41 +00:00
|
|
|
};
|
2023-08-02 17:52:59 +00:00
|
|
|
|
|
|
|
}
|