mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont respond to keypresses while the overlay is visible
This commit is contained in:
parent
21f5fbdf1d
commit
36af3928b0
@ -31,7 +31,9 @@ from read_book.settings import (
|
||||
apply_colors, apply_font_size, apply_settings, apply_stylesheet, opts,
|
||||
update_settings
|
||||
)
|
||||
from read_book.shortcuts import create_shortcut_map, shortcut_for_key_event
|
||||
from read_book.shortcuts import (
|
||||
create_shortcut_map, keyevent_as_shortcut, shortcut_for_key_event
|
||||
)
|
||||
from read_book.toc import update_visible_toc_anchors
|
||||
from read_book.touch import create_handlers as create_touch_handlers
|
||||
from read_book.viewport import scroll_viewport
|
||||
@ -76,6 +78,7 @@ class IframeBoss:
|
||||
self.resource_urls = {}
|
||||
self.content_ready = False
|
||||
self.last_window_width = self.last_window_height = -1
|
||||
self.forward_keypresses = False
|
||||
set_boss(self)
|
||||
handlers = {
|
||||
'initialize':self.initialize,
|
||||
@ -88,11 +91,15 @@ class IframeBoss:
|
||||
'find': self.find,
|
||||
'window_size': self.received_window_size,
|
||||
'get_current_cfi': self.get_current_cfi,
|
||||
'set_forward_keypresses': self.set_forward_keypresses
|
||||
}
|
||||
self.comm = IframeClient(handlers)
|
||||
self.last_window_ypos = 0
|
||||
self.length_before = None
|
||||
|
||||
def set_forward_keypresses(self, data):
|
||||
self.forward_keypresses = data.forward
|
||||
|
||||
def initialize(self, data):
|
||||
scroll_viewport.update_window_size(data.width, data.height)
|
||||
window.onerror = self.onerror
|
||||
@ -348,6 +355,10 @@ class IframeBoss:
|
||||
if current_layout_mode() is not 'flow' and evt.key is 'Tab':
|
||||
# Prevent the TAB key from shifting focus as it causes partial scrolling
|
||||
evt.preventDefault()
|
||||
if self.forward_keypresses:
|
||||
self.send_message('handle_keypress', evt=keyevent_as_shortcut(evt))
|
||||
evt.preventDefault(), evt.stopPropagation()
|
||||
return
|
||||
if self.content_ready:
|
||||
sc_name = shortcut_for_key_event(evt, self.keyboard_shortcut_map)
|
||||
if sc_name:
|
||||
|
@ -455,7 +455,9 @@ class Overlay:
|
||||
clear(c)
|
||||
c.style.backgroundColor = 'transparent'
|
||||
c.style.color = get_color('window-foreground')
|
||||
c.style.display = 'block'
|
||||
if c.style.display is not 'block':
|
||||
c.style.display = 'block'
|
||||
self.view.overlay_visibility_changed(True)
|
||||
return c
|
||||
|
||||
@property
|
||||
@ -469,9 +471,11 @@ class Overlay:
|
||||
def update_visibility(self):
|
||||
if self.panels.length:
|
||||
self.container.style.display = 'block'
|
||||
self.view.overlay_visibility_changed(True)
|
||||
elif self.container.style.display is 'block':
|
||||
self.container.style.display = 'none'
|
||||
self.view.focus_iframe()
|
||||
self.view.overlay_visibility_changed(False)
|
||||
|
||||
def container_clicked(self, evt):
|
||||
if self.panels.length and jstype(self.panels[-1].on_container_click) is 'function':
|
||||
|
@ -186,6 +186,7 @@ class View:
|
||||
'human_scroll': self.on_human_scroll,
|
||||
'selectionchange': self.on_selection_change,
|
||||
'handle_shortcut': self.on_handle_shortcut,
|
||||
'handle_keypress': self.on_handle_keypress,
|
||||
}
|
||||
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)
|
||||
@ -251,6 +252,15 @@ class View:
|
||||
amt_scrolled = data.scrolled_by_frac * length
|
||||
self.timers.on_human_scroll(amt_scrolled)
|
||||
|
||||
def on_handle_keypress(self, data):
|
||||
if self.overlay.is_visible and data.evt.key is 'Escape':
|
||||
self.overlay.hide_current_panel()
|
||||
return
|
||||
|
||||
def overlay_visibility_changed(self, visible):
|
||||
if self.iframe_wrapper.send_message:
|
||||
self.iframe_wrapper.send_message('set_forward_keypresses', forward=v'!!visible')
|
||||
|
||||
def on_handle_shortcut(self, data):
|
||||
if data.name is 'back':
|
||||
window.history.back()
|
||||
|
Loading…
x
Reference in New Issue
Block a user