BrowserWindow.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. /*
  2. * Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Matthew Costa <ucosty@gmail.com>
  4. * Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
  5. * Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #include "BrowserWindow.h"
  10. #include "Application.h"
  11. #include "Icon.h"
  12. #include "Settings.h"
  13. #include "SettingsDialog.h"
  14. #include "StringUtils.h"
  15. #include "TaskManagerWindow.h"
  16. #include "WebContentView.h"
  17. #include <AK/TypeCasts.h>
  18. #include <Ladybird/Qt/TabBar.h>
  19. #include <Ladybird/Utilities.h>
  20. #include <LibWeb/CSS/PreferredColorScheme.h>
  21. #include <LibWeb/Loader/UserAgent.h>
  22. #include <LibWebView/CookieJar.h>
  23. #include <LibWebView/UserAgent.h>
  24. #include <QAction>
  25. #include <QActionGroup>
  26. #include <QApplication>
  27. #include <QClipboard>
  28. #include <QGuiApplication>
  29. #include <QInputDialog>
  30. #include <QPlainTextEdit>
  31. #include <QShortcut>
  32. #include <QTabBar>
  33. #include <QWindow>
  34. namespace Ladybird {
  35. static QIcon const& app_icon()
  36. {
  37. static QIcon icon;
  38. if (icon.isNull()) {
  39. QPixmap pixmap;
  40. pixmap.load(":/Icons/ladybird.png");
  41. icon = QIcon(pixmap);
  42. }
  43. return icon;
  44. }
  45. class HamburgerMenu : public QMenu {
  46. public:
  47. using QMenu::QMenu;
  48. virtual ~HamburgerMenu() override = default;
  49. virtual void showEvent(QShowEvent*) override
  50. {
  51. if (!isVisible())
  52. return;
  53. auto* browser_window = verify_cast<BrowserWindow>(parentWidget());
  54. if (!browser_window)
  55. return;
  56. auto* current_tab = browser_window->current_tab();
  57. if (!current_tab)
  58. return;
  59. // Ensure the hamburger menu placed within the browser window.
  60. auto* hamburger_button = current_tab->hamburger_button();
  61. auto button_top_right = hamburger_button->mapToGlobal(hamburger_button->rect().bottomRight());
  62. move(button_top_right - QPoint(rect().width(), 0));
  63. }
  64. };
  65. BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, Tab* parent_tab, Optional<u64> page_index)
  66. : m_tabs_container(new TabWidget(this))
  67. , m_cookie_jar(cookie_jar)
  68. , m_web_content_options(web_content_options)
  69. , m_webdriver_content_ipc_path(webdriver_content_ipc_path)
  70. {
  71. setWindowIcon(app_icon());
  72. // Listen for DPI changes
  73. m_device_pixel_ratio = devicePixelRatio();
  74. m_current_screen = screen();
  75. if (QT_VERSION < QT_VERSION_CHECK(6, 6, 0) || QGuiApplication::platformName() != "wayland") {
  76. setAttribute(Qt::WA_NativeWindow);
  77. setAttribute(Qt::WA_DontCreateNativeAncestors);
  78. QObject::connect(m_current_screen, &QScreen::logicalDotsPerInchChanged, this, &BrowserWindow::device_pixel_ratio_changed);
  79. QObject::connect(windowHandle(), &QWindow::screenChanged, this, [this](QScreen* screen) {
  80. if (m_device_pixel_ratio != devicePixelRatio())
  81. device_pixel_ratio_changed(devicePixelRatio());
  82. // Listen for logicalDotsPerInchChanged signals on new screen
  83. QObject::disconnect(m_current_screen, &QScreen::logicalDotsPerInchChanged, nullptr, nullptr);
  84. m_current_screen = screen;
  85. QObject::connect(m_current_screen, &QScreen::logicalDotsPerInchChanged, this, &BrowserWindow::device_pixel_ratio_changed);
  86. });
  87. }
  88. m_hamburger_menu = new HamburgerMenu(this);
  89. if (!Settings::the()->show_menubar())
  90. menuBar()->hide();
  91. QObject::connect(Settings::the(), &Settings::show_menubar_changed, this, [this](bool show_menubar) {
  92. menuBar()->setVisible(show_menubar);
  93. });
  94. auto* file_menu = menuBar()->addMenu("&File");
  95. m_new_tab_action = new QAction("New &Tab", this);
  96. m_new_tab_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::AddTab));
  97. m_hamburger_menu->addAction(m_new_tab_action);
  98. file_menu->addAction(m_new_tab_action);
  99. m_new_window_action = new QAction("New &Window", this);
  100. m_new_window_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::New));
  101. m_hamburger_menu->addAction(m_new_window_action);
  102. file_menu->addAction(m_new_window_action);
  103. auto* close_current_tab_action = new QAction("&Close Current Tab", this);
  104. close_current_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/close-tab.png"sv));
  105. close_current_tab_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Close));
  106. m_hamburger_menu->addAction(close_current_tab_action);
  107. file_menu->addAction(close_current_tab_action);
  108. auto* open_file_action = new QAction("&Open File...", this);
  109. open_file_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-folder-open.png"sv));
  110. open_file_action->setShortcut(QKeySequence(QKeySequence::StandardKey::Open));
  111. m_hamburger_menu->addAction(open_file_action);
  112. file_menu->addAction(open_file_action);
  113. m_hamburger_menu->addSeparator();
  114. auto* edit_menu = m_hamburger_menu->addMenu("&Edit");
  115. menuBar()->addMenu(edit_menu);
  116. m_copy_selection_action = new QAction("&Copy", this);
  117. m_copy_selection_action->setIcon(load_icon_from_uri("resource://icons/16x16/edit-copy.png"sv));
  118. m_copy_selection_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Copy));
  119. edit_menu->addAction(m_copy_selection_action);
  120. QObject::connect(m_copy_selection_action, &QAction::triggered, this, &BrowserWindow::copy_selected_text);
  121. m_paste_action = new QAction("&Paste", this);
  122. m_paste_action->setIcon(load_icon_from_uri("resource://icons/16x16/paste.png"sv));
  123. m_paste_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Paste));
  124. edit_menu->addAction(m_paste_action);
  125. QObject::connect(m_paste_action, &QAction::triggered, this, &BrowserWindow::paste);
  126. m_select_all_action = new QAction("Select &All", this);
  127. m_select_all_action->setIcon(load_icon_from_uri("resource://icons/16x16/select-all.png"sv));
  128. m_select_all_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::SelectAll));
  129. edit_menu->addAction(m_select_all_action);
  130. QObject::connect(m_select_all_action, &QAction::triggered, this, &BrowserWindow::select_all);
  131. edit_menu->addSeparator();
  132. m_find_in_page_action = new QAction("&Find in Page...", this);
  133. m_find_in_page_action->setIcon(load_icon_from_uri("resource://icons/16x16/find.png"sv));
  134. m_find_in_page_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Find));
  135. edit_menu->addAction(m_find_in_page_action);
  136. QObject::connect(m_find_in_page_action, &QAction::triggered, this, &BrowserWindow::show_find_in_page);
  137. edit_menu->addSeparator();
  138. auto* settings_action = new QAction("&Settings", this);
  139. settings_action->setIcon(load_icon_from_uri("resource://icons/16x16/settings.png"sv));
  140. settings_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Preferences));
  141. edit_menu->addAction(settings_action);
  142. auto* view_menu = m_hamburger_menu->addMenu("&View");
  143. menuBar()->addMenu(view_menu);
  144. auto* open_next_tab_action = new QAction("Open &Next Tab", this);
  145. open_next_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_PageDown));
  146. view_menu->addAction(open_next_tab_action);
  147. QObject::connect(open_next_tab_action, &QAction::triggered, this, &BrowserWindow::open_next_tab);
  148. auto* open_previous_tab_action = new QAction("Open &Previous Tab", this);
  149. open_previous_tab_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_PageUp));
  150. view_menu->addAction(open_previous_tab_action);
  151. QObject::connect(open_previous_tab_action, &QAction::triggered, this, &BrowserWindow::open_previous_tab);
  152. view_menu->addSeparator();
  153. m_zoom_menu = view_menu->addMenu("&Zoom");
  154. auto* zoom_in_action = new QAction("Zoom &In", this);
  155. zoom_in_action->setIcon(load_icon_from_uri("resource://icons/16x16/zoom-in.png"sv));
  156. auto zoom_in_shortcuts = QKeySequence::keyBindings(QKeySequence::StandardKey::ZoomIn);
  157. zoom_in_shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_Equal));
  158. zoom_in_action->setShortcuts(zoom_in_shortcuts);
  159. m_zoom_menu->addAction(zoom_in_action);
  160. QObject::connect(zoom_in_action, &QAction::triggered, this, &BrowserWindow::zoom_in);
  161. auto* zoom_out_action = new QAction("Zoom &Out", this);
  162. zoom_out_action->setIcon(load_icon_from_uri("resource://icons/16x16/zoom-out.png"sv));
  163. zoom_out_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::ZoomOut));
  164. m_zoom_menu->addAction(zoom_out_action);
  165. QObject::connect(zoom_out_action, &QAction::triggered, this, &BrowserWindow::zoom_out);
  166. auto* reset_zoom_action = new QAction("&Reset Zoom", this);
  167. reset_zoom_action->setIcon(load_icon_from_uri("resource://icons/16x16/zoom-reset.png"sv));
  168. reset_zoom_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_0));
  169. m_zoom_menu->addAction(reset_zoom_action);
  170. QObject::connect(reset_zoom_action, &QAction::triggered, this, &BrowserWindow::reset_zoom);
  171. view_menu->addSeparator();
  172. auto* color_scheme_menu = view_menu->addMenu("&Color Scheme");
  173. auto* color_scheme_group = new QActionGroup(this);
  174. auto* auto_color_scheme = new QAction("&Auto", this);
  175. auto_color_scheme->setCheckable(true);
  176. color_scheme_group->addAction(auto_color_scheme);
  177. color_scheme_menu->addAction(auto_color_scheme);
  178. QObject::connect(auto_color_scheme, &QAction::triggered, this, &BrowserWindow::enable_auto_color_scheme);
  179. auto* light_color_scheme = new QAction("&Light", this);
  180. light_color_scheme->setCheckable(true);
  181. color_scheme_group->addAction(light_color_scheme);
  182. color_scheme_menu->addAction(light_color_scheme);
  183. QObject::connect(light_color_scheme, &QAction::triggered, this, &BrowserWindow::enable_light_color_scheme);
  184. auto* dark_color_scheme = new QAction("&Dark", this);
  185. dark_color_scheme->setCheckable(true);
  186. color_scheme_group->addAction(dark_color_scheme);
  187. color_scheme_menu->addAction(dark_color_scheme);
  188. QObject::connect(dark_color_scheme, &QAction::triggered, this, &BrowserWindow::enable_dark_color_scheme);
  189. auto_color_scheme->setChecked(true);
  190. auto* show_menubar = new QAction("Show &Menubar", this);
  191. show_menubar->setCheckable(true);
  192. show_menubar->setChecked(Settings::the()->show_menubar());
  193. view_menu->addAction(show_menubar);
  194. QObject::connect(show_menubar, &QAction::triggered, this, [](bool checked) {
  195. Settings::the()->set_show_menubar(checked);
  196. });
  197. auto* inspect_menu = m_hamburger_menu->addMenu("&Inspect");
  198. menuBar()->addMenu(inspect_menu);
  199. m_view_source_action = new QAction("View &Source", this);
  200. m_view_source_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-html.png"sv));
  201. m_view_source_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_U));
  202. inspect_menu->addAction(m_view_source_action);
  203. QObject::connect(m_view_source_action, &QAction::triggered, this, [this] {
  204. if (m_current_tab) {
  205. m_current_tab->view().get_source();
  206. }
  207. });
  208. auto* inspector_action = new QAction("Open &Inspector", this);
  209. inspector_action->setIcon(load_icon_from_uri("resource://icons/browser/dom-tree.png"sv));
  210. inspector_action->setShortcuts({ QKeySequence("Ctrl+Shift+I"), QKeySequence("F12") });
  211. inspect_menu->addAction(inspector_action);
  212. QObject::connect(inspector_action, &QAction::triggered, this, [this] {
  213. if (m_current_tab) {
  214. m_current_tab->show_inspector_window();
  215. }
  216. });
  217. auto* task_manager_action = new QAction("Open Task &Manager", this);
  218. task_manager_action->setIcon(load_icon_from_uri("resource://icons/16x16/app-system-monitor.png"sv));
  219. task_manager_action->setShortcuts({ QKeySequence("Ctrl+Shift+M") });
  220. inspect_menu->addAction(task_manager_action);
  221. QObject::connect(task_manager_action, &QAction::triggered, this, [] {
  222. static_cast<Ladybird::Application*>(QApplication::instance())->show_task_manager_window();
  223. });
  224. auto* debug_menu = m_hamburger_menu->addMenu("&Debug");
  225. menuBar()->addMenu(debug_menu);
  226. auto* dump_session_history_tree_action = new QAction("Dump Session History Tree", this);
  227. dump_session_history_tree_action->setIcon(load_icon_from_uri("resource://icons/16x16/history.png"sv));
  228. debug_menu->addAction(dump_session_history_tree_action);
  229. QObject::connect(dump_session_history_tree_action, &QAction::triggered, this, [this] {
  230. debug_request("dump-session-history");
  231. });
  232. auto* dump_dom_tree_action = new QAction("Dump &DOM Tree", this);
  233. dump_dom_tree_action->setIcon(load_icon_from_uri("resource://icons/browser/dom-tree.png"sv));
  234. debug_menu->addAction(dump_dom_tree_action);
  235. QObject::connect(dump_dom_tree_action, &QAction::triggered, this, [this] {
  236. debug_request("dump-dom-tree");
  237. });
  238. auto* dump_layout_tree_action = new QAction("Dump &Layout Tree", this);
  239. dump_layout_tree_action->setIcon(load_icon_from_uri("resource://icons/16x16/layout.png"sv));
  240. debug_menu->addAction(dump_layout_tree_action);
  241. QObject::connect(dump_layout_tree_action, &QAction::triggered, this, [this] {
  242. debug_request("dump-layout-tree");
  243. });
  244. auto* dump_paint_tree_action = new QAction("Dump &Paint Tree", this);
  245. dump_paint_tree_action->setIcon(load_icon_from_uri("resource://icons/16x16/layout.png"sv));
  246. debug_menu->addAction(dump_paint_tree_action);
  247. QObject::connect(dump_paint_tree_action, &QAction::triggered, this, [this] {
  248. debug_request("dump-paint-tree");
  249. });
  250. auto* dump_stacking_context_tree_action = new QAction("Dump S&tacking Context Tree", this);
  251. dump_stacking_context_tree_action->setIcon(load_icon_from_uri("resource://icons/16x16/layers.png"sv));
  252. debug_menu->addAction(dump_stacking_context_tree_action);
  253. QObject::connect(dump_stacking_context_tree_action, &QAction::triggered, this, [this] {
  254. debug_request("dump-stacking-context-tree");
  255. });
  256. auto* dump_style_sheets_action = new QAction("Dump &Style Sheets", this);
  257. dump_style_sheets_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-css.png"sv));
  258. debug_menu->addAction(dump_style_sheets_action);
  259. QObject::connect(dump_style_sheets_action, &QAction::triggered, this, [this] {
  260. debug_request("dump-style-sheets");
  261. });
  262. auto* dump_styles_action = new QAction("Dump &All Resolved Styles", this);
  263. dump_styles_action->setIcon(load_icon_from_uri("resource://icons/16x16/filetype-css.png"sv));
  264. debug_menu->addAction(dump_styles_action);
  265. QObject::connect(dump_styles_action, &QAction::triggered, this, [this] {
  266. debug_request("dump-all-resolved-styles");
  267. });
  268. auto* dump_cookies_action = new QAction("Dump C&ookies", this);
  269. dump_cookies_action->setIcon(load_icon_from_uri("resource://icons/browser/cookie.png"sv));
  270. debug_menu->addAction(dump_cookies_action);
  271. QObject::connect(dump_cookies_action, &QAction::triggered, this, [this] {
  272. m_cookie_jar.dump_cookies();
  273. });
  274. auto* dump_local_storage_action = new QAction("Dump Loc&al Storage", this);
  275. dump_local_storage_action->setIcon(load_icon_from_uri("resource://icons/browser/local-storage.png"sv));
  276. debug_menu->addAction(dump_local_storage_action);
  277. QObject::connect(dump_local_storage_action, &QAction::triggered, this, [this] {
  278. debug_request("dump-local-storage");
  279. });
  280. debug_menu->addSeparator();
  281. m_show_line_box_borders_action = new QAction("Show Line Box Borders", this);
  282. m_show_line_box_borders_action->setCheckable(true);
  283. debug_menu->addAction(m_show_line_box_borders_action);
  284. QObject::connect(m_show_line_box_borders_action, &QAction::triggered, this, [this] {
  285. bool state = m_show_line_box_borders_action->isChecked();
  286. for_each_tab([state](auto& tab) {
  287. tab.set_line_box_borders(state);
  288. });
  289. });
  290. debug_menu->addSeparator();
  291. auto* collect_garbage_action = new QAction("Collect &Garbage", this);
  292. collect_garbage_action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_G));
  293. collect_garbage_action->setIcon(load_icon_from_uri("resource://icons/16x16/trash-can.png"sv));
  294. debug_menu->addAction(collect_garbage_action);
  295. QObject::connect(collect_garbage_action, &QAction::triggered, this, [this] {
  296. debug_request("collect-garbage");
  297. });
  298. auto* dump_gc_graph_action = new QAction("Dump GC graph", this);
  299. debug_menu->addAction(dump_gc_graph_action);
  300. QObject::connect(dump_gc_graph_action, &QAction::triggered, this, [this] {
  301. if (m_current_tab) {
  302. auto gc_graph_path = m_current_tab->view().dump_gc_graph();
  303. warnln("\033[33;1mDumped GC-graph into {}"
  304. "\033[0m",
  305. gc_graph_path);
  306. }
  307. });
  308. auto* clear_cache_action = new QAction("Clear &Cache", this);
  309. clear_cache_action->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_C));
  310. clear_cache_action->setIcon(load_icon_from_uri("resource://icons/browser/clear-cache.png"sv));
  311. debug_menu->addAction(clear_cache_action);
  312. QObject::connect(clear_cache_action, &QAction::triggered, this, [this] {
  313. debug_request("clear-cache");
  314. });
  315. auto* spoof_user_agent_menu = debug_menu->addMenu("Spoof &User Agent");
  316. spoof_user_agent_menu->setIcon(load_icon_from_uri("resource://icons/16x16/spoof.png"sv));
  317. auto* user_agent_group = new QActionGroup(this);
  318. auto add_user_agent = [this, &user_agent_group, &spoof_user_agent_menu](auto name, auto const& user_agent) {
  319. auto* action = new QAction(qstring_from_ak_string(name), this);
  320. action->setCheckable(true);
  321. user_agent_group->addAction(action);
  322. spoof_user_agent_menu->addAction(action);
  323. QObject::connect(action, &QAction::triggered, this, [this, user_agent] {
  324. for_each_tab([user_agent](auto& tab) {
  325. tab.set_user_agent_string(user_agent);
  326. });
  327. set_user_agent_string(user_agent);
  328. });
  329. return action;
  330. };
  331. set_user_agent_string(Web::default_user_agent);
  332. auto* disable_spoofing = add_user_agent("Disabled"sv, Web::default_user_agent);
  333. disable_spoofing->setChecked(true);
  334. for (auto const& user_agent : WebView::user_agents)
  335. add_user_agent(user_agent.key, user_agent.value.to_byte_string());
  336. auto* custom_user_agent_action = new QAction("Custom...", this);
  337. custom_user_agent_action->setCheckable(true);
  338. user_agent_group->addAction(custom_user_agent_action);
  339. spoof_user_agent_menu->addAction(custom_user_agent_action);
  340. QObject::connect(custom_user_agent_action, &QAction::triggered, this, [this, disable_spoofing] {
  341. auto user_agent = QInputDialog::getText(this, "Custom User Agent", "Enter User Agent:");
  342. if (!user_agent.isEmpty()) {
  343. auto user_agent_byte_string = ak_byte_string_from_qstring(user_agent);
  344. for_each_tab([&](auto& tab) {
  345. tab.set_user_agent_string(user_agent_byte_string);
  346. });
  347. set_user_agent_string(user_agent_byte_string);
  348. } else {
  349. disable_spoofing->activate(QAction::Trigger);
  350. }
  351. });
  352. debug_menu->addSeparator();
  353. m_enable_scripting_action = new QAction("Enable Scripting", this);
  354. m_enable_scripting_action->setCheckable(true);
  355. m_enable_scripting_action->setChecked(true);
  356. debug_menu->addAction(m_enable_scripting_action);
  357. QObject::connect(m_enable_scripting_action, &QAction::triggered, this, [this] {
  358. bool state = m_enable_scripting_action->isChecked();
  359. for_each_tab([state](auto& tab) {
  360. tab.set_scripting(state);
  361. });
  362. });
  363. m_block_pop_ups_action = new QAction("Block Pop-ups", this);
  364. m_block_pop_ups_action->setCheckable(true);
  365. m_block_pop_ups_action->setChecked(true);
  366. debug_menu->addAction(m_block_pop_ups_action);
  367. QObject::connect(m_block_pop_ups_action, &QAction::triggered, this, [this] {
  368. bool state = m_block_pop_ups_action->isChecked();
  369. for_each_tab([state](auto& tab) {
  370. tab.set_block_popups(state);
  371. });
  372. });
  373. m_enable_same_origin_policy_action = new QAction("Enable Same-Origin Policy", this);
  374. m_enable_same_origin_policy_action->setCheckable(true);
  375. debug_menu->addAction(m_enable_same_origin_policy_action);
  376. QObject::connect(m_enable_same_origin_policy_action, &QAction::triggered, this, [this] {
  377. bool state = m_enable_same_origin_policy_action->isChecked();
  378. for_each_tab([state](auto& tab) {
  379. tab.set_same_origin_policy(state);
  380. });
  381. });
  382. auto* help_menu = m_hamburger_menu->addMenu("&Help");
  383. menuBar()->addMenu(help_menu);
  384. auto* about_action = new QAction("&About Ladybird", this);
  385. help_menu->addAction(about_action);
  386. QObject::connect(about_action, &QAction::triggered, this, [this] {
  387. new_tab_from_url("about:version"sv, Web::HTML::ActivateTab::Yes);
  388. });
  389. m_hamburger_menu->addSeparator();
  390. file_menu->addSeparator();
  391. auto* quit_action = new QAction("&Quit", this);
  392. quit_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Quit));
  393. m_hamburger_menu->addAction(quit_action);
  394. file_menu->addAction(quit_action);
  395. QObject::connect(quit_action, &QAction::triggered, this, &QMainWindow::close);
  396. QObject::connect(m_new_tab_action, &QAction::triggered, this, [this] {
  397. new_tab_from_url(ak_url_from_qstring(Settings::the()->new_tab_page()), Web::HTML::ActivateTab::Yes);
  398. });
  399. QObject::connect(m_new_window_action, &QAction::triggered, this, [this] {
  400. auto initial_urls = Vector<URL::URL> { ak_url_from_qstring(Settings::the()->new_tab_page()) };
  401. (void)static_cast<Ladybird::Application*>(QApplication::instance())->new_window(initial_urls, m_cookie_jar, m_web_content_options, m_webdriver_content_ipc_path);
  402. });
  403. QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file);
  404. QObject::connect(settings_action, &QAction::triggered, this, [this] {
  405. if (!m_settings_dialog) {
  406. m_settings_dialog = new SettingsDialog(this);
  407. }
  408. m_settings_dialog->show();
  409. m_settings_dialog->setFocus();
  410. });
  411. QObject::connect(m_tabs_container, &QTabWidget::currentChanged, [this](int index) {
  412. auto* tab = verify_cast<Tab>(m_tabs_container->widget(index));
  413. if (tab)
  414. setWindowTitle(QString("%1 - Ladybird").arg(tab->title()));
  415. set_current_tab(tab);
  416. });
  417. QObject::connect(m_tabs_container, &QTabWidget::tabCloseRequested, this, &BrowserWindow::close_tab);
  418. QObject::connect(close_current_tab_action, &QAction::triggered, this, &BrowserWindow::close_current_tab);
  419. m_inspect_dom_node_action = new QAction("&Inspect Element", this);
  420. connect(m_inspect_dom_node_action, &QAction::triggered, this, [this] {
  421. if (m_current_tab)
  422. m_current_tab->show_inspector_window(Tab::InspectorTarget::HoveredElement);
  423. });
  424. m_go_back_action = new QAction("Go Back", this);
  425. connect(m_go_back_action, &QAction::triggered, this, [this] {
  426. if (m_current_tab)
  427. m_current_tab->back();
  428. });
  429. m_go_forward_action = new QAction("Go Forward", this);
  430. connect(m_go_forward_action, &QAction::triggered, this, [this] {
  431. if (m_current_tab)
  432. m_current_tab->forward();
  433. });
  434. m_reload_action = new QAction("&Reload", this);
  435. connect(m_reload_action, &QAction::triggered, this, [this] {
  436. if (m_current_tab)
  437. m_current_tab->reload();
  438. });
  439. m_go_back_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Back));
  440. m_go_forward_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Forward));
  441. m_reload_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Refresh));
  442. m_go_back_action->setEnabled(false);
  443. m_go_forward_action->setEnabled(false);
  444. m_reload_action->setEnabled(true);
  445. for (int i = 0; i <= 7; ++i) {
  446. new QShortcut(QKeySequence(Qt::CTRL | static_cast<Qt::Key>(Qt::Key_1 + i)), this, [this, i] {
  447. if (m_tabs_container->count() <= 1)
  448. return;
  449. m_tabs_container->setCurrentIndex(min(i, m_tabs_container->count() - 1));
  450. });
  451. }
  452. new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_9), this, [this] {
  453. if (m_tabs_container->count() <= 1)
  454. return;
  455. m_tabs_container->setCurrentIndex(m_tabs_container->count() - 1);
  456. });
  457. if (parent_tab) {
  458. new_child_tab(Web::HTML::ActivateTab::Yes, *parent_tab, AK::move(page_index));
  459. } else {
  460. for (size_t i = 0; i < initial_urls.size(); ++i) {
  461. new_tab_from_url(initial_urls[i], (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No);
  462. }
  463. }
  464. setCentralWidget(m_tabs_container);
  465. setContextMenuPolicy(Qt::PreventContextMenu);
  466. }
  467. void BrowserWindow::set_current_tab(Tab* tab)
  468. {
  469. m_current_tab = tab;
  470. if (tab) {
  471. update_displayed_zoom_level();
  472. tab->update_navigation_buttons_state();
  473. }
  474. }
  475. void BrowserWindow::debug_request(ByteString const& request, ByteString const& argument)
  476. {
  477. if (!m_current_tab)
  478. return;
  479. m_current_tab->debug_request(request, argument);
  480. }
  481. Tab& BrowserWindow::new_tab_from_url(URL::URL const& url, Web::HTML::ActivateTab activate_tab)
  482. {
  483. auto& tab = create_new_tab(activate_tab);
  484. tab.navigate(url);
  485. return tab;
  486. }
  487. Tab& BrowserWindow::new_tab_from_content(StringView html, Web::HTML::ActivateTab activate_tab)
  488. {
  489. auto& tab = create_new_tab(activate_tab);
  490. tab.load_html(html);
  491. return tab;
  492. }
  493. Tab& BrowserWindow::new_child_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Optional<u64> page_index)
  494. {
  495. return create_new_tab(activate_tab, parent, page_index);
  496. }
  497. Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab, Tab& parent, Optional<u64> page_index)
  498. {
  499. if (!page_index.has_value())
  500. return create_new_tab(activate_tab);
  501. auto* tab = new Tab(this, m_web_content_options, m_webdriver_content_ipc_path, parent.view().client(), page_index.value());
  502. // FIXME: Merge with other overload
  503. if (m_current_tab == nullptr) {
  504. set_current_tab(tab);
  505. }
  506. m_tabs_container->addTab(tab, "New Tab");
  507. if (activate_tab == Web::HTML::ActivateTab::Yes)
  508. m_tabs_container->setCurrentWidget(tab);
  509. initialize_tab(tab);
  510. return *tab;
  511. }
  512. Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab)
  513. {
  514. auto* tab = new Tab(this, m_web_content_options, m_webdriver_content_ipc_path);
  515. if (m_current_tab == nullptr) {
  516. set_current_tab(tab);
  517. }
  518. m_tabs_container->addTab(tab, "New Tab");
  519. if (activate_tab == Web::HTML::ActivateTab::Yes)
  520. m_tabs_container->setCurrentWidget(tab);
  521. initialize_tab(tab);
  522. return *tab;
  523. }
  524. void BrowserWindow::initialize_tab(Tab* tab)
  525. {
  526. QObject::connect(tab, &Tab::title_changed, this, &BrowserWindow::tab_title_changed);
  527. QObject::connect(tab, &Tab::favicon_changed, this, &BrowserWindow::tab_favicon_changed);
  528. QObject::connect(tab, &Tab::audio_play_state_changed, this, &BrowserWindow::tab_audio_play_state_changed);
  529. QObject::connect(tab, &Tab::navigation_buttons_state_changed, this, &BrowserWindow::tab_navigation_buttons_state_changed);
  530. QObject::connect(&tab->view(), &WebContentView::urls_dropped, this, [this](auto& urls) {
  531. VERIFY(urls.size());
  532. m_current_tab->navigate(ak_url_from_qurl(urls[0]));
  533. for (qsizetype i = 1; i < urls.size(); ++i)
  534. new_tab_from_url(ak_url_from_qurl(urls[i]), Web::HTML::ActivateTab::No);
  535. });
  536. tab->view().on_new_web_view = [this, tab](auto activate_tab, Web::HTML::WebViewHints hints, Optional<u64> page_index) {
  537. if (hints.popup) {
  538. auto& window = static_cast<Ladybird::Application*>(QApplication::instance())->new_window({}, m_cookie_jar, m_web_content_options, m_webdriver_content_ipc_path, tab, AK::move(page_index));
  539. window.set_window_rect(hints.screen_x, hints.screen_y, hints.width, hints.height);
  540. return window.current_tab()->view().handle();
  541. }
  542. auto& new_tab = new_child_tab(activate_tab, *tab, page_index);
  543. return new_tab.view().handle();
  544. };
  545. tab->view().on_tab_open_request = [this](auto url, auto activate_tab) {
  546. auto& tab = new_tab_from_url(url, activate_tab);
  547. return tab.view().handle();
  548. };
  549. tab->view().on_link_click = [this](auto url, auto target, unsigned modifiers) {
  550. // TODO: maybe activate tabs according to some configuration, this is just normal current browser behavior
  551. if (modifiers == Mod_Ctrl) {
  552. m_current_tab->view().on_tab_open_request(url, Web::HTML::ActivateTab::No);
  553. } else if (target == "_blank") {
  554. m_current_tab->view().on_tab_open_request(url, Web::HTML::ActivateTab::Yes);
  555. } else {
  556. m_current_tab->view().load(url);
  557. }
  558. };
  559. tab->view().on_link_middle_click = [this](auto url, auto target, unsigned modifiers) {
  560. m_current_tab->view().on_link_click(url, target, Mod_Ctrl);
  561. (void)modifiers;
  562. };
  563. tab->view().on_get_all_cookies = [this](auto const& url) {
  564. return m_cookie_jar.get_all_cookies(url);
  565. };
  566. tab->view().on_get_named_cookie = [this](auto const& url, auto const& name) {
  567. return m_cookie_jar.get_named_cookie(url, name);
  568. };
  569. tab->view().on_get_cookie = [this](auto& url, auto source) {
  570. return m_cookie_jar.get_cookie(url, source);
  571. };
  572. tab->view().on_set_cookie = [this](auto& url, auto& cookie, auto source) {
  573. m_cookie_jar.set_cookie(url, cookie, source);
  574. };
  575. tab->view().on_update_cookie = [this](auto const& cookie) {
  576. m_cookie_jar.update_cookie(cookie);
  577. };
  578. m_tabs_container->setTabIcon(m_tabs_container->indexOf(tab), tab->favicon());
  579. create_close_button_for_tab(tab);
  580. tab->focus_location_editor();
  581. tab->set_line_box_borders(m_show_line_box_borders_action->isChecked());
  582. tab->set_scripting(m_enable_scripting_action->isChecked());
  583. tab->set_block_popups(m_block_pop_ups_action->isChecked());
  584. tab->set_same_origin_policy(m_enable_same_origin_policy_action->isChecked());
  585. tab->set_user_agent_string(user_agent_string());
  586. }
  587. void BrowserWindow::activate_tab(int index)
  588. {
  589. m_tabs_container->setCurrentIndex(index);
  590. }
  591. void BrowserWindow::close_tab(int index)
  592. {
  593. auto* tab = m_tabs_container->widget(index);
  594. m_tabs_container->removeTab(index);
  595. tab->deleteLater();
  596. if (m_tabs_container->count() == 0)
  597. close();
  598. }
  599. void BrowserWindow::move_tab(int old_index, int new_index)
  600. {
  601. m_tabs_container->tabBar()->moveTab(old_index, new_index);
  602. }
  603. void BrowserWindow::open_file()
  604. {
  605. m_current_tab->open_file();
  606. }
  607. void BrowserWindow::close_current_tab()
  608. {
  609. close_tab(m_tabs_container->currentIndex());
  610. }
  611. int BrowserWindow::tab_index(Tab* tab)
  612. {
  613. return m_tabs_container->indexOf(tab);
  614. }
  615. void BrowserWindow::device_pixel_ratio_changed(qreal dpi)
  616. {
  617. m_device_pixel_ratio = dpi;
  618. for_each_tab([this](auto& tab) {
  619. tab.view().set_device_pixel_ratio(m_device_pixel_ratio);
  620. });
  621. }
  622. void BrowserWindow::tab_title_changed(int index, QString const& title)
  623. {
  624. m_tabs_container->setTabText(index, title);
  625. m_tabs_container->setTabToolTip(index, title);
  626. if (m_tabs_container->currentIndex() == index)
  627. setWindowTitle(QString("%1 - Ladybird").arg(title));
  628. }
  629. void BrowserWindow::tab_favicon_changed(int index, QIcon const& icon)
  630. {
  631. m_tabs_container->setTabIcon(index, icon);
  632. }
  633. void BrowserWindow::create_close_button_for_tab(Tab* tab)
  634. {
  635. auto index = m_tabs_container->indexOf(tab);
  636. m_tabs_container->setTabIcon(index, tab->favicon());
  637. auto* button = new TabBarButton(create_tvg_icon_with_theme_colors("close", palette()));
  638. auto position = audio_button_position_for_tab(index) == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide;
  639. connect(button, &QPushButton::clicked, this, [this, tab]() {
  640. auto index = m_tabs_container->indexOf(tab);
  641. close_tab(index);
  642. });
  643. m_tabs_container->tabBar()->setTabButton(index, position, button);
  644. }
  645. void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlayState play_state)
  646. {
  647. auto* tab = verify_cast<Tab>(m_tabs_container->widget(index));
  648. auto position = audio_button_position_for_tab(index);
  649. switch (play_state) {
  650. case Web::HTML::AudioPlayState::Paused:
  651. if (tab->view().page_mute_state() == Web::HTML::MuteState::Unmuted)
  652. m_tabs_container->tabBar()->setTabButton(index, position, nullptr);
  653. break;
  654. case Web::HTML::AudioPlayState::Playing:
  655. auto* button = new TabBarButton(icon_for_page_mute_state(*tab));
  656. button->setToolTip(tool_tip_for_page_mute_state(*tab));
  657. button->setObjectName("LadybirdAudioState");
  658. connect(button, &QPushButton::clicked, this, [this, tab, position]() {
  659. tab->view().toggle_page_mute_state();
  660. auto index = tab_index(tab);
  661. switch (tab->view().audio_play_state()) {
  662. case Web::HTML::AudioPlayState::Paused:
  663. m_tabs_container->tabBar()->setTabButton(index, position, nullptr);
  664. break;
  665. case Web::HTML::AudioPlayState::Playing:
  666. auto* button = m_tabs_container->tabBar()->tabButton(index, position);
  667. verify_cast<TabBarButton>(button)->setIcon(icon_for_page_mute_state(*tab));
  668. button->setToolTip(tool_tip_for_page_mute_state(*tab));
  669. break;
  670. }
  671. });
  672. m_tabs_container->tabBar()->setTabButton(index, position, button);
  673. break;
  674. }
  675. }
  676. void BrowserWindow::tab_navigation_buttons_state_changed(int index)
  677. {
  678. auto* tab = verify_cast<Tab>(m_tabs_container->widget(index));
  679. tab->update_navigation_buttons_state();
  680. }
  681. QIcon BrowserWindow::icon_for_page_mute_state(Tab& tab) const
  682. {
  683. switch (tab.view().page_mute_state()) {
  684. case Web::HTML::MuteState::Muted:
  685. return style()->standardIcon(QStyle::SP_MediaVolumeMuted);
  686. case Web::HTML::MuteState::Unmuted:
  687. return style()->standardIcon(QStyle::SP_MediaVolume);
  688. }
  689. VERIFY_NOT_REACHED();
  690. }
  691. QString BrowserWindow::tool_tip_for_page_mute_state(Tab& tab) const
  692. {
  693. switch (tab.view().page_mute_state()) {
  694. case Web::HTML::MuteState::Muted:
  695. return "Unmute tab";
  696. case Web::HTML::MuteState::Unmuted:
  697. return "Mute tab";
  698. }
  699. VERIFY_NOT_REACHED();
  700. }
  701. QTabBar::ButtonPosition BrowserWindow::audio_button_position_for_tab(int tab_index) const
  702. {
  703. if (auto* button = m_tabs_container->tabBar()->tabButton(tab_index, QTabBar::LeftSide)) {
  704. if (button->objectName() != "LadybirdAudioState")
  705. return QTabBar::RightSide;
  706. }
  707. return QTabBar::LeftSide;
  708. }
  709. void BrowserWindow::open_next_tab()
  710. {
  711. if (m_tabs_container->count() <= 1)
  712. return;
  713. auto next_index = m_tabs_container->currentIndex() + 1;
  714. if (next_index >= m_tabs_container->count())
  715. next_index = 0;
  716. m_tabs_container->setCurrentIndex(next_index);
  717. }
  718. void BrowserWindow::open_previous_tab()
  719. {
  720. if (m_tabs_container->count() <= 1)
  721. return;
  722. auto next_index = m_tabs_container->currentIndex() - 1;
  723. if (next_index < 0)
  724. next_index = m_tabs_container->count() - 1;
  725. m_tabs_container->setCurrentIndex(next_index);
  726. }
  727. void BrowserWindow::enable_auto_color_scheme()
  728. {
  729. for_each_tab([](auto& tab) {
  730. tab.view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Auto);
  731. });
  732. }
  733. void BrowserWindow::enable_light_color_scheme()
  734. {
  735. for_each_tab([](auto& tab) {
  736. tab.view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Light);
  737. });
  738. }
  739. void BrowserWindow::enable_dark_color_scheme()
  740. {
  741. for_each_tab([](auto& tab) {
  742. tab.view().set_preferred_color_scheme(Web::CSS::PreferredColorScheme::Dark);
  743. });
  744. }
  745. void BrowserWindow::zoom_in()
  746. {
  747. if (!m_current_tab)
  748. return;
  749. m_current_tab->view().zoom_in();
  750. update_displayed_zoom_level();
  751. }
  752. void BrowserWindow::zoom_out()
  753. {
  754. if (!m_current_tab)
  755. return;
  756. m_current_tab->view().zoom_out();
  757. update_displayed_zoom_level();
  758. }
  759. void BrowserWindow::reset_zoom()
  760. {
  761. if (!m_current_tab)
  762. return;
  763. m_current_tab->view().reset_zoom();
  764. update_displayed_zoom_level();
  765. }
  766. void BrowserWindow::update_zoom_menu()
  767. {
  768. VERIFY(m_zoom_menu);
  769. auto zoom_level_text = MUST(String::formatted("&Zoom ({}%)", round_to<int>(m_current_tab->view().zoom_level() * 100)));
  770. m_zoom_menu->setTitle(qstring_from_ak_string(zoom_level_text));
  771. }
  772. void BrowserWindow::select_all()
  773. {
  774. if (!m_current_tab)
  775. return;
  776. m_current_tab->view().select_all();
  777. }
  778. void BrowserWindow::show_find_in_page()
  779. {
  780. if (!m_current_tab)
  781. return;
  782. m_current_tab->show_find_in_page();
  783. }
  784. void BrowserWindow::paste()
  785. {
  786. if (!m_current_tab)
  787. return;
  788. auto* clipboard = QGuiApplication::clipboard();
  789. m_current_tab->view().paste(ak_string_from_qstring(clipboard->text()));
  790. }
  791. void BrowserWindow::update_displayed_zoom_level()
  792. {
  793. VERIFY(m_current_tab);
  794. update_zoom_menu();
  795. m_current_tab->update_reset_zoom_button();
  796. }
  797. void BrowserWindow::set_window_rect(Optional<Web::DevicePixels> x, Optional<Web::DevicePixels> y, Optional<Web::DevicePixels> width, Optional<Web::DevicePixels> height)
  798. {
  799. x = x.value_or(0);
  800. y = y.value_or(0);
  801. if (!width.has_value() || width.value() == 0)
  802. width = 800;
  803. if (!height.has_value() || height.value() == 0)
  804. height = 600;
  805. setGeometry(x.value().value(), y.value().value(), width.value().value(), height.value().value());
  806. }
  807. void BrowserWindow::copy_selected_text()
  808. {
  809. if (!m_current_tab)
  810. return;
  811. auto text = m_current_tab->view().selected_text();
  812. auto* clipboard = QGuiApplication::clipboard();
  813. clipboard->setText(qstring_from_ak_string(text));
  814. }
  815. bool BrowserWindow::event(QEvent* event)
  816. {
  817. #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
  818. if (event->type() == QEvent::DevicePixelRatioChange) {
  819. if (m_device_pixel_ratio != devicePixelRatio())
  820. device_pixel_ratio_changed(devicePixelRatio());
  821. }
  822. #endif
  823. if (event->type() == QEvent::WindowActivate)
  824. static_cast<Ladybird::Application*>(QApplication::instance())->set_active_window(*this);
  825. return QMainWindow::event(event);
  826. }
  827. void BrowserWindow::resizeEvent(QResizeEvent* event)
  828. {
  829. QWidget::resizeEvent(event);
  830. for_each_tab([&](auto& tab) {
  831. tab.view().set_window_size({ frameSize().width() * m_device_pixel_ratio, frameSize().height() * m_device_pixel_ratio });
  832. });
  833. }
  834. void BrowserWindow::moveEvent(QMoveEvent* event)
  835. {
  836. QWidget::moveEvent(event);
  837. for_each_tab([&](auto& tab) {
  838. tab.view().set_window_position({ event->pos().x() * m_device_pixel_ratio, event->pos().y() * m_device_pixel_ratio });
  839. });
  840. }
  841. void BrowserWindow::wheelEvent(QWheelEvent* event)
  842. {
  843. if ((event->modifiers() & Qt::ControlModifier) != 0) {
  844. if (event->angleDelta().y() > 0)
  845. zoom_in();
  846. else if (event->angleDelta().y() < 0)
  847. zoom_out();
  848. }
  849. }
  850. bool BrowserWindow::eventFilter(QObject* obj, QEvent* event)
  851. {
  852. if (event->type() == QEvent::MouseButtonRelease) {
  853. auto const* const mouse_event = static_cast<QMouseEvent*>(event);
  854. if (mouse_event->button() == Qt::MouseButton::MiddleButton) {
  855. if (obj == m_tabs_container) {
  856. auto const tab_index = m_tabs_container->tabBar()->tabAt(mouse_event->pos());
  857. close_tab(tab_index);
  858. return true;
  859. }
  860. }
  861. }
  862. return QMainWindow::eventFilter(obj, event);
  863. }
  864. void BrowserWindow::closeEvent(QCloseEvent* event)
  865. {
  866. Settings::the()->set_last_position(pos());
  867. Settings::the()->set_last_size(size());
  868. Settings::the()->set_is_maximized(isMaximized());
  869. QObject::deleteLater();
  870. QMainWindow::closeEvent(event);
  871. }
  872. }