mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Abstract out window.scrollTo
This commit is contained in:
parent
d96b798d45
commit
eeca0a8489
@ -491,7 +491,7 @@ def scroll_to(cfi, callback, doc): # {{{
|
||||
x += (point_.x*node.offsetWidth)/100
|
||||
if jstype(point_.y) is 'number' and node.offsetHeight:
|
||||
y += (point_.y*node.offsetHeight)/100
|
||||
window.scrollTo(x, y)
|
||||
scroll_viewport.scroll_to(x, y)
|
||||
if callback:
|
||||
callback(x, y)
|
||||
|
||||
|
@ -8,7 +8,7 @@ from keycodes import get_key
|
||||
from utils import document_height, document_width, viewport_to_document
|
||||
|
||||
def flow_to_scroll_fraction(frac):
|
||||
window.scrollTo(0, document_height() * frac)
|
||||
scroll_viewport.scroll_to(0, document_height() * frac)
|
||||
|
||||
def check_for_scroll_end(func):
|
||||
return def ():
|
||||
@ -59,7 +59,7 @@ def smooth_y_scroll(up):
|
||||
|
||||
@check_for_scroll_end
|
||||
def goto_boundary(y):
|
||||
window.scrollTo(window.pageXOffset, 0)
|
||||
scroll_viewport.scroll_to(window.pageXOffset, 0)
|
||||
|
||||
@check_for_scroll_end
|
||||
def scroll_by_page(backward):
|
||||
@ -78,7 +78,7 @@ def flow_onkeydown(evt):
|
||||
elif (key is 'left' or key is 'right') and not evt.altKey:
|
||||
handled = True
|
||||
if evt.ctrlKey:
|
||||
window.scrollTo(0 if key is 'left' else document_width(), window.pageYOffset)
|
||||
scroll_viewport.scroll_to(0 if key is 'left' else document_width(), window.pageYOffset)
|
||||
else:
|
||||
window.scrollBy(-15 if key is 'left' else 15, 0)
|
||||
elif key is 'home' or key is 'end':
|
||||
@ -87,9 +87,9 @@ def flow_onkeydown(evt):
|
||||
get_boss().send_message('goto_doc_boundary', start=key is 'home')
|
||||
else:
|
||||
if key is 'home':
|
||||
window.scrollTo(window.pageXOffset, 0)
|
||||
scroll_viewport.scroll_to(window.pageXOffset, 0)
|
||||
else:
|
||||
window.scrollTo(window.pageXOffset, document_height())
|
||||
scroll_viewport.scroll_to(window.pageXOffset, document_height())
|
||||
elif key is 'pageup' or key is 'pagedown' or key is 'space':
|
||||
handled = True
|
||||
scroll_by_page(key is 'pageup')
|
||||
|
@ -4,28 +4,31 @@ from __python__ import bound_methods, hash_literals
|
||||
|
||||
import traceback
|
||||
from aes import GCM
|
||||
from gettext import install, gettext as _
|
||||
from utils import html_escape
|
||||
from gettext import gettext as _, install
|
||||
|
||||
from read_book.cfi import at_current, scroll_to as scroll_to_cfi
|
||||
from read_book.globals import set_boss, set_current_spine_item, current_layout_mode, current_spine_item, set_layout_mode, current_book, window_width, window_height
|
||||
from read_book.mathjax import apply_mathjax
|
||||
from read_book.toc import update_visible_toc_anchors
|
||||
from read_book.resources import finalize_resources, unserialize_html
|
||||
from read_book.flow_mode import (
|
||||
flow_to_scroll_fraction, flow_onwheel, flow_onkeydown, layout as flow_layout, handle_gesture as flow_handle_gesture,
|
||||
scroll_by_page as flow_scroll_by_page, anchor_funcs as flow_anchor_funcs
|
||||
anchor_funcs as flow_anchor_funcs, flow_onkeydown, flow_onwheel,
|
||||
flow_to_scroll_fraction, handle_gesture as flow_handle_gesture,
|
||||
layout as flow_layout, scroll_by_page as flow_scroll_by_page
|
||||
)
|
||||
from read_book.globals import (
|
||||
current_book, current_layout_mode, current_spine_item, scroll_viewport, set_boss,
|
||||
set_current_spine_item, set_layout_mode, window_height, window_width
|
||||
)
|
||||
from read_book.mathjax import apply_mathjax
|
||||
from read_book.paged_mode import (
|
||||
layout as paged_layout, scroll_to_fraction as paged_scroll_to_fraction,
|
||||
onwheel as paged_onwheel, onkeydown as paged_onkeydown, scroll_to_elem,
|
||||
jump_to_cfi as paged_jump_to_cfi, handle_gesture as paged_handle_gesture,
|
||||
scroll_by_page as paged_scroll_by_page, anchor_funcs as paged_anchor_funcs,
|
||||
snap_to_selection, reset_paged_mode_globals, progress_frac
|
||||
anchor_funcs as paged_anchor_funcs, handle_gesture as paged_handle_gesture,
|
||||
jump_to_cfi as paged_jump_to_cfi, layout as paged_layout,
|
||||
onkeydown as paged_onkeydown, onwheel as paged_onwheel, progress_frac,
|
||||
reset_paged_mode_globals, scroll_by_page as paged_scroll_by_page, scroll_to_elem,
|
||||
scroll_to_fraction as paged_scroll_to_fraction, snap_to_selection
|
||||
)
|
||||
from read_book.resources import finalize_resources, unserialize_html
|
||||
from read_book.settings import apply_settings, opts
|
||||
from read_book.toc import update_visible_toc_anchors
|
||||
from read_book.touch import create_handlers as create_touch_handlers
|
||||
from utils import debounce, is_ios
|
||||
from utils import debounce, html_escape, is_ios
|
||||
|
||||
FORCE_FLOW_MODE = False
|
||||
CALIBRE_VERSION = '__CALIBRE_VERSION__'
|
||||
@ -379,7 +382,7 @@ class IframeBoss:
|
||||
if elem:
|
||||
scroll_to_elem(elem)
|
||||
else:
|
||||
window.scrollTo(0, 0)
|
||||
scroll_viewport.scroll_to(0, 0)
|
||||
|
||||
def find(self, data, from_load):
|
||||
if data.searched_in_spine:
|
||||
|
@ -223,11 +223,11 @@ def layout(is_single_page):
|
||||
return gap
|
||||
|
||||
def current_scroll_offset():
|
||||
return window.pageXOffset
|
||||
return scroll_viewport.x()
|
||||
|
||||
|
||||
def scroll_to_offset(x):
|
||||
window.scrollTo(x, 0)
|
||||
scroll_viewport.scroll_to(x, 0)
|
||||
|
||||
|
||||
def scroll_to_column(number, notify=False, duration=1000):
|
||||
@ -381,7 +381,7 @@ def jump_to_cfi(cfi):
|
||||
if in_paged_mode:
|
||||
scroll_to_xpos(x)
|
||||
else:
|
||||
window.scrollTo(0, y)
|
||||
scroll_viewport.scroll_to(0, y)
|
||||
)
|
||||
|
||||
def current_cfi():
|
||||
|
Loading…
x
Reference in New Issue
Block a user