diff --git a/Telegram/Resources/iv_html/page.css b/Telegram/Resources/iv_html/page.css index 1da34f68ac..e6bd5af80f 100644 --- a/Telegram/Resources/iv_html/page.css +++ b/Telegram/Resources/iv_html/page.css @@ -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%; diff --git a/Telegram/Resources/iv_html/page.js b/Telegram/Resources/iv_html/page.js index 8628592033..333c127f1e 100644 --- a/Telegram/Resources/iv_html/page.js +++ b/Telegram/Resources/iv_html/page.js @@ -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 = '
'; @@ -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); diff --git a/Telegram/SourceFiles/iv/iv_controller.cpp b/Telegram/SourceFiles/iv/iv_controller.cpp index 98de7e49d6..b26ca82371 100644 --- a/Telegram/SourceFiles/iv/iv_controller.cpp +++ b/Telegram/SourceFiles/iv/iv_controller.cpp @@ -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