Commit Graph

2243 Commits

Author SHA1 Message Date
Jonas Jenwald
3c622ef048 Replace the cloneObj helper function, in the viewer, with native Object.assign (PR 9795 follow-up) 2018-06-27 20:39:39 +02:00
Jonas Jenwald
95a4fa25b9 Don't wait arbitrary long for all pages to be resolved before attempting to re-apply the initial position on load (PR 6318 follow-up)
With the current code, the location in the viewer could change *well* after the user has started to interact with the viewer (for very large and/or slow loading documents). Attempt to reduce the likelyhood of that happening, by adding an upper bound to the time spent waiting before attempting to re-apply the initial position.
2018-06-26 14:19:59 +02:00
Jonas Jenwald
3691f9cc78 Simplify the handling of the defaultZoomValue preference in PDFViewerApplication.load 2018-06-26 14:13:44 +02:00
Jonas Jenwald
5bbbbf152e Stop storing/using the 'exists' property of ViewHistory database entries
Rather than using a "special" property to check if a `ViewHistory` database entry existed on load, it seems that you could just as well check for the existence of one of the actually needed properties instead (here 'page' is used).

This way we can avoid storing what, more of less, amounts to useless state, which will help reduce the size of the `ViewHistory` database. Given that we don't directly, nor need to, validate the `ViewHistory` data but rely on other parts of the code-base to do so, the existance of an 'exists' property doesn't in and of itself really add much utility.

Finally, to simplify the implementation the 'exists' property won't be actively removed from the `ViewHistory` data. Instead we'll simply stop adding 'exists' when writing `ViewHistory` data, and rely on the existing pruning of old entries to eventually remove any remnants of 'exists' from storage.
2018-06-26 14:12:21 +02:00
Jonas Jenwald
253aae15fc Ensure that all entries above the current cacheSize is removed when initializing a ViewHistory instance
Note how, in the current code, only *one* old history entry would ever be removed. That would mean that if e.g. the `cacheSize` is reduced, it would potentially require loading of multiple files before the database would be correctly pruned.

Furthermore, in the case where the database was empty on load there's no need to attempt to shrink it, since trying to reduce the size of an *empty* array won't do much :-)
2018-06-26 14:07:52 +02:00
Tim van der Meij
e8b5088370
Merge pull request #9832 from Snuffleupagus/scrollMode-fixes
Fix a number of regressions/inefficiencies introduced by adding Scroll/Spread modes to the viewer (PR 9208 follow-up)
2018-06-23 21:09:55 +02:00
Jonas Jenwald
c8384061cf Ensure that the locale viewer option is never defined in the (various) extension builds (PR 9493 follow-up) 2018-06-23 13:33:40 +02:00
Jonas Jenwald
bfbe2b411c Simplify the _setScale call when changing Scroll modes
Since the current page will be explicitly scrolled into view *directly* afterwards anyway (compare with e.g. the `pagesRotation` code), trying to maintain the current position when re-applying the zoom level during changing of Scroll modes is redundant.
2018-06-23 11:47:53 +02:00
Jonas Jenwald
d3cb5e7117 Don't attempt to modify the DOM and/or trigger rendering when changing Scroll/Spread modes without a PDF document being loaded 2018-06-23 10:30:22 +02:00
Jonas Jenwald
05f682cd4b [Regression] Ensure that pre-rendering of the next/previous page works correctly in Presentation Mode, when horizontal scrolling was enabled
Note how in `BaseViewer.forceRendering` the Scroll mode is used to determine how pre-rendering will work. Currently this is broken in Presentation Mode, if horizontal scrolling was enabled prior to entering fullscreen.

Furthermore, there's a few additional cases where the `this.scrollMode === ScrollMode.HORIZONTAL` check is pointless either in Presentation Mode or when a `PDFSinglePageViewer` instance is used.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
6a086fa0b9 Refactor setScrollMode/setSpreadMode, in the viewer classes, such that they are no-ops in PDFSinglePageViewer instances
Since the Scroll/Spread modes doesn't make (any) sense in `PDFSinglePageViewer` instances, the general structure of these methods can be improved to reflect that.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
8bd1244298 Move _updateScrollModeClasses from BaseViewer to PDFViewer
Given that this method is a no-op in `PDFSinglePageViewer`, similar to `_regroupSpreads`, let's improve the general code structure by simply moving the method.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
da52dff04b Add validation of the argument in the BaseViewer.{setScrollMode, setSpreadMode} methods
Since all the other "public" methods validate the arguments, these (new) ones really ought to do the same.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
9b0ed6f821 Remove all pages from the DOM at once, rather than using a loop, in PDFViewer._regroupSpreads
There's no good reason to iterate through an arbitrary number of DOM elements this way, since a document could contain thousands of pages, when everything can be easily removed at once; compare with e.g. `BaseViewer._resetView` and `PDFThumbnailViewer._resetView`.

