Commit Graph

1630 Commits

Author SHA1 Message Date
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
9fc8e1ea25 Fix a regression, from PR 5356, that breaks all scrolling in PresentationMode
*This regressed in PR 5356.*

Rather than just backing out the offending code, this patch restores scrolling in PresentationMode by making the `overflow: hidden;` check optional and letting the callers that need it (e.g. `PDFFindController`) opt-in to use it.
2015-10-13 16:27:50 +02:00
Rob Wu
7e345b223c [CRX] Call callback instead of onCompleted 2015-10-11 17:35:16 +02:00
Brendan Dahl
42ddb7151b Merge pull request #5356 from Rob--W/scroll-issue-5355
scrollIntoView: Skip overflow:hidden elements
2015-10-05 11:15:34 -07:00
Tim van der Meij
dd9d0b8770 Merge pull request #5480 from CodingFabian/issue-5458
Remove TryCatch in canvas for EvenOdd winding rule.
2015-10-04 15:31:34 +02:00
Tim van der Meij
e28ad20d15 Merge pull request #6475 from Snuffleupagus/PDFPageView-annotationLayer-div
Tweak `PDFPageView` to reflect that `this.annotationLayer` is an `AnnotationsLayerBuilder` instance, instead of a DOM element (PR 5552 follow-up)
2015-09-29 23:38:04 +02:00
Brendan Dahl
7cdc6f3c12 Merge pull request #6468 from Snuffleupagus/issue-6467
Don't clear the `canvas` until re-rendering is finished when the `scale` or `rotation` is changed (issue 6467)
2015-09-29 11:09:44 -07:00
Jonas Jenwald
7a8b0fb107 Merge pull request #6200 from Rob--W/hashchange-use-newURL
Refactor the previous history rewriting logic
2015-09-27 17:59:01 +02:00
Rob Wu
cdea75dc39 Refactor the previous history rewriting logic
When the user edits the URL and changes the reference fragment (hash),
PDF.js intercepts this action, and saves the then-current history state
in the previous history entry. This is implemented by navigating back,
editing the history and navigating forward again.

The current logic has a flaw: It assumes that calling history.back() and
history.forward() immediately updates the history state. This is however
not guaranteed by the web standards, which states that calling e.g.
history.back "must traverse the history by a delta -1", which means that
the browser must QUEUE a task to traverse the session history, per spec:
http://w3.org/TR/2011/WD-html5-20110113/history.html#dom-history-back
https://html.spec.whatwg.org/multipage/browsers.html#dom-history-back

Firefox and Internet Explorer deviate from the standards by immediately
changing the history state instead of queuing the navigation.
WebKit derived browsers (Chrome, Opera, Safari) and Opera presto do not.

The user-visible consequence of strictly adhering to the standards in
PDF.js can be shown as follows:

1. Edit the URL.
2. Append #page=2 for example.
3. Press Enter.
   -> Presto and WebKit: PDF.js reverts to the previous URL.
   -> Gecko and Trident: PDF.js keeps the new URL, as expected.

To fix the issue, modification of the previous history item happens in
a few asynchronous steps, guided by the popstate event to detect when
the history navigation request has been committed.

--
Some more implementation notes:

I have removed the preventDefault and stopPropagation calls, because
popstate is not cancelable, and window is already the last target of the
event propagation.

The previous allowHashChange logic was hard to follow, because it did
not explain that hashchange will be called twice; once during the
popstate handler for history.back() (which will reset allowHashChange),
and again for history.forward() (where allowHashChange will be false).
The purpose of allowHashChange is now more explicit, by incorporating
the logic in the replacePreviousHistoryState helper function.
2015-09-26 23:15:29 +02:00
Jonas Jenwald
5e7ce9d62d Fix incorrect indentation, and remove else after return, in PDFPageView_update 2015-09-26 15:41:02 +02:00
Jonas Jenwald
1ae9ba1d64 Don't clear the canvas until re-rendering is finished when the scale or rotation is changed (issue 6467)
*This regressed in PR 4920.*

The main motivation for PR 4920 was to quickly get rid of old canvases when pages are evicted from the `PDFPageViewBuffer` cache. However it inadvertently broke the use-case where the `canvas` is used as a preview, on scale or rotation changes, until the re-rendering is finished.

Fixes 6467.
2015-09-26 15:40:59 +02:00
Jonas Jenwald
c7fd7f898f Tweak PDFPageView to reflect that this.annotationLayer is an AnnotationsLayerBuilder instance, instead of a DOM element (PR 5552 follow-up)
In PR 5552, specifically commit 9f384bbb41, the meaning of `this.annotationLayer` changed in `PDFPageView`. Previously it referred directly to a DOM element, but now it's instead an instance of `AnnotationsLayerBuilder`.
This patch tweaks things so that we won't try to hide a non-existent `annotationLayer` div in `PDFPageView_reset`, and also so that we don't attempt to insert empty (`null`) DOM elements in `PDFPageView_draw`.
2015-09-24 12:24:47 +02:00
Jonas Jenwald
1b50932eaa Don't show thumbnails until the canvas to image conversion is done (issue 6442) 2015-09-12 12:05:40 +02:00
Jonas Jenwald
d7a90d83de Delete, and clear, the image in PDFThumbnailView_reset
*Follow-up to PR 6299.*
2015-09-11 14:12:58 +02:00
Jonas Jenwald
555c7925a0 Prevent setImage from failing to display small thumbnails, by adding a missing canvas to image conversion
*Follow-up to PR 6299.*
2015-09-11 14:12:57 +02:00
Jonas Jenwald
ebce928149 Extract the conversion from canvas to image into a helper function in PDFThumbnailView
*Follow-up to PR 6299.*

