diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index d8a65d2d2e..e8f0bb4cc7 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -256,6 +256,8 @@ class WebPage(QWebEnginePage): def acceptNavigationRequest(self, url, req_type, is_main_frame): if req_type == self.NavigationTypeReload: return True + if req_type == self.NavigationTypeBackForward: + return True if url.scheme() in (FAKE_PROTOCOL, 'data'): return True open_url(url) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 3fb207081f..45603b10da 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -353,6 +353,8 @@ class IframeBoss: if sc_name: if self.handle_navigation_shortcut(sc_name, evt): evt.preventDefault() + else: + self.send_message('handle_shortcut', name=sc_name) def oncontextmenu(self, evt): if self.content_ready: diff --git a/src/pyj/read_book/shortcuts.pyj b/src/pyj/read_book/shortcuts.pyj index 69df6c66b5..740f6fd5ea 100644 --- a/src/pyj/read_book/shortcuts.pyj +++ b/src/pyj/read_book/shortcuts.pyj @@ -138,6 +138,20 @@ SHORTCUTS = { _('Scroll forwards by screen-fulls'), ), + 'back': desc( + v"['Alt+ArrowLeft', 'Shift+ArrowLeft']", + 'scroll', + _('Back'), + ), + + 'forward': desc( + v"['Alt+ArrowRight', 'Shift+ArrowRight']", + 'scroll', + _('Forward'), + ), + + + } diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index a89f991052..64f01735c8 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -150,6 +150,7 @@ class View: 'print': self.on_print, 'human_scroll': self.on_human_scroll, 'selectionchange': self.on_selection_change, + 'handle_shortcut': self.on_handle_shortcut, } entry_point = None if runtime.is_standalone_viewer else 'read_book.iframe' self.iframe_wrapper = IframeWrapper(handlers, document.getElementById(iframe_id), entry_point, _('Bootstrapping book reader...'), runtime.FAKE_PROTOCOL, runtime.FAKE_HOST) @@ -215,6 +216,12 @@ class View: amt_scrolled = data.scrolled_by_frac * length self.timers.on_human_scroll(amt_scrolled) + def on_handle_shortcut(self, data): + if data.name is 'back': + window.history.back() + elif data.name is 'forward': + window.history.forward() + def on_selection_change(self, data): self.currently_showing.selected_text = data.text if ui_operations.selection_changed: