Commit Graph

960 Commits

Author SHA1 Message Date
Tim van der Meij
f4ae277355 Convert the secondary toolbar to a class 2016-05-11 20:53:39 +02:00
Yury Delendik
a4c81c203b Enables debugger only when needed. 2016-05-09 18:18:43 -05:00
Yury Delendik
eb3d1ca003 Removes circular dependency of secondary toolbar on app.js. 2016-04-28 15:04:09 -05:00
Yury Delendik
7fd3db9977 Adds EventBus. 2016-04-28 06:57:24 -05:00
Yury Delendik
3132941948 Removes app.js dependency on mozPrintCallback_polyfill.js. 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
Yury Delendik
4165cedc9f Replace pdfjsLib with module that represents pdf.js. 2016-04-13 10:11:34 -05:00
Yury Delendik
006e8fb59d Introduces UMD headers to the web/ folder. 2016-04-13 10:09:48 -05:00
Yury Delendik
1e3e14e6b2 Exposes all functional members via lib exports and use them in viewer. 2016-04-07 13:46:07 -05:00
Yury Delendik
313b418a20 Prepare viewer.js for async loading and module separation. 2016-04-01 10:29:44 -05:00
Yury Delendik
b371785fbb Rename web/viewer.js -> web/app.js 2016-04-01 10:27:16 -05:00
Tobias Schneider
aeabd0db20 Fix insertion of blank pages during printing due to non-matching page sizes 2016-03-21 14:21:07 -07:00
Jonas Jenwald
39cba5d25d Remove PDFThumbnailViewer_ensureThumbnailVisible
Functionality wise, `ensureThumbnailVisible` is essentially just a shorthand for `scrollThumbnailIntoView`. (And note that `PDFViewer` doesn't implement a `ensurePageVisible` method.)

The only remaining usage of `PDFThumbnailViewer_ensureThumbnailVisible` is inside `PDFPresentationMode`, which introduces an otherwise unnecessary `PDFThumbnailViewer` dependency there.

We're already relying on the `presentationmodechanged` event, in various files, to track the state of Presentation Mode. Thus we can simply listen for that event in `PDFSidebar` too, and update the thumbnails if necessary.
2016-02-28 18:21:59 +01:00
Jonas Jenwald
67a1dfcfb5 Move the sidebar related code from viewer.js into PDFSidebar
The sidebar code has, except for minor fixes/additions (such as attachments), been largely untouch for years.
To avoid having a bunch of sidebar code sprinkled throughout viewer.js, this patch moves the sidebar code into a separate file (pdf_sidebar.js), similar to how most other functionality has been moved in the last few years.

Besides simply moving code around, this patch also has the added benefit that we now keep track of the sidebar state (not just opened/closed).
This now makes it possible to handle both `Preferences` *and* `ViewHistory` settings for the sidebar state in a cleaner way, preventing strange and confusing interactions between the two.
2016-02-27 14:13:09 +01:00
Jonas Jenwald
21f048234d Refactor how PDFOutlineView/PDFAttachmentView is initialized in viewer.js, rename the classes, and refactor their render methods
Changes `PDFOutlineView`/`PDFAttachmentView` to be initialized once, since we're always creating them, and refactor their `render` methods to instead pass in the `outline`/`attachments`.

For consistency with other "classes", the `PDFOutlineView`/`PDFAttachmentView` are renamed to `PDFOutlineViewer`/`PDFAttachmentViewer`.

Also, make sure that the outline/attachments are reset when the document is closed. Currently we keep the old ones around until the `getOutline`/`getAttachments` API calls are resolved for a new document.
2016-02-27 14:13:08 +01:00
Jonas Jenwald
c7a44391cf Add a reset method to PDFFindbar, and use it to clear parts of the find UI when the document is closed 2016-02-26 18:35:45 +01:00
Jonas Jenwald
e7d039dbce Ensure that PDFFindController_reset actually resets *all* state (issue 7034)
To reduce code duplication, the initialization code now uses the `reset` method.
Also, this patch moves `charactersToNormalize` out of `PDFFindController`, since it seemed better suited to be a "constant".
2016-02-26 18:35:17 +01:00
Tim van der Meij
0351c7eff4 Move the getFileName helper function to the core
This is required to be able to use it in the annotation display code,
where we now apply it to sanitize the filename of the FileAttachment
annotation. The PDF file from https://bugzilla.mozilla.org/show_bug.cgi?id=1230933 has shown that some PDF generators include the path of the file rather than the filename, which causes filenames with weird initial characters. PDF viewers handle this differently (for example Foxit Reader just replaces forward slashes with spaces), but we think it's better to only show the filename as intended.

Additionally we add unit tests for the `getFilenameFromUrl` helper
function.
2016-02-23 22:49:53 +01:00
Tim van der Meij
6a33dfd13a Implement support for FileAttachment annotations 2016-02-23 22:49:53 +01:00
Yury Delendik
7c89bdc8d6 Allow foriegn origin URLs only for hosted viewers. 2016-01-22 11:54:19 -06:00
Yury Delendik
f340dd5cd5 Adds pdfjs/main_loader module to better mirror pdfjs-dist/build/pdf. 2015-12-30 13:28:57 -06:00
Yury Delendik
85e95d34ed Use RequireJS in the viewer, examples and tests. 2015-12-29 09:20:52 -06:00
Tim van der Meij
df81b832bb Remove unused variables 2015-12-16 23:52:16 +01:00
Yury Delendik
c9cb6a3025 Replaces UnsupportedManager with callback. 2015-11-30 14:42:47 -06:00
Sebastian Hengst
27577a714f Issue #6569 - document_colors_disabled shouldn't escape quotes (compare-locales warning) 2015-11-22 10:14:25 +01:00
Manas
a2ba1b8189 Uses editorconfig to maintain consistent coding styles
Removes the following as they unnecessary
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-11-14 07:32:18 +05:30
Yury Delendik
a4ca9986e1 Merge pull request #6318 from Snuffleupagus/bug-1191279
For documents with different page sizes, ensure that the correct page becomes visible on load when e.g. the 'page' hash parameter was provided (bug 1191279, issue 6393)
2015-11-10 17:51:02 -06:00
Tim van der Meij
7681def0de Move VIEW_HISTORY_MEMORY constant to view_history.js
Currently this constant is present in `viewer.js`, but it is not used there at all. Instead, it is used in `view_history.js` where we have a global for it. We might as well move the constant to `view_history.js` as that is the only place where it is used, thereby removing a global and an unused constant from `viewer.js`.
2015-11-01 15:45:12 +01:00
Yury Delendik
c8c211602b Merge pull request #6073 from Snuffleupagus/bug-1170063
[Firefox] Handle the user modifying the "mousewheel.with_meta.action" and "mousewheel.with_control.action" prefs (bug 1170063)
2015-10-30 11:54:04 -05:00
Andy Parisi
17fe0b1470 Added find match counter 2015-10-30 10:21:26 -05:00
Yury Delendik
62afa9f695 Fixes PDFViewerApplication.open/close methods signature. 2015-10-23 09:06:32 -05:00
Yury Delendik
5135aa9bec Adds deprecation warning for the API calls. 2015-10-23 09:06:32 -05:00
Yury Delendik
59c13b32aa Adds destroy method to the document loading task.
Also renames PDFPageProxy.destroy method to cleanup.
2015-10-23 08:57:14 -05:00
Jonas Jenwald
610df45bad Prevent external links from "replacing" the viewer when it's embedded (bug 976541)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=976541.

This patch also adds a `externalLinkTarget` preference, to make the behaviour user configurable.
2015-10-13 22:18:08 +02:00
Jonas Jenwald
59548921d1 For documents with different page sizes, ensure that the correct page becomes visible on load when e.g. the 'page' hash parameter was provided (bug 1191279, issue 6393)
This issue is actually, in a sense, "caused" by the fact that the API/viewer supports partial loading/rendering. Previously when the *entire* document was always fetched before rendering begun, we knew all page sizes in advance and this issue didn't exist.

Now we use the size of *one* page in order to set the initial size of every page, until we've fetched the pages and thus know their correct sizes.
This means that during loading the size of the pages can change, which may cause the initial position to become scrolled out of view.

The most naive solution to this problem would perhaps be to delay setting the initial position on load for all documents, until all pages are fetched. However I think that would be a *really* bad idea, since doing so would make the initial rendering slower and make it feel sluggish for most documents.

Since there is generally no way of knowing if a document has different sized pages prior to loading it, we can only check once the pages are available.
Hence this patch, which treats documents with different sized pages as a special case, by re-applying the initial position when all pages have become available.
2015-09-06 12:09:22 +02:00
Yury Delendik
70fd360d51 Merge pull request #6242 from Rob--W/outline-collapsible
Allow outline to be collapsed / shown via +/-.
2015-08-27 08:41:34 -05:00
Rob Wu
7c992243fd Allow outline to be collapsed / shown via icon.
- This commit adds a '>' before every outline item that has subitems.
- Click on the '>' to collapse all subitems under that item (which turns
  the '>' in a 'v').
- Shift + click expands/collapses all descendant items under that tree.
- Double-clicking on the "Show Document Outline" button in the toolbar
  expands/collapses all outline items.
2015-08-22 18:49:08 +02:00
Jonas Jenwald
a6d10af3b4 Add disableStream to the list of preferences read by PDFViewerApplication.initialize (issue 6361)
Fixes 6361.
2015-08-18 12:35:42 +02:00
Tim van der Meij
26b9205c7e Merge pull request #6327 from Snuffleupagus/viewer-sidebar-prevent-switching-to-disabled-views
Prevent switching to disabled views (i.e. outline or attachments) in the sidebar
2015-08-07 22:54:08 +02:00
Jonas Jenwald
f063c78cbf Prevent switching to disabled views (i.e. outline or attachments) in the sidebar
Currently in `switchSidebarView` there is code that attempts to handle the `outline` or `attachments` being disabled. However, given the placement of it, that code does not actually accomplish anything. Even more strange is the fact that the way that the buttons are disabled, that code won't ever be hit.
(Looking back with `git blame`, it seems that it has never worked as you'd expect.)

Hence this patch, which correctly disables switching to the `outline` or `attachments` views when they are disabled.
Once PR 6314 restores the 'pagemode' hash parameter, this patch thus makes it impossible to switch to a disabled sidebar view by modifying the 'pagemode' hash of an already loaded document.
2015-08-07 13:45:32 +02:00
Jonas Jenwald
76cfd106d5 Fix 'namedaction' regression that breaks the 'Find' action
This regressed in 0ef6212b64.
2015-08-07 12:05:21 +02:00
Jonas Jenwald
5c26e5e2cd Move handling of the 'pagemode' hash parameter into viewer.js to restore the functionality
This regressed in 0ef6212b64.

Since the 'pagemode' hash parameter requires certain viewer functionality (e.g. thumbnails and an outline) in order to work, it seemed reasonable to move the functionality from `pdf_link_service.js` into `viewer.js`.
Similar to `namedaction`, this patch makes use of an event to forward the 'pagemode' parameter.
2015-08-07 12:05:17 +02:00
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