Fix focusing IV content.

This commit is contained in:
John Preston 2024-02-16 11:25:15 +04:00
parent 5f3c380d56
commit 0a87dbea68
3 changed files with 40 additions and 6 deletions

View File

@ -135,6 +135,9 @@ html.custom_scroll ::-webkit-scrollbar-thumb:hover {
overflow-x: hidden;
overflow-y: auto;
}
.page-scroll:focus {
outline: none;
}
.page-slide {
position: relative;
width: 100%;

View File

@ -79,10 +79,14 @@ var IV = {
});
} else if (e.key === 'Escape' || e.keyCode === 27) {
e.preventDefault();
IV.notify({
event: 'keydown',
key: 'escape',
});
if (IV.position) {
window.history.back();
} else {
IV.notify({
event: 'keydown',
key: 'escape',
});
}
}
},
frameMouseEnter: function (e) {
@ -250,6 +254,8 @@ var IV = {
}
IV.initMedia();
IV.notify({ event: 'ready' });
IV.forceScrollFocus();
},
initMedia: function () {
const photos = document.getElementsByClassName('photo');
@ -356,6 +362,7 @@ var IV = {
var data = JSON.parse(IV.cache[index].content);
var el = document.createElement('div');
el.className = 'page-scroll';
el.tabIndex = '-1';
el.innerHTML = '<div class="page-slide"><article>'
+ data.html
+ '</article></div>';
@ -370,6 +377,7 @@ var IV = {
IV.pending = null;
if (IV.index == index) {
IV.jumpToHash(hash, IV.mac);
IV.forceScrollFocus();
return;
}
window.history.replaceState(IV.computeCurrentState(), '');
@ -452,6 +460,15 @@ var IV = {
} else {
IV.jumpToHash(hash, IV.mac);
}
IV.forceScrollFocus();
},
forceScrollFocus: function () {
IV.findPageScroll().focus();
setTimeout(function () {
// Doesn't work on #hash-ed pages in Windows WebView2 otherwise.
IV.findPageScroll().focus();
}, 100);
},
back: function () {
window.history.back();
@ -467,9 +484,9 @@ document.onkeydown = IV.frameKeyDown;
document.onmouseenter = IV.frameMouseEnter;
document.onmouseup = IV.frameMouseUp;
window.onmessage = IV.postMessageHandler;
window.addEventListener('popstate', function (e) {
if (e.state) {
IV.showDOM(e.state.index, e.state.hash, e.state.scroll);
}
});
document.addEventListener("DOMContentLoaded", IV.forceScrollFocus);

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "base/invoke_queued.h"
#include "base/qt_signal_producer.h"
#include "iv/iv_data.h"
#include "lang/lang_keys.h"
#include "ui/platform/ui_platform_window_title.h"
@ -31,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtCore/QJsonValue>
#include <QtCore/QFile>
#include <QtGui/QPainter>
#include <QtGui/QWindow>
#include <charconv>
namespace Iv {
@ -182,7 +184,7 @@ namespace {
<path d="M14.9972363,18 L9.13865768,12.1414214 C9.06055283,12.0633165 9.06055283,11.9366835 9.13865768,11.8585786 L14.9972363,6 L14.9972363,6" transform="translate(11.997236, 12.000000) scale(-1, -1) rotate(-90.000000) translate(-11.997236, -12.000000) "></path>
</svg>
</button>
<div class="page-scroll"><div class="page-slide">
<div class="page-scroll" tabindex="-1"><div class="page-slide">
<article)"_q + contentAttributes + ">"_q + page.content + R"(</article>
</div></div>
<script>)"_q + js + R"(</script>
@ -286,6 +288,15 @@ void Controller::createWindow() {
_window->setTitleStyle(st::ivTitle);
const auto window = _window.get();
base::qt_signal_producer(
window->window()->windowHandle(),
&QWindow::activeChanged
) | rpl::filter([=] {
return _webview && window->window()->windowHandle()->isActive();
}) | rpl::start_with_next([=] {
_webview->focus();
}, window->lifetime());
_title = std::make_unique<Ui::RpWidget>(window);
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
_title->paintRequest() | rpl::start_with_next([=](QRect clip) {
@ -521,6 +532,7 @@ void Controller::showInWindow(const QString &dataPath, Prepared page) {
id += '#' + hash;
}
_webview->navigateToData(id);
_webview->focus();
} else {
_events.fire({ Event::Type::Close });
}
@ -529,12 +541,14 @@ void Controller::showInWindow(const QString &dataPath, Prepared page) {
_window->raise();
_window->activateWindow();
_window->setFocus();
_webview->focus();
} else {
_navigateToIndexWhenReady = index;
_navigateToHashWhenReady = hash;
_window->raise();
_window->activateWindow();
_window->setFocus();
_webview->focus();
}
}