Commit Graph

917 Commits

Author SHA1 Message Date
Tim van der Meij
d08895d659 Merge pull request #6236 from Rob--W/print-javascript-action
Detect scripted auto-print requests
2015-07-25 19:42:31 +02:00
Tim van der Meij
9c510bd6e6 Remove unused globals and updateViewarea function from viewer.js 2015-07-23 16:02:39 +02:00
Tim van der Meij
d162dba85e Merge pull request #6256 from Snuffleupagus/bug-1186842
Ensure that the viewer always receives focus when the HOME/END keys are pressed (bug 1186842)
2015-07-23 14:46:32 +02:00
Jonas Jenwald
8275dff1b1 Reduce code duplication in the 'keydown' event handler in viewer.js, by re-factoring the code which ensures that the viewerContainer is focused 2015-07-23 13:01:55 +02:00
Jonas Jenwald
d5232f5b5a Ensure that the viewer always receives focus when the HOME/END keys are pressed (bug 1186842)
It appears that I broke this with PR 4941.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1186842.
2015-07-23 12:04:49 +02:00
Jonas Jenwald
fa53cd6ca3 Use DEFAULT_SCALE_VALUE as default when fetching the zoom parameter from PDFViewerApplication.store (i.e. ViewHistory)
Since the zoom value should be in percent, using `PDFViewer.currentScale` will be wrong by a factor of 100, potentially causing the zoom level of the document to become wrong on load.
2015-07-22 23:58:30 +02:00
Jonas Jenwald
299d05eaa5 Prevent documents from intermittently opening with the zoom level set to 1% (issue 6253)
*This fixes a regression from PR 6192.*

Under some circumstances, the `resize` event handler in `viewer.js` is fired before the scale has been set. This can lead to PDF documents being rendered at the wrong zoom level when they are opened.
It seems that a way to reliably trigger this is to, using the Firefox addon, open a PDF file that triggers the `fallback` bar, in a new background tab (i.e. middle clicking on a link, or use the context menu).

Prior to PR 6192, we checked the selected option in the `scaleSelect` dropdown instead. Since `pageAutoOption` is selected by default in `viewer.html`, this should explain why the issue wasn't visible previously.
2015-07-22 23:45:33 +02:00
Rob Wu
c676ecb5a0 Detect scripted auto-print requests
Fixes #6106

To avoid future regressions, two new unit tests were added:
1. A new PDF based on the report from #6106, which contains an
   OpenAction of type JavaScript and a string "this.print({...}".
2. An existing PDF from https://bugzil.la/1001080 (from #4698).

Although it does not matter, since we don't execute the JavaScript code,
I have also changed "print(true)" to "print({})" since the print method
takes an object (not a boolean). See "Printing PDF documents", page 62:
http://adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_developer_guide.pdf
2015-07-20 18:25:02 +02:00
Jonas Jenwald
93d82e21d5 Move handling of the 'custom' scale value from pdf_viewer.js to viewer.js
The special handling of the 'custom' scale value is only relevant for the `scaleSelect` dropdown in the standard viewer, hence I think that it should be placed in `viewer.js` instead.
2015-07-19 20:02:47 +02:00
Jonas Jenwald
0c08113e39 Remove PDFViewerApplication.setScale and further simplify the scalechange event handler (issue 6158)
This finally fixes 6158.
2015-07-14 10:06:59 +02:00
Jonas Jenwald
2608757620 Simplify the code that resets the value of the pageNumber element in PDFViewerApplication.setInitialView
After the creation of `PDFViewer`, its `_resetView` method takes care of resetting, among other things, the page number property. Hence we don't need to set `pdfViewer.currentPageNumber = 1;` here any more, and the comment is no longer accurate either.
2015-07-12 16:24:07 +02:00
Jonas Jenwald
5cb15874fa Remove PDFViewerApplication.updateScaleControls (issue 6158)
*With this patch we're getting very close to fixing 6158.*

The only use-case for `PDFViewerApplication.updateScaleControls` is to try and avoid calling `selectScaleOption` from the `scalechange` event handler in viewer.js.
This will *only* happen when the user has manually changed the scale by using the `<select>` dropdown, which means that in reality this is just a micro optimization. Furthermore, `selectScaleOption` is only skipped for the "named" scale values (e.g. `auto`, `page-actual`, `page-fit`, `page-width`), thus further reducing the value of this code.

