WebContentView.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #define AK_DONT_REPLACE_STD
  8. #include "WebContentView.h"
  9. #include "ConsoleWidget.h"
  10. #include "HelperProcess.h"
  11. #include "InspectorWidget.h"
  12. #include "Utilities.h"
  13. #include <AK/Assertions.h>
  14. #include <AK/ByteBuffer.h>
  15. #include <AK/Format.h>
  16. #include <AK/HashTable.h>
  17. #include <AK/LexicalPath.h>
  18. #include <AK/NonnullOwnPtr.h>
  19. #include <AK/StringBuilder.h>
  20. #include <AK/Types.h>
  21. #include <Browser/CookieJar.h>
  22. #include <Kernel/API/KeyCode.h>
  23. #include <LibCore/ArgsParser.h>
  24. #include <LibCore/EventLoop.h>
  25. #include <LibCore/IODevice.h>
  26. #include <LibCore/System.h>
  27. #include <LibCore/Timer.h>
  28. #include <LibGfx/Bitmap.h>
  29. #include <LibGfx/Font/FontDatabase.h>
  30. #include <LibGfx/ImageFormats/PNGWriter.h>
  31. #include <LibGfx/Painter.h>
  32. #include <LibGfx/Palette.h>
  33. #include <LibGfx/Rect.h>
  34. #include <LibGfx/SystemTheme.h>
  35. #include <LibJS/Runtime/ConsoleObject.h>
  36. #include <LibMain/Main.h>
  37. #include <LibWeb/Crypto/Crypto.h>
  38. #include <LibWeb/Loader/ContentFilter.h>
  39. #include <LibWebView/WebContentClient.h>
  40. #include <QApplication>
  41. #include <QCursor>
  42. #include <QIcon>
  43. #include <QInputDialog>
  44. #include <QLineEdit>
  45. #include <QMessageBox>
  46. #include <QMimeData>
  47. #include <QMouseEvent>
  48. #include <QPaintEvent>
  49. #include <QPainter>
  50. #include <QPalette>
  51. #include <QScrollBar>
  52. #include <QTextEdit>
  53. #include <QTimer>
  54. #include <QToolTip>
  55. WebContentView::WebContentView(StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling)
  56. : m_webdriver_content_ipc_path(webdriver_content_ipc_path)
  57. {
  58. setMouseTracking(true);
  59. setAcceptDrops(true);
  60. setFocusPolicy(Qt::FocusPolicy::StrongFocus);
  61. m_device_pixel_ratio = devicePixelRatio();
  62. m_inverse_pixel_scaling_ratio = 1.0 / m_device_pixel_ratio;
  63. verticalScrollBar()->setSingleStep(24);
  64. horizontalScrollBar()->setSingleStep(24);
  65. QObject::connect(verticalScrollBar(), &QScrollBar::valueChanged, [this](int) {
  66. update_viewport_rect();
  67. });
  68. QObject::connect(horizontalScrollBar(), &QScrollBar::valueChanged, [this](int) {
  69. update_viewport_rect();
  70. });
  71. create_client(enable_callgrind_profiling);
  72. }
  73. WebContentView::~WebContentView()
  74. {
  75. close_sub_widgets();
  76. }
  77. unsigned get_button_from_qt_event(QMouseEvent const& event)
  78. {
  79. if (event.button() == Qt::MouseButton::LeftButton)
  80. return 1;
  81. if (event.button() == Qt::MouseButton::RightButton)
  82. return 2;
  83. if (event.button() == Qt::MouseButton::MiddleButton)
  84. return 4;
  85. if (event.button() == Qt::MouseButton::BackButton)
  86. return 8;
  87. if (event.buttons() == Qt::MouseButton::ForwardButton)
  88. return 16;
  89. return 0;
  90. }
  91. unsigned get_buttons_from_qt_event(QMouseEvent const& event)
  92. {
  93. unsigned buttons = 0;
  94. if (event.buttons() & Qt::MouseButton::LeftButton)
  95. buttons |= 1;
  96. if (event.buttons() & Qt::MouseButton::RightButton)
  97. buttons |= 2;
  98. if (event.buttons() & Qt::MouseButton::MiddleButton)
  99. buttons |= 4;
  100. if (event.buttons() & Qt::MouseButton::BackButton)
  101. buttons |= 8;
  102. if (event.buttons() & Qt::MouseButton::ForwardButton)
  103. buttons |= 16;
  104. return buttons;
  105. }
  106. unsigned get_modifiers_from_qt_mouse_event(QMouseEvent const& event)
  107. {
  108. unsigned modifiers = 0;
  109. if (event.modifiers() & Qt::Modifier::ALT)
  110. modifiers |= 1;
  111. if (event.modifiers() & Qt::Modifier::CTRL)
  112. modifiers |= 2;
  113. if (event.modifiers() & Qt::Modifier::SHIFT)
  114. modifiers |= 4;
  115. return modifiers;
  116. }
  117. unsigned get_modifiers_from_qt_keyboard_event(QKeyEvent const& event)
  118. {
  119. auto modifiers = 0;
  120. if (event.modifiers().testFlag(Qt::AltModifier))
  121. modifiers |= KeyModifier::Mod_Alt;
  122. if (event.modifiers().testFlag(Qt::ControlModifier))
  123. modifiers |= KeyModifier::Mod_Ctrl;
  124. if (event.modifiers().testFlag(Qt::MetaModifier))
  125. modifiers |= KeyModifier::Mod_Super;
  126. if (event.modifiers().testFlag(Qt::ShiftModifier))
  127. modifiers |= KeyModifier::Mod_Shift;
  128. if (event.modifiers().testFlag(Qt::AltModifier))
  129. modifiers |= KeyModifier::Mod_AltGr;
  130. return modifiers;
  131. }
  132. KeyCode get_keycode_from_qt_keyboard_event(QKeyEvent const& event)
  133. {
  134. struct Mapping {
  135. constexpr Mapping(Qt::Key q, KeyCode s)
  136. : qt_key(q)
  137. , serenity_key(s)
  138. {
  139. }
  140. Qt::Key qt_key;
  141. KeyCode serenity_key;
  142. };
  143. constexpr Mapping mappings[] = {
  144. { Qt::Key_0, Key_0 },
  145. { Qt::Key_1, Key_1 },
  146. { Qt::Key_2, Key_2 },
  147. { Qt::Key_3, Key_3 },
  148. { Qt::Key_4, Key_4 },
  149. { Qt::Key_5, Key_5 },
  150. { Qt::Key_6, Key_6 },
  151. { Qt::Key_7, Key_7 },
  152. { Qt::Key_8, Key_8 },
  153. { Qt::Key_9, Key_9 },
  154. { Qt::Key_A, Key_A },
  155. { Qt::Key_Alt, Key_Alt },
  156. { Qt::Key_Ampersand, Key_Ampersand },
  157. { Qt::Key_Apostrophe, Key_Apostrophe },
  158. { Qt::Key_AsciiCircum, Key_Circumflex },
  159. { Qt::Key_AsciiTilde, Key_Tilde },
  160. { Qt::Key_Asterisk, Key_Asterisk },
  161. { Qt::Key_At, Key_AtSign },
  162. { Qt::Key_B, Key_B },
  163. { Qt::Key_Backslash, Key_Backslash },
  164. { Qt::Key_Backspace, Key_Backspace },
  165. { Qt::Key_Bar, Key_Pipe },
  166. { Qt::Key_BraceLeft, Key_LeftBrace },
  167. { Qt::Key_BraceRight, Key_RightBrace },
  168. { Qt::Key_BracketLeft, Key_LeftBracket },
  169. { Qt::Key_BracketRight, Key_RightBracket },
  170. { Qt::Key_C, Key_C },
  171. { Qt::Key_CapsLock, Key_CapsLock },
  172. { Qt::Key_Colon, Key_Colon },
  173. { Qt::Key_Comma, Key_Comma },
  174. { Qt::Key_Control, Key_Control },
  175. { Qt::Key_D, Key_D },
  176. { Qt::Key_Delete, Key_Delete },
  177. { Qt::Key_Dollar, Key_Dollar },
  178. { Qt::Key_Down, Key_Down },
  179. { Qt::Key_E, Key_E },
  180. { Qt::Key_End, Key_End },
  181. { Qt::Key_Equal, Key_Equal },
  182. { Qt::Key_Escape, Key_Escape },
  183. { Qt::Key_exclamdown, Key_ExclamationPoint },
  184. { Qt::Key_F, Key_F },
  185. { Qt::Key_F1, Key_F1 },
  186. { Qt::Key_F10, Key_F10 },
  187. { Qt::Key_F11, Key_F11 },
  188. { Qt::Key_F12, Key_F12 },
  189. { Qt::Key_F2, Key_F2 },
  190. { Qt::Key_F3, Key_F3 },
  191. { Qt::Key_F4, Key_F4 },
  192. { Qt::Key_F5, Key_F5 },
  193. { Qt::Key_F6, Key_F6 },
  194. { Qt::Key_F7, Key_F7 },
  195. { Qt::Key_F8, Key_F8 },
  196. { Qt::Key_F9, Key_F9 },
  197. { Qt::Key_G, Key_G },
  198. { Qt::Key_Greater, Key_GreaterThan },
  199. { Qt::Key_H, Key_H },
  200. { Qt::Key_Home, Key_Home },
  201. { Qt::Key_I, Key_I },
  202. { Qt::Key_Insert, Key_Insert },
  203. { Qt::Key_J, Key_J },
  204. { Qt::Key_K, Key_K },
  205. { Qt::Key_L, Key_L },
  206. { Qt::Key_Left, Key_Left },
  207. { Qt::Key_Less, Key_LessThan },
  208. { Qt::Key_M, Key_M },
  209. { Qt::Key_Menu, Key_Menu },
  210. { Qt::Key_Minus, Key_Minus },
  211. { Qt::Key_N, Key_N },
  212. { Qt::Key_NumLock, Key_NumLock },
  213. { Qt::Key_O, Key_O },
  214. { Qt::Key_P, Key_P },
  215. { Qt::Key_PageDown, Key_PageDown },
  216. { Qt::Key_PageUp, Key_PageUp },
  217. { Qt::Key_ParenLeft, Key_LeftParen },
  218. { Qt::Key_ParenRight, Key_RightParen },
  219. { Qt::Key_Percent, Key_Percent },
  220. { Qt::Key_Period, Key_Period },
  221. { Qt::Key_Plus, Key_Plus },
  222. { Qt::Key_Print, Key_PrintScreen },
  223. { Qt::Key_Q, Key_Q },
  224. { Qt::Key_Question, Key_QuestionMark },
  225. { Qt::Key_QuoteDbl, Key_DoubleQuote },
  226. { Qt::Key_R, Key_R },
  227. { Qt::Key_Return, Key_Return },
  228. { Qt::Key_Right, Key_Right },
  229. { Qt::Key_S, Key_S },
  230. { Qt::Key_ScrollLock, Key_ScrollLock },
  231. { Qt::Key_Semicolon, Key_Semicolon },
  232. { Qt::Key_Shift, Key_LeftShift },
  233. { Qt::Key_Slash, Key_Slash },
  234. { Qt::Key_Space, Key_Space },
  235. { Qt::Key_Super_L, Key_Super },
  236. { Qt::Key_SysReq, Key_SysRq },
  237. { Qt::Key_T, Key_T },
  238. { Qt::Key_Tab, Key_Tab },
  239. { Qt::Key_U, Key_U },
  240. { Qt::Key_Underscore, Key_Underscore },
  241. { Qt::Key_Up, Key_Up },
  242. { Qt::Key_V, Key_V },
  243. { Qt::Key_W, Key_W },
  244. { Qt::Key_X, Key_X },
  245. { Qt::Key_Y, Key_Y },
  246. { Qt::Key_Z, Key_Z },
  247. };
  248. for (auto const& mapping : mappings) {
  249. if (event.key() == mapping.qt_key)
  250. return mapping.serenity_key;
  251. }
  252. return Key_Invalid;
  253. }
  254. void WebContentView::mouseMoveEvent(QMouseEvent* event)
  255. {
  256. Gfx::IntPoint position(event->position().x() / m_inverse_pixel_scaling_ratio, event->position().y() / m_inverse_pixel_scaling_ratio);
  257. auto buttons = get_buttons_from_qt_event(*event);
  258. auto modifiers = get_modifiers_from_qt_mouse_event(*event);
  259. client().async_mouse_move(to_content(position), 0, buttons, modifiers);
  260. }
  261. void WebContentView::mousePressEvent(QMouseEvent* event)
  262. {
  263. Gfx::IntPoint position(event->position().x() / m_inverse_pixel_scaling_ratio, event->position().y() / m_inverse_pixel_scaling_ratio);
  264. auto button = get_button_from_qt_event(*event);
  265. if (button == 0) {
  266. // We could not convert Qt buttons to something that Lagom can
  267. // recognize - don't even bother propagating this to the web engine
  268. // as it will not handle it anyway, and it will (currently) assert
  269. return;
  270. }
  271. auto modifiers = get_modifiers_from_qt_mouse_event(*event);
  272. auto buttons = get_buttons_from_qt_event(*event);
  273. client().async_mouse_down(to_content(position), button, buttons, modifiers);
  274. }
  275. void WebContentView::mouseReleaseEvent(QMouseEvent* event)
  276. {
  277. Gfx::IntPoint position(event->position().x() / m_inverse_pixel_scaling_ratio, event->position().y() / m_inverse_pixel_scaling_ratio);
  278. auto button = get_button_from_qt_event(*event);
  279. if (event->button() & Qt::MouseButton::BackButton) {
  280. emit back_mouse_button();
  281. } else if (event->button() & Qt::MouseButton::ForwardButton) {
  282. emit forward_mouse_button();
  283. }
  284. if (button == 0) {
  285. // We could not convert Qt buttons to something that Lagom can
  286. // recognize - don't even bother propagating this to the web engine
  287. // as it will not handle it anyway, and it will (currently) assert
  288. return;
  289. }
  290. auto modifiers = get_modifiers_from_qt_mouse_event(*event);
  291. auto buttons = get_buttons_from_qt_event(*event);
  292. client().async_mouse_up(to_content(position), button, buttons, modifiers);
  293. }
  294. void WebContentView::dragEnterEvent(QDragEnterEvent* event)
  295. {
  296. if (event->mimeData()->hasUrls())
  297. event->acceptProposedAction();
  298. }
  299. void WebContentView::dropEvent(QDropEvent* event)
  300. {
  301. VERIFY(event->mimeData()->hasUrls());
  302. emit urls_dropped(event->mimeData()->urls());
  303. event->acceptProposedAction();
  304. }
  305. void WebContentView::keyPressEvent(QKeyEvent* event)
  306. {
  307. switch (event->key()) {
  308. case Qt::Key_Left:
  309. case Qt::Key_Right:
  310. case Qt::Key_Up:
  311. case Qt::Key_Down:
  312. case Qt::Key_PageUp:
  313. case Qt::Key_PageDown:
  314. QAbstractScrollArea::keyPressEvent(event);
  315. break;
  316. default:
  317. break;
  318. }
  319. if (event->key() == Qt::Key_Backtab) {
  320. // NOTE: Qt transforms Shift+Tab into a "Backtab", so we undo that transformation here.
  321. client().async_key_down(KeyCode::Key_Tab, Mod_Shift, '\t');
  322. return;
  323. }
  324. auto text = event->text();
  325. if (text.isEmpty()) {
  326. return;
  327. }
  328. auto point = event->text()[0].unicode();
  329. auto keycode = get_keycode_from_qt_keyboard_event(*event);
  330. auto modifiers = get_modifiers_from_qt_keyboard_event(*event);
  331. client().async_key_down(keycode, modifiers, point);
  332. }
  333. void WebContentView::keyReleaseEvent(QKeyEvent* event)
  334. {
  335. auto text = event->text();
  336. if (text.isEmpty()) {
  337. return;
  338. }
  339. auto point = event->text()[0].unicode();
  340. auto keycode = get_keycode_from_qt_keyboard_event(*event);
  341. auto modifiers = get_modifiers_from_qt_keyboard_event(*event);
  342. client().async_key_up(keycode, modifiers, point);
  343. }
  344. void WebContentView::focusInEvent(QFocusEvent*)
  345. {
  346. client().async_set_has_focus(true);
  347. }
  348. void WebContentView::focusOutEvent(QFocusEvent*)
  349. {
  350. client().async_set_has_focus(false);
  351. }
  352. Gfx::IntPoint WebContentView::to_content(Gfx::IntPoint viewport_position) const
  353. {
  354. return viewport_position.translated(horizontalScrollBar()->value(), verticalScrollBar()->value());
  355. }
  356. Gfx::IntPoint WebContentView::to_widget(Gfx::IntPoint content_position) const
  357. {
  358. return content_position.translated(-horizontalScrollBar()->value(), -verticalScrollBar()->value());
  359. }
  360. void WebContentView::paintEvent(QPaintEvent*)
  361. {
  362. QPainter painter(viewport());
  363. painter.scale(m_inverse_pixel_scaling_ratio, m_inverse_pixel_scaling_ratio);
  364. if (auto* bitmap = m_client_state.has_usable_bitmap ? m_client_state.front_bitmap.bitmap.ptr() : m_backup_bitmap.ptr()) {
  365. QImage q_image(bitmap->scanline_u8(0), bitmap->width(), bitmap->height(), QImage::Format_RGB32);
  366. painter.drawImage(QPoint(0, 0), q_image);
  367. return;
  368. }
  369. painter.fillRect(rect(), palette().base());
  370. }
  371. void WebContentView::resizeEvent(QResizeEvent* event)
  372. {
  373. QAbstractScrollArea::resizeEvent(event);
  374. handle_resize();
  375. }
  376. void WebContentView::handle_resize()
  377. {
  378. update_viewport_rect();
  379. if (m_client_state.has_usable_bitmap) {
  380. // NOTE: We keep the outgoing front bitmap as a backup so we have something to paint until we get a new one.
  381. m_backup_bitmap = m_client_state.front_bitmap.bitmap;
  382. }
  383. if (m_client_state.front_bitmap.bitmap)
  384. client().async_remove_backing_store(m_client_state.front_bitmap.id);
  385. if (m_client_state.back_bitmap.bitmap)
  386. client().async_remove_backing_store(m_client_state.back_bitmap.id);
  387. m_client_state.front_bitmap = {};
  388. m_client_state.back_bitmap = {};
  389. m_client_state.has_usable_bitmap = false;
  390. auto available_size = m_viewport_rect.size();
  391. if (available_size.is_empty())
  392. return;
  393. if (auto new_bitmap_or_error = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size); !new_bitmap_or_error.is_error()) {
  394. m_client_state.front_bitmap.bitmap = new_bitmap_or_error.release_value();
  395. m_client_state.front_bitmap.id = m_client_state.next_bitmap_id++;
  396. client().async_add_backing_store(m_client_state.front_bitmap.id, m_client_state.front_bitmap.bitmap->to_shareable_bitmap());
  397. }
  398. if (auto new_bitmap_or_error = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size); !new_bitmap_or_error.is_error()) {
  399. m_client_state.back_bitmap.bitmap = new_bitmap_or_error.release_value();
  400. m_client_state.back_bitmap.id = m_client_state.next_bitmap_id++;
  401. client().async_add_backing_store(m_client_state.back_bitmap.id, m_client_state.back_bitmap.bitmap->to_shareable_bitmap());
  402. }
  403. request_repaint();
  404. }
  405. void WebContentView::set_viewport_rect(Gfx::IntRect rect)
  406. {
  407. m_viewport_rect = rect;
  408. client().async_set_viewport_rect(rect);
  409. }
  410. void WebContentView::set_window_size(Gfx::IntSize size)
  411. {
  412. client().async_set_window_size(size);
  413. }
  414. void WebContentView::set_window_position(Gfx::IntPoint position)
  415. {
  416. client().async_set_window_position(position);
  417. }
  418. void WebContentView::update_viewport_rect()
  419. {
  420. auto scaled_width = int(viewport()->width() / m_inverse_pixel_scaling_ratio);
  421. auto scaled_height = int(viewport()->height() / m_inverse_pixel_scaling_ratio);
  422. Gfx::IntRect rect(horizontalScrollBar()->value(), verticalScrollBar()->value(), scaled_width, scaled_height);
  423. set_viewport_rect(rect);
  424. request_repaint();
  425. }
  426. void WebContentView::did_output_js_console_message(i32 message_index)
  427. {
  428. if (m_console_widget)
  429. m_console_widget->notify_about_new_console_message(message_index);
  430. }
  431. void WebContentView::did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> message_types, Vector<DeprecatedString> messages)
  432. {
  433. if (m_console_widget)
  434. m_console_widget->handle_console_messages(start_index, message_types, messages);
  435. }
  436. void WebContentView::ensure_js_console_widget()
  437. {
  438. if (!m_console_widget) {
  439. m_console_widget = new Ladybird::ConsoleWidget;
  440. m_console_widget->setWindowTitle("JS Console");
  441. m_console_widget->resize(640, 480);
  442. m_console_widget->on_js_input = [this](auto js_source) {
  443. client().async_js_console_input(js_source);
  444. };
  445. m_console_widget->on_request_messages = [this](i32 start_index) {
  446. client().async_js_console_request_messages(start_index);
  447. };
  448. }
  449. }
  450. void WebContentView::show_js_console()
  451. {
  452. ensure_js_console_widget();
  453. m_console_widget->show();
  454. }
  455. void WebContentView::ensure_inspector_widget()
  456. {
  457. if (m_inspector_widget)
  458. return;
  459. m_inspector_widget = new Ladybird::InspectorWidget;
  460. m_inspector_widget->setWindowTitle("Inspector");
  461. m_inspector_widget->resize(640, 480);
  462. m_inspector_widget->on_close = [this] {
  463. clear_inspected_dom_node();
  464. };
  465. m_inspector_widget->on_dom_node_inspected = [&](auto id, auto pseudo_element) {
  466. return inspect_dom_node(id, pseudo_element);
  467. };
  468. }
  469. void WebContentView::close_sub_widgets()
  470. {
  471. auto close_widget_window = [](auto* widget) {
  472. if (widget)
  473. widget->close();
  474. };
  475. close_widget_window(m_console_widget);
  476. close_widget_window(m_inspector_widget);
  477. }
  478. bool WebContentView::is_inspector_open() const
  479. {
  480. return m_inspector_widget && m_inspector_widget->isVisible();
  481. }
  482. void WebContentView::show_inspector()
  483. {
  484. ensure_inspector_widget();
  485. m_inspector_widget->show();
  486. inspect_dom_tree();
  487. inspect_accessibility_tree();
  488. }
  489. void WebContentView::update_zoom()
  490. {
  491. client().async_set_device_pixels_per_css_pixel(m_device_pixel_ratio * m_zoom_level);
  492. update_viewport_rect();
  493. request_repaint();
  494. }
  495. void WebContentView::showEvent(QShowEvent* event)
  496. {
  497. QAbstractScrollArea::showEvent(event);
  498. client().async_set_system_visibility_state(true);
  499. }
  500. void WebContentView::hideEvent(QHideEvent* event)
  501. {
  502. QAbstractScrollArea::hideEvent(event);
  503. client().async_set_system_visibility_state(false);
  504. }
  505. static Core::AnonymousBuffer make_system_theme_from_qt_palette(QWidget& widget, WebContentView::PaletteMode mode)
  506. {
  507. auto qt_palette = widget.palette();
  508. auto theme_file = mode == WebContentView::PaletteMode::Default ? "Default"sv : "Dark"sv;
  509. auto theme = Gfx::load_system_theme(DeprecatedString::formatted("{}/res/themes/{}.ini", s_serenity_resource_root, theme_file)).release_value_but_fixme_should_propagate_errors();
  510. auto palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
  511. auto palette = Gfx::Palette(move(palette_impl));
  512. auto translate = [&](Gfx::ColorRole gfx_color_role, QPalette::ColorRole qt_color_role) {
  513. auto new_color = Gfx::Color::from_argb(qt_palette.color(qt_color_role).rgba());
  514. palette.set_color(gfx_color_role, new_color);
  515. };
  516. translate(Gfx::ColorRole::ThreedHighlight, QPalette::ColorRole::Light);
  517. translate(Gfx::ColorRole::ThreedShadow1, QPalette::ColorRole::Mid);
  518. translate(Gfx::ColorRole::ThreedShadow2, QPalette::ColorRole::Dark);
  519. translate(Gfx::ColorRole::HoverHighlight, QPalette::ColorRole::Light);
  520. translate(Gfx::ColorRole::Link, QPalette::ColorRole::Link);
  521. translate(Gfx::ColorRole::VisitedLink, QPalette::ColorRole::LinkVisited);
  522. translate(Gfx::ColorRole::Button, QPalette::ColorRole::Button);
  523. translate(Gfx::ColorRole::ButtonText, QPalette::ColorRole::ButtonText);
  524. translate(Gfx::ColorRole::Selection, QPalette::ColorRole::Highlight);
  525. translate(Gfx::ColorRole::SelectionText, QPalette::ColorRole::HighlightedText);
  526. return theme;
  527. }
  528. void WebContentView::update_palette(PaletteMode mode)
  529. {
  530. client().async_update_system_theme(make_system_theme_from_qt_palette(*this, mode));
  531. }
  532. void WebContentView::create_client(WebView::EnableCallgrindProfiling enable_callgrind_profiling)
  533. {
  534. m_client_state = {};
  535. auto candidate_web_content_paths = get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors();
  536. auto new_client = launch_web_content_process(candidate_web_content_paths, enable_callgrind_profiling).release_value_but_fixme_should_propagate_errors();
  537. m_web_content_notifier.setSocket(new_client->socket().fd().value());
  538. m_web_content_notifier.setEnabled(true);
  539. QObject::connect(&m_web_content_notifier, &QSocketNotifier::activated, [new_client = new_client.ptr()] {
  540. if (auto notifier = new_client->socket().notifier())
  541. notifier->on_ready_to_read();
  542. });
  543. struct DeferredInvokerQt final : IPC::DeferredInvoker {
  544. virtual ~DeferredInvokerQt() = default;
  545. virtual void schedule(Function<void()> callback) override
  546. {
  547. QTimer::singleShot(0, std::move(callback));
  548. }
  549. };
  550. new_client->set_deferred_invoker(make<DeferredInvokerQt>());
  551. m_client_state.client = new_client;
  552. m_client_state.client->on_web_content_process_crash = [this] {
  553. QTimer::singleShot(0, [this] {
  554. handle_web_content_process_crash();
  555. });
  556. };
  557. m_client_state.client_handle = Web::Crypto::generate_random_uuid().release_value_but_fixme_should_propagate_errors();
  558. client().async_set_window_handle(m_client_state.client_handle);
  559. client().async_set_device_pixels_per_css_pixel(m_device_pixel_ratio);
  560. update_palette();
  561. client().async_update_system_fonts(Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query(), Gfx::FontDatabase::window_title_font_query());
  562. // FIXME: Get the screen rect.
  563. // client().async_update_screen_rects(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index());
  564. if (!m_webdriver_content_ipc_path.is_empty())
  565. client().async_connect_to_webdriver(m_webdriver_content_ipc_path);
  566. }
  567. void WebContentView::handle_web_content_process_crash()
  568. {
  569. dbgln("WebContent process crashed!");
  570. create_client();
  571. VERIFY(m_client_state.client);
  572. // Don't keep a stale backup bitmap around.
  573. m_backup_bitmap = nullptr;
  574. handle_resize();
  575. StringBuilder builder;
  576. builder.append("<html><head><title>Crashed: "sv);
  577. builder.append(escape_html_entities(m_url.to_deprecated_string()));
  578. builder.append("</title></head><body>"sv);
  579. builder.append("<h1>Web page crashed"sv);
  580. if (!m_url.host().is_empty()) {
  581. builder.appendff(" on {}", escape_html_entities(m_url.host()));
  582. }
  583. builder.append("</h1>"sv);
  584. auto escaped_url = escape_html_entities(m_url.to_deprecated_string());
  585. builder.appendff("The web page <a href=\"{}\">{}</a> has crashed.<br><br>You can reload the page to try again.", escaped_url, escaped_url);
  586. builder.append("</body></html>"sv);
  587. load_html(builder.to_deprecated_string(), m_url);
  588. }
  589. void WebContentView::notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id)
  590. {
  591. if (m_client_state.back_bitmap.id == bitmap_id) {
  592. m_client_state.has_usable_bitmap = true;
  593. m_client_state.back_bitmap.pending_paints--;
  594. swap(m_client_state.back_bitmap, m_client_state.front_bitmap);
  595. // We don't need the backup bitmap anymore, so drop it.
  596. m_backup_bitmap = nullptr;
  597. viewport()->update();
  598. if (m_client_state.got_repaint_requests_while_painting) {
  599. m_client_state.got_repaint_requests_while_painting = false;
  600. request_repaint();
  601. }
  602. }
  603. }
  604. void WebContentView::notify_server_did_invalidate_content_rect(Badge<WebContentClient>, [[maybe_unused]] Gfx::IntRect const& content_rect)
  605. {
  606. request_repaint();
  607. }
  608. void WebContentView::notify_server_did_change_selection(Badge<WebContentClient>)
  609. {
  610. request_repaint();
  611. }
  612. void WebContentView::notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor)
  613. {
  614. switch (cursor) {
  615. case Gfx::StandardCursor::Hidden:
  616. setCursor(Qt::BlankCursor);
  617. break;
  618. case Gfx::StandardCursor::Arrow:
  619. setCursor(Qt::ArrowCursor);
  620. break;
  621. case Gfx::StandardCursor::Crosshair:
  622. setCursor(Qt::CrossCursor);
  623. break;
  624. case Gfx::StandardCursor::IBeam:
  625. setCursor(Qt::IBeamCursor);
  626. break;
  627. case Gfx::StandardCursor::ResizeHorizontal:
  628. setCursor(Qt::SizeHorCursor);
  629. break;
  630. case Gfx::StandardCursor::ResizeVertical:
  631. setCursor(Qt::SizeVerCursor);
  632. break;
  633. case Gfx::StandardCursor::ResizeDiagonalTLBR:
  634. setCursor(Qt::SizeFDiagCursor);
  635. break;
  636. case Gfx::StandardCursor::ResizeDiagonalBLTR:
  637. setCursor(Qt::SizeBDiagCursor);
  638. break;
  639. case Gfx::StandardCursor::ResizeColumn:
  640. setCursor(Qt::SplitHCursor);
  641. break;
  642. case Gfx::StandardCursor::ResizeRow:
  643. setCursor(Qt::SplitVCursor);
  644. break;
  645. case Gfx::StandardCursor::Hand:
  646. setCursor(Qt::PointingHandCursor);
  647. break;
  648. case Gfx::StandardCursor::Help:
  649. setCursor(Qt::WhatsThisCursor);
  650. break;
  651. case Gfx::StandardCursor::Drag:
  652. setCursor(Qt::ClosedHandCursor);
  653. break;
  654. case Gfx::StandardCursor::DragCopy:
  655. setCursor(Qt::DragCopyCursor);
  656. break;
  657. case Gfx::StandardCursor::Move:
  658. setCursor(Qt::DragMoveCursor);
  659. break;
  660. case Gfx::StandardCursor::Wait:
  661. setCursor(Qt::BusyCursor);
  662. break;
  663. case Gfx::StandardCursor::Disallowed:
  664. setCursor(Qt::ForbiddenCursor);
  665. break;
  666. case Gfx::StandardCursor::Eyedropper:
  667. case Gfx::StandardCursor::Zoom:
  668. // FIXME: No corresponding Qt cursors, default to Arrow
  669. default:
  670. setCursor(Qt::ArrowCursor);
  671. break;
  672. }
  673. }
  674. void WebContentView::notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size)
  675. {
  676. verticalScrollBar()->setMinimum(0);
  677. verticalScrollBar()->setMaximum(content_size.height() - m_viewport_rect.height());
  678. verticalScrollBar()->setPageStep(m_viewport_rect.height());
  679. horizontalScrollBar()->setMinimum(0);
  680. horizontalScrollBar()->setMaximum(content_size.width() - m_viewport_rect.width());
  681. horizontalScrollBar()->setPageStep(m_viewport_rect.width());
  682. }
  683. void WebContentView::notify_server_did_change_title(Badge<WebContentClient>, DeprecatedString const& title)
  684. {
  685. emit title_changed(qstring_from_ak_deprecated_string(title));
  686. }
  687. void WebContentView::notify_server_did_request_scroll(Badge<WebContentClient>, i32 x_delta, i32 y_delta)
  688. {
  689. horizontalScrollBar()->setValue(horizontalScrollBar()->value() + x_delta);
  690. verticalScrollBar()->setValue(verticalScrollBar()->value() + y_delta);
  691. }
  692. void WebContentView::notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint scroll_position)
  693. {
  694. horizontalScrollBar()->setValue(scroll_position.x());
  695. verticalScrollBar()->setValue(scroll_position.y());
  696. }
  697. void WebContentView::notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const& rect)
  698. {
  699. if (m_viewport_rect.contains(rect))
  700. return;
  701. if (rect.top() < m_viewport_rect.top()) {
  702. verticalScrollBar()->setValue(rect.top());
  703. } else if (rect.top() > m_viewport_rect.top() && rect.bottom() > m_viewport_rect.bottom()) {
  704. verticalScrollBar()->setValue(rect.bottom() - m_viewport_rect.height() + 1);
  705. }
  706. }
  707. void WebContentView::notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint content_position, DeprecatedString const& tooltip)
  708. {
  709. auto widget_position = to_widget(content_position);
  710. QToolTip::showText(
  711. mapToGlobal(QPoint(widget_position.x(), widget_position.y())),
  712. qstring_from_ak_deprecated_string(tooltip),
  713. this);
  714. }
  715. void WebContentView::notify_server_did_leave_tooltip_area(Badge<WebContentClient>)
  716. {
  717. QToolTip::hideText();
  718. }
  719. void WebContentView::notify_server_did_hover_link(Badge<WebContentClient>, AK::URL const& url)
  720. {
  721. emit link_hovered(qstring_from_ak_deprecated_string(url.to_deprecated_string()));
  722. }
  723. void WebContentView::notify_server_did_unhover_link(Badge<WebContentClient>)
  724. {
  725. emit link_unhovered();
  726. }
  727. void WebContentView::notify_server_did_click_link(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& target, unsigned int modifiers)
  728. {
  729. if (on_link_click) {
  730. on_link_click(url, target, modifiers);
  731. }
  732. }
  733. void WebContentView::notify_server_did_middle_click_link(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& target, unsigned int modifiers)
  734. {
  735. if (on_link_middle_click) {
  736. on_link_middle_click(url, target, modifiers);
  737. }
  738. }
  739. void WebContentView::notify_server_did_start_loading(Badge<WebContentClient>, AK::URL const& url, bool is_redirect)
  740. {
  741. m_url = url;
  742. emit load_started(url, is_redirect);
  743. if (m_inspector_widget)
  744. m_inspector_widget->clear_dom_json();
  745. }
  746. void WebContentView::notify_server_did_finish_loading(Badge<WebContentClient>, AK::URL const& url)
  747. {
  748. m_url = url;
  749. if (is_inspector_open()) {
  750. inspect_dom_tree();
  751. inspect_accessibility_tree();
  752. }
  753. if (on_load_finish)
  754. on_load_finish(url);
  755. }
  756. void WebContentView::notify_server_did_request_navigate_back(Badge<WebContentClient>)
  757. {
  758. emit navigate_back();
  759. }
  760. void WebContentView::notify_server_did_request_navigate_forward(Badge<WebContentClient>)
  761. {
  762. emit navigate_forward();
  763. }
  764. void WebContentView::notify_server_did_request_refresh(Badge<WebContentClient>)
  765. {
  766. emit refresh();
  767. }
  768. void WebContentView::notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position)
  769. {
  770. // FIXME
  771. (void)content_position;
  772. }
  773. void WebContentView::notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned)
  774. {
  775. // FIXME
  776. (void)content_position;
  777. (void)url;
  778. }
  779. void WebContentView::notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned, Gfx::ShareableBitmap const& bitmap)
  780. {
  781. // FIXME
  782. (void)content_position;
  783. (void)url;
  784. (void)bitmap;
  785. }
  786. void WebContentView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
  787. {
  788. m_dialog = new QMessageBox(QMessageBox::Icon::Warning, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok, this);
  789. m_dialog->exec();
  790. client().async_alert_closed();
  791. m_dialog = nullptr;
  792. }
  793. void WebContentView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
  794. {
  795. m_dialog = new QMessageBox(QMessageBox::Icon::Question, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, this);
  796. auto result = m_dialog->exec();
  797. client().async_confirm_closed(result == QMessageBox::StandardButton::Ok || result == QDialog::Accepted);
  798. m_dialog = nullptr;
  799. }
  800. void WebContentView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
  801. {
  802. m_dialog = new QInputDialog(this);
  803. auto& dialog = static_cast<QInputDialog&>(*m_dialog);
  804. dialog.setWindowTitle("Ladybird");
  805. dialog.setLabelText(qstring_from_ak_string(message));
  806. dialog.setTextValue(qstring_from_ak_string(default_));
  807. if (dialog.exec() == QDialog::Accepted)
  808. client().async_prompt_closed(ak_string_from_qstring(dialog.textValue()).release_value_but_fixme_should_propagate_errors());
  809. else
  810. client().async_prompt_closed({});
  811. m_dialog = nullptr;
  812. }
  813. void WebContentView::notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message)
  814. {
  815. if (m_dialog && is<QInputDialog>(*m_dialog))
  816. static_cast<QInputDialog&>(*m_dialog).setTextValue(qstring_from_ak_string(message));
  817. }
  818. void WebContentView::notify_server_did_request_accept_dialog(Badge<WebContentClient>)
  819. {
  820. if (m_dialog)
  821. m_dialog->accept();
  822. }
  823. void WebContentView::notify_server_did_request_dismiss_dialog(Badge<WebContentClient>)
  824. {
  825. if (m_dialog)
  826. m_dialog->reject();
  827. }
  828. void WebContentView::notify_server_did_get_source(AK::URL const& url, DeprecatedString const& source)
  829. {
  830. emit got_source(url, qstring_from_ak_deprecated_string(source));
  831. }
  832. void WebContentView::notify_server_did_get_dom_tree(DeprecatedString const& dom_tree)
  833. {
  834. if (on_get_dom_tree)
  835. on_get_dom_tree(dom_tree);
  836. if (m_inspector_widget)
  837. m_inspector_widget->set_dom_json(dom_tree);
  838. }
  839. void WebContentView::notify_server_did_get_dom_node_properties(i32 node_id, DeprecatedString const& specified_style, DeprecatedString const& computed_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing)
  840. {
  841. if (on_get_dom_node_properties)
  842. on_get_dom_node_properties(node_id, specified_style, computed_style, custom_properties, node_box_sizing);
  843. }
  844. void WebContentView::notify_server_did_output_js_console_message(i32 message_index)
  845. {
  846. if (m_console_widget)
  847. m_console_widget->notify_about_new_console_message(message_index);
  848. }
  849. void WebContentView::notify_server_did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages)
  850. {
  851. if (m_console_widget)
  852. m_console_widget->handle_console_messages(start_index, message_types, messages);
  853. }
  854. void WebContentView::notify_server_did_change_favicon(Gfx::Bitmap const& bitmap)
  855. {
  856. auto qimage = QImage(bitmap.scanline_u8(0), bitmap.width(), bitmap.height(), QImage::Format_ARGB32);
  857. if (qimage.isNull())
  858. return;
  859. auto qpixmap = QPixmap::fromImage(qimage);
  860. if (qpixmap.isNull())
  861. return;
  862. emit favicon_changed(QIcon(qpixmap));
  863. }
  864. Vector<Web::Cookie::Cookie> WebContentView::notify_server_did_request_all_cookies(Badge<WebContentClient>, AK::URL const& url)
  865. {
  866. if (on_get_all_cookies)
  867. return on_get_all_cookies(url);
  868. return {};
  869. }
  870. Optional<Web::Cookie::Cookie> WebContentView::notify_server_did_request_named_cookie(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& name)
  871. {
  872. if (on_get_named_cookie)
  873. return on_get_named_cookie(url, name);
  874. return {};
  875. }
  876. DeprecatedString WebContentView::notify_server_did_request_cookie(Badge<WebContentClient>, AK::URL const& url, Web::Cookie::Source source)
  877. {
  878. if (on_get_cookie)
  879. return on_get_cookie(url, source);
  880. return {};
  881. }
  882. void WebContentView::notify_server_did_set_cookie(Badge<WebContentClient>, AK::URL const& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)
  883. {
  884. if (on_set_cookie)
  885. on_set_cookie(url, cookie, source);
  886. }
  887. void WebContentView::notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie)
  888. {
  889. if (on_update_cookie)
  890. on_update_cookie(cookie);
  891. }
  892. void WebContentView::notify_server_did_close_browsing_context(Badge<WebContentClient>)
  893. {
  894. emit close();
  895. }
  896. String WebContentView::notify_server_did_request_new_tab(Badge<WebContentClient>, Web::HTML::ActivateTab activate_tab)
  897. {
  898. if (on_new_tab)
  899. return on_new_tab(activate_tab);
  900. return {};
  901. }
  902. void WebContentView::notify_server_did_request_activate_tab(Badge<WebContentClient>)
  903. {
  904. emit activate_tab();
  905. }
  906. void WebContentView::notify_server_did_update_resource_count(i32 count_waiting)
  907. {
  908. // FIXME
  909. (void)count_waiting;
  910. }
  911. void WebContentView::notify_server_did_request_restore_window()
  912. {
  913. emit restore_window();
  914. }
  915. Gfx::IntPoint WebContentView::notify_server_did_request_reposition_window(Gfx::IntPoint position)
  916. {
  917. return emit reposition_window(position);
  918. }
  919. Gfx::IntSize WebContentView::notify_server_did_request_resize_window(Gfx::IntSize size)
  920. {
  921. return emit resize_window(size);
  922. }
  923. Gfx::IntRect WebContentView::notify_server_did_request_maximize_window()
  924. {
  925. return emit maximize_window();
  926. }
  927. Gfx::IntRect WebContentView::notify_server_did_request_minimize_window()
  928. {
  929. return emit minimize_window();
  930. }
  931. Gfx::IntRect WebContentView::notify_server_did_request_fullscreen_window()
  932. {
  933. return emit fullscreen_window();
  934. }
  935. void WebContentView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id)
  936. {
  937. auto file = Core::File::open(path, Core::File::OpenMode::Read);
  938. if (file.is_error())
  939. client().async_handle_file_return(file.error().code(), {}, request_id);
  940. else
  941. client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
  942. }
  943. void WebContentView::request_repaint()
  944. {
  945. // If this widget was instantiated but not yet added to a window,
  946. // it won't have a back bitmap yet, so we can just skip repaint requests.
  947. if (!m_client_state.back_bitmap.bitmap)
  948. return;
  949. // Don't request a repaint until pending paint requests have finished.
  950. if (m_client_state.back_bitmap.pending_paints) {
  951. m_client_state.got_repaint_requests_while_painting = true;
  952. return;
  953. }
  954. m_client_state.back_bitmap.pending_paints++;
  955. client().async_paint(m_client_state.back_bitmap.bitmap->rect().translated(horizontalScrollBar()->value(), verticalScrollBar()->value()), m_client_state.back_bitmap.id);
  956. }
  957. bool WebContentView::event(QEvent* event)
  958. {
  959. // NOTE: We have to implement event() manually as Qt's focus navigation mechanism
  960. // eats all the Tab key presses by default.
  961. if (event->type() == QEvent::KeyPress) {
  962. keyPressEvent(static_cast<QKeyEvent*>(event));
  963. return true;
  964. }
  965. if (event->type() == QEvent::KeyRelease) {
  966. keyReleaseEvent(static_cast<QKeyEvent*>(event));
  967. return true;
  968. }
  969. if (event->type() == QEvent::PaletteChange) {
  970. update_palette();
  971. request_repaint();
  972. return QAbstractScrollArea::event(event);
  973. }
  974. return QAbstractScrollArea::event(event);
  975. }
  976. void WebContentView::notify_server_did_finish_handling_input_event(bool event_was_accepted)
  977. {
  978. // FIXME: Currently Ladybird handles the keyboard shortcuts before passing the event to web content, so
  979. // we don't need to do anything here. But we'll need to once we start asking web content first.
  980. (void)event_was_accepted;
  981. }
  982. void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_json)
  983. {
  984. if (m_inspector_widget)
  985. m_inspector_widget->set_accessibility_json(accessibility_json);
  986. }
  987. ErrorOr<String> WebContentView::dump_layout_tree()
  988. {
  989. return String::from_deprecated_string(client().dump_layout_tree());
  990. }