This commit is contained in:
Kovid Goyal 2016-04-29 14:19:59 +05:30
parent b4f793507a
commit f21ea7f9ae

View File

@ -6,6 +6,7 @@ from dom import set_css
from elementmaker import E from elementmaker import E
from keycodes import get_key from keycodes import get_key
from read_book.cfi import scroll_to as cfi_scroll_to, at_point as cfi_at_point, at_current as cfi_at_current from read_book.cfi import scroll_to as cfi_scroll_to, at_point as cfi_at_point, at_current as cfi_at_current
from read_book.globals import get_boss
from read_book.settings import opts from read_book.settings import opts
import traceback import traceback
from utils import get_elem_data, set_elem_data, viewport_to_document from utils import get_elem_data, set_elem_data, viewport_to_document
@ -102,8 +103,8 @@ def fit_images():
def layout(is_single_page): def layout(is_single_page):
nonlocal _in_paged_mode, col_width, page_width, page_height, side_margin, screen_width, margin_top, margin_bottom, is_full_screen_layout, cols_per_screen nonlocal _in_paged_mode, col_width, page_width, page_height, side_margin, screen_width, margin_top, margin_bottom, is_full_screen_layout, cols_per_screen
body_style = window.getComputedStyle(document.body) body_style = window.getComputedStyle(document.body)
first_layout = False first_layout = not _in_paged_mode
if not _in_paged_mode: if first_layout:
handle_rtl_body(body_style) handle_rtl_body(body_style)
# Check if the current document is a full screen layout like # Check if the current document is a full screen layout like
# cover, if so we treat it specially. # cover, if so we treat it specially.
@ -138,6 +139,7 @@ def layout(is_single_page):
page_width = col_width + 2*sm page_width = col_width + 2*sm
side_margin = sm side_margin = sm
screen_width = page_width * n screen_width = page_width * n
page_height = window.innerHeight
set_css(document.body, column_gap=2*sm + 'px', column_width=col_width + 'px', column_rule='0px inset blue', set_css(document.body, column_gap=2*sm + 'px', column_width=col_width + 'px', column_rule='0px inset blue',
min_width='0', max_width='none', min_height='0', max_height='none', min_width='0', max_width='none', min_height='0', max_height='none',
@ -179,7 +181,7 @@ def layout(is_single_page):
# anyway and if it is >= 2*body_width it can't be a full screen # anyway and if it is >= 2*body_width it can't be a full screen
# layout # layout
body_width = document.body.offsetWidth + 2 * sm body_width = document.body.offsetWidth + 2 * sm
is_full_screen_layout = (only_img or has_svg) and single_screen and document.body.scrollWidth > body_width and document.body.scrollWidth < 2 * body_width is_full_screen_layout = (only_img or has_svg) and single_screen and (document.body.scrollWidth <= body_width or (body_width < document.body.scrollWidth < 2 * body_width))
if is_single_page: if is_single_page:
is_full_screen_layout = True is_full_screen_layout = True
@ -454,3 +456,12 @@ def current_cfi():
# if ans: # if ans:
# print('Viewport cfi:', ans) # print('Viewport cfi:', ans)
return ans return ans
def onwheel(evt):
if evt.deltaY:
backward = evt.deltaY < 0
x = previous_col_location() if backward else next_col_location()
if x is -1:
get_boss().send_message('next_spine_item', previous=backward)
else:
scroll_to_xpos(x)