Also, since we're updating the scale `<select>` dropdown from an event handler, we're currently depending on the event being dispatched (and handled) completely before the next `scalechange` event. Relying on the execution order of the code in this way, even though it currently works, seems unfortunate since it *could* potentially cause the internal scale value and the UI from getting out of sync.
2015-07-11 11:25:32 +02:00
Jonas Jenwald
35ee1e1b0a Refactor the 'resize' event handler in viewer.js (issue 6158)
*This is the next step towards fixing 6158.*

This patch removes the dependency on the state of the scale `<select>` dropdown from the `resize` event handler, and instead uses the (in `PDFViewer`) stored `currentScaleValue`.
I believe that the way this code is currently written is purely for historical reasons, since originally *only* the numerical scale was stored internally (hence there was no other way to access the scale value).
However, since we now store the scale value, we should use it instead of quering the DOM. This helps ensure that the internally stored scale value is always accurately displayed in the UI (which should be good since, after the creation of `PDFViewer`, the `<select>` DOM element is now updated by an event handler).
2015-07-10 11:50:54 +02:00
Jonas Jenwald
1c0115a7e4 Remove the currentScaleValue getter from PDFViewerApplication (issue 6158)
*The next step towards fixing issue 6158.*

We can just as well access `pdfViewer.currentScaleValue` directly in `PDFViewerApplication`, instead of having a helper function which just acts as a wrapper for it.
2015-07-07 09:17:05 +02:00
Jonas Jenwald
6b2810f1f0 Pass in a PDFViewer instance to PDFPresentationMode and use it to eliminate all references to PDFViewerApplication
This patch is the the first step towards to addressing issue 6158, which will be done by refactoring the code for setting/getting the current scale in `viewer.js`.
2015-07-06 09:49:51 +02:00
Rob Wu
2932f7c676 Zoom relative to cursor position via mouse wheel
Before this patch, zooming in/out via the scroll wheel caused the page
to be zoomed relative to the upper-left corner of the page, i.e. the
upper-left corner of the page stays at a fixed position.

After this patch, the page is zoomed relative to the cursor position,
i.e. after zooming in/out, the part under the cursor 'has not moved'.

