check link on the fly when tapping

pull/476/head
chrox 10 years ago
parent 7aca27c2a0
commit 9e3e070522

@ -233,6 +233,10 @@ function CreDocument:getPageLinks()
return self._document:getPageLinks()
end
function CreDocument:getLinkFromPosition(pos)
return self._document:getLinkFromPosition(pos.x, pos.y)
end
function Document:gotoPos(pos)
DEBUG("CreDocument: goto position", pos)
self._document:gotoPos(pos)

@ -61,8 +61,8 @@ function ReaderLink:onTap(arg, ges)
end
end
end
local pos = self.view:screenToPageTransform(ges.pos)
if self.ui.document.info.has_pages then
local pos = self.view:screenToPageTransform(ges.pos)
local page_links = self.ui.document:getPageLinks(pos.page)
--DEBUG("page links", page_links)
if page_links then
@ -81,34 +81,20 @@ function ReaderLink:onTap(arg, ges)
end
end
else
if self.view.links then
for i = 1, #self.view.links do
local link = self.view.links[i]
-- enlarge tappable link box
local lbox = Geom:new{
x = link.start_x - Screen:scaleByDPI(15),
y = link.start_y - Screen:scaleByDPI(15),
w = link.end_x - link.start_x + Screen:scaleByDPI(30),
h = link.end_y - link.start_y > 0
and link.end_y - link.start_y + Screen:scaleByDPI(30)
or Screen:scaleByDPI(50),
}
if inside_box(pos, lbox) then
return self:onGotoLink(link)
end
end
local link = self.ui.document:getLinkFromPosition(ges.pos)
if link ~= "" then
return self:onGotoLink(link)
end
end
end
function ReaderLink:onGotoLink(link)
DEBUG("goto link", link)
if self.ui.document.info.has_pages then
table.insert(self.link_states, self.view.state.page)
self.ui:handleEvent(Event:new("PageUpdate", link.page + 1))
else
table.insert(self.link_states, self.ui.document:getXPointer())
self.document:gotoLink(link.section)
self.document:gotoLink(link)
self.ui:handleEvent(Event:new("UpdateXPointer"))
end
return true

@ -204,13 +204,11 @@ end
function ReaderRolling:onPosUpdate(new_pos)
self.current_pos = new_pos
self:updatePageLink()
self:updateBatteryState()
end
function ReaderRolling:onPageUpdate(new_page)
self.current_page = new_page
self:updatePageLink()
self:updateBatteryState()
end
@ -367,6 +365,10 @@ function ReaderRolling:onGotoPage(number)
return true
end
--[[
currently we don't need to get page links on each page/pos update
since we can check link on the fly when tapping on the screen
--]]
function ReaderRolling:updatePageLink()
DEBUG("update page link")
local links = self.ui.document:getPageLinks()

@ -1 +1 @@
Subproject commit c788775467c238e025ca04ca0a60b1e71af85576
Subproject commit f1d49a43e69848d186ce4e96caa11f11697ef4b0
Loading…
Cancel
Save