Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LVDocView::getBookmark() which could be slow or wrong #313

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crengine/src/lvdocview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4703,7 +4703,9 @@ ldomXPointer LVDocView::getBookmark() {
bool found = false;
ldomXPointer fallback_ptr;
for (int y = page->start; y < page->start + page->height; y++) {
ptr = m_doc->createXPointer(lvPoint(0, y));
// Use direction=1 to avoid any x check (in case there
// is some left margin)
ptr = m_doc->createXPointer(lvPoint(0, y), 1);
lvPoint pt = ptr.toPoint();
if (pt.y >= page->start) {
if (!fallback_ptr)
Expand Down Expand Up @@ -4747,7 +4749,7 @@ ldomXPointer LVDocView::getBookmark() {
// Let's do the same in that case: get the previous text node
// position
for (int y = _pos; y >= 0; y--) {
ptr = m_doc->createXPointer(lvPoint(0, y));
ptr = m_doc->createXPointer(lvPoint(0, y), -1);
if (!ptr.isNull())
break;
}
Expand Down
52 changes: 30 additions & 22 deletions crengine/src/lvtinydom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13430,36 +13430,44 @@ ldomNode * ldomNode::elementFromPoint( lvPoint pt, int direction )
}
}

if (!direction && pt.x != 0) {
if ( !direction ) {
// We shouldn't do the following if we are given a direction
// (full text search) as we may get locked on some page.
// We also don't need to do it if pt.x=0, which is often used
// to get current page top or range xpointers.
// We are given a x>0 when tap/hold to highlight text or find
// a link, and checking x vs fmt.x and width allows for doing
// that correctly in 2nd+ table cells.
// When interested only in finding the slice of a page
// at y (to get the current page top or range xpointers),
// use direction=1 or -1.
// Use direction=0 to exactly find the final node at y AND x,
// which is necessary when selecting text or finding links
// in table cells or floats.
if ( pt.x >= fmt.getX() + fmt.getWidth() ) {
return NULL;
}
// No more true:
// (No need to check if ( pt.x < fmt.getX() ): we probably
// meet the multiple elements that can be formatted on a same
// line in the order they appear as children of their parent,
// we can simply just ignore those who end before our pt.x)
// But check x if we happen to be on a floating node (which,
// with float:right, can appear first in the DOM but be
// displayed at a higher x)
// if ( pt.x < fmt.getX() && enode->isFloatingBox() ) {
// return NULL;
// }
//
// Now that we support RTL tables, we can meet cells
// no more in logical order.
// We could add more conditions (like parentNode->getRendMethod()>=erm_table),
// but let's just check this in all cases.
if ( pt.x < fmt.getX() ) {
return NULL;
}
// We now do this above check in all cases.
// Previously:
//
// We also don't need to do it if pt.x=0, which is often used
// to get current page top or range xpointers.
// We are given a x>0 when tap/hold to highlight text or find
// a link, and checking x vs fmt.x and width allows for doing
// that correctly in 2nd+ table cells.
//
// No need to check if ( pt.x < fmt.getX() ): we probably
// meet the multiple elements that can be formatted on a same
// line in the order they appear as children of their parent,
// we can simply just ignore those who end before our pt.x.
// But check x if we happen to be on a floating node (which,
// with float:right, can appear first in the DOM but be
// displayed at a higher x)
// if ( pt.x < fmt.getX() && enode->isFloatingBox() ) {
// return NULL;
// }
// This is no more true, now that we support RTL tables and
// we can meet cells in the reverse of their logical order.
// We could add more conditions (like parentNode->getRendMethod()>=erm_table),
// but let's just check this in all cases when direction=0.
}
if ( rm == erm_final || rm == erm_list_item || rm == erm_table_caption ) {
// Final node, that's what we looked for
Expand Down