Browser viewer: Fix regression in 5.0 that broke scrolling on iOS

viewport_to_document() cannot reset transforms, as transforms are used
for scrolling on iOS
This commit is contained in:
Kovid Goyal 2020-12-22 09:46:45 +05:30
parent 38aec680fc
commit ecea8435e6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2,7 +2,7 @@
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import bound_methods, hash_literals from __python__ import bound_methods, hash_literals
FUNCTIONS = 'x y scroll_to scroll_into_view reset_globals __reset_transforms'.split(' ') FUNCTIONS = 'x y scroll_to scroll_into_view reset_globals __reset_transforms window_scroll_pos'.split(' ')
from read_book.globals import get_boss, viewport_mode_changer from read_book.globals import get_boss, viewport_mode_changer
from utils import document_height, document_width, is_ios from utils import document_height, document_width, is_ios
@ -56,6 +56,9 @@ class ScrollViewport:
def flow_y(self): def flow_y(self):
return window.pageYOffset return window.pageYOffset
def flow_window_scroll_pos(self):
return window.pageXOffset, window.pageYOffset
def inline_pos(self): def inline_pos(self):
if self.vertical_writing_mode: if self.vertical_writing_mode:
return self.y() return self.y()
@ -160,8 +163,6 @@ class ScrollViewport:
# Assure that the viewport position returned is corrected for the RTL # Assure that the viewport position returned is corrected for the RTL
# mode of ScrollViewport. # mode of ScrollViewport.
def viewport_to_document(self, x, y, doc): def viewport_to_document(self, x, y, doc):
self.__reset_transforms()
# Convert x, y from the viewport (window) co-ordinate system to the # Convert x, y from the viewport (window) co-ordinate system to the
# document (body) co-ordinate system # document (body) co-ordinate system
doc = doc or window.document doc = doc or window.document
@ -173,12 +174,11 @@ class ScrollViewport:
x += rect.left x += rect.left
y += rect.top y += rect.top
doc = frame.ownerDocument doc = frame.ownerDocument
win = doc.defaultView or window wx, wy = self.window_scroll_pos()
wx, wy = win.pageXOffset, win.pageYOffset
x += wx x += wx
y += wy y += wy
if self.rtl: if self.rtl:
return -x, y x *= -1
return x, y return x, y
def rect_inline_start(self, rect): def rect_inline_start(self, rect):
@ -270,28 +270,25 @@ class IOSScrollViewport(ScrollViewport):
if boss: if boss:
boss.onscroll() boss.onscroll()
def paged_x(self): def transform_val(self, y):
raw = document.documentElement.style.transform raw = document.documentElement.style.transform
if not raw or raw is 'none': if not raw or raw is 'none':
return 0 return 0
raw = raw[raw.indexOf('(') + 1:] idx = raw.lastIndexOf('(') if y else raw.indexOf('(')
raw = raw[idx + 1:]
ans = parseInt(raw) ans = parseInt(raw)
if isNaN(ans): if isNaN(ans):
return 0 ans = 0
return ans
def paged_x(self):
ans = self.transform_val()
if self.ltr: if self.ltr:
ans *= -1 ans *= -1
return ans return ans
def paged_y(self): def paged_y(self):
raw = document.documentElement.style.transform return -1 * self.transform_val(True)
if not raw or raw is 'none':
return 0
raw = raw[raw.lastIndexOf('(') + 1:]
ans = parseInt(raw)
if isNaN(ans):
return 0
ans *= -1
return ans
def paged_scroll_into_view(self, elem): def paged_scroll_into_view(self, elem):
left = elem.offsetLeft left = elem.offsetLeft
@ -306,6 +303,9 @@ class IOSScrollViewport(ScrollViewport):
# left -= window_width() // 2 # left -= window_width() // 2
self._scroll_implementation(max(0, left), 0) self._scroll_implementation(max(0, left), 0)
def paged_window_scroll_pos(self):
return self.transform_val(), self.transform_val(True)
def paged___reset_transforms(self): def paged___reset_transforms(self):
s = document.documentElement.style s = document.documentElement.style
if s.transform is not 'none': if s.transform is not 'none':