Viewer: Fix right clicking on margins not showing controls

This commit is contained in:
Kovid Goyal 2019-10-15 05:00:07 +05:30
parent 8f8a5f7561
commit dfdf3e113a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -121,7 +121,7 @@ def show_controls_help():
# }}} # }}}
def margin_elem(sd, which, id, onclick): def margin_elem(sd, which, id, onclick, oncontextmenu):
sz = sd.get(which, 20) sz = sd.get(which, 20)
fsz = min(max(0, sz - 6), 12) fsz = min(max(0, sz - 6), 12)
s = '; text-overflow: ellipsis; white-space: nowrap; overflow: hidden' s = '; text-overflow: ellipsis; white-space: nowrap; overflow: hidden'
@ -132,6 +132,8 @@ def margin_elem(sd, which, id, onclick):
) )
if onclick: if onclick:
ans.addEventListener('click', onclick) ans.addEventListener('click', onclick)
if oncontextmenu:
ans.addEventListener('contextmenu', onclick)
if is_ios and which is 'margin_bottom' and not window.navigator.standalone and not /CriOS\//.test(window.navigator.userAgent): if is_ios and which is 'margin_bottom' and not window.navigator.standalone and not /CriOS\//.test(window.navigator.userAgent):
# On iOS Safari 100vh includes the size of the navbar and there is no way to # On iOS Safari 100vh includes the size of the navbar and there is no way to
# go fullscreen, so to make the bottom bar visible we add a margin to # go fullscreen, so to make the bottom bar visible we add a margin to
@ -157,9 +159,15 @@ class View:
self.keyboard_shortcut_map = create_shortcut_map(sd.get('keyboard_shortcuts')) self.keyboard_shortcut_map = create_shortcut_map(sd.get('keyboard_shortcuts'))
if ui_operations.export_shortcut_map: if ui_operations.export_shortcut_map:
ui_operations.export_shortcut_map(self.keyboard_shortcut_map) ui_operations.export_shortcut_map(self.keyboard_shortcut_map)
left_margin = E.div(svgicon('caret-left'), style='width:{}px;'.format(sd.get('margin_left', 20)), class_='book-side-margin', id='book-left-margin', onclick=self.left_margin_clicked) left_margin = E.div(
svgicon('caret-left'), style='width:{}px;'.format(sd.get('margin_left', 20)),
class_='book-side-margin', id='book-left-margin', onclick=self.left_margin_clicked,
oncontextmenu=self.margin_context_menu.bind(None, 'left'))
set_left_margin_handler(left_margin) set_left_margin_handler(left_margin)
right_margin = E.div(svgicon('caret-right'), style='width:{}px;'.format(sd.get('margin_right', 20)), class_='book-side-margin', id='book-right-margin', onclick=self.right_margin_clicked) right_margin = E.div(
svgicon('caret-right'), style='width:{}px;'.format(sd.get('margin_right', 20)),
class_='book-side-margin', id='book-right-margin', onclick=self.right_margin_clicked,
oncontextmenu=self.margin_context_menu.bind(None, 'right'))
set_right_margin_handler(right_margin) set_right_margin_handler(right_margin)
iframe_id = unique_id('read-book-iframe') iframe_id = unique_id('read-book-iframe')
container.appendChild( container.appendChild(
@ -168,9 +176,9 @@ class View:
E.div(style='max-height: 100vh; flex-grow: 2; display:flex; align-items: stretch', # container for iframe and its overlay E.div(style='max-height: 100vh; flex-grow: 2; display:flex; align-items: stretch', # container for iframe and its overlay
left_margin, left_margin,
E.div(style='flex-grow:2; display:flex; align-items:stretch; flex-direction: column', # container for top and bottom margins E.div(style='flex-grow:2; display:flex; align-items:stretch; flex-direction: column', # container for top and bottom margins
margin_elem(sd, 'margin_top', 'book-top-margin', self.top_margin_clicked), margin_elem(sd, 'margin_top', 'book-top-margin', self.top_margin_clicked, self.margin_context_menu.bind(None, 'top')),
E.iframe(id=iframe_id, seamless=True, sandbox='allow-popups allow-scripts allow-popups-to-escape-sandbox', style='flex-grow: 2', allowfullscreen='true'), E.iframe(id=iframe_id, seamless=True, sandbox='allow-popups allow-scripts allow-popups-to-escape-sandbox', style='flex-grow: 2', allowfullscreen='true'),
margin_elem(sd, 'margin_bottom', 'book-bottom-margin', self.bottom_margin_clicked), margin_elem(sd, 'margin_bottom', 'book-bottom-margin', self.bottom_margin_clicked, self.margin_context_menu.bind(None, 'bottom')),
), ),
right_margin, right_margin,
self.book_scrollbar.create(), self.book_scrollbar.create(),
@ -234,6 +242,9 @@ class View:
event.preventDefault(), event.stopPropagation() event.preventDefault(), event.stopPropagation()
sd = get_session_data() sd = get_session_data()
self.iframe_wrapper.send_message('next_screen', backwards=True, all_pages_on_screen=sd.get('paged_margin_clicks_scroll_by_screen')) self.iframe_wrapper.send_message('next_screen', backwards=True, all_pages_on_screen=sd.get('paged_margin_clicks_scroll_by_screen'))
elif event.button is 2:
event.preventDefault(), event.stopPropagation()
window.setTimeout(self.show_chrome, 0)
self.focus_iframe() self.focus_iframe()
def right_margin_clicked(self, event): def right_margin_clicked(self, event):
@ -241,18 +252,28 @@ class View:
event.preventDefault(), event.stopPropagation() event.preventDefault(), event.stopPropagation()
sd = get_session_data() sd = get_session_data()
self.iframe_wrapper.send_message('next_screen', backwards=False, all_pages_on_screen=sd.get('paged_margin_clicks_scroll_by_screen')) self.iframe_wrapper.send_message('next_screen', backwards=False, all_pages_on_screen=sd.get('paged_margin_clicks_scroll_by_screen'))
elif event.button is 2:
event.preventDefault(), event.stopPropagation()
window.setTimeout(self.show_chrome, 0)
self.focus_iframe() self.focus_iframe()
def top_margin_clicked(self, event): def top_margin_clicked(self, event):
if event.button is 0: if event.button is 0 or event.button is 2:
event.preventDefault(), event.stopPropagation() event.preventDefault(), event.stopPropagation()
self.show_chrome() self.show_chrome()
else: else:
self.focus_iframe() self.focus_iframe()
def bottom_margin_clicked(self, event): def bottom_margin_clicked(self, event):
if event.button is 2:
event.preventDefault(), event.stopPropagation()
window.setTimeout(self.show_chrome, 0)
self.focus_iframe() self.focus_iframe()
def margin_context_menu(self, which, event):
event.preventDefault(), event.stopPropagation()
self.show_chrome()
def forward_gesture(self, gesture): def forward_gesture(self, gesture):
self.iframe_wrapper.send_message('gesture_from_margin', gesture=gesture) self.iframe_wrapper.send_message('gesture_from_margin', gesture=gesture)