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,
|
apply_colors, apply_font_size, apply_settings, apply_stylesheet, opts,
|
||||||
update_settings
|
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.toc import update_visible_toc_anchors
|
||||||
from read_book.touch import create_handlers as create_touch_handlers
|
from read_book.touch import create_handlers as create_touch_handlers
|
||||||
from read_book.viewport import scroll_viewport
|
from read_book.viewport import scroll_viewport
|
||||||
@ -76,6 +78,7 @@ class IframeBoss:
|
|||||||
self.resource_urls = {}
|
self.resource_urls = {}
|
||||||
self.content_ready = False
|
self.content_ready = False
|
||||||
self.last_window_width = self.last_window_height = -1
|
self.last_window_width = self.last_window_height = -1
|
||||||
|
self.forward_keypresses = False
|
||||||
set_boss(self)
|
set_boss(self)
|
||||||
handlers = {
|
handlers = {
|
||||||
'initialize':self.initialize,
|
'initialize':self.initialize,
|
||||||
@ -88,11 +91,15 @@ class IframeBoss:
|
|||||||
'find': self.find,
|
'find': self.find,
|
||||||
'window_size': self.received_window_size,
|
'window_size': self.received_window_size,
|
||||||
'get_current_cfi': self.get_current_cfi,
|
'get_current_cfi': self.get_current_cfi,
|
||||||
|
'set_forward_keypresses': self.set_forward_keypresses
|
||||||
}
|
}
|
||||||
self.comm = IframeClient(handlers)
|
self.comm = IframeClient(handlers)
|
||||||
self.last_window_ypos = 0
|
self.last_window_ypos = 0
|
||||||
self.length_before = None
|
self.length_before = None
|
||||||
|
|
||||||
|
def set_forward_keypresses(self, data):
|
||||||
|
self.forward_keypresses = data.forward
|
||||||
|
|
||||||
def initialize(self, data):
|
def initialize(self, data):
|
||||||
scroll_viewport.update_window_size(data.width, data.height)
|
scroll_viewport.update_window_size(data.width, data.height)
|
||||||
window.onerror = self.onerror
|
window.onerror = self.onerror
|
||||||
@ -348,6 +355,10 @@ class IframeBoss:
|
|||||||
if current_layout_mode() is not 'flow' and evt.key is 'Tab':
|
if current_layout_mode() is not 'flow' and evt.key is 'Tab':
|
||||||
# Prevent the TAB key from shifting focus as it causes partial scrolling
|
# Prevent the TAB key from shifting focus as it causes partial scrolling
|
||||||
evt.preventDefault()
|
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:
|
if self.content_ready:
|
||||||
sc_name = shortcut_for_key_event(evt, self.keyboard_shortcut_map)
|
sc_name = shortcut_for_key_event(evt, self.keyboard_shortcut_map)
|
||||||
if sc_name:
|
if sc_name:
|
||||||
|
@ -455,7 +455,9 @@ class Overlay:
|
|||||||
clear(c)
|
clear(c)
|
||||||
c.style.backgroundColor = 'transparent'
|
c.style.backgroundColor = 'transparent'
|
||||||
c.style.color = get_color('window-foreground')
|
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
|
return c
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -469,9 +471,11 @@ class Overlay:
|
|||||||
def update_visibility(self):
|
def update_visibility(self):
|
||||||
if self.panels.length:
|
if self.panels.length:
|
||||||
self.container.style.display = 'block'
|
self.container.style.display = 'block'
|
||||||
|
self.view.overlay_visibility_changed(True)
|
||||||
elif self.container.style.display is 'block':
|
elif self.container.style.display is 'block':
|
||||||
self.container.style.display = 'none'
|
self.container.style.display = 'none'
|
||||||
self.view.focus_iframe()
|
self.view.focus_iframe()
|
||||||
|
self.view.overlay_visibility_changed(False)
|
||||||
|
|
||||||
def container_clicked(self, evt):
|
def container_clicked(self, evt):
|
||||||
if self.panels.length and jstype(self.panels[-1].on_container_click) is 'function':
|
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,
|
'human_scroll': self.on_human_scroll,
|
||||||
'selectionchange': self.on_selection_change,
|
'selectionchange': self.on_selection_change,
|
||||||
'handle_shortcut': self.on_handle_shortcut,
|
'handle_shortcut': self.on_handle_shortcut,
|
||||||
|
'handle_keypress': self.on_handle_keypress,
|
||||||
}
|
}
|
||||||
entry_point = None if runtime.is_standalone_viewer else 'read_book.iframe'
|
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)
|
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
|
amt_scrolled = data.scrolled_by_frac * length
|
||||||
self.timers.on_human_scroll(amt_scrolled)
|
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):
|
def on_handle_shortcut(self, data):
|
||||||
if data.name is 'back':
|
if data.name is 'back':
|
||||||
window.history.back()
|
window.history.back()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user