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

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

Issue 293613002: Add a minimum offset for the OOP PDF toolbar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <include src="../../../../ui/webui/resources/js/util.js"> 7 <include src="../../../../ui/webui/resources/js/util.js">
8 <include src="pdf_scripting_api.js"> 8 <include src="pdf_scripting_api.js">
9 <include src="viewport.js"> 9 <include src="viewport.js">
10 10
11 /** 11 /**
12 * @return {number} Width of a scrollbar in pixels 12 * @return {number} Width of a scrollbar in pixels
13 */ 13 */
14 function getScrollbarWidth() { 14 function getScrollbarWidth() {
15 var div = document.createElement('div'); 15 var div = document.createElement('div');
16 div.style.visibility = 'hidden'; 16 div.style.visibility = 'hidden';
17 div.style.overflow = 'scroll'; 17 div.style.overflow = 'scroll';
18 div.style.width = '50px'; 18 div.style.width = '50px';
19 div.style.height = '50px'; 19 div.style.height = '50px';
20 div.style.position = 'absolute'; 20 div.style.position = 'absolute';
21 document.body.appendChild(div); 21 document.body.appendChild(div);
22 var result = div.offsetWidth - div.clientWidth; 22 var result = div.offsetWidth - div.clientWidth;
23 div.parentNode.removeChild(div); 23 div.parentNode.removeChild(div);
24 return result; 24 return result;
25 } 25 }
26 26
27 /** 27 /**
28 * The minimum number of pixels to offset the toolbar by from the bottom and
29 * right side of the screen.
30 */
31 PDFViewer.MIN_TOOLBAR_OFFSET = 15;
32
33 /**
28 * Creates a new PDFViewer. There should only be one of these objects per 34 * Creates a new PDFViewer. There should only be one of these objects per
29 * document. 35 * document.
30 */ 36 */
31 function PDFViewer() { 37 function PDFViewer() {
32 // The sizer element is placed behind the plugin element to cause scrollbars 38 // The sizer element is placed behind the plugin element to cause scrollbars
33 // to be displayed in the window. It is sized according to the document size 39 // to be displayed in the window. It is sized according to the document size
34 // of the pdf and zoom level. 40 // of the pdf and zoom level.
35 this.sizer_ = $('sizer'); 41 this.sizer_ = $('sizer');
36 this.toolbar_ = $('toolbar'); 42 this.toolbar_ = $('toolbar');
37 this.pageIndicator_ = $('page-indicator'); 43 this.pageIndicator_ = $('page-indicator');
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { 310 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
305 $('fit-to-page-button').classList.add('polymer-selected'); 311 $('fit-to-page-button').classList.add('polymer-selected');
306 } else if (this.viewport_.fittingType == 312 } else if (this.viewport_.fittingType ==
307 Viewport.FittingType.FIT_TO_WIDTH) { 313 Viewport.FittingType.FIT_TO_WIDTH) {
308 $('fit-to-width-button').classList.add('polymer-selected'); 314 $('fit-to-width-button').classList.add('polymer-selected');
309 } 315 }
310 316
311 var hasScrollbars = this.viewport_.documentHasScrollbars(); 317 var hasScrollbars = this.viewport_.documentHasScrollbars();
312 var scrollbarWidth = this.viewport_.scrollbarWidth; 318 var scrollbarWidth = this.viewport_.scrollbarWidth;
313 // Offset the toolbar position so that it doesn't move if scrollbars appear. 319 // Offset the toolbar position so that it doesn't move if scrollbars appear.
314 var toolbarRight = hasScrollbars.vertical ? 0 : scrollbarWidth; 320 var toolbarRight = Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
315 var toolbarBottom = hasScrollbars.horizontal ? 0 : scrollbarWidth; 321 var toolbarBottom = Math.max(PDFViewer.MIN_TOOLBAR_OFFSET, scrollbarWidth);
322 if (hasScrollbars.vertical)
323 toolbarRight -= scrollbarWidth;
324 if (hasScrollbars.horizontal)
325 toolbarBottom -= scrollbarWidth;
316 this.toolbar_.style.right = toolbarRight + 'px'; 326 this.toolbar_.style.right = toolbarRight + 'px';
317 this.toolbar_.style.bottom = toolbarBottom + 'px'; 327 this.toolbar_.style.bottom = toolbarBottom + 'px';
318 328
319 // Update the page indicator. 329 // Update the page indicator.
320 var visiblePage = this.viewport_.getMostVisiblePage(); 330 var visiblePage = this.viewport_.getMostVisiblePage();
321 this.pageIndicator_.index = visiblePage; 331 this.pageIndicator_.index = visiblePage;
322 if (this.documentDimensions_.pageDimensions.length > 1 && 332 if (this.documentDimensions_.pageDimensions.length > 1 &&
323 hasScrollbars.vertical) { 333 hasScrollbars.vertical) {
324 this.pageIndicator_.style.visibility = 'visible'; 334 this.pageIndicator_.style.visibility = 'visible';
325 } else { 335 } else {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 417
408 /** 418 /**
409 * @type {Viewport} the viewport of the PDF viewer. 419 * @type {Viewport} the viewport of the PDF viewer.
410 */ 420 */
411 get viewport() { 421 get viewport() {
412 return this.viewport_; 422 return this.viewport_;
413 } 423 }
414 }; 424 };
415 425
416 var viewer = new PDFViewer(); 426 var viewer = new PDFViewer();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698