This patch reduces unnecessary code duplication for the `canvas` to `image` conversion. It also does a bit of re-ordering (and adds new lines) in `_getPageDrawContext`, since that function currently is a bit hard to read.
2015-09-11 14:12:48 +02:00
Tim van der Meij
dffb2efe9e Merge pull request #6299 from zinking/6035_png_thumb_nail
Convert canvas thumbnails to PNG
2015-09-10 23:54:27 +02:00
Jonas Jenwald
b7d1bed463 Add a utility function, for the viewer, that removes null (\x00) characters (issue 6416)
Since some browsers render `null` characters, and others don't, this patch adds a way to remove them to prevent display issues in the viewer UI.

Given that documents may contain very long outlines, I've added a utility function to avoid creating a lot of unnecessary `RegExp` objects.
To avoid any future issues, this utility function is used for both the outline and the attachments.

Fixes 6416.
2015-09-09 23:49:03 +02:00
Rob Wu
9f80060a18 Add mirrored triangle (TOC item icon) 2015-09-06 15:35:58 +02:00
Jonas Jenwald
da1b9df74a Adjust the min-width of outline items and use more consistent border-radius (PR 6242 follow-up)
Prior to PR 6242, the width of all outline items was set such that their right (or left, in RTL locales) edges lined up vertically. In my opinion that looked more consistent, therefore this patch adjusts the CSS to make sure that this will be the case again.

The patch also makes the `border-radius` values of outline items a bit more consistent.
2015-09-06 13:01:30 +02:00
Fabian Lange
063ca95f5f Remove TryCatch in canvas fill
As verified by @Rob--W, the evenodd fill rule works correctly in all supported browsers. This now allows optimization by JS engines.

This fixes #5458
2015-09-05 11:10:51 +02:00
awang
161def7f4e Convert canvas thumbnails to PNG #6299 2015-09-04 09:58:47 +08:00
Jonas Jenwald
2df1b7b3cd Switch expanded/collapsed in the names of the treeitem-* assets
It appears to me that the `expanded/collapsed` part of the names got switched around, since I'd expect the following convention:
 - `v` == expanded
 - `>` == collapsed
2015-08-27 23:21:34 +02:00
Jonas Jenwald
b1950d3657 Use the Retina assets for outlineItemToggler when in HiDPI mode 2015-08-27 17:50:35 +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
Jonas Jenwald
421289c7bc Merge pull request #6233 from Rob--W/crx-local-files
Improve support for viewing PDFs from file://-URLs in the Chrome extension
2015-08-15 14:15:36 +02:00
Rob Wu
4ac8863e30 Restore extension tab after reload
Work-around for https://crbug.com/511670
2015-08-14 19:00:12 +02:00
Rob Wu
cf1d398bd2 Add translations of "Allow access to file URLs"
The JSON file is generated as follows.

1. Go to the src/chrome/app/resources directory of Chromium's source.

2. Find the translation ID of the "Allow access to file URLs" string:

grep 'Allow access to file URLs' generated_resources_en-GB.xtb

3. With the ID that you've found, locate the other translations.

grep 3341703758641437857 generated_resources_*.xtb

4. If the result looks OK, serialize the result as JSON and save it.

> path/to/pdf.js/web/chrome-i18n-allow-access-to-file-urls.json \
python -c "import json;print(json.dumps({ \
$(grep 3341703758641437857 generated_resources_*.xtb | \
 sed "s@generated_resources_\([^.]\+\)\.xtb:<translation[^>]\+>\(.\+\)</translation>@'\1':'''\2''',@" \
)}, sort_keys=True, indent=2))"

(Strings are taken from Chromium 45.0.2448.0 (ccrev.com/337313).
2015-08-14 18:59:55 +02:00
Rob Wu
775d4e69cf Teach users how to enable access to local files. 2015-08-14 18:59:30 +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
Daan Sprenkels
c3b7ed4541 Apply hover style to .overlayButton not only when hovered, but also when focused (issue #6261) 2015-08-04 14:20:43 +02:00
Tim van der Meij
a9d0e42871 Keep the Link annotation's data URL on one line
Fixes #6278.
2015-07-30 17:18:42 +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
0c15f8a777 Merge pull request #6268 from Rob--W/text-layer-optimize-access
Optimize text layer: Avoid unneeded .textContent access
2015-07-25 16:33:17 +02:00
Rob Wu
47f2c14723 Optimize text layer: Avoid unneeded .textContent
Built-in DOM properties are slower than plain JS properties.
A few lines before, textContent is assigned as follows:
  textDiv.textContent = geom.str;
So replacing textDiv.textContent.length with geom.str.length slightly
improves performance without side effects.
2015-07-25 10:55:00 +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