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

Unprecise CFI for getFirstVisibleElementCfi() / cfi_navigation_logic.js #47

Closed
edas opened this issue Jul 2, 2014 · 3 comments
Closed

Comments

@edas
Copy link

edas commented Jul 2, 2014

The CFI returned by getFirstVisibleElementCfi() in cfi_navigation_logic.js is unprecise.

Procedure to reproduce

Open the redium-js-viewer with the embedded book 'accessible epub 3'. Go to chapter 2 and turn a few pages. Launch getFirstVisibleElementCfi()

Actual result

The partial CFI returned is always ""/4/2[building_a_better_epub]/2@0:xx". This targets the first <section> of the chapter, which include the whole text content of the chapter, then add a positionning in % in that chapter.

Expected result

CFI returned should be more precise and return an CFI pointing to an inner <p>inside the <section>, like "/4/2[building_a_better_epub]/10/32/12@0:xx".

Explaination

This is because the first child of the <section> element, which is a blank text node, is reported by both Chrome and Firefox as visible on all columns in a multi-columns layout. When walking the DOM to find the first visible text node, this one is always checked first and always answer "yes".

The code should ignore blank text nodes but this one is not ignored. Probably because it contains tabulations, carriage returns or other characters than space and line feed.

Fix

In cfi_navigation_logic.js :

function isValidTextNode(node) {
    if(node.nodeType === Node.TEXT_NODE) {
        return (! node.nodeValue.match(/^\s*$/) );
     }
     return false;
}

This replace the all code that just strip spaces and line feeds then check that the length is not 0.

Problem

I did not send a PR because when fixing this bug, I trigger a browser bug on Firefox which forbids Firefox from being able to jump to these more precise CFI (the getClientRects() of the targeted element are always totally incoherent).

@edas edas changed the title Unprecise CFI for Unprecise CFI for getFirstVisibleElementCfi() / cfi_navigation_logic.js Jul 2, 2014
@edas
Copy link
Author

edas commented Jul 2, 2014

@dmitrym0
Copy link
Contributor

dmitrym0 commented Jul 2, 2014

Hi @edas, I believe we may have a fix for this. @jccr can you comment?

@danielweck
Copy link
Member

@edas, @dmitrym0, @jccr, can you please continue working on this issue in the correct repository (readium-shared-js)

readium/readium-shared-js#35

Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants