diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-11 17:17:49 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-25 07:58:58 -0700 |
commit | 195cdb33de6c4c25a03704aff198d48027b2b892 (patch) | |
tree | d80d90d461baae61dcf2d40f6d2f939e5ab9ddbc /Ladybird | |
parent | c154d94964773ae0e1de3125dbeb284b870c489f (diff) | |
download | serenity-195cdb33de6c4c25a03704aff198d48027b2b892.zip |
Ladybird/WebContentView: Make Tab and Shift+Tab work
These didn't work, for two reasons:
1. Qt swallows all Tab key presses by default. We have to override
the event() function in order to receive them.
2. Qt transforms Shift+Tab into a fake "Backtab" key. We have to
undo this transformation and send Shift+Tab to WebContent.
Diffstat (limited to 'Ladybird')
-rw-r--r-- | Ladybird/WebContentView.cpp | 22 | ||||
-rw-r--r-- | Ladybird/WebContentView.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 939bb3036b..4dbbe424f9 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -334,6 +334,12 @@ void WebContentView::keyPressEvent(QKeyEvent* event) break; } + if (event->key() == Qt::Key_Backtab) { + // NOTE: Qt transforms Shift+Tab into a "Backtab", so we undo that transformation here. + client().async_key_down(KeyCode::Key_Tab, Mod_Shift, '\t'); + return; + } + auto text = event->text(); if (text.isEmpty()) { return; @@ -919,3 +925,19 @@ void WebContentView::request_repaint() m_client_state.back_bitmap.pending_paints++; client().async_paint(m_client_state.back_bitmap.bitmap->rect().translated(horizontalScrollBar()->value(), verticalScrollBar()->value()), m_client_state.back_bitmap.id); } + +bool WebContentView::event(QEvent* event) +{ + // NOTE: We have to implement event() manually as Qt's focus navigation mechanism + // eats all the Tab key presses by default. + + if (event->type() == QEvent::KeyPress) { + keyPressEvent(static_cast<QKeyEvent*>(event)); + return true; + } + if (event->type() == QEvent::KeyRelease) { + keyReleaseEvent(static_cast<QKeyEvent*>(event)); + return true; + } + return QAbstractScrollArea::event(event); +} diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index 975ca0b68a..b11277af6f 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -87,6 +87,7 @@ public: virtual void hideEvent(QHideEvent*) override; virtual void focusInEvent(QFocusEvent*) override; virtual void focusOutEvent(QFocusEvent*) override; + virtual bool event(QEvent*) override; void debug_request(String const& request, String const& argument); |