| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-05-14 18:57:14 +02: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 15:23:41 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  | #include <AK/ByteString.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | #include <AK/Function.h>
 | 
					
						
							|  |  |  | #include <AK/HashMap.h>
 | 
					
						
							|  |  |  | #include <AK/OwnPtr.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Forward.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Rect.h>
 | 
					
						
							|  |  |  | #include <LibGfx/StandardCursor.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | #include <LibURL/URL.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-12 18:27:34 +00:00
										 |  |  | #include <LibWeb/CSS/PreferredColorScheme.h>
 | 
					
						
							| 
									
										
										
										
											2024-06-13 01:03:56 +02:00
										 |  |  | #include <LibWeb/CSS/PreferredContrast.h>
 | 
					
						
							| 
									
										
										
										
											2022-12-18 00:50:53 +00:00
										 |  |  | #include <LibWeb/CSS/Selector.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-20 18:39:20 -04:00
										 |  |  | #include <LibWeb/HTML/ActivateTab.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-31 08:45:11 -05:00
										 |  |  | #include <LibWebView/ViewImplementation.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | #include <QAbstractScrollArea>
 | 
					
						
							| 
									
										
										
										
											2024-07-02 14:16:24 +02:00
										 |  |  | #include <QTimer>
 | 
					
						
							| 
									
										
										
										
											2023-04-29 08:49:18 -06:00
										 |  |  | #include <QUrl>
 | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 07:53:57 -05:00
										 |  |  | class QKeyEvent; | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | class QLineEdit; | 
					
						
							| 
									
										
										
										
											2024-03-05 07:53:57 -05:00
										 |  |  | class QSinglePointEvent; | 
					
						
							|  |  |  | class QTextEdit; | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace WebView { | 
					
						
							|  |  |  | class WebContentClient; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using WebView::WebContentClient; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 11:52:59 -06:00
										 |  |  | namespace Ladybird { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | class Tab; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WebContentView final | 
					
						
							|  |  |  |     : public QAbstractScrollArea | 
					
						
							|  |  |  |     , public WebView::ViewImplementation { | 
					
						
							|  |  |  |     Q_OBJECT | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-07-30 14:01:05 -04:00
										 |  |  |     WebContentView(QWidget* window, RefPtr<WebView::WebContentClient> parent_client = nullptr, size_t page_index = 0); | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  |     virtual ~WebContentView() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     Function<String(const URL::URL&, Web::HTML::ActivateTab)> on_tab_open_request; | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02: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 17:46:09 +01:00
										 |  |  |     virtual void wheelEvent(QWheelEvent*) override; | 
					
						
							| 
									
										
										
										
											2023-05-13 15:55:10 +01:00
										 |  |  |     virtual void mouseDoubleClickEvent(QMouseEvent*) override; | 
					
						
							| 
									
										
										
										
											2023-01-07 17:40:04 +01:00
										 |  |  |     virtual void dragEnterEvent(QDragEnterEvent*) override; | 
					
						
							| 
									
										
										
										
											2024-08-17 14:47:28 -04:00
										 |  |  |     virtual void dragMoveEvent(QDragMoveEvent*) override; | 
					
						
							|  |  |  |     virtual void dragLeaveEvent(QDragLeaveEvent*) override; | 
					
						
							| 
									
										
										
										
											2023-01-07 17:40:04 +01:00
										 |  |  |     virtual void dropEvent(QDropEvent*) override; | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  |     virtual void keyPressEvent(QKeyEvent* event) override; | 
					
						
							|  |  |  |     virtual void keyReleaseEvent(QKeyEvent* event) override; | 
					
						
							| 
									
										
										
										
											2024-08-12 14:06:41 +02:00
										 |  |  |     virtual void inputMethodEvent(QInputMethodEvent*) override; | 
					
						
							|  |  |  |     virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const override; | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  |     virtual void showEvent(QShowEvent*) override; | 
					
						
							|  |  |  |     virtual void hideEvent(QHideEvent*) override; | 
					
						
							| 
									
										
										
										
											2022-10-11 11:38:03 +02:00
										 |  |  |     virtual void focusInEvent(QFocusEvent*) override; | 
					
						
							|  |  |  |     virtual void focusOutEvent(QFocusEvent*) override; | 
					
						
							| 
									
										
										
										
											2022-10-11 17:17:49 +02:00
										 |  |  |     virtual bool event(QEvent*) override; | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-27 10:41:24 +01:00
										 |  |  |     ErrorOr<String> dump_layout_tree(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-30 23:38:19 +03:00
										 |  |  |     void set_viewport_rect(Gfx::IntRect); | 
					
						
							| 
									
										
										
										
											2023-03-08 23:57:24 +03:00
										 |  |  |     void set_window_size(Gfx::IntSize); | 
					
						
							|  |  |  |     void set_window_position(Gfx::IntPoint); | 
					
						
							| 
									
										
										
										
											2023-12-13 19:10:05 +01:00
										 |  |  |     void set_device_pixel_ratio(double); | 
					
						
							| 
									
										
										
										
											2023-01-30 23:38:19 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-22 21:57:08 -04:00
										 |  |  |     enum class PaletteMode { | 
					
						
							|  |  |  |         Default, | 
					
						
							|  |  |  |         Dark, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     void update_palette(PaletteMode = PaletteMode::Default); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-30 20:05:00 -07:00
										 |  |  |     using ViewImplementation::client; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-10 22:15:06 -04:00
										 |  |  |     QPoint map_point_to_global_position(Gfx::IntPoint) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | signals: | 
					
						
							| 
									
										
										
										
											2023-01-07 17:40:04 +01:00
										 |  |  |     void urls_dropped(QList<QUrl> const&); | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-01-12 19:27:17 +00:00
										 |  |  |     // ^WebView::ViewImplementation
 | 
					
						
							| 
									
										
										
										
											2024-01-30 09:12:14 -07:00
										 |  |  |     virtual void initialize_client(CreateNewClient) override; | 
					
						
							| 
									
										
										
										
											2023-01-12 19:49:49 +00:00
										 |  |  |     virtual void update_zoom() override; | 
					
						
							| 
									
										
										
										
											2024-06-03 17:53:55 +03:00
										 |  |  |     virtual Web::DevicePixelSize viewport_size() const override; | 
					
						
							| 
									
										
										
										
											2023-05-17 10:12:13 -04: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-03 17:53:55 +03:00
										 |  |  |     void update_viewport_size(); | 
					
						
							| 
									
										
										
										
											2023-08-23 10:43:27 -04:00
										 |  |  |     void update_cursor(Gfx::StandardCursor cursor); | 
					
						
							| 
									
										
										
										
											2023-05-14 18:57:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 07:53:57 -05:00
										 |  |  |     void enqueue_native_event(Web::MouseEvent::Type, QSinglePointEvent const& event); | 
					
						
							| 
									
										
										
										
											2024-08-17 14:47:28 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void enqueue_native_event(Web::DragEvent::Type, QDropEvent const& event); | 
					
						
							|  |  |  |     void finish_handling_drag_event(Web::DragEvent const&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-05 07:53:57 -05:00
										 |  |  |     void enqueue_native_event(Web::KeyEvent::Type, QKeyEvent const& event); | 
					
						
							|  |  |  |     void finish_handling_key_event(Web::KeyEvent const&); | 
					
						
							| 
									
										
										
										
											2024-08-17 14:47:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-11 15:00:00 +12:00
										 |  |  |     void update_screen_rects(); | 
					
						
							| 
									
										
										
										
											2024-03-05 07:53:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-02 16:48:57 +02:00
										 |  |  |     bool m_tooltip_override { false }; | 
					
						
							| 
									
										
										
										
											2024-07-02 14:16:24 +02:00
										 |  |  |     Optional<ByteString> m_tooltip_text; | 
					
						
							|  |  |  |     QTimer m_tooltip_hover_timer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  |     bool m_should_show_line_box_borders { false }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-03 17:53:55 +03:00
										 |  |  |     Gfx::IntSize m_viewport_size; | 
					
						
							| 
									
										
										
										
											2022-10-05 15:23:41 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2023-08-02 11:52:59 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |