From 5fc6b6db398b480499bf97c0d24c2ed3caa3d8df Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 22 Aug 2016 14:50:23 +0530 Subject: [PATCH] Tapping in the top quarter of the page now shows the chrome --- src/pyj/read_book/iframe.pyj | 10 ++++++++-- src/pyj/read_book/touch.pyj | 11 +++++++---- src/pyj/read_book/view.pyj | 6 +++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 3b559611b5..602eb5f73c 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -94,7 +94,7 @@ class IframeBoss: self.do_layout = flow_layout self.handle_wheel = flow_onwheel self.handle_keydown = flow_onkeydown - self.handle_gesture = flow_handle_gesture + self._handle_gesture = flow_handle_gesture self.to_scroll_fraction = flow_to_scroll_fraction self.jump_to_cfi = scroll_to_cfi else: @@ -103,13 +103,19 @@ class IframeBoss: self.handle_keydown = paged_onkeydown self.to_scroll_fraction = paged_scroll_to_fraction self.jump_to_cfi = paged_jump_to_cfi - self.handle_gesture = paged_handle_gesture + self._handle_gesture = paged_handle_gesture apply_settings(data.settings) set_current_spine_item({'name':data.name, 'is_first':index is 0, 'is_last':index is spine.length - 1, 'initial_position':data.initial_position}) self.last_cfi = None root_data, self.mathjax = finalize_resources(self.book, data.name, data.resource_data) unserialize_html(root_data, self.content_loaded) + def handle_gesture(self, gesture): + if gesture.type is 'show-chrome': + self.send_message('show_chrome') + else: + self._handle_gesture(gesture) + def on_scroll_to_anchor(self, data): frag = data.frag if frag: diff --git a/src/pyj/read_book/touch.pyj b/src/pyj/read_book/touch.pyj index 1079f62249..0a6fe46f3b 100644 --- a/src/pyj/read_book/touch.pyj +++ b/src/pyj/read_book/touch.pyj @@ -204,10 +204,13 @@ class TouchHandler: elem.dispatchEvent(fake_click) return if not tap_on_link(gesture): - # TODO: Convert the tap gesture into - # semantic gestures based on position of tap (next page/previous - # page/show ui) as these are common to both paged and flow mode. - pass + if gesture.viewport_y < window.innerHeight / 4: + gesture.type = 'show-chrome' + else: + # TODO: Convert the tap gesture into + # semantic gestures based on position of tap (next page/previous + # page/show ui) as these are common to both paged and flow mode. + pass get_boss().handle_gesture(gesture) touch_handler = TouchHandler() diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 1eb3bec66f..1639ba2831 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -66,6 +66,7 @@ class View: 'scroll_to_anchor': self.on_scroll_to_anchor, 'update_cfi': self.on_update_cfi, 'content_loaded': self.on_content_loaded, + 'show_chrome': self.show_chrome, } self.currently_showing = {} document.getElementById('book-top-margin').addEventListener('click', self.top_margin_clicked) @@ -77,7 +78,10 @@ class View: def top_margin_clicked(self, event): if event.button is 0: event.preventDefault(), event.stopPropagation() - self.overlay.show() + self.show_chrome() + + def show_chrome(self): + self.overlay.show() def set_margins(self, no_margins): sd = get_session_data()