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

Implement a PDFSinglePageViewer class (issue 8188) #8724

Merged
merged 3 commits into from
Sep 24, 2017
Merged

Implement a PDFSinglePageViewer class (issue 8188) #8724

merged 3 commits into from
Sep 24, 2017

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Jul 30, 2017

This PR contains a suggested approach for addressing only #8188 (comment), but doesn't include a components example.[1]
For testing purposes, the second temporary commit uses the new PDFSinglePageViewer class in the default viewer (all normal viewer functionality appears to work in my quick tests).


[1] Please note: I initially intended to try and provide feedback on PR #8716, but the new example provided there didn't even run. Fixing that locally, I couldn't help but noticing that the new class there looks and also behaves just like a verbatim copy of the existing web/pdf_viewer.js file; which I cannot imagine is what we want, since then why not simply use PDFViewer directly?

It thus seemed to me that the suggested solution in #8716 was too far from workable that it'd be difficult to provide meaningful review comments; and I figured that I'd see how difficult it would be to implement this.

@timvandermeij
Copy link
Contributor

I think this would be a really good approach! Duplicating and having to maintain a verbatim copy of the code does not sound like the way to go, whereas this is much easier to manage.

@yurydelendik
Copy link
Contributor

Cool, let try it this way. May I suggest splitting into several files as well: rename to BaseViewer, then move the code into separate pdf_viewer.js and pdf_single_page_viewer.js files.

scrollIntoView(pageDiv, pageSpot);

// Always update the scroll direction, since it most likely isn't correct.
this.scroll.down = scrolledDown;
Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really an ugly hack that doesn't even work in all cases, so a more robust solution for tracking scroll direction seems necessary (taking into account first of all the page-switching direction and also the user scroll direction somehow, I'll look into it later in the week).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code currently relies on this.scroll when determining which page should be pre-rendered, and I didn't feel like refactoring all of that here too, this patch is still updating this.scroll.down according to the page switching direction.
However it's now done in such a way that it at least should be consistent, since it waits for the next scroll event; and unless someone complains violently I'd lean towards keeping this for now.

@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Aug 5, 2017

#8188 (comment) mentions the possibility of using the PDFSinglePageViewer in presentation mode, which seems like a really nice idea!
I don't know if we should try to fix that in this PR as well, to try and reduce churn in the code, since I suppose that it may require some further changes?

What's not clear to me is exactly how that would work though, since just replacing a PDFViewer instance with a PDFSinglePageViewer one probably isn't entirely straightforward. Considering that we have a number of setViewer methods that are used to pass around references to a PDFViewer instance, we'd need to update all of those when switching to presentation mode. Not to mention all of the state, such as current page/scale/rotation and more, that we'd need to propagate.

If we want to try and address the above in the scope of this PR, then I'd appreciate ideas for how that can be achieved! (If we come up with a good approach it might also be helpful when addressing issue #2638.)

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Aug 29, 2017

@yurydelendik Do you have any feedback on the questions/ideas in #8724 (comment), or should we just land this as-is and iterate on that in follow-ups instead?

@yurydelendik
Copy link
Contributor

should we just land this as-is and iterate on that in follow-ups instead?

yes. If there is no breaking api changes, let's do just that.

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Aug 30, 2017

If there is no breaking api changes,

Since this patch only touches code in the web/ folder, I'm assuming that the question was meant to ask if the interface of PDFViewer somehow changed with these patches!?
The answer should be a definite no, unless I managed to make some sort of typo/error in the code :-)

Since I'm not sure if anyone has really reviewed this, besides quickly skimming though the diff, I'm not going to land this myself.

@mozilla mozilla deleted a comment from pdfjsbot Sep 7, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 7, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 9, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 9, 2017
Please note that the only reason for this change is to try and improve reviewability of later patches, by keeping the diffs more manageable.
This patch introduces an abstract `BaseViewer` class, that the existing `PDFViewer` then extends. *Please note:* This lays the necessary foundation for the next patch.
The new `PDFSinglePageViewer` class extends the previously created abstract `BaseViewer` class.

There's *a lot* of existing functionality in `PDFViewer` that depends on all the pages being loaded and synchronously available, once the `setDocument` method has been called.
Given that initializing `PDFPageView` instances requires passing a DOM element to which the page is attached, the simplest solution I could come up with is to append all pages to a (hidden) document fragment and just swap them (one at a time) into the viewer when page switching occurs.
@mozilla mozilla deleted a comment from pdfjsbot Sep 24, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 24, 2017
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/d407cc8dc50d6bb/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/d407cc8dc50d6bb/output.txt

Total script time: 2.40 mins

Published

@timvandermeij timvandermeij merged commit f3987bb into mozilla:master Sep 24, 2017
@timvandermeij
Copy link
Contributor

Nice work! I'll file follow-up issues for the other ideas.

movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Implement a `PDFSinglePageViewer` class (issue 8188)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants