From 01c64414a766b5f0aa9c7cd1a86d842b6b9f90b5 Mon Sep 17 00:00:00 2001 From: simonvg Date: Sat, 15 Feb 2020 21:29:01 +0100 Subject: [PATCH] Fix looping hold timer due to missing touch end event on content loaded --- src/pyj/read_book/iframe.pyj | 5 ++++- src/pyj/read_book/touch.pyj | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 1130130c88..c2bc8b3a17 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -44,7 +44,8 @@ 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.touch import (create_handlers as create_touch_handlers, + reset_handlers as reset_touch_handlers) from read_book.viewport import scroll_viewport from utils import ( apply_cloned_selection, clone_selection, debounce, html_escape, is_ios @@ -334,6 +335,8 @@ class IframeBoss: self.send_message('content_loaded', progress_frac=self.calculate_progress_frac(), file_progress_frac=progress_frac()) self.last_cfi = None self.auto_scroll_action('resume') + reset_touch_handlers() # Needed to mitigate issue https://bugs.chromium.org/p/chromium/issues/detail?id=464579 + window.setTimeout(self.update_cfi, 0) window.setTimeout(self.update_toc_position, 0) diff --git a/src/pyj/read_book/touch.pyj b/src/pyj/read_book/touch.pyj index 8858350fd3..07e4bf5b28 100644 --- a/src/pyj/read_book/touch.pyj +++ b/src/pyj/read_book/touch.pyj @@ -140,6 +140,12 @@ class TouchHandler: return True return False + def reset_handlers(self): + self.stop_hold_timer() + self.ongoing_touches = {} + self.gesture_id = None + self.handled_tap_hold = False + def start_hold_timer(self): self.stop_hold_timer() self.hold_timer = window.setTimeout(self.check_for_hold, 100) @@ -199,9 +205,7 @@ class TouchHandler: self.prune_expired_touches() if not self.has_active_touches: self.dispatch_gesture() - self.ongoing_touches = {} - self.gesture_id = None - self.handled_tap_hold = False + self.reset_handlers() def handle_touchcancel(self, ev): ev.preventDefault(), ev.stopPropagation() @@ -279,6 +283,9 @@ def create_handlers(): # on window instead of document install_handlers(document, main_touch_handler) +def reset_handlers(): + main_touch_handler.reset_handlers() + def set_left_margin_handler(elem): install_handlers(elem, left_margin_handler)