From b480086d004fca1c0b3cc9aa5b4baf4f7bee1762 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 19 Aug 2019 10:00:12 +0530 Subject: [PATCH] Ensure iframe is focused after controls help is shown --- src/pyj/read_book/globals.pyj | 1 + src/pyj/read_book/ui.pyj | 4 ++++ src/pyj/read_book/view.pyj | 3 ++- src/pyj/viewer-main.pyj | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pyj/read_book/globals.pyj b/src/pyj/read_book/globals.pyj index 0c5dd471ad..d0f66de8b3 100644 --- a/src/pyj/read_book/globals.pyj +++ b/src/pyj/read_book/globals.pyj @@ -80,4 +80,5 @@ ui_operations = { 'update_font_size': None, 'goto_bookpos': None, 'delete_book': None, + 'focus_iframe': None, } diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 535ca554be..e4b3739f31 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -67,6 +67,7 @@ class ReadUI: ui_operations.update_font_size = self.update_font_size.bind(self) ui_operations.goto_bookpos = self.goto_bookpos.bind(self) ui_operations.delete_book = self.delete_book.bind(self) + ui_operations.focus_iframe = self.focus_iframe.bind(self) def on_resize(self): self.view.on_resize() @@ -162,6 +163,9 @@ class ReadUI: def delete_book(self, book, proceed): self.db.delete_book(book, proceed) + def focus_iframe(self): + self.view.focus_iframe() + def update_color_scheme(self): self.view.update_color_scheme() diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 5c89ea3154..95efde4ca6 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -47,7 +47,8 @@ def show_controls_help(): if not show_controls_help.listener_added: show_controls_help.listener_added = True container.addEventListener('click', def(): - document.getElementById('controls-help-overlay').style.display = 'none' + document.getElementById('controls-help-overlay').style.display = 'none' + ui_operations.focus_iframe() ) def msg(txt): return set_css(E.div(txt), padding='1ex 1em', text_align='center', margin='auto') diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 5b75f4838e..1478a3c6f4 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -251,6 +251,8 @@ if window is window.top: view.update_color_scheme() ui_operations.update_font_size = def(): view.update_font_size() + ui_operations.focus_iframe = def(): + view.focus_iframe() ui_operations.goto_bookpos = def(cfi): return view.goto_bookpos(cfi) ui_operations.toggle_toc = def(): @@ -267,6 +269,7 @@ if window is window.top: to_python.report_cfi(request_id, data) ui_operations.ask_for_open = def(path): to_python.ask_for_open(path) + document.body.appendChild(E.div(id='view')) window.onerror = onerror create_modal_container()