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
|
|
|
|
|
|
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/Tab.h>
|
|
|
|
|
|
2022-07-05 05:53:11 +01:00
|
|
|
#include <QIcon>
|
2022-07-03 21:26:51 +02:00
|
|
|
#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 {
|
|
|
|
|
|
2025-09-03 12:42:06 -04:00
|
|
|
class Tab;
|
2023-08-02 11:52:59 -06:00
|
|
|
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*);
|
2023-05-13 13:07:12 +01:00
|
|
|
|
2025-09-01 08:20:14 -04:00
|
|
|
Tab& create_new_tab(Web::HTML::ActivateTab activate_tab);
|
|
|
|
|
Tab* current_tab() const { return m_current_tab; }
|
2024-03-22 11:56:49 +01:00
|
|
|
|
2025-09-01 08:20:14 -04:00
|
|
|
QMenu& hamburger_menu() const { return *m_hamburger_menu; }
|
2023-05-15 11:49:44 -04:00
|
|
|
|
2025-09-01 08:20:14 -04:00
|
|
|
QAction& new_tab_action() const { return *m_new_tab_action; }
|
|
|
|
|
QAction& new_window_action() const { return *m_new_window_action; }
|
|
|
|
|
QAction& find_action() const { return *m_find_in_page_action; }
|
2024-05-07 23:39:25 +01:00
|
|
|
|
2025-07-25 16:43:27 +01:00
|
|
|
double refresh_rate() const { return m_refresh_rate; }
|
|
|
|
|
|
2025-09-17 10:03:01 -04:00
|
|
|
void on_devtools_enabled();
|
|
|
|
|
void on_devtools_disabled();
|
|
|
|
|
|
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-03-18 16:22:27 +13:00
|
|
|
Tab& new_tab_from_url(URL::URL const&, 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-05-29 20:12:21 +01:00
|
|
|
void show_find_in_page();
|
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
|
|
|
|
2025-09-10 07:23:15 -04:00
|
|
|
void set_current_tab(Tab* tab) { m_current_tab = tab; }
|
2023-03-26 18:56:17 +01:00
|
|
|
|
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);
|
|
|
|
|
|
2025-08-04 11:46:51 +01:00
|
|
|
QScreen* m_current_screen { nullptr };
|
2023-12-13 19:10:05 +01:00
|
|
|
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
|
|
|
|
2022-07-05 23:18:21 +01:00
|
|
|
QTabWidget* m_tabs_container { nullptr };
|
|
|
|
|
Tab* m_current_tab { 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 };
|
|
|
|
|
|
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 };
|
2024-05-29 20:12:21 +01:00
|
|
|
QAction* m_find_in_page_action { nullptr };
|
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
|
|
|
|
|
|
|
|
}
|