mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
ltr and rtl should both be properties
Otherwise its easy to forget which is which
This commit is contained in:
parent
1001f254a3
commit
b0e1506976
@ -672,7 +672,7 @@ def scroll_to(cfi, callback, doc): # {{{
|
|||||||
r = node.getBoundingClientRect()
|
r = node.getBoundingClientRect()
|
||||||
# Start of element is right side in RTL, so be sure to get that side in RTL mode
|
# Start of element is right side in RTL, so be sure to get that side in RTL mode
|
||||||
x, y = scroll_viewport.viewport_to_document(
|
x, y = scroll_viewport.viewport_to_document(
|
||||||
r.left if scroll_viewport.ltr() else r.right, r.top, node.ownerDocument)
|
r.left if scroll_viewport.ltr else r.right, r.top, node.ownerDocument)
|
||||||
if jstype(point_.x) is 'number' and node.offsetWidth:
|
if jstype(point_.x) is 'number' and node.offsetWidth:
|
||||||
x += (point_.x*node.offsetWidth)/100
|
x += (point_.x*node.offsetWidth)/100
|
||||||
if jstype(point_.y) is 'number' and node.offsetHeight:
|
if jstype(point_.y) is 'number' and node.offsetHeight:
|
||||||
@ -716,7 +716,7 @@ def at_point(ox, oy): # {{{
|
|||||||
r = node.getBoundingClientRect()
|
r = node.getBoundingClientRect()
|
||||||
# Start of element is right side in RTL, so be sure to get that side in RTL mode
|
# Start of element is right side in RTL, so be sure to get that side in RTL mode
|
||||||
x, y = scroll_viewport.viewport_to_document(
|
x, y = scroll_viewport.viewport_to_document(
|
||||||
r.left if scroll_viewport.ltr() else r.right, r.top, node.ownerDocument)
|
r.left if scroll_viewport.ltr else r.right, r.top, node.ownerDocument)
|
||||||
if jstype(p.x) is 'number' and node.offsetWidth:
|
if jstype(p.x) is 'number' and node.offsetWidth:
|
||||||
x += (p.x*node.offsetWidth)/100
|
x += (p.x*node.offsetWidth)/100
|
||||||
if jstype(p.y) is 'number' and node.offsetHeight:
|
if jstype(p.y) is 'number' and node.offsetHeight:
|
||||||
|
@ -502,7 +502,7 @@ anchor_funcs = {
|
|||||||
# Elements start on the right side in RTL mode,
|
# Elements start on the right side in RTL mode,
|
||||||
# so be sure to return that side if in RTL.
|
# so be sure to return that side if in RTL.
|
||||||
x, y = scroll_viewport.viewport_to_document(
|
x, y = scroll_viewport.viewport_to_document(
|
||||||
br.left if scroll_viewport.ltr() else br.right,
|
br.left if scroll_viewport.ltr else br.right,
|
||||||
br.top, elem.ownerDocument)
|
br.top, elem.ownerDocument)
|
||||||
return y, x
|
return y, x
|
||||||
,
|
,
|
||||||
|
@ -430,10 +430,10 @@ def scroll_to_elem(elem):
|
|||||||
# inaccurate results, so we prefer the bounding client rect,
|
# inaccurate results, so we prefer the bounding client rect,
|
||||||
# when possible.
|
# when possible.
|
||||||
# Columns start on the right side in RTL mode, so get that instead here...
|
# Columns start on the right side in RTL mode, so get that instead here...
|
||||||
pos = elem.scrollLeft if scroll_viewport.ltr() else elem.scrollRight
|
pos = elem.scrollLeft if scroll_viewport.ltr else elem.scrollRight
|
||||||
else:
|
else:
|
||||||
# and here.
|
# and here.
|
||||||
pos = br.left if scroll_viewport.ltr() else br.right
|
pos = br.left if scroll_viewport.ltr else br.right
|
||||||
scroll_to_xpos(scroll_viewport.viewport_to_document(
|
scroll_to_xpos(scroll_viewport.viewport_to_document(
|
||||||
pos+2, elem.scrollTop, elem.ownerDocument)[0])
|
pos+2, elem.scrollTop, elem.ownerDocument)[0])
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ def snap_to_selection():
|
|||||||
node = sel.anchorNode
|
node = sel.anchorNode
|
||||||
# In RTL mode, the "start" of selection is on the right side.
|
# In RTL mode, the "start" of selection is on the right side.
|
||||||
pos = scroll_viewport.viewport_to_document(
|
pos = scroll_viewport.viewport_to_document(
|
||||||
r.left if scroll_viewport.ltr() else r.right,
|
r.left if scroll_viewport.ltr else r.right,
|
||||||
r.top, doc=node.ownerDocument)[0]
|
r.top, doc=node.ownerDocument)[0]
|
||||||
|
|
||||||
# Ensure we are scrolled to the column containing the start of the
|
# Ensure we are scrolled to the column containing the start of the
|
||||||
@ -663,7 +663,7 @@ def handle_gesture(gesture):
|
|||||||
else:
|
else:
|
||||||
if not gesture.active or gesture.is_held:
|
if not gesture.active or gesture.is_held:
|
||||||
scroll_by_page(gesture.direction is 'right', True, flip_if_rtl_page_progression=True)
|
scroll_by_page(gesture.direction is 'right', True, flip_if_rtl_page_progression=True)
|
||||||
# Gesture progression direction is determined in the gesture code;
|
# Gesture progression direction is determined in the gesture code,
|
||||||
# don't set flip_if_rtl_page_progression=True here.
|
# don't set flip_if_rtl_page_progression=True here.
|
||||||
elif gesture.type is 'prev-page':
|
elif gesture.type is 'prev-page':
|
||||||
scroll_by_page(True, opts.paged_taps_scroll_by_screen, flip_if_rtl_page_progression=False)
|
scroll_by_page(True, opts.paged_taps_scroll_by_screen, flip_if_rtl_page_progression=False)
|
||||||
@ -678,7 +678,7 @@ anchor_funcs = {
|
|||||||
br = elem.getBoundingClientRect()
|
br = elem.getBoundingClientRect()
|
||||||
# In RTL mode, the start of something is on the right side.
|
# In RTL mode, the start of something is on the right side.
|
||||||
x = scroll_viewport.viewport_to_document(
|
x = scroll_viewport.viewport_to_document(
|
||||||
br.left if scroll_viewport.ltr() else br.right,
|
br.left if scroll_viewport.ltr else br.right,
|
||||||
br.top, elem.ownerDocument)[0]
|
br.top, elem.ownerDocument)[0]
|
||||||
return column_at(x)
|
return column_at(x)
|
||||||
,
|
,
|
||||||
|
@ -16,6 +16,7 @@ class ScrollViewport:
|
|||||||
# current X position and the requested X scroll position, which fools the reader
|
# current X position and the requested X scroll position, which fools the reader
|
||||||
# code into thinking that it's always scrolling in positive X.
|
# code into thinking that it's always scrolling in positive X.
|
||||||
self.rtl = False
|
self.rtl = False
|
||||||
|
self.ltr = True
|
||||||
|
|
||||||
def set_mode(self, mode):
|
def set_mode(self, mode):
|
||||||
prefix = ('flow' if mode is 'flow' else 'paged') + '_'
|
prefix = ('flow' if mode is 'flow' else 'paged') + '_'
|
||||||
@ -24,12 +25,11 @@ class ScrollViewport:
|
|||||||
|
|
||||||
def initialize_on_layout(self):
|
def initialize_on_layout(self):
|
||||||
self.rtl = False
|
self.rtl = False
|
||||||
|
self.ltr = True
|
||||||
body_style = window.getComputedStyle(document.body)
|
body_style = window.getComputedStyle(document.body)
|
||||||
if body_style.direction is "rtl":
|
if body_style.direction is "rtl":
|
||||||
self.rtl = True
|
self.rtl = True
|
||||||
|
self.ltr = False
|
||||||
def ltr(self):
|
|
||||||
return not self.rtl
|
|
||||||
|
|
||||||
def flow_x(self):
|
def flow_x(self):
|
||||||
if self.rtl:
|
if self.rtl:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user