[app] Improved link detection

The previous one was detecting any tap after the link within the
paragraph as a tap on the link. That's wrong. You have to hit the
link between its start and the end, otherwise it's a miss.
This commit is contained in:
Slava Monich 2016-10-15 13:27:43 +03:00
parent 6d0b79fb16
commit cd3194e1a2

View file

@ -194,23 +194,39 @@ void BooksPageWidget::LongPressTask::performTask()
if (rect->Kind == ZLTextElement::WORD_ELEMENT) { if (rect->Kind == ZLTextElement::WORD_ELEMENT) {
ZLTextWordCursor cursor = area.startCursor(); ZLTextWordCursor cursor = area.startCursor();
cursor.moveToParagraph(rect->ParagraphIndex); cursor.moveToParagraph(rect->ParagraphIndex);
cursor.moveToParagraphStart(); cursor.moveTo(rect->ElementIndex, 0);
for (int i=0; i<rect->ElementIndex && !isCanceled(); i++) {
// Basically, the idea is that we are going backwards
// looking for the START of the link. If we have crossed
// the END of the linked element, it means that we have
// missed it. We are recording which stop control elements
// we have encountered, to avoid making assumptions which
// ones are links and which are not. We rely on isHyperlink()
// method to tell us the ultimate truth.
bool stopped[NUM_KINDS];
memset(stopped, 0, sizeof(stopped));
while (!cursor.isStartOfParagraph() && !isCanceled()) {
cursor.previousWord();
const ZLTextElement& element = cursor.element(); const ZLTextElement& element = cursor.element();
if (element.kind() == ZLTextElement::CONTROL_ELEMENT) { if (element.kind() == ZLTextElement::CONTROL_ELEMENT) {
const ZLTextControlEntry& controlEntry = const ZLTextControlEntry& entry =
((const ZLTextControlElement&)element).entry(); ((ZLTextControlElement&)element).entry();
if (controlEntry.isHyperlink()) { ZLTextKind kind = entry.kind();
const ZLTextHyperlinkControlEntry& hyperLinkEntry = if (kind < NUM_KINDS && !entry.isStart()) {
((const ZLTextHyperlinkControlEntry&)controlEntry); stopped[kind] = true;
iKind = hyperLinkEntry.kind(); }
iLink = hyperLinkEntry.label(); if (entry.isHyperlink()) {
iLinkType = hyperLinkEntry.hyperlinkType(); if (entry.isStart() && !stopped[entry.kind()]) {
const ZLTextHyperlinkControlEntry& link =
(ZLTextHyperlinkControlEntry&) entry;
iKind = link.kind();
iLink = link.label();
iLinkType = link.hyperlinkType();
HDEBUG("link" << iLink.c_str()); HDEBUG("link" << iLink.c_str());
}
return; return;
} }
} }
cursor.nextWord();
} }
} else if (rect->Kind == ZLTextElement::IMAGE_ELEMENT) { } else if (rect->Kind == ZLTextElement::IMAGE_ELEMENT) {
ZLTextWordCursor cursor = area.startCursor(); ZLTextWordCursor cursor = area.startCursor();