Commit Graph

64 Commits

Author SHA1 Message Date
Jonas Jenwald
885ba83624 Add the number of textDivs to the textlayerrendered event, to avoid having to manually get that information in the event handler 2016-10-11 22:36:02 +02:00
Jonas Jenwald
3904be8889 Ensure that we cancel any pending textLayer rendering operations when the viewer is closed (issue 7274) 2016-10-11 22:01:22 +02:00
Jonas Jenwald
a824c6c4f6 Ensure that any pending rendering operations in PDFViewer/PDFThumbnailViewer are cancelled when the viewer is closed 2016-10-11 22:01:22 +02:00
Yury Delendik
c09f634bb6 Removes mozPrintCallback polyfill, converts canvas to PNG. 2016-10-11 10:08:13 -05:00
Yury Delendik
24a7a58da7 Moves mozPrintCallback specific code to firefox_printservice.js 2016-10-08 07:33:07 -05:00
Yury Delendik
223a18ccc8 Simplified wheel processing. 2016-09-27 15:27:42 -05:00
Jonas Jenwald
1a2f142a14 Prevent errors if the 'resize' event is fired before the eventBus has been initialized
When opening a PDF file that triggers the browser fallback bar in the Firefox addon/built-in version, e.g. http://web.archive.org/web/20110918100215/http://www.irs.gov/pub/irs-pdf/f1040.pdf (with forms *disabled*), and then reloading the document an error can be thrown.
The reason is that displaying the fallback bar triggers 'resize' events, and they can arrive *before* the viewer has had a chance to run all the necessary initialization code.
2016-09-21 13:32:17 +02:00
Tim van der Meij
2da2c45889 Interactive forms: remove global PDFJS usage 2016-09-19 00:12:42 +02:00
Tim van der Meij
22c7ff494a Merge pull request #7609 from Snuffleupagus/enhanceTextSelection-pref-hack
Add a `enhanceTextSelection` preference
2016-09-09 16:38:45 +02:00
Jonas Jenwald
6e126b31dc Only update the max-height of the SecondaryToolbar when it's actually visible
There's really no good reason to attempt to adjust the `max-height` of the `SecondaryToolbar` when it's not visible, so let's not do that anymore.
Also, we can listen for the `resize` event in `SecondaryToolbar`, to avoid having to manually call the `max-height` adjust function from various event handlers in `app.js`. Please note that by always adjusting the `max-height` when the toolbar is opened we no longer need the `localized` event, since it was mainly used to set a correct inital `max-height` value.
2016-09-09 08:16:09 +02:00
Jonas Jenwald
e12c48b73f Add a enhanceTextSelection preference
Please note that this is a hack, but I think that it should be OK for now to atleast get the preference landed. Refer to the code comment for further information.

Re: issue 7584 and PR 7586.
2016-09-08 10:22:01 +02:00
Tim van der Meij
e686db250c Render interactive form (AcroForm) text widget annotations
This patch is the first step towards implementing support for
interactive forms (AcroForms). It makes it possible to render text
widget annotations exactly like Adobe Reader/Acrobat.

Everything we implement for AcroForms is disabled by default using a
preference, mainly because it is not ready to use yet, but has to
implemented in many steps to avoid complexity. The preference allows us
to work with the code while not exposing the behavior by default. Mainly
storing entered values and printing them is still absent, which would be
minimal requirements for enabling this by default.
2016-09-07 15:37:28 +02:00
Tim van der Meij
eb2ba3287a Revert "Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing the viewer components"
This reverts commit ffb876fdf4.
2016-09-03 20:27:01 +02:00
Tim van der Meij
a2525a8ba3 Revert "Add a enhanceTextSelection preference to the viewer"
This reverts commit 15e45d772f.
2016-09-03 20:26:46 +02:00
Jonas Jenwald
15e45d772f Add a enhanceTextSelection preference to the viewer 2016-09-02 14:38:51 +02:00
Jonas Jenwald
ffb876fdf4 Move the Preferences initialization/fetching code to the top of PDFViewerApplication.initialize, to enable using them when initializing the viewer components 2016-09-02 14:38:48 +02:00
Tim van der Meij
6bb95e3129 Merge pull request #7539 from jeremypress/fairexpand
[api-minor] Expanding divs to improve selection
2016-09-01 17:43:31 +02:00
Jonas Jenwald
0db76dc58c Change the GoToPage Named Action to select the contents of the pageNumber input, rather than just focusing the element
When clicking on the `pageNumber` input, or when using the keyboard shortcut <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>G</kbd>, the element isn't just focused but its contents is actually *selected* so that the user doesn't need to clear the input before entering a new `pageNumber`.
However, the `GoToPage` named action is only using `focus`, so let's change this to be consistent.

The following document can be used for testing: http://www2.informatik.uni-freiburg.de/~frank/ENG/beamer/example/Beamer-class-example1.pdf#zoom=page-fit