Furthermore given that it's a `PDFViewer` instance, the `this.viewer` property can be accessed directly. Besides, `_setDocumentViewerElement` only exists as a helper method for `setDocument` in the base class and none of this code applies for `PDFSinglePageViewer` instances either.
2018-06-23 10:16:04 +02:00
Jonas Jenwald
36111a1f40 [Regression] Remove instances of Element.classList.toggle() with *two* parameters, since browser support is limited
The Secondary Toolbar buttons for, not to mention the actual toggling of, Scroll/Spread modes are currently completely broken in older browsers (such as IE11).

As a follow-up, it'd probably be a good idea to try and find a *feature complete* `classList` polyfill that could be used instead, but this patch at least addresses the immediate regression.

Please refer to the compatibility information in https://developer.mozilla.org/en-US/docs/Web/API/Element/classList#Browser_compatibility
2018-06-23 10:16:04 +02:00
eugenesqr
331ac8ae74 removed safari compatibility check 2018-06-21 12:57:56 +03:00
Jonas Jenwald
3e4a159a45 Set the correct document title when opening a new file in the GENERIC default viewer 2018-06-17 13:55:53 +02:00
Jonas Jenwald
84920f39b2 Change the casing of the originalURL parameter, to originalUrl, in the onOpenWithURL method
The `onOpenWithURL` method, in `PDFViewerApplication.initPassiveLoading`, accepts a `originalURL` parameter which is then passed on to `PDFViewerApplication.open` as is. However, the latter method expects the name of the parameter to be `originalUrl` (note the casing), meaning that `getDocument` will fail in this case.

For consistency, and to avoid confusion, the renaming is done in `web/chromecom.js` as well.
2018-06-17 13:32:30 +02:00
Tim van der Meij
5dacc8155c
Merge pull request #9819 from Snuffleupagus/viewerContainer-offset-small-window
Fix regression affecting the horizontal `viewerContainer` offset for small window widths (PR 9816 follow-up)
2018-06-16 00:19:41 +02:00
Brendan Dahl
7892122201
Merge pull request #9595 from Rob--W/crx-ftp-file
Disable ftp support in Chrome 59+, add file chooser at file
2018-06-15 14:48:19 -07:00
Jonas Jenwald
5198b6d0dc Fix regression affecting the horizontal viewerContainer offset for small window widths (PR 9816 follow-up)
*The danger of fixing one bug is that it can, sometimes too easily, cause another one in the process; sorry for not catching this when testing PR 9816 locally.*

When the *entire* viewer becomes narrow enough, as controlled by the `@media all and (max-width: 840px)` media query, the sidebar should (semi-transparently) overlay the `viewerContainer` instead of moving it horizontally. Unfortunately the changes made in PR 9816 caused the relevant CSS rules to be skipped, because of how the inheritance model works in CSS.

I'm well aware that `!important` is usually advised against, since it "breaks" the CSS inheritance model. However in this case it seemed reasonable to use it, to not only fix the bug at hand but to also prevent similar bugs from occurring in the future.
2018-06-15 20:27:02 +02:00
Tim van der Meij
790e21242a
Merge pull request #9816 from Snuffleupagus/presentationMode-page-offset-regression
Fix regression causing the pages to be offset horizontally in Presentation Mode (PR 8993 follow-up)
2018-06-14 23:22:57 +02:00
Jonas Jenwald
39fc1c72fc Fix regression causing the pages to be offset horizontally in Presentation Mode (PR 8993 follow-up)
This is a regression from PR 8993; it causes the pages to be offset horizontally in Presentation Mode, if and only if the sidebar is currently open when the user triggers Presentation Mode.

Please note that while this doesn't seem to affect Firefox, both Chrome and IE are however affected.
Interestingly enough, despite the Chrome extension being affected as well, I cannot find any issue filed about this. (Either Presentation Mode isn't used much at all, or users don't open the sidebar before entering Presentation Mode.)
2018-06-14 16:32:19 +02:00
Jonas Jenwald
349b7d5e9c Remove the disableFullscreen hack for embedded IE 11 (issue 9585)
It appears that Microsoft silently fixed the problem that required disabling of fullscreen mode, in e.g. `iframe`s, in IE 11; please see issue 4711 and PR 5525 for historical context.