This only applies when the page does not fit in the viewport, because
pages smaller than the viewpoer are always centered.
2015-07-02 23:20:37 +02:00
Yury Delendik
f3c3b1fc2d Removes B2G preprocessing directives. 2015-06-30 16:53:32 -05:00
Yury Delendik
1b847df2f3 Using pdfjs-dist as a library for b2g viewer. 2015-06-30 16:53:32 -05:00
Jonas Jenwald
ffeba9c630 Move the page switching code into set currentPageNumber in PDFViewer instead of placing it in the pagechange event handler
The reason that this code can be moved is that the `if (this.loading && page === 1)` check, in the `pagechange` event handler in viewer.js, is never satisfied since `this.loading` is not defined in that scope.
This *could* be considered a regression from PR 5295, since prior to that `this.loading` was using the `PDFViewerApplication` scope (or `PDFView` as it were).
However, I don't think that we need to fix that since we've been shipping this code in no less than *three* Firefox releases (uplifted in https://bugzilla.mozilla.org/show_bug.cgi?id=1084158), without breaking the world.

An explanation of why the `pagechange` code works, despite `this.loading === undefined`, is that `set currentPageNumber` (in `PDFViewer`) returns early whenever `this.pdfDocument` isn't set. This check is, for all intents and purposes, functionally equivalent to checking `PDFViewerApplication.loading`.
Hence we can move the page switching code into `PDFViewer`, and also remove `PDFViewerApplication.loading` since it's not used any more.
(The `this.loading` property was added in PR 686, which was before the current viewer even existed.)

*Note:* The changes in this patch should also be beneficial to the viewer `components`, since requiring every implementer to provide their own `pagechange` event handler just to get `PDFViewer.currentPageNumber` to actually work seems like an unnecessary complication.
2015-06-24 14:07:07 +02:00
Jonas Jenwald
7cb62089ad Fix a typo causing a TypeError when attempting to call pdfHistory_clearHistoryState (issue 6121)
Fixes 6121.

Note: This "regressed" in PR 5823.
2015-06-16 13:16:12 +02:00
Rob Wu
f4ba0e342e Check availability of canvas & PDF before printing 2015-06-05 23:55:08 +02:00
Rob Wu
adb2f8ae21 [CRX] Add Referer request header if needed
This patch adds the Referer request header to PDF requests if
the original PDF request included the Referer header.
2015-06-05 23:24:40 +02:00
Jonas Jenwald
27713f9454 Ensure that PDFHistory does not incorrectly replace the initial document hash (issue 6079)
This is fallout from PR 5971; fixes 6079.
2015-06-04 13:58:45 +02:00
Yury Delendik
5cff06e52a Refactors PDFHistory.
# Conflicts:
#	extensions/b2g/viewer.js
#	web/pdf_history.js
#	web/pdf_viewer.component.js
#	web/viewer.js
2015-05-16 11:20:36 -05:00
Yury Delendik
0ef6212b64 Refactors PDFLinkService.
# Conflicts:
#	web/viewer.js
2015-05-16 11:20:36 -05:00
Jonas Jenwald
9deae0eb6d Merge pull request #6014 from NotablePDF/fix_scroll_zoom
Fix scroll to zoom jump between 25% and 1000%
2015-05-15 01:18:47 +02:00
Xiliang Chen
ed540a8d00 Fix scroll to zoom jump between 25% and 1000% 2015-05-15 10:16:52 +12:00
Tim van der Meij
d7aa95d6b1 Merge pull request #5857 from Rob--W/print-page-size
Set page size via @page + size
2015-05-14 16:52:40 +02:00
Jonas Jenwald
ba0eb7fdc6 Add the |location| to the |updateviewarea| UI event
*This patch addresses an issue I stumbled upon while working on rewriting the history implementation.*

Currently the `updateviewarea` UI event doesn't include the `location`, and in the event handler in viewer.js we instead reach into `PDFViewer` to retrieve it. Not only does this seem conceptually wrong, it also makes the `updateviewarea` event less useful in general since it's currently only possible to access the `location` if you have a reference to the `PDFViewer`.

To me, this simply appears to be an oversight in the implementation, hence this patch which adds `location` to the `updateviewarea` event. It also changes `location` to be a "private" property of `PDFViewer`.
2015-05-08 12:15:50 +02:00
David Flanagan
ae740768b0 Bug 1152841 - make pdf.js viewer app handle open requests from file viewers 2015-05-05 01:04:45 +02:00
Jonas Jenwald
66b12974c9 Prevent Firefox from warning about |unreachable code after return statement|
*This is a follow-up to PR 5966.*

Now that https://bugzilla.mozilla.org/show_bug.cgi?id=1151931 has landed, we're unfortunately in a situation where Firefox warns about `unreachable code after return statement` multiple times when using the PDF.js code in `node make server` mode.

I'm really sorry about the churn in this code!
However I don't think it's a good idea to let Firefox continue to printing these warnings in the console, since it increases the risk of missing actual errors.
2015-04-29 19:26:05 +02:00
Tim van der Meij
080ab204d6 Merge pull request #5953 from Snuffleupagus/issue-3498
Remove no longer needed hacks that enable spacebar scrolling in Firefox (issue 3498)
2015-04-27 19:10:49 +02:00
Tim van der Meij
c91f736db7 Merge pull request #5966 from Snuffleupagus/lint-viewer-preprocesser-code
Enable linting of Firefox specific code in viewer.js
2015-04-27 18:59:55 +02:00
Tim van der Meij
6abf3d6ba3 Simplify document properties field logic
This patch:
- Simplifies the way fields are passed to the document properties overlay
- Simplifies the way fields are filled internally in the document properties overlay
- Avoids passing a document properties reference to the secondary toolbar
2015-04-27 15:25:40 +02:00
Jonas Jenwald
91ce16bc1d Enable linting of Firefox specific code in viewer.js
- This patch uncomments a large portion of the Firefox specific code in viewer.js, by using a preprocessor "trick", to enable linting. Doing this actually uncovered some issues, e.g. variables defined multiple times.

 - This patch also fixes a spelling error, `adobe pdfwritter` -> `abobe pdfwriter`, in the `KNOWN_GENERATORS` list used when reporting telemetry data in Firefox.

*Please note:* there's still some Firefox specific code that is commented out, but it's usually just one (or two) lines of code. Hence the risk that errors creep in should be much lower, compared to entire code-blocks.
2015-04-26 19:52:09 +02:00
Tim van der Meij
1a5de56675 Group public/private methods and add comments
This patch:
- Puts public methods at the top of the file
- Puts private methods below the public methods and marks them with an underscore
- Adds JSDoc comments to the class
- Adds setDocumentAndUrl to avoid having to handle that in `viewer.js`
2015-04-26 15:50:28 +02:00
Tim van der Meij
7cf440c560 Refactor PDFDocumentProperties to be more class-like 2015-04-24 20:47:38 +02:00
Tim van der Meij
ca8f842d87 Rename DocumentProperties to PDFDocumentProperties 2015-04-24 20:35:11 +02:00
Jonas Jenwald
10f134bcc2 Remove no longer needed hacks that enable spacebar scrolling in Firefox (issue 3498)
Now that [bug 915962](https://bugzilla.mozilla.org/show_bug.cgi?id=915962) has landed, we no longer need any hacks to enable <kbd>spacebar</kbd> scrolling in Firefox.

Fixes 3498.
2015-04-21 22:26:50 +02:00
Jonas Jenwald
4211df63eb Refactor PDFPresentationMode to be more class-like 2015-04-21 16:28:50 +02:00
Jonas Jenwald
d5089f42fa Initial refactoring of the PDFPresentationMode code
Noteworthy changes:

 - Adds JSDoc comments to PDFPresentationMode.

 - Removes a couple of, no longer necessary, helper functions.
2015-04-21 16:28:49 +02:00
Jonas Jenwald
f15d5c8cfe Rename the presentation_mode.js file and adjust the function names
Also moves the |fullscreenchange| event listeners into PDFPresentationMode.
2015-04-21 16:28:48 +02:00
Jonas Jenwald
e7fd5b4d4d Refactor the options passed to |PresentationMode.initialize| and clean-up some code in viewer.js and presentation_mode.js
This patch:
 - Passes in a reference to the current PDFThumbnailViewer, which is used to ensure that the current thumbnail becomes visible when exiting PresentationMode.

 - Changes the way that the event listeners for the contextmenu items are defined, to avoid passing in a reference to the SecondaryToolbar.

 - Ensures that |supportsFullscreen| always returns a boolean.
   Currently `supportsFullscreen` will, when the browser supports the fullscreen API, return e.g. `function mozRequestFullScreen()` instead of `true`.

 - Simplifies the |click| handler code when PresentationMode is active.
   This code has been obsolete ever since PR 2919 landed.

 - Removes hack used to workaround a bug in WebKit browsers, which caused |mousemove| events to be fired when the cursor changed.
   This was fixed close to a year ago, see http://code.google.com/p/chromium/issues/detail?id=103041.
2015-04-21 16:27:41 +02:00
Jonas Jenwald
95b2ec124b Move the PresentationMode-specific scrollWheel code from PDFViewerApplication 2015-04-21 16:08:37 +02:00
Jonas Jenwald
2dc1af8028 Break dependencies between PresentationMode and other code, and add PresentationMode related utility methods to PDFViewer
This patch:
 - Adds a couple of utility methods to `PDFViewer` to enable checking `presentationModeState` without cumbersome comparisons.

 - Disentangles `PresentationMode` from `PDFHistory` and `HandTool`, by adding event listeners for `presentationmodechanged` to both of them.

 - Adds a utility function to `PDFViewerApplication` for requesting PresentationMode.

 - Prevents initialization of `PresentationMode` if the browser does not support the fullscreen API.
2015-04-21 16:02:32 +02:00
arai
5c4e3c31b8 Bug 1156287 - Do not extract unreachable code after return 2015-04-21 00:22:45 +09:00
Taylor Brown
34d3b96b52 prevent viewer from zooming on cmd+mousewheel 2015-04-10 15:08:32 -07:00
Jonas Jenwald
48242abe72 [B2G] Stub the |DownloadManager| to avoid error
After the refactoring in PR 5678, the B2G viewer now prints the following in the console:
```
ReferenceError: DownloadManager is not defined
```

This will obviously not matter once the B2G viewer is replaced with the new components-based one. But until that happens, I think it makes sense to just stub the class to suppress the error.
2015-04-04 21:26:33 +02:00
Jonas Jenwald
e5c4819601 Small refactoring of the code that calls |PDFViewerApplication.setInitialView|
This is a minor cleanup, to avoid an unnecessary `Promise.all` and to simplify catching |ViewHistory| errors.
2015-03-31 20:35:00 +02:00
Jonas Jenwald
6091e7bd6b Move the code that resets the history state when the |showPreviousViewOnLoad| preference is set to |false|
Since this code is *only* necessary if/when the history is actually enabled, this patch refactors it to actually reflect that.
2015-03-31 18:12:15 +02:00