2022-07-05 23:18:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2023-01-12 14:39:53 +00:00
|
|
|
* Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
|
2022-07-05 23:18:21 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2022-12-05 13:09:42 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-07-05 18:42:45 +01:00
|
|
|
#include <LibCore/Forward.h>
|
2023-03-20 18:39:20 -04:00
|
|
|
#include <LibWeb/HTML/ActivateTab.h>
|
2024-03-28 11:16:10 -04:00
|
|
|
#include <LibWeb/HTML/AudioPlayState.h>
|
2023-08-31 07:07:07 -04:00
|
|
|
#include <LibWebView/Forward.h>
|
2024-11-09 12:50:33 -05:00
|
|
|
#include <UI/Qt/FindInPageWidget.h>
|
|
|
|
|
#include <UI/Qt/Tab.h>
|
|
|
|
|
|
2022-07-05 05:53:11 +01:00
|
|
|
#include <QIcon>
|
2022-07-03 21:26:51 +02:00
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QMainWindow>
|
2022-07-05 23:18:21 +01:00
|
|
|
#include <QMenuBar>
|
2025-03-30 15:04:14 -04:00
|
|
|
#include <QTabBar>
|
2022-07-05 23:18:21 +01:00
|
|
|
#include <QTabWidget>
|
2022-07-03 21:26:51 +02:00
|
|
|
#include <QToolBar>
|
|
|
|
|
|
2023-08-02 11:52:59 -06:00
|
|
|
namespace Ladybird {
|
|
|
|
|
|
|
|
|
|
class WebContentView;
|
|
|
|
|
|
2022-07-03 21:26:51 +02:00
|
|
|
class BrowserWindow : public QMainWindow {
|
|
|
|
|
Q_OBJECT
|
2023-12-01 12:18:40 -05:00
|
|
|
|
2022-07-03 21:26:51 +02:00
|
|
|
public:
|
2024-07-27 11:38:39 +01:00
|
|
|
enum class IsPopupWindow {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-05 18:19:51 -04:00
|
|
|
BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow is_popup_window = IsPopupWindow::No, Tab* parent_tab = nullptr, Optional<u64> page_index = {});
|
2022-07-03 21:26:51 +02:00
|
|
|
|
2022-10-05 15:23:41 +02:00
|
|
|
WebContentView& view() const { return m_current_tab->view(); }
|
2022-07-03 21:26:51 +02:00
|
|
|
|
2024-04-28 15:07:23 +01:00
|
|
|
int tab_count() { return m_tabs_container->count(); }
|
2022-07-05 23:18:21 +01:00
|
|
|
int tab_index(Tab*);
|
2024-04-26 15:23:20 -06:00
|
|
|
Tab& create_new_tab(Web::HTML::ActivateTab activate_tab);
|
2022-07-05 18:42:45 +01:00
|
|
|
|
2024-05-05 16:11:51 +01:00
|
|
|
QMenu& hamburger_menu()
|
|
|
|
|
{
|
|
|
|
|
return *m_hamburger_menu;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-13 13:07:12 +01:00
|
|
|
QAction& go_back_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_go_back_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction& go_forward_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_go_forward_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction& reload_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_reload_action;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 07:21:48 -04:00
|
|
|
QAction& new_tab_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_new_tab_action;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 18:53:55 -06:00
|
|
|
QAction& new_window_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_new_window_action;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-15 11:49:44 -04:00
|
|
|
QAction& copy_selection_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_copy_selection_action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction& select_all_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_select_all_action;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-29 20:12:21 +01:00
|
|
|
QAction& find_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_find_in_page_action;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-22 11:56:49 +01:00
|
|
|
QAction& paste_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_paste_action;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-15 11:49:44 -04:00
|
|
|
QAction& view_source_action()
|
|
|
|
|
{
|
|
|
|
|
return *m_view_source_action;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-07 23:39:25 +01:00
|
|
|
Tab* current_tab() const { return m_current_tab; }
|
|
|
|
|
|
2025-07-25 16:43:27 +01:00
|
|
|
double refresh_rate() const { return m_refresh_rate; }
|
|
|
|
|
|
2022-07-05 21:10:50 +02:00
|
|
|
public slots:
|
2023-12-13 19:10:05 +01:00
|
|
|
void device_pixel_ratio_changed(qreal dpi);
|
2025-07-25 16:43:27 +01:00
|
|
|
void refresh_rate_changed(qreal refresh_rate);
|
2022-07-05 23:18:21 +01:00
|
|
|
void tab_title_changed(int index, QString const&);
|
2023-05-29 19:05:40 +10:00
|
|
|
void tab_favicon_changed(int index, QIcon const& icon);
|
2024-03-28 11:16:10 -04:00
|
|
|
void tab_audio_play_state_changed(int index, Web::HTML::AudioPlayState);
|
2024-04-14 00:05:47 +02:00
|
|
|
void tab_navigation_buttons_state_changed(int index);
|
2024-03-18 16:22:27 +13:00
|
|
|
Tab& new_tab_from_url(URL::URL const&, Web::HTML::ActivateTab);
|
2024-01-30 18:52:59 -07:00
|
|
|
Tab& new_tab_from_content(StringView html, Web::HTML::ActivateTab);
|
2024-05-28 13:27:57 -06:00
|
|
|
Tab& new_child_tab(Web::HTML::ActivateTab, Tab& parent, Optional<u64> page_index);
|
2023-03-20 19:52:00 -04:00
|
|
|
void activate_tab(int index);
|
2022-07-06 14:36:49 +01:00
|
|
|
void close_tab(int index);
|
2024-04-28 15:07:23 +01:00
|
|
|
void move_tab(int old_index, int new_index);
|
2022-07-19 06:16:46 -04:00
|
|
|
void close_current_tab();
|
2022-09-12 09:22:43 +02:00
|
|
|
void open_next_tab();
|
|
|
|
|
void open_previous_tab();
|
2023-05-25 23:47:12 +02:00
|
|
|
void open_file();
|
2024-06-13 01:03:56 +02:00
|
|
|
void enable_auto_contrast();
|
|
|
|
|
void enable_less_contrast();
|
|
|
|
|
void enable_more_contrast();
|
|
|
|
|
void enable_no_preference_contrast();
|
2024-06-13 16:15:59 +02:00
|
|
|
void enable_auto_motion();
|
|
|
|
|
void enable_no_preference_motion();
|
|
|
|
|
void enable_reduce_motion();
|
2023-01-12 14:39:53 +00:00
|
|
|
void zoom_in();
|
|
|
|
|
void zoom_out();
|
|
|
|
|
void reset_zoom();
|
2023-08-04 13:37:52 +02:00
|
|
|
void update_zoom_menu();
|
2024-12-23 22:15:06 +01:00
|
|
|
void update_displayed_zoom_level();
|
2023-01-11 20:09:52 +01:00
|
|
|
void select_all();
|
2024-05-29 20:12:21 +01:00
|
|
|
void show_find_in_page();
|
2024-03-22 11:56:49 +01:00
|
|
|
void paste();
|
2023-01-11 20:09:52 +01:00
|
|
|
void copy_selected_text();
|
2022-07-05 21:10:50 +02:00
|
|
|
|
2023-02-05 03:26:20 +01:00
|
|
|
protected:
|
2023-03-08 23:57:24 +03:00
|
|
|
bool eventFilter(QObject* obj, QEvent* event) override;
|
2023-02-05 03:26:20 +01:00
|
|
|
|
2022-07-03 21:26:51 +02:00
|
|
|
private:
|
2024-01-26 23:14:41 -05:00
|
|
|
virtual bool event(QEvent*) override;
|
2023-03-08 23:57:24 +03:00
|
|
|
virtual void resizeEvent(QResizeEvent*) override;
|
|
|
|
|
virtual void moveEvent(QMoveEvent*) override;
|
2023-06-30 17:33:04 -05:00
|
|
|
virtual void wheelEvent(QWheelEvent*) override;
|
2023-08-09 12:23:32 +02:00
|
|
|
virtual void closeEvent(QCloseEvent*) override;
|
2023-03-08 23:57:24 +03:00
|
|
|
|
2024-05-28 13:27:57 -06:00
|
|
|
Tab& create_new_tab(Web::HTML::ActivateTab, Tab& parent, Optional<u64> page_index);
|
2024-01-30 20:05:00 -07:00
|
|
|
void initialize_tab(Tab*);
|
2023-08-28 16:14:34 -04:00
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
void debug_request(ByteString const& request, ByteString const& argument = "");
|
2022-07-08 14:14:40 +02:00
|
|
|
|
2023-03-26 18:56:17 +01:00
|
|
|
void set_current_tab(Tab* tab);
|
|
|
|
|
|
2023-12-04 09:39:22 -05:00
|
|
|
template<typename Callback>
|
|
|
|
|
void for_each_tab(Callback&& callback)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_tabs_container->count(); ++i) {
|
2025-01-21 09:12:05 -05:00
|
|
|
auto& tab = as<Tab>(*m_tabs_container->widget(i));
|
2023-12-04 09:39:22 -05:00
|
|
|
callback(tab);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 21:35:52 -04:00
|
|
|
void create_close_button_for_tab(Tab*);
|
|
|
|
|
|
2024-03-30 18:36:26 -04:00
|
|
|
QIcon icon_for_page_mute_state(Tab&) const;
|
|
|
|
|
QString tool_tip_for_page_mute_state(Tab&) const;
|
2024-03-30 18:47:50 -04:00
|
|
|
QTabBar::ButtonPosition audio_button_position_for_tab(int tab_index) const;
|
2024-03-30 09:48:33 -04:00
|
|
|
|
2024-05-28 13:27:57 -06:00
|
|
|
void set_window_rect(Optional<Web::DevicePixels> x, Optional<Web::DevicePixels> y, Optional<Web::DevicePixels> width, Optional<Web::DevicePixels> height);
|
|
|
|
|
|
2024-06-06 00:07:10 +01:00
|
|
|
ByteString user_agent_string() const { return m_user_agent_string; }
|
|
|
|
|
void set_user_agent_string(ByteString const& user_agent_string) { m_user_agent_string = user_agent_string; }
|
2024-07-02 19:28:39 +01:00
|
|
|
ByteString navigator_compatibility_mode() const { return m_navigator_compatibility_mode; }
|
|
|
|
|
void set_navigator_compatibility_mode(ByteString const& navigator_compatibility_mode) { m_navigator_compatibility_mode = navigator_compatibility_mode; }
|
2024-06-06 00:07:10 +01:00
|
|
|
|
2023-12-13 19:10:05 +01:00
|
|
|
QScreen* m_current_screen;
|
|
|
|
|
double m_device_pixel_ratio { 0 };
|
2025-07-25 16:43:27 +01:00
|
|
|
double m_refresh_rate { 60.0 };
|
2023-12-13 19:10:05 +01:00
|
|
|
|
2024-07-06 15:19:09 -03:00
|
|
|
Web::CSS::PreferredColorScheme m_preferred_color_scheme;
|
|
|
|
|
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme);
|
|
|
|
|
|
2025-03-15 10:10:25 -04:00
|
|
|
void devtools_disabled();
|
|
|
|
|
void devtools_enabled();
|
|
|
|
|
|
2022-07-05 23:18:21 +01:00
|
|
|
QTabWidget* m_tabs_container { nullptr };
|
|
|
|
|
Tab* m_current_tab { nullptr };
|
2023-03-26 18:56:17 +01:00
|
|
|
QMenu* m_zoom_menu { nullptr };
|
2022-10-11 10:53:28 +02:00
|
|
|
|
2024-07-14 16:24:48 -04:00
|
|
|
QToolBar* m_new_tab_button_toolbar { nullptr };
|
|
|
|
|
|
2024-05-05 16:11:51 +01:00
|
|
|
QMenu* m_hamburger_menu { nullptr };
|
|
|
|
|
|
2023-12-04 09:39:22 -05:00
|
|
|
QAction* m_go_back_action { nullptr };
|
|
|
|
|
QAction* m_go_forward_action { nullptr };
|
|
|
|
|
QAction* m_reload_action { nullptr };
|
2024-04-05 07:21:48 -04:00
|
|
|
QAction* m_new_tab_action { nullptr };
|
2024-04-26 18:53:55 -06:00
|
|
|
QAction* m_new_window_action { nullptr };
|
2023-12-04 09:39:22 -05:00
|
|
|
QAction* m_copy_selection_action { nullptr };
|
2024-03-22 11:56:49 +01:00
|
|
|
QAction* m_paste_action { nullptr };
|
2023-12-04 09:39:22 -05:00
|
|
|
QAction* m_select_all_action { nullptr };
|
2024-05-29 20:12:21 +01:00
|
|
|
QAction* m_find_in_page_action { nullptr };
|
2023-12-04 09:39:22 -05:00
|
|
|
QAction* m_view_source_action { nullptr };
|
2025-03-15 10:10:25 -04:00
|
|
|
QAction* m_enable_devtools_action { nullptr };
|
2024-06-04 13:28:48 +01:00
|
|
|
QAction* m_show_line_box_borders_action { nullptr };
|
2024-06-05 20:29:12 +01:00
|
|
|
QAction* m_enable_scripting_action { nullptr };
|
2025-03-06 17:54:40 -06:00
|
|
|
QAction* m_enable_content_filtering_action { nullptr };
|
2024-06-05 20:29:12 +01:00
|
|
|
QAction* m_block_pop_ups_action { nullptr };
|
|
|
|
|
QAction* m_enable_same_origin_policy_action { nullptr };
|
2023-12-04 09:39:22 -05:00
|
|
|
|
2024-06-06 00:07:10 +01:00
|
|
|
ByteString m_user_agent_string {};
|
2024-07-02 19:28:39 +01:00
|
|
|
ByteString m_navigator_compatibility_mode {};
|
2024-06-06 00:07:10 +01:00
|
|
|
|
2024-07-27 11:38:39 +01:00
|
|
|
IsPopupWindow m_is_popup_window { IsPopupWindow::No };
|
2022-07-03 21:26:51 +02:00
|
|
|
};
|
2023-08-02 11:52:59 -06:00
|
|
|
|
|
|
|
|
}
|