WebContentView.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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. #include "WebContentView.h"
  8. #include "ConsoleWidget.h"
  9. #include "HelperProcess.h"
  10. #include "InspectorWidget.h"
  11. #include "Utilities.h"
  12. #include <AK/Assertions.h>
  13. #include <AK/ByteBuffer.h>
  14. #include <AK/Format.h>
  15. #include <AK/HashTable.h>
  16. #include <AK/LexicalPath.h>
  17. #include <AK/NonnullOwnPtr.h>
  18. #include <AK/StringBuilder.h>
  19. #include <AK/Types.h>
  20. #include <Browser/CookieJar.h>
  21. #include <Kernel/API/KeyCode.h>
  22. #include <LibCore/ArgsParser.h>
  23. #include <LibCore/EventLoop.h>
  24. #include <LibCore/IODevice.h>
  25. #include <LibCore/System.h>
  26. #include <LibCore/Timer.h>
  27. #include <LibGfx/Bitmap.h>
  28. #include <LibGfx/Font/FontDatabase.h>
  29. #include <LibGfx/ImageFormats/PNGWriter.h>
  30. #include <LibGfx/Painter.h>
  31. #include <LibGfx/Palette.h>
  32. #include <LibGfx/Rect.h>
  33. #include <LibGfx/SystemTheme.h>
  34. #include <LibJS/Runtime/ConsoleObject.h>
  35. #include <LibMain/Main.h>
  36. #include <LibWeb/Crypto/Crypto.h>
  37. #include <LibWeb/Loader/ContentFilter.h>
  38. #include <LibWebView/WebContentClient.h>
  39. #include <QApplication>
  40. #include <QCursor>
  41. #include <QIcon>
  42. #include <QInputDialog>
  43. #include <QLineEdit>
  44. #include <QMessageBox>
  45. #include <QMimeData>
  46. #include <QMouseEvent>
  47. #include <QPaintEvent>
  48. #include <QPainter>
  49. #include <QPalette>
  50. #include <QScrollBar>
  51. #include <QTextEdit>
  52. #include <QTimer>
  53. #include <QToolTip>
  54. bool is_using_dark_system_theme(QWidget&);
  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::mouseDoubleClickEvent(QMouseEvent* event)
  295. {
  296. Gfx::IntPoint position(event->position().x() / m_inverse_pixel_scaling_ratio, event->position().y() / m_inverse_pixel_scaling_ratio);
  297. auto button = get_button_from_qt_event(*event);
  298. if (button == 0) {
  299. // We could not convert Qt buttons to something that Lagom can
  300. // recognize - don't even bother propagating this to the web engine
  301. // as it will not handle it anyway, and it will (currently) assert
  302. return;
  303. }
  304. auto modifiers = get_modifiers_from_qt_mouse_event(*event);
  305. auto buttons = get_buttons_from_qt_event(*event);
  306. client().async_doubleclick(to_content(position), button, buttons, modifiers);
  307. }
  308. void WebContentView::dragEnterEvent(QDragEnterEvent* event)
  309. {
  310. if (event->mimeData()->hasUrls())
  311. event->acceptProposedAction();
  312. }
  313. void WebContentView::dropEvent(QDropEvent* event)
  314. {
  315. VERIFY(event->mimeData()->hasUrls());
  316. emit urls_dropped(event->mimeData()->urls());
  317. event->acceptProposedAction();
  318. }
  319. void WebContentView::keyPressEvent(QKeyEvent* event)
  320. {
  321. switch (event->key()) {
  322. case Qt::Key_Left:
  323. case Qt::Key_Right:
  324. case Qt::Key_Up:
  325. case Qt::Key_Down:
  326. case Qt::Key_PageUp:
  327. case Qt::Key_PageDown:
  328. QAbstractScrollArea::keyPressEvent(event);
  329. break;
  330. default:
  331. break;
  332. }
  333. if (event->key() == Qt::Key_Backtab) {
  334. // NOTE: Qt transforms Shift+Tab into a "Backtab", so we undo that transformation here.
  335. client().async_key_down(KeyCode::Key_Tab, Mod_Shift, '\t');
  336. return;
  337. }
  338. auto text = event->text();
  339. if (text.isEmpty()) {
  340. return;
  341. }
  342. auto point = event->text()[0].unicode();
  343. auto keycode = get_keycode_from_qt_keyboard_event(*event);
  344. auto modifiers = get_modifiers_from_qt_keyboard_event(*event);
  345. client().async_key_down(keycode, modifiers, point);
  346. }
  347. void WebContentView::keyReleaseEvent(QKeyEvent* event)
  348. {
  349. auto text = event->text();
  350. if (text.isEmpty()) {
  351. return;
  352. }
  353. auto point = event->text()[0].unicode();
  354. auto keycode = get_keycode_from_qt_keyboard_event(*event);
  355. auto modifiers = get_modifiers_from_qt_keyboard_event(*event);
  356. client().async_key_up(keycode, modifiers, point);
  357. }
  358. void WebContentView::focusInEvent(QFocusEvent*)
  359. {
  360. client().async_set_has_focus(true);
  361. }
  362. void WebContentView::focusOutEvent(QFocusEvent*)
  363. {
  364. client().async_set_has_focus(false);
  365. }
  366. Gfx::IntPoint WebContentView::to_content(Gfx::IntPoint viewport_position) const
  367. {
  368. return viewport_position.translated(max(0, horizontalScrollBar()->value()), max(0, verticalScrollBar()->value()));
  369. }
  370. Gfx::IntPoint WebContentView::to_widget(Gfx::IntPoint content_position) const
  371. {
  372. return content_position.translated(-(max(0, horizontalScrollBar()->value())), -(max(0, verticalScrollBar()->value())));
  373. }
  374. void WebContentView::paintEvent(QPaintEvent*)
  375. {
  376. QPainter painter(viewport());
  377. painter.scale(m_inverse_pixel_scaling_ratio, m_inverse_pixel_scaling_ratio);
  378. if (auto* bitmap = m_client_state.has_usable_bitmap ? m_client_state.front_bitmap.bitmap.ptr() : m_backup_bitmap.ptr()) {
  379. QImage q_image(bitmap->scanline_u8(0), bitmap->width(), bitmap->height(), QImage::Format_RGB32);
  380. painter.drawImage(QPoint(0, 0), q_image);
  381. return;
  382. }
  383. painter.fillRect(rect(), palette().base());
  384. }
  385. void WebContentView::resizeEvent(QResizeEvent* event)
  386. {
  387. QAbstractScrollArea::resizeEvent(event);
  388. handle_resize();
  389. }
  390. void WebContentView::handle_resize()
  391. {
  392. update_viewport_rect();
  393. if (m_client_state.has_usable_bitmap) {
  394. // NOTE: We keep the outgoing front bitmap as a backup so we have something to paint until we get a new one.
  395. m_backup_bitmap = m_client_state.front_bitmap.bitmap;
  396. }
  397. if (m_client_state.front_bitmap.bitmap)
  398. client().async_remove_backing_store(m_client_state.front_bitmap.id);
  399. if (m_client_state.back_bitmap.bitmap)
  400. client().async_remove_backing_store(m_client_state.back_bitmap.id);
  401. m_client_state.front_bitmap = {};
  402. m_client_state.back_bitmap = {};
  403. m_client_state.has_usable_bitmap = false;
  404. auto available_size = m_viewport_rect.size();
  405. if (available_size.is_empty())
  406. return;
  407. if (auto new_bitmap_or_error = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size); !new_bitmap_or_error.is_error()) {
  408. m_client_state.front_bitmap.bitmap = new_bitmap_or_error.release_value();
  409. m_client_state.front_bitmap.id = m_client_state.next_bitmap_id++;
  410. client().async_add_backing_store(m_client_state.front_bitmap.id, m_client_state.front_bitmap.bitmap->to_shareable_bitmap());
  411. }
  412. if (auto new_bitmap_or_error = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size); !new_bitmap_or_error.is_error()) {
  413. m_client_state.back_bitmap.bitmap = new_bitmap_or_error.release_value();
  414. m_client_state.back_bitmap.id = m_client_state.next_bitmap_id++;
  415. client().async_add_backing_store(m_client_state.back_bitmap.id, m_client_state.back_bitmap.bitmap->to_shareable_bitmap());
  416. }
  417. request_repaint();
  418. }
  419. void WebContentView::set_viewport_rect(Gfx::IntRect rect)
  420. {
  421. m_viewport_rect = rect;
  422. client().async_set_viewport_rect(rect);
  423. }
  424. void WebContentView::set_window_size(Gfx::IntSize size)
  425. {
  426. client().async_set_window_size(size);
  427. }
  428. void WebContentView::set_window_position(Gfx::IntPoint position)
  429. {
  430. client().async_set_window_position(position);
  431. }
  432. void WebContentView::update_viewport_rect()
  433. {
  434. auto scaled_width = int(viewport()->width() / m_inverse_pixel_scaling_ratio);
  435. auto scaled_height = int(viewport()->height() / m_inverse_pixel_scaling_ratio);
  436. Gfx::IntRect rect(max(0, horizontalScrollBar()->value()), max(0, verticalScrollBar()->value()), scaled_width, scaled_height);
  437. set_viewport_rect(rect);
  438. request_repaint();
  439. }
  440. void WebContentView::did_output_js_console_message(i32 message_index)
  441. {
  442. if (m_console_widget)
  443. m_console_widget->notify_about_new_console_message(message_index);
  444. }
  445. void WebContentView::did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> message_types, Vector<DeprecatedString> messages)
  446. {
  447. if (m_console_widget)
  448. m_console_widget->handle_console_messages(start_index, message_types, messages);
  449. }
  450. void WebContentView::ensure_js_console_widget()
  451. {
  452. if (!m_console_widget) {
  453. m_console_widget = new Ladybird::ConsoleWidget;
  454. m_console_widget->setWindowTitle("JS Console");
  455. m_console_widget->resize(640, 480);
  456. m_console_widget->on_js_input = [this](auto js_source) {
  457. client().async_js_console_input(js_source);
  458. };
  459. m_console_widget->on_request_messages = [this](i32 start_index) {
  460. client().async_js_console_request_messages(start_index);
  461. };
  462. }
  463. }
  464. void WebContentView::show_js_console()
  465. {
  466. ensure_js_console_widget();
  467. m_console_widget->show();
  468. }
  469. void WebContentView::ensure_inspector_widget()
  470. {
  471. if (m_inspector_widget)
  472. return;
  473. m_inspector_widget = new Ladybird::InspectorWidget;
  474. m_inspector_widget->setWindowTitle("Inspector");
  475. m_inspector_widget->resize(640, 480);
  476. m_inspector_widget->on_close = [this] {
  477. clear_inspected_dom_node();
  478. };
  479. m_inspector_widget->on_dom_node_inspected = [&](auto id, auto pseudo_element) {
  480. return inspect_dom_node(id, pseudo_element);
  481. };
  482. }
  483. void WebContentView::close_sub_widgets()
  484. {
  485. auto close_widget_window = [](auto* widget) {
  486. if (widget)
  487. widget->close();
  488. };
  489. close_widget_window(m_console_widget);
  490. close_widget_window(m_inspector_widget);
  491. }
  492. bool WebContentView::is_inspector_open() const
  493. {
  494. return m_inspector_widget && m_inspector_widget->isVisible();
  495. }
  496. void WebContentView::show_inspector(InspectorTarget inspector_target)
  497. {
  498. bool inspector_previously_loaded = m_inspector_widget;
  499. ensure_inspector_widget();
  500. if (!inspector_previously_loaded || !m_inspector_widget->dom_loaded()) {
  501. inspect_dom_tree();
  502. inspect_accessibility_tree();
  503. }
  504. m_inspector_widget->show();
  505. if (inspector_target == InspectorTarget::HoveredElement) {
  506. auto hovered_node = get_hovered_node_id();
  507. m_inspector_widget->set_selection({ hovered_node });
  508. } else {
  509. m_inspector_widget->select_default_node();
  510. }
  511. }
  512. void WebContentView::update_zoom()
  513. {
  514. client().async_set_device_pixels_per_css_pixel(m_device_pixel_ratio * m_zoom_level);
  515. update_viewport_rect();
  516. request_repaint();
  517. }
  518. void WebContentView::showEvent(QShowEvent* event)
  519. {
  520. QAbstractScrollArea::showEvent(event);
  521. client().async_set_system_visibility_state(true);
  522. }
  523. void WebContentView::hideEvent(QHideEvent* event)
  524. {
  525. QAbstractScrollArea::hideEvent(event);
  526. client().async_set_system_visibility_state(false);
  527. }
  528. static Core::AnonymousBuffer make_system_theme_from_qt_palette(QWidget& widget, WebContentView::PaletteMode mode)
  529. {
  530. auto qt_palette = widget.palette();
  531. auto theme_file = mode == WebContentView::PaletteMode::Default ? "Default"sv : "Dark"sv;
  532. auto theme = Gfx::load_system_theme(DeprecatedString::formatted("{}/res/themes/{}.ini", s_serenity_resource_root, theme_file)).release_value_but_fixme_should_propagate_errors();
  533. auto palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
  534. auto palette = Gfx::Palette(move(palette_impl));
  535. auto translate = [&](Gfx::ColorRole gfx_color_role, QPalette::ColorRole qt_color_role) {
  536. auto new_color = Gfx::Color::from_argb(qt_palette.color(qt_color_role).rgba());
  537. palette.set_color(gfx_color_role, new_color);
  538. };
  539. translate(Gfx::ColorRole::ThreedHighlight, QPalette::ColorRole::Light);
  540. translate(Gfx::ColorRole::ThreedShadow1, QPalette::ColorRole::Mid);
  541. translate(Gfx::ColorRole::ThreedShadow2, QPalette::ColorRole::Dark);
  542. translate(Gfx::ColorRole::HoverHighlight, QPalette::ColorRole::Light);
  543. translate(Gfx::ColorRole::Link, QPalette::ColorRole::Link);
  544. translate(Gfx::ColorRole::VisitedLink, QPalette::ColorRole::LinkVisited);
  545. translate(Gfx::ColorRole::Button, QPalette::ColorRole::Button);
  546. translate(Gfx::ColorRole::ButtonText, QPalette::ColorRole::ButtonText);
  547. translate(Gfx::ColorRole::Selection, QPalette::ColorRole::Highlight);
  548. translate(Gfx::ColorRole::SelectionText, QPalette::ColorRole::HighlightedText);
  549. palette.set_flag(Gfx::FlagRole::IsDark, is_using_dark_system_theme(widget));
  550. return theme;
  551. }
  552. void WebContentView::update_palette(PaletteMode mode)
  553. {
  554. client().async_update_system_theme(make_system_theme_from_qt_palette(*this, mode));
  555. }
  556. void WebContentView::create_client(WebView::EnableCallgrindProfiling enable_callgrind_profiling)
  557. {
  558. m_client_state = {};
  559. auto candidate_web_content_paths = get_paths_for_helper_process("WebContent"sv).release_value_but_fixme_should_propagate_errors();
  560. auto new_client = launch_web_content_process(candidate_web_content_paths, enable_callgrind_profiling).release_value_but_fixme_should_propagate_errors();
  561. m_client_state.client = new_client;
  562. m_client_state.client->on_web_content_process_crash = [this] {
  563. Core::deferred_invoke([this] {
  564. handle_web_content_process_crash();
  565. });
  566. };
  567. m_client_state.client_handle = Web::Crypto::generate_random_uuid().release_value_but_fixme_should_propagate_errors();
  568. client().async_set_window_handle(m_client_state.client_handle);
  569. client().async_set_device_pixels_per_css_pixel(m_device_pixel_ratio);
  570. update_palette();
  571. client().async_update_system_fonts(Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query(), Gfx::FontDatabase::window_title_font_query());
  572. // FIXME: Get the screen rect.
  573. // client().async_update_screen_rects(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index());
  574. if (!m_webdriver_content_ipc_path.is_empty())
  575. client().async_connect_to_webdriver(m_webdriver_content_ipc_path);
  576. }
  577. void WebContentView::handle_web_content_process_crash()
  578. {
  579. dbgln("WebContent process crashed!");
  580. create_client();
  581. VERIFY(m_client_state.client);
  582. // Don't keep a stale backup bitmap around.
  583. m_backup_bitmap = nullptr;
  584. handle_resize();
  585. StringBuilder builder;
  586. builder.append("<html><head><title>Crashed: "sv);
  587. builder.append(escape_html_entities(m_url.to_deprecated_string()));
  588. builder.append("</title></head><body>"sv);
  589. builder.append("<h1>Web page crashed"sv);
  590. if (!m_url.host().is_empty()) {
  591. builder.appendff(" on {}", escape_html_entities(m_url.host()));
  592. }
  593. builder.append("</h1>"sv);
  594. auto escaped_url = escape_html_entities(m_url.to_deprecated_string());
  595. builder.appendff("The web page <a href=\"{}\">{}</a> has crashed.<br><br>You can reload the page to try again.", escaped_url, escaped_url);
  596. builder.append("</body></html>"sv);
  597. load_html(builder.to_deprecated_string(), m_url);
  598. }
  599. void WebContentView::notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size)
  600. {
  601. if (m_client_state.back_bitmap.id == bitmap_id) {
  602. m_client_state.has_usable_bitmap = true;
  603. m_client_state.back_bitmap.pending_paints--;
  604. m_client_state.back_bitmap.last_painted_size = size;
  605. swap(m_client_state.back_bitmap, m_client_state.front_bitmap);
  606. // We don't need the backup bitmap anymore, so drop it.
  607. m_backup_bitmap = nullptr;
  608. viewport()->update();
  609. if (m_client_state.got_repaint_requests_while_painting) {
  610. m_client_state.got_repaint_requests_while_painting = false;
  611. request_repaint();
  612. }
  613. }
  614. }
  615. void WebContentView::notify_server_did_invalidate_content_rect(Badge<WebContentClient>, [[maybe_unused]] Gfx::IntRect const& content_rect)
  616. {
  617. request_repaint();
  618. }
  619. void WebContentView::notify_server_did_change_selection(Badge<WebContentClient>)
  620. {
  621. request_repaint();
  622. }
  623. void WebContentView::notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor)
  624. {
  625. switch (cursor) {
  626. case Gfx::StandardCursor::Hidden:
  627. setCursor(Qt::BlankCursor);
  628. break;
  629. case Gfx::StandardCursor::Arrow:
  630. setCursor(Qt::ArrowCursor);
  631. break;
  632. case Gfx::StandardCursor::Crosshair:
  633. setCursor(Qt::CrossCursor);
  634. break;
  635. case Gfx::StandardCursor::IBeam:
  636. setCursor(Qt::IBeamCursor);
  637. break;
  638. case Gfx::StandardCursor::ResizeHorizontal:
  639. setCursor(Qt::SizeHorCursor);
  640. break;
  641. case Gfx::StandardCursor::ResizeVertical:
  642. setCursor(Qt::SizeVerCursor);
  643. break;
  644. case Gfx::StandardCursor::ResizeDiagonalTLBR:
  645. setCursor(Qt::SizeFDiagCursor);
  646. break;
  647. case Gfx::StandardCursor::ResizeDiagonalBLTR:
  648. setCursor(Qt::SizeBDiagCursor);
  649. break;
  650. case Gfx::StandardCursor::ResizeColumn:
  651. setCursor(Qt::SplitHCursor);
  652. break;
  653. case Gfx::StandardCursor::ResizeRow:
  654. setCursor(Qt::SplitVCursor);
  655. break;
  656. case Gfx::StandardCursor::Hand:
  657. setCursor(Qt::PointingHandCursor);
  658. break;
  659. case Gfx::StandardCursor::Help:
  660. setCursor(Qt::WhatsThisCursor);
  661. break;
  662. case Gfx::StandardCursor::Drag:
  663. setCursor(Qt::ClosedHandCursor);
  664. break;
  665. case Gfx::StandardCursor::DragCopy:
  666. setCursor(Qt::DragCopyCursor);
  667. break;
  668. case Gfx::StandardCursor::Move:
  669. setCursor(Qt::DragMoveCursor);
  670. break;
  671. case Gfx::StandardCursor::Wait:
  672. setCursor(Qt::BusyCursor);
  673. break;
  674. case Gfx::StandardCursor::Disallowed:
  675. setCursor(Qt::ForbiddenCursor);
  676. break;
  677. case Gfx::StandardCursor::Eyedropper:
  678. case Gfx::StandardCursor::Zoom:
  679. // FIXME: No corresponding Qt cursors, default to Arrow
  680. default:
  681. setCursor(Qt::ArrowCursor);
  682. break;
  683. }
  684. }
  685. void WebContentView::notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size)
  686. {
  687. verticalScrollBar()->setMinimum(0);
  688. verticalScrollBar()->setMaximum(content_size.height() - m_viewport_rect.height());
  689. verticalScrollBar()->setPageStep(m_viewport_rect.height());
  690. horizontalScrollBar()->setMinimum(0);
  691. horizontalScrollBar()->setMaximum(content_size.width() - m_viewport_rect.width());
  692. horizontalScrollBar()->setPageStep(m_viewport_rect.width());
  693. }
  694. void WebContentView::notify_server_did_change_title(Badge<WebContentClient>, DeprecatedString const& title)
  695. {
  696. emit title_changed(qstring_from_ak_deprecated_string(title));
  697. }
  698. void WebContentView::notify_server_did_request_scroll(Badge<WebContentClient>, i32 x_delta, i32 y_delta)
  699. {
  700. horizontalScrollBar()->setValue(max(0, horizontalScrollBar()->value() + x_delta));
  701. verticalScrollBar()->setValue(max(0, verticalScrollBar()->value() + y_delta));
  702. }
  703. void WebContentView::notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint scroll_position)
  704. {
  705. horizontalScrollBar()->setValue(scroll_position.x());
  706. verticalScrollBar()->setValue(scroll_position.y());
  707. }
  708. void WebContentView::notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const& rect)
  709. {
  710. if (m_viewport_rect.contains(rect))
  711. return;
  712. if (rect.top() < m_viewport_rect.top()) {
  713. verticalScrollBar()->setValue(rect.top());
  714. } else if (rect.top() > m_viewport_rect.top() && rect.bottom() > m_viewport_rect.bottom()) {
  715. verticalScrollBar()->setValue(rect.bottom() - m_viewport_rect.height() + 1);
  716. }
  717. }
  718. void WebContentView::notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint content_position, DeprecatedString const& tooltip)
  719. {
  720. auto widget_position = to_widget(content_position);
  721. QToolTip::showText(
  722. mapToGlobal(QPoint(widget_position.x(), widget_position.y())),
  723. qstring_from_ak_deprecated_string(tooltip),
  724. this);
  725. }
  726. void WebContentView::notify_server_did_leave_tooltip_area(Badge<WebContentClient>)
  727. {
  728. QToolTip::hideText();
  729. }
  730. void WebContentView::notify_server_did_hover_link(Badge<WebContentClient>, AK::URL const& url)
  731. {
  732. emit link_hovered(qstring_from_ak_deprecated_string(url.to_deprecated_string()));
  733. }
  734. void WebContentView::notify_server_did_unhover_link(Badge<WebContentClient>)
  735. {
  736. emit link_unhovered();
  737. }
  738. void WebContentView::notify_server_did_click_link(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& target, unsigned int modifiers)
  739. {
  740. if (on_link_click) {
  741. on_link_click(url, target, modifiers);
  742. }
  743. }
  744. void WebContentView::notify_server_did_middle_click_link(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& target, unsigned int modifiers)
  745. {
  746. if (on_link_middle_click) {
  747. on_link_middle_click(url, target, modifiers);
  748. }
  749. }
  750. void WebContentView::notify_server_did_start_loading(Badge<WebContentClient>, AK::URL const& url, bool is_redirect)
  751. {
  752. m_url = url;
  753. emit load_started(url, is_redirect);
  754. if (m_inspector_widget)
  755. m_inspector_widget->clear_dom_json();
  756. }
  757. void WebContentView::notify_server_did_finish_loading(Badge<WebContentClient>, AK::URL const& url)
  758. {
  759. m_url = url;
  760. if (is_inspector_open()) {
  761. inspect_dom_tree();
  762. inspect_accessibility_tree();
  763. }
  764. if (on_load_finish)
  765. on_load_finish(url);
  766. }
  767. void WebContentView::notify_server_did_request_navigate_back(Badge<WebContentClient>)
  768. {
  769. emit navigate_back();
  770. }
  771. void WebContentView::notify_server_did_request_navigate_forward(Badge<WebContentClient>)
  772. {
  773. emit navigate_forward();
  774. }
  775. void WebContentView::notify_server_did_request_refresh(Badge<WebContentClient>)
  776. {
  777. emit refresh();
  778. }
  779. void WebContentView::notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position)
  780. {
  781. // FIXME
  782. (void)content_position;
  783. }
  784. void WebContentView::notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned)
  785. {
  786. // FIXME
  787. (void)content_position;
  788. (void)url;
  789. }
  790. 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)
  791. {
  792. // FIXME
  793. (void)content_position;
  794. (void)url;
  795. (void)bitmap;
  796. }
  797. void WebContentView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
  798. {
  799. m_dialog = new QMessageBox(QMessageBox::Icon::Warning, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok, this);
  800. m_dialog->exec();
  801. client().async_alert_closed();
  802. m_dialog = nullptr;
  803. }
  804. void WebContentView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
  805. {
  806. m_dialog = new QMessageBox(QMessageBox::Icon::Question, "Ladybird", qstring_from_ak_string(message), QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, this);
  807. auto result = m_dialog->exec();
  808. client().async_confirm_closed(result == QMessageBox::StandardButton::Ok || result == QDialog::Accepted);
  809. m_dialog = nullptr;
  810. }
  811. void WebContentView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
  812. {
  813. m_dialog = new QInputDialog(this);
  814. auto& dialog = static_cast<QInputDialog&>(*m_dialog);
  815. dialog.setWindowTitle("Ladybird");
  816. dialog.setLabelText(qstring_from_ak_string(message));
  817. dialog.setTextValue(qstring_from_ak_string(default_));
  818. if (dialog.exec() == QDialog::Accepted)
  819. client().async_prompt_closed(ak_string_from_qstring(dialog.textValue()).release_value_but_fixme_should_propagate_errors());
  820. else
  821. client().async_prompt_closed({});
  822. m_dialog = nullptr;
  823. }
  824. void WebContentView::notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message)
  825. {
  826. if (m_dialog && is<QInputDialog>(*m_dialog))
  827. static_cast<QInputDialog&>(*m_dialog).setTextValue(qstring_from_ak_string(message));
  828. }
  829. void WebContentView::notify_server_did_request_accept_dialog(Badge<WebContentClient>)
  830. {
  831. if (m_dialog)
  832. m_dialog->accept();
  833. }
  834. void WebContentView::notify_server_did_request_dismiss_dialog(Badge<WebContentClient>)
  835. {
  836. if (m_dialog)
  837. m_dialog->reject();
  838. }
  839. void WebContentView::notify_server_did_get_source(AK::URL const& url, DeprecatedString const& source)
  840. {
  841. emit got_source(url, qstring_from_ak_deprecated_string(source));
  842. }
  843. void WebContentView::notify_server_did_get_dom_tree(DeprecatedString const& dom_tree)
  844. {
  845. if (on_get_dom_tree)
  846. on_get_dom_tree(dom_tree);
  847. if (m_inspector_widget)
  848. m_inspector_widget->set_dom_json(dom_tree);
  849. }
  850. 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)
  851. {
  852. if (on_get_dom_node_properties)
  853. on_get_dom_node_properties(node_id, specified_style, computed_style, custom_properties, node_box_sizing);
  854. }
  855. void WebContentView::notify_server_did_output_js_console_message(i32 message_index)
  856. {
  857. if (m_console_widget)
  858. m_console_widget->notify_about_new_console_message(message_index);
  859. }
  860. void WebContentView::notify_server_did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages)
  861. {
  862. if (m_console_widget)
  863. m_console_widget->handle_console_messages(start_index, message_types, messages);
  864. }
  865. void WebContentView::notify_server_did_change_favicon(Gfx::Bitmap const& bitmap)
  866. {
  867. auto qimage = QImage(bitmap.scanline_u8(0), bitmap.width(), bitmap.height(), QImage::Format_ARGB32);
  868. if (qimage.isNull())
  869. return;
  870. auto qpixmap = QPixmap::fromImage(qimage);
  871. if (qpixmap.isNull())
  872. return;
  873. emit favicon_changed(QIcon(qpixmap));
  874. }
  875. Vector<Web::Cookie::Cookie> WebContentView::notify_server_did_request_all_cookies(Badge<WebContentClient>, AK::URL const& url)
  876. {
  877. if (on_get_all_cookies)
  878. return on_get_all_cookies(url);
  879. return {};
  880. }
  881. Optional<Web::Cookie::Cookie> WebContentView::notify_server_did_request_named_cookie(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& name)
  882. {
  883. if (on_get_named_cookie)
  884. return on_get_named_cookie(url, name);
  885. return {};
  886. }
  887. DeprecatedString WebContentView::notify_server_did_request_cookie(Badge<WebContentClient>, AK::URL const& url, Web::Cookie::Source source)
  888. {
  889. if (on_get_cookie)
  890. return on_get_cookie(url, source);
  891. return {};
  892. }
  893. void WebContentView::notify_server_did_set_cookie(Badge<WebContentClient>, AK::URL const& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)
  894. {
  895. if (on_set_cookie)
  896. on_set_cookie(url, cookie, source);
  897. }
  898. void WebContentView::notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie)
  899. {
  900. if (on_update_cookie)
  901. on_update_cookie(cookie);
  902. }
  903. void WebContentView::notify_server_did_close_browsing_context(Badge<WebContentClient>)
  904. {
  905. emit close();
  906. }
  907. String WebContentView::notify_server_did_request_new_tab(Badge<WebContentClient>, Web::HTML::ActivateTab activate_tab)
  908. {
  909. if (on_new_tab)
  910. return on_new_tab(activate_tab);
  911. return {};
  912. }
  913. void WebContentView::notify_server_did_request_activate_tab(Badge<WebContentClient>)
  914. {
  915. emit activate_tab();
  916. }
  917. void WebContentView::notify_server_did_update_resource_count(i32 count_waiting)
  918. {
  919. // FIXME
  920. (void)count_waiting;
  921. }
  922. void WebContentView::notify_server_did_request_restore_window()
  923. {
  924. emit restore_window();
  925. }
  926. Gfx::IntPoint WebContentView::notify_server_did_request_reposition_window(Gfx::IntPoint position)
  927. {
  928. return emit reposition_window(position);
  929. }
  930. Gfx::IntSize WebContentView::notify_server_did_request_resize_window(Gfx::IntSize size)
  931. {
  932. return emit resize_window(size);
  933. }
  934. Gfx::IntRect WebContentView::notify_server_did_request_maximize_window()
  935. {
  936. return emit maximize_window();
  937. }
  938. Gfx::IntRect WebContentView::notify_server_did_request_minimize_window()
  939. {
  940. return emit minimize_window();
  941. }
  942. Gfx::IntRect WebContentView::notify_server_did_request_fullscreen_window()
  943. {
  944. return emit fullscreen_window();
  945. }
  946. void WebContentView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id)
  947. {
  948. auto file = Core::File::open(path, Core::File::OpenMode::Read);
  949. if (file.is_error())
  950. client().async_handle_file_return(file.error().code(), {}, request_id);
  951. else
  952. client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
  953. }
  954. void WebContentView::request_repaint()
  955. {
  956. // If this widget was instantiated but not yet added to a window,
  957. // it won't have a back bitmap yet, so we can just skip repaint requests.
  958. if (!m_client_state.back_bitmap.bitmap)
  959. return;
  960. // Don't request a repaint until pending paint requests have finished.
  961. if (m_client_state.back_bitmap.pending_paints) {
  962. m_client_state.got_repaint_requests_while_painting = true;
  963. return;
  964. }
  965. m_client_state.back_bitmap.pending_paints++;
  966. client().async_paint(m_client_state.back_bitmap.bitmap->rect().translated(horizontalScrollBar()->value(), verticalScrollBar()->value()), m_client_state.back_bitmap.id);
  967. }
  968. bool WebContentView::event(QEvent* event)
  969. {
  970. // NOTE: We have to implement event() manually as Qt's focus navigation mechanism
  971. // eats all the Tab key presses by default.
  972. if (event->type() == QEvent::KeyPress) {
  973. keyPressEvent(static_cast<QKeyEvent*>(event));
  974. return true;
  975. }
  976. if (event->type() == QEvent::KeyRelease) {
  977. keyReleaseEvent(static_cast<QKeyEvent*>(event));
  978. return true;
  979. }
  980. if (event->type() == QEvent::PaletteChange) {
  981. update_palette();
  982. request_repaint();
  983. return QAbstractScrollArea::event(event);
  984. }
  985. return QAbstractScrollArea::event(event);
  986. }
  987. void WebContentView::notify_server_did_finish_handling_input_event(bool event_was_accepted)
  988. {
  989. // FIXME: Currently Ladybird handles the keyboard shortcuts before passing the event to web content, so
  990. // we don't need to do anything here. But we'll need to once we start asking web content first.
  991. (void)event_was_accepted;
  992. }
  993. void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_json)
  994. {
  995. if (m_inspector_widget)
  996. m_inspector_widget->set_accessibility_json(accessibility_json);
  997. }
  998. ErrorOr<String> WebContentView::dump_layout_tree()
  999. {
  1000. return String::from_deprecated_string(client().dump_layout_tree());
  1001. }