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

Refactoring to move page display code into separate class #5295

Merged
merged 11 commits into from
Sep 29, 2014

Conversation

yurydelendik
Copy link
Contributor

Idea is to create reusable PDFViewer that will not have dependency on the PDFView (toolbars, find controller, etc).

  • Move pages container logic into PDFViewer (?) out of PDFView
  • Move thumbs container logic into PDFThumbnailsViewer (?) out of PDFView
  • Remove all dependency on PDFView in PDFViewer and classes it's using
  • Remove any rendering logic from PDFView
  • Isolate PDFPageSource logic and use in PDFViewer, PDFThumbnailsViewer, PDFFindController
  • Refactor PresentationMode (minimal, to remove dependency from PDFViewer)

NOTE: The refactoring shall not include any optimization or bug fixes

@Snuffleupagus
Copy link
Collaborator

Adding a class named PDFViewer might be slightly confusing when PDFView already exists. Should we rename one (or both) of them to mitigate this?

I've done some quick testing, and the viewer still appears to (mostly) work as before :-)


Given that one of the TODOs is "Refactor PresentationMode", I'm not sure how relevant this comment is, but I thought I should mention it anyway. I noticed that the zoom level isn't reset properly when exiting presentation mode. To reproduce:

  • Set the zoom level to one of the predefined levels (e.g. auto or page-width).
  • Enter presentation mode.
  • Exit presentation mode.
  • Resize the browser window.

Actual result:
The zoom level of the document is now page-fit.

Expected result:
The zoom level of the document should be the same as before (e.g. auto or page-width).


'use strict';

var PDFViewer = (function pdfViewer() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: function PDFViewerClosure() instead?

@yurydelendik
Copy link
Contributor Author

Adding a class named PDFViewer might be slightly confusing when PDFView already exists. Should we rename one (or both) of them to mitigate this?

I have to decisions made yet, however we started to name everything as PDFXxxx. I'm proposing to keep PDFViewer (since other names will not fit here). PDFView is a bad name here. So I decided to deprecate it, in the future it can be e.g. an alias for PDFViewerApplication.instance.

@yurydelendik
Copy link
Contributor Author

I noticed that the zoom level isn't reset properly when exiting presentation mode.

Fixed that.

PresentationMode stuff is not was I expected, I'm going to keep that mostly as is, except removing dependency from PDFViewer on this object.

@yurydelendik
Copy link
Contributor Author

I think I'm done. Here is minimal viewer https://gist.github.com/yurydelendik/5e7eda82bfd67a5a15df

@Snuffleupagus
Copy link
Collaborator

I noticed that the zoom level isn't reset properly when exiting presentation mode.

Fixed that.

Confirmed fixed, thank you!

'use strict';

var PresentationModeState = {
UKNOWN: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: UNKNOWN.

downloadedPromise.then(function () {
var event = document.createEvent('CustomEvent');
event.initCustomEvent('documentload', true, true, {});
window.dispatchEvent(event);
});

PDFView.loadingBar.setWidth(container);
self.loadingBar.setWidth(document.getElementById('viewerContainer'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to use the DOM element viewer instead, otherwise it won't work.

For some reason, in this scope, the variable container doesn't refer to what you would expect; see https://github.com/mozilla/pdf.js/pull/5295/files#diff-dd42e9b2d2a652b8e312efa567698aa6L994

OverlayManager, PDFFindController, PDFFindBar, getVisibleElements,
watchScroll, PDFViewer, PDFRenderingQueue, PresentationModeState,
DEFAULT_SCALE, UNKNOWN_SCALE,
IGNORE_CURRENT_POSITION_ON_ZOOM: true */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not typo -- signals lint that property can be overwritten

* @returns {number}
*/
get pagesRotation() {
return this._pageRotation;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this (and in the setter below) be this._pagesRotation to match L#286?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thank you

return;
}
dest = null;
PDFView.setScale(PDFView.currentScaleValue, true, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't removing this line reintroduce the issue that PR #3829 fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, /test/pdfs/rotation.pdf a test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

brendandahl added a commit that referenced this pull request Sep 29, 2014
Refactoring to move page display code into separate class
@brendandahl brendandahl merged commit 1145eb8 into mozilla:master Sep 29, 2014
yurydelendik added a commit to yurydelendik/pdf.js that referenced this pull request Sep 30, 2014
yurydelendik added a commit that referenced this pull request Sep 30, 2014
Fixes typo/regression of #5295 for presentation mode
joelkuiper added a commit to joelkuiper/pdf.js that referenced this pull request Sep 30, 2014
* 'master' of https://github.com/mozilla/pdf.js:
  Move text_layer_builder and pdf_viewer styles out
  Adds css import preprocessing
  Moves scrollPageIntoView to the PDFViewer.
  Followup fix for entering/exiting Presentation mode
  Fixes typo/regression of mozilla#5295 for presentation mode
  Renames and refactors PDFView to PDFViewerApplication.
  Adds types definitions (jsdoc) for the PDFViewer code.
  Marks some private methods in PDFViewer and PDFThumbnailViewer
  Moves constants to avoid dependency on PDFView
  Removes any usage of PDFView in the PageView
  Removes PresentationMode dependency from PDFViewer
  Moves rendering queue logic from PDFView
  Moves pdfDocument.getPage/getTextContent requests out of PDFView
  Moves viewer code into PDFViewer and some code from PageView.
  Moves thumbs logic into PDFThumbnailViewer.
  Moves watchScroll and getVisibleElements from PDFView
  Fix Symbol fonts without font file but with Encoding dictionary (issue 5238)
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