Unfortunately my Google-fu isn't strong enough to find any *official* information regarding the fixing of the browser bug in IE. However testing of the default viewer in IE 11, with this patch applied, it now appears that Presentation Mode is working correctly even in an `iframe` in IE 11.
Further anecdotal evidence that the bug is in fact fixed, is for example that jQuery previously contained a work-around for the IE bug. However, that's removed over two years ago now; see ff1a0822f7 and the issues referenced there.

Given that the default viewer isn't intended to be used as-is anyway (in custom deployments), it didn't seem necessary to keep the `disableFullscreen` option around since it was *only* ever added for compatibility purposes.

Fixes 9585.
2018-06-14 12:25:28 +02:00
Jonas Jenwald
ba623c77d2 Disable (drag-and-drop) file opening if Presentation Mode is active (PR 9794 follow-up) 2018-06-11 10:51:43 +02:00
Dimitris Kountanis
8e95506116
Implement drag-and-drop support in the viewer for local files 2018-06-10 15:42:55 +02:00
Jonas Jenwald
07d610615c Move, and modernize, Util.loadScript from src/shared/util.js to src/display/dom_utils.js
Not only is the `Util.loadScript` helper function unused on the Worker side, even trying to use it there would throw an Error (since `document` isn't defined/available in Workers).
Hence this helper function is moved, and its code modernized slightly by having it return a Promise rather than needing a callback function.

Finally, to reduced code duplication, the "new" loadScript function is exported and used in the viewer.
2018-06-07 13:52:40 +02:00
Jonas Jenwald
0ecc22cb04 Attempt to provide better default values for the disableFontFace/nativeImageDecoderSupport API options in Node.js
This should provide a better out-of-the-box experience when using PDF.js in a Node.js environment, since it's missing native support for both `@font-face` and `Image`.
Please note that this change *only* affects the default values, hence it's still possible for an API consumer to override those values when calling `getDocument`.

Also, prevents "ReferenceError: document is not defined" errors, when running the unit-tests in Node.js/Travis.
2018-06-03 00:28:37 +02:00
Jonas Jenwald
dcc7f33ee7 Prevent "ReferenceError: window is not defined" errors, from web/ui_utils.js, when running the unit-tests in Node.js/Travis 2018-06-03 00:23:07 +02:00
Tim van der Meij
057994d781
Backout of pull request #9345 2018-05-28 22:54:09 +02:00
Ryan Hendrickson
d7c051e807 Add preferences for default scroll/spread modes
This commit adds `scrollModeOnLoad` and `spreadModeOnLoad` preferences
that control the default viewer state when opening a new document for
the first time.

This commit also contains a minor refactoring of some of the option UI
rendering code in extensions/chromium/options/options.js, as I couldn't
bear creating two more functions nearly identical to the four that
already existed.
2018-05-14 23:10:33 -04:00
Ryan Hendrickson
c24bc29757 Remember last used scroll and spread modes 2018-05-14 23:10:33 -04:00
Ryan Hendrickson
eaf14e5d47 Modify key events for horizontal scrolling
Specifically, when there is no vertical scrollbar, let up, down, page
up, and page down all trigger moving to the next or previous page.
2018-05-14 23:10:32 -04:00
Ryan Hendrickson
3d83c646c6 Add spread modes to web viewer
This builds on the scrolling mode work to add three buttons for joining
page spreads together: one for the default view, with no page spreads,
and two for spreads starting on odd-numbered or even-numbered pages.
2018-05-14 23:10:32 -04:00
Ryan Hendrickson
91cbc185da Add scrolling modes to web viewer
In addition to the default scrolling mode (vertical), this commit adds
horizontal and wrapped scrolling, implemented primarily with CSS.
2018-05-14 23:10:32 -04:00
Ryan Hendrickson
65c8549759 Fix bug in scrollIntoView
Prior to this commit, if the vertical scroll bar is absent and the horizontal
scroll bar is present, a link to a particular point on the page which should
induce a horizontal scroll did not do so, because the absence of a vertical
scroll bar meant that the viewer was not recognized as the nearest scrolling
ancestor. This commit adds a check for horizontal scroll bars when searching
for the scrolling ancestor.
2018-05-14 23:10:32 -04:00
Wojciech Maj
dbb0e88bc1 Clean up browser-specific CSS 2018-04-04 00:25:12 +02:00
Wojciech Maj
ea2850e9a7 Fix typos 2018-04-01 23:20:41 +02:00
Jonas Jenwald
8b09f7c34e Clean-up getMainThreadWorkerMessageHandler for non-PRODUCTION mode
*This is a final piece of clean-up of code that I recently wrote, after which I'm done :-)*

When the `getMainThreadWorkerMessageHandler` function was added, in PR 9385, it did so by basically introducing a `web/app.js` dependency in `src/display/api.js` through the `window.pdfjsNonProductionPdfWorker` property[1]. Even though this is limited to non-`PRODUCTION` mode, i.e. `gulp server`, it still seems unfortunate to have that sort of viewer dependency in the API code itself.

With the new, much nicer and shorter, names introduced in PR 9565 we can remove this non-`PRODUCTION` hack and just use `window.pdfjsWorker` in both the viewer and the API regardless of the build mode.

---

[1] It didn't seem correct to piggy-back on the `window.pdfjsDistBuildPdfWorker` property in non-`PRODUCTION` mode.
2018-03-29 11:03:47 +02:00
Jonas Jenwald
b004308f88 Attempt to improve the detection of (metric) page names, by fuzzy matching the dimensions
The following is an example of a PDF file (the specification to be exact) where the page size (compare the size displayed in Adobe Reader), and the page name, isn't correctly displayed without the patch: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
2018-03-25 18:53:45 +02:00
Jonas Jenwald
d86b816c2b Display the names, for a couple of standard page sizes, in the document properties dialog
Please note that this patch *purposely* doesn't add every standard (or semi-standard) page name in existence, but rather only a few common ones. This is done to lessen the burden on localizers, since it's quite possible that all of the page names could need translation (depending on locale).

It's easy to add more standard page sizes in the future, but we should take care to *only* add those that are very commonly used in actual PDF files.
2018-03-25 18:50:17 +02:00
Jonas Jenwald
fc0038d609 Add orientation description to the pageSize information, displayed in the properties dialog
Since the l10n strings were added in a previous commit, modifying them here shouldn't be a problem since they haven't landed in mozilla-central yet.
2018-03-25 18:50:17 +02:00
Jonas Jenwald
f3b74c5028 Display the pageSize, in the document properties dialog, with locale dependent units
This uses a whitelist, based on the locale, to determine where non-metric units should be used.
Note that the behaviour implemented here seem consistent with desktop PDF viewers (e.g. Adobe Reader), where the pageSizes are *always* displayed with locale dependent units rather than pageSize dependent ones (since the latter would probably be quite confusing).
2018-03-25 18:49:46 +02:00
Jonas Jenwald
513412c92e Add a new getLanguage method to the various IL10n implementations 2018-03-25 18:49:46 +02:00
Jonas Jenwald
ab74b32054 Adjust the displayed pageSize, in the document properties dialog, depending on the current *viewer* rotation (PR 9586 follow-up)
Please note that the behaviour implemented here mirrors the one used in Adobe Reader.
2018-03-25 18:49:46 +02:00
Jonas Jenwald
b7b5d93231 Reduce the duplication for the document_properties_page_size_* strings, by defining the units separately 2018-03-25 18:48:53 +02:00
Jonas Jenwald
77d025dc14 Move the isPortraitOrientation helper function from web/base_viewer.js to web/ui_utils.js
A couple of basic unit-tests are added, and a manual `isLandscape` check (in `web/base_viewer.js`) is also converted to use the helper function instead.
2018-03-25 18:48:53 +02:00
Tim van der Meij
5c1a16ba6e
Merge pull request #9586 from Snuffleupagus/pageSize-api-rotate
Ensure that `PDFPageProxy.pageSizeInches` handles non-default /Rotate entries correctly
2018-03-25 18:03:32 +02:00
Jonas Jenwald
d547936827 Ensure that PDFPageProxy.pageSizeInches handles non-default /Rotate entries correctly
Without this patch, the pageSize will be incorrectly reported for some PDF files.

---

Move pageSizeInches to ui_utils
2018-03-25 16:48:29 +02:00
Rob Wu
29c370af27 [CRX] Add file chooser as fallback (fixes #9411)
Test case to exercise the different encodings:
1. Create a file "some file#@%M<br>%25 .pdf"
2. Build the extension with `gulp chromium` and load it in Chrome.
3. Go to `chrome://extensions/` and ensure that the
   "Allow access to file URLs" is disabled.
4. Try to open the file from step 1 in Chrome (maybe reload once).
5. PDF.js should be showing a file chooser button.
6. Click on that button and select a different file.

   Test: Check that a confirmation dialog pops up that warns about
   a different file name. Cancel the dialog.

7. Click on the button again and select the original file.

   Test: Check that the file opens as expected.
2018-03-21 18:21:46 +01:00