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

Side by Side Diff: chrome/browser/resources/pdf/elements/viewer-page-selector/viewer-page-selector.js

Issue 1371913002: Material PDF: Adjust behaviour of page selector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pdf_material_rtl
Patch Set: Rebase Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 Polymer({ 5 Polymer({
6 is: 'viewer-page-selector', 6 is: 'viewer-page-selector',
7 7
8 properties: { 8 properties: {
9 /** 9 /**
10 * The number of pages the document contains. 10 * The number of pages the document contains.
11 */ 11 */
12 docLength: { 12 docLength: {
13 type: Number, 13 type: Number,
14 value: 1, 14 value: 1,
15 observer: 'docLengthChanged' 15 observer: 'docLengthChanged'
16 }, 16 },
17 17
18 /** 18 /**
19 * The current page being viewed (1-based). 19 * The current page being viewed (1-based). A change to pageNo is mirrored
20 * immediately to the input field. A change to the input field is not
21 * mirrored back until pageNoCommitted() is called and change-page is fired.
20 */ 22 */
21 pageNo: { 23 pageNo: {
22 type: String, 24 type: Number,
23 value: '1' 25 value: 1
24 }, 26 },
25 27
26 strings: Object 28 strings: Object
27 }, 29 },
28 30
29 pageNoCommitted: function() { 31 pageNoCommitted: function() {
30 var page = parseInt(this.pageNo); 32 var page = parseInt(this.$.input.value);
31 if (!isNaN(page)) { 33
34 if (!isNaN(page) && page <= this.docLength && page > 0)
32 this.fire('change-page', {page: page - 1}); 35 this.fire('change-page', {page: page - 1});
33 this.$.input.blur(); 36 else
34 } 37 this.$.input.value = this.pageNo;
38 this.$.input.blur();
35 }, 39 },
36 40
37 docLengthChanged: function() { 41 docLengthChanged: function() {
38 var numDigits = this.docLength.toString().length; 42 var numDigits = this.docLength.toString().length;
39 this.$.pageselector.style.width = numDigits + 'ch'; 43 this.$.pageselector.style.width = numDigits + 'ch';
40 // Set both sides of the slash to the same width, so that the layout is 44 // Set both sides of the slash to the same width, so that the layout is
41 // exactly centered. 45 // exactly centered.
42 this.$['pagelength-spacer'].style.width = numDigits + 'ch'; 46 this.$['pagelength-spacer'].style.width = numDigits + 'ch';
43 }, 47 },
44 48
45 select: function() { 49 select: function() {
46 this.$.input.select(); 50 this.$.input.select();
47 }, 51 },
48 52
49 /** 53 /**
50 * @return {boolean} True if the selector input field is currently focused. 54 * @return {boolean} True if the selector input field is currently focused.
51 */ 55 */
52 isActive: function() { 56 isActive: function() {
53 return this.shadowRoot.activeElement == this.$.input; 57 return this.shadowRoot.activeElement == this.$.input;
54 } 58 }
55 }); 59 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698