[screeenshot]
2016-09-01 13:48:49 +02:00
Jeremy Press
6faa84abdb Continuing fairexpand #6663
1. Expanding divs to improve text selection. (Yury)
2. Adding enhanceTextSelection as an option.
3. Moving feature functionality from text_layer_builder.js to text_layer.js.
4. Added expandTextDivs method to only load expanded divs on first click, and only show on subsequent clicks
2016-08-31 09:54:52 -07:00
Jonas Jenwald
f3b7fa091d Ensure that the zoom buttons are disabled correctly if the scale is smaller/larger than MIN_SCALE/MAX_SCALE in PDFViewerApplication._updateUIToolbar
In the `zoom{In, Out}` functions in `PDFViewerApplication`, we prevent the zoom value from becoming smaller/larger than `MIN_SCALE/MAX_SCALE`.
However, if the user sets the zoom level through the hash parameter the zoom buttons might not be correctly disabled; try http://mozilla.github.io/pdf.js/web/viewer.html#zoom=10.

Note that this issue has been present since "forever", but given that the solution is so simple I think that we should just fix this. (I'm also fixing a stupid typo I previously made in the JSDoc comment.)
2016-08-31 13:28:38 +02:00
Jonas Jenwald
076e25f1ca Prevent destinations with bad left/top values from scrolling the wrong page into view (bug 874482)
There are PDF generators which create destinations with e.g. too large top values, which cause the wrong page to be scrolled into view because the offset becomes negative.
By ignoring negative offsets, we can prevent this issue, and get a similar behaviour as in Adobe Reader.

However, since we're also using `PDFViewer_scrollPageIntoView` in more cases than just when links (in the document/outline) are clicked, the patch adds a way to allow the caller to opt-out of this behaviour.
In e.g. the following situations, I think that we still want to be able to allow negative offsets: when restoring a position from the `ViewHistory`, when the `viewBookmark` button is used to obtain a link to the current position, or when maintaining the current position on zooming.

Rather than adding another parameter to `PDFViewer_scrollPageIntoView`, I've changed the signature to take an parameter object instead. To maintain backwards compatibility, I've added fallback code enclosed in a `GENERIC` preprocessor tag.

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=874482.
2016-08-07 16:20:18 +02:00
Jonas Jenwald
7706cfa9fe Log an error when the value passed to set currentPageNumber is out of bounds (PR 7502 followup)
With PR 7502 we no longer dispatch an event when the `val` is out of bounds, so to better communicate why nothing happens this patch logs an error in that case (similar to the logging of errors when trying to set an invalid scale).

The way that the default viewer is currently implemented, means that e.g. keyboard short-cuts could trigger the new error. Hence this patch also adds the necessary validation code, both to `app.js` and `pdf_link_service.js` to prevent unnecessary errors.
2016-08-07 14:24:09 +02:00
Jonas Jenwald
b7cb44af88 Remove the previousPageNumber parameter from the pagechanging/pagechange` events, and stop dispatching the events if the input is out of bounds
This patch attempts to cleanup a couple of things:
 - Remove the `previousPageNumber` paramater. Prior to PR 7289, when the events were dispatched even when the active page didn't change, it made sense to be able to detect that in an event listener. However, now that's no longer the case, and furthermore other similar events (e.g. `scalechanging`/`scalechange`) don't include information about the previous state.

 - Don't dispatch the events when the value passed to `set currentPageNumber` is out of bounds. Given that the active page doesn't change in this case, again similar to PR 7289, I don't think that the events should actually be dispatched in this case.

 - Ensure that the value passed to `set currentPageNumber` is actually an integer, to avoid any issues (note how e.g. `set currentScale` has similar validation code).

Given that these changes could possibly affect the PDF.js `mochitest` integration tests in mozilla-central, in particular https://dxr.mozilla.org/mozilla-central/source/browser/extensions/pdfjs/test/browser_pdfjs_navigation.js, I ran the tests locally with this patch applied to ensure that they still pass.
2016-07-25 10:08:53 +02:00
Tim van der Meij
43613f19f9 Merge pull request #7466 from Snuffleupagus/PDFViewerApplication-open-remove-fallback-args
Remove handling of fallback arguments from `PDFViewerApplication.open`
2016-07-09 15:51:25 +02:00
Yury Delendik
bca1aebeac Merge pull request #7458 from Snuffleupagus/updateUIToolbar
Consolidate updating of various Toolbar state (e.g. page and scale) in one method in `PDFViewerApplication`
2016-07-08 12:34:39 -05:00
Jonas Jenwald
cb6a7e5503 Remove handling of fallback arguments from PDFViewerApplication.open
The method signature was improved in PR 6546, which was included in the `1.2.109` release from last November.
Hence I think that we should now be able to remove the fallback code for the old method signature. Note that this patch now throws an `Error` in `GENERIC` builds, to clearly indicate that the `open` callsite must be modified.
2016-07-02 11:31:32 +02:00
Jonas Jenwald
2f127df97b Add back moz-specific fullscreen support code for ´MOZCENTRAL` builds (bug 1268749, PR 7273 follow-up)
In PR 7273, we simplified the `MOZCENTRAL` specific check for fullscreen support. Unfortunately I've just, by coincidence, found out about https://bugzilla.mozilla.org/show_bug.cgi?id=1268749, which disabled the unprefixed fullscreen support in release versions of Firefox. If we do nothing, this will lead to Presentation Mode being unavailable in future Firefox releases.

This patch should fix things for now, and I'm afraid that we'll need to uplift it to Firefox 49 as well.
2016-07-01 14:11:58 +02:00
Jonas Jenwald
dd0fe10a52 Consolidate updating of various Toolbar state (e.g. page and scale) in one method in PDFViewerApplication
With the changes in PR 7289, we no longer dispatch a 'pagechanging' event on load. Since most PDF documents open on the first page, this means that the `previous` and `firstPage` buttons are no longer correctly disabled.
To avoid this, this patch moves the code that updates various UI toolbar state into one method, which is then called on document initialization and from the various existing event handling functions.
2016-06-29 22:36:45 +02:00
Tim van der Meij
f97d52182a Merge pull request #7341 from Snuffleupagus/getDestinationHash-Array
[api-minor] Improve handling of links that are using explicit destination arrays
2016-06-09 00:29:10 +02:00
Yury Delendik
5aefce6ba6 Merge pull request #5579 from jazzy-em/master
Added multiple term search functionality (with default phrase search)
2016-05-27 14:23:26 -05:00
jazzy-em
0a347ec04d Added multiple term search functionality (with default phrase search) 2016-05-26 18:24:58 +05:00
Jonas Jenwald
b354682dd6 [api-minor] Let LinkAnnotation/PDFLinkService_getDestinationHash return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.

Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.

With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.

*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.

 - First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.

 - Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.

 - Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".

---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-21 14:14:07 +02:00
Tim van der Meij
db46829ef7 Merge pull request #7316 from timvandermeij/remove-unused
Remove unused variables
2016-05-21 14:07:33 +02:00
Tim van der Meij
f4ae277355 Convert the secondary toolbar to a class 2016-05-11 20:53:39 +02:00
Tim van der Meij
6a7012aaca Remove unused variables
These have been found using `gulp lint` in combination with the `unused:
true` parameter for JSHint. Unfortunately there are too many false
positives to enable this feature, but now that most globals have been
removed because of the conversion to UMD the results are much more
useful than before.
2016-05-11 16:11:13 +02:00
Yury Delendik
a4c81c203b Enables debugger only when needed. 2016-05-09 18:18:43 -05:00
Yury Delendik
d20002b6b1 Merge pull request #7273 from Snuffleupagus/issue-7270
Prevent "Prefixed Fullscreen API is deprecated." warnings in the MOZCENTRAL version (issue 7270)
2016-04-29 10:37:11 -05:00
Jonas Jenwald
9dd6017901 Prevent "Prefixed Fullscreen API is deprecated." warnings in the MOZCENTRAL version (issue 7270)
We're already, since quite some time, using the standard Fullscreen API provided that it's available in the browser. The warning is only caused by the code that checks if the Fullscreen API is supported.

This patch uses a simple preprocessor tag to avoid the warning, since I'm assuming that in general, we want to try and remain backwards compatible with the prefixed versions of the Fullscreen API.

Fixes 7270.
2016-04-29 17:28:24 +02:00
Yury Delendik
4a2c76a34f Adds pre and post UI control change events. 2016-04-29 10:05:04 -05:00
Yury Delendik
eb3d1ca003 Removes circular dependency of secondary toolbar on app.js. 2016-04-28 15:04:09 -05:00
Jonas Jenwald
61a4c740d2 Merge pull request #7254 from yurydelendik/eventbus
Introducing EventBus for the viewer UI.
2016-04-28 15:19:49 +02:00
Yury Delendik
3e6e294fd4 Refactors PDFFindBar and FirefoxCom find events. 2016-04-28 07:11:40 -05:00
Yury Delendik
7fd3db9977 Adds EventBus. 2016-04-28 06:57:24 -05:00
Yury Delendik
5568a19ee3 Moves bundle target/task to gulpfile.js 2016-04-24 08:37:39 -05:00
Yury Delendik
3132941948 Removes app.js dependency on mozPrintCallback_polyfill.js. 2016-04-24 08:25:55 -05:00
Yury Delendik
3b21b51716 Refactors preferences and PDF opening related chromecom code. 2016-04-24 08:25:55 -05:00
Yury Delendik
148102b626 Refactors firefoxcom dependency on app and l10n. 2016-04-24 08:25:55 -05:00
Yury Delendik
81fc46e666 Refactors FindController dependencies. 2016-04-24 08:25:55 -05:00
Yury Delendik
b6c74f2056 Moves all document.getElementById lookups into viewer.js 2016-04-21 11:39:11 -05:00
Tim van der Meij
2b7137ba0a Convert the password prompt to a class
Furthermore we introduce two new methods named `setCallback` and
`setReason` so external code does not change the properties of the class
directly. Finally we update various names of properties and methods to
be more self-explanatory.
2016-04-21 14:06:10 +02:00