Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: chrome/browser/resources/pdf/pdf.js

Issue 706823004: OOP PDF: Change the save toolbar button to match the save menu behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@embedded-pdfs
Patch Set: rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @return {number} Width of a scrollbar in pixels 8 * @return {number} Width of a scrollbar in pixels
9 */ 9 */
10 function getScrollbarWidth() { 10 function getScrollbarWidth() {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 // Setup the button event listeners. 100 // Setup the button event listeners.
101 $('fit-to-width-button').addEventListener('click', 101 $('fit-to-width-button').addEventListener('click',
102 this.viewport_.fitToWidth.bind(this.viewport_)); 102 this.viewport_.fitToWidth.bind(this.viewport_));
103 $('fit-to-page-button').addEventListener('click', 103 $('fit-to-page-button').addEventListener('click',
104 this.viewport_.fitToPage.bind(this.viewport_)); 104 this.viewport_.fitToPage.bind(this.viewport_));
105 $('zoom-in-button').addEventListener('click', 105 $('zoom-in-button').addEventListener('click',
106 this.viewport_.zoomIn.bind(this.viewport_)); 106 this.viewport_.zoomIn.bind(this.viewport_));
107 $('zoom-out-button').addEventListener('click', 107 $('zoom-out-button').addEventListener('click',
108 this.viewport_.zoomOut.bind(this.viewport_)); 108 this.viewport_.zoomOut.bind(this.viewport_));
109 $('save-button-link').href = this.streamDetails.originalUrl; 109 $('save-button').addEventListener('click', this.save_.bind(this));
110 $('print-button').addEventListener('click', this.print_.bind(this)); 110 $('print-button').addEventListener('click', this.print_.bind(this));
111 111
112 // Setup the keyboard event listener. 112 // Setup the keyboard event listener.
113 document.onkeydown = this.handleKeyEvent_.bind(this); 113 document.onkeydown = this.handleKeyEvent_.bind(this);
114 114
115 // Set up the zoom API. 115 // Set up the zoom API.
116 if (chrome.tabs) { 116 if (chrome.tabs) {
117 chrome.tabs.setZoomSettings(this.streamDetails.tabId, 117 chrome.tabs.setZoomSettings(this.streamDetails.tabId,
118 {mode: 'manual', scope: 'per-tab'}, 118 {mode: 'manual', scope: 'per-tab'},
119 this.afterZoom_.bind(this)); 119 this.afterZoom_.bind(this));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 this.viewport.position = position; 221 this.viewport.position = position;
222 } 222 }
223 return; 223 return;
224 case 65: // a key. 224 case 65: // a key.
225 if (e.ctrlKey || e.metaKey) { 225 if (e.ctrlKey || e.metaKey) {
226 this.plugin_.postMessage({ 226 this.plugin_.postMessage({
227 type: 'selectAll', 227 type: 'selectAll',
228 }); 228 });
229 } 229 }
230 return; 230 return;
231 case 83: // s key.
232 if (e.ctrlKey || e.metaKey) {
233 // Simulate a click on the button so that the <a download ...>
234 // attribute is used.
235 $('save-button-link').click();
236 // Since we do the saving of the page.
237 e.preventDefault();
238 }
239 return;
240 case 80: // p key. 231 case 80: // p key.
241 if (e.ctrlKey || e.metaKey) { 232 if (e.ctrlKey || e.metaKey) {
242 this.print_(); 233 this.print_();
243 // Since we do the printing of the page. 234 // Since we do the printing of the page.
244 e.preventDefault(); 235 e.preventDefault();
245 } 236 }
246 return; 237 return;
247 case 219: // left bracket. 238 case 219: // left bracket.
248 if (e.ctrlKey) { 239 if (e.ctrlKey) {
249 this.plugin_.postMessage({ 240 this.plugin_.postMessage({
(...skipping 16 matching lines...) Expand all
266 * Notify the plugin to print. 257 * Notify the plugin to print.
267 */ 258 */
268 print_: function() { 259 print_: function() {
269 this.plugin_.postMessage({ 260 this.plugin_.postMessage({
270 type: 'print', 261 type: 'print',
271 }); 262 });
272 }, 263 },
273 264
274 /** 265 /**
275 * @private 266 * @private
267 * Notify the plugin to save.
268 */
269 save_: function() {
270 this.plugin_.postMessage({
271 type: 'save',
272 });
273 },
274
275 /**
276 * @private
276 * Handle open pdf parameters. This function updates the viewport as per 277 * Handle open pdf parameters. This function updates the viewport as per
277 * the parameters mentioned in the url while opening pdf. The order is 278 * the parameters mentioned in the url while opening pdf. The order is
278 * important as later actions can override the effects of previous actions. 279 * important as later actions can override the effects of previous actions.
279 */ 280 */
280 handleURLParams_: function() { 281 handleURLParams_: function() {
281 if (this.urlParams_.page) 282 if (this.urlParams_.page)
282 this.viewport_.goToPage(this.urlParams_.page); 283 this.viewport_.goToPage(this.urlParams_.page);
283 if (this.urlParams_.position) { 284 if (this.urlParams_.position) {
284 // Make sure we don't cancel effect of page parameter. 285 // Make sure we don't cancel effect of page parameter.
285 this.viewport_.position = { 286 this.viewport_.position = {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 window.parent.postMessage(message, '*'); 574 window.parent.postMessage(message, '*');
574 }, 575 },
575 576
576 /** 577 /**
577 * @type {Viewport} the viewport of the PDF viewer. 578 * @type {Viewport} the viewport of the PDF viewer.
578 */ 579 */
579 get viewport() { 580 get viewport() {
580 return this.viewport_; 581 return this.viewport_;
581 } 582 }
582 }; 583 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/index.html ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698