From 752cec5d6b6f75adf20463beef0166983c806e03 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 27 May 2017 20:09:20 +0530 Subject: [PATCH] Add a hacky workaround for the lack of fullscreen on the ipad --- src/pyj/read_book/iframe.pyj | 8 +++++--- src/pyj/read_book/view.pyj | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index bce2f9ec37..40da5f35f9 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -300,10 +300,11 @@ class IframeBoss: self.update_toc_position() def onresize(self): + self.send_message('request_size') if self.content_ready: if is_ios: - # On iOS window.innerWidth/Height are wrong inside the iframe - self.send_message('request_size') + # On iOS window.innerWidth/Height are wrong inside the iframe, + # so we wait for the reply from request_size return self.onresize_stage2() @@ -323,7 +324,8 @@ class IframeBoss: def received_window_size(self, data): window_width.from_parent, window_height.from_parent = data.width, data.height - self.onresize_stage2() + if self.content_ready: + self.onresize_stage2() def onwheel(self, evt): if self.content_ready: diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index efe496e504..71be972c2f 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -22,7 +22,7 @@ from read_book.touch import set_left_margin_handler, set_right_margin_handler from read_book.toc import update_visible_toc_nodes from read_book.goto import get_next_section from book_list.theme import get_color, get_font_family -from utils import parse_url_params, username_key +from utils import parse_url_params, username_key, is_ios LOADING_DOC = ''' @@ -62,6 +62,11 @@ def margin_elem(sd, which, id, onclick): ) if onclick: ans.addEventListener('click', onclick) + if is_ios and which is 'margin_bottom': + # On iOS 100vh includes the size of the navbar and there is no way to + # go fullscreen, so to make the bottom bar visible we add a margin to + # the bottom bar + ans.style.marginBottom = '25px' return ans @@ -140,14 +145,16 @@ class View: self.send_message('gesture_from_margin', gesture=gesture) def iframe_size(self): - w, h = window.innerWidth, window.innerHeight iframe = self.iframe - w -= 2 * iframe.offsetLeft - h -= 2 * iframe.offsetTop + l, r = document.getElementById('book-left-margin'), document.getElementById('book-right-margin') + w = r.offsetLeft - l.offsetLeft - iframe.offsetLeft + t, b = document.getElementById('book-top-margin'), document.getElementById('book-bottom-margin') + h = b.offsetTop - t.offsetTop - iframe.offsetTop return w, h def on_request_size(self, data): # On iOS/Safari window.innerWidth/Height are incorrect inside an iframe + window.scrollTo(0, 0) # ensure the window is at 0 because otherwise it sometimes moves down a bit on mobile thanks to the disappearing nav bar w, h = self.iframe_size() self.send_message('window_size', width=w, height=h) @@ -279,10 +286,12 @@ class View: ans = resolve_color_scheme() if apply_to_margins: for which in 'left top right bottom'.split(' '): - s = document.getElementById('book-{}-margin'.format(which)).style + m = document.getElementById('book-{}-margin'.format(which)) + s = m.style if which is 'top' or which is 'bottom': s.color = ans.foreground # Setting a color for the side margins causes the hover arrow to become visible s.backgroundColor = ans.background + m.parentNode.style.backgroundColor = ans.background # this is needed on iOS where the bottom margin has its own margin, so we dont want the body background color to bleed through return ans def on_resize(self):