OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('print_preview.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Page range ticket item whose value is a {@code string} that represents | 9 * Page range ticket item whose value is a {@code string} that represents |
10 * which pages in the document should be printed. | 10 * which pages in the document should be printed. |
11 * @param {!print_preview.DocumentInfo} documentInfo Information about the | 11 * @param {!print_preview.DocumentInfo} documentInfo Information about the |
12 * document to print. | 12 * document to print. |
13 * @constructor | 13 * @constructor |
14 * @extends {print_preview.ticket_items.TicketItem} | 14 * @extends {print_preview.ticket_items.TicketItem} |
15 */ | 15 */ |
16 function PageRange(documentInfo) { | 16 function PageRange(documentInfo) { |
17 print_preview.ticket_items.TicketItem.call(this); | 17 print_preview.ticket_items.TicketItem.call(this); |
18 | 18 |
19 /** | 19 /** |
20 * Information about the document to print. | 20 * Information about the document to print. |
21 * @type {!print_preview.DocumentInfo} | 21 * @type {!print_preview.DocumentInfo} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.documentInfo_ = documentInfo; | 24 this.documentInfo_ = documentInfo; |
25 }; | 25 }; |
26 | 26 |
27 /** | |
28 * Impossibly large page number. | |
29 * @type {number} | |
30 * @const | |
31 * @private | |
32 */ | |
33 PageRange.MAX_PAGE_NUMBER_ = 1000000000; | |
34 | |
27 PageRange.prototype = { | 35 PageRange.prototype = { |
28 __proto__: print_preview.ticket_items.TicketItem.prototype, | 36 __proto__: print_preview.ticket_items.TicketItem.prototype, |
29 | 37 |
30 /** @override */ | 38 /** @override */ |
31 wouldValueBeValid: function(value) { | 39 wouldValueBeValid: function(value) { |
32 return value == '' || | 40 return null != pageRangeTextToPageRanges(value, |
33 isPageRangeTextValid(value, this.documentInfo_.pageCount); | 41 this.documentInfo_.pageCount); |
Toscano
2013/02/11 21:25:13
if this.documentInfo_.pageCount is 0, then this co
Vitaly Buka (NO REVIEWS)
2013/02/12 00:46:44
Done.
| |
34 }, | 42 }, |
35 | 43 |
36 /** | 44 /** |
37 * @return {!print_preview.PageNumberSet} Set of page numbers defined by the | 45 * @return {!print_preview.PageNumberSet} Set of page numbers defined by the |
38 * page range string. | 46 * page range string. |
39 */ | 47 */ |
40 getPageNumberSet: function() { | 48 getPageNumberSet: function() { |
41 if (this.isValid()) { | 49 var pageNumberList = pageRangeTextToPageList( |
42 return print_preview.PageNumberSet.parse( | 50 this.getValue(), this.documentInfo_.pageCount); |
43 this.getValue(), this.documentInfo_.pageCount); | 51 return new print_preview.PageNumberSet(pageNumberList); |
44 } else { | |
45 return print_preview.PageNumberSet.parse( | |
46 this.getDefaultValueInternal(), this.documentInfo_.pageCount); | |
47 } | |
48 }, | 52 }, |
49 | 53 |
50 /** @override */ | 54 /** @override */ |
51 isCapabilityAvailable: function() { | 55 isCapabilityAvailable: function() { |
52 return true; | 56 return true; |
53 }, | 57 }, |
54 | 58 |
55 /** @override */ | 59 /** @override */ |
56 getDefaultValueInternal: function() { | 60 getDefaultValueInternal: function() { |
57 return ''; | 61 return ''; |
58 }, | 62 }, |
59 | 63 |
60 /** @override */ | 64 /** @override */ |
61 getCapabilityNotAvailableValueInternal: function() { | 65 getCapabilityNotAvailableValueInternal: function() { |
62 return ''; | 66 return ''; |
67 }, | |
68 | |
69 /** | |
70 * @return {!Array.<object.<{from: number, to: number}>>} A list of page | |
71 * ranges suitable for use in the native layer. | |
72 */ | |
73 getPageRanges: function(page_count) { | |
74 if (page_count === undefined) | |
75 page_count = this.documentInfo_.pageCount; | |
76 var page_ranges = pageRangeTextToPageRanges(this.getValue(), page_count); | |
77 return page_ranges ? page_ranges : []; | |
78 }, | |
79 | |
80 /** | |
81 * @return {print_preview.ticket_items.PageRange} Copy of this object. | |
82 */ | |
83 clone: function() { | |
84 var range = new PageRange(this.documentInfo_); | |
85 range.updateValue(this.getValue()); | |
86 return range; | |
87 }, | |
88 | |
89 /** | |
90 * @param {print_preview.ticket_items.PageRange} other Page range to compare | |
91 * against. | |
92 * @return {boolean} Whether another page range is equal to current one. | |
93 */ | |
94 equals: function(other) { | |
95 if (other == null) | |
Toscano
2013/02/11 21:25:13
Plz always use braces.
Vitaly Buka (NO REVIEWS)
2013/02/12 00:46:44
Done.
| |
96 return false; | |
97 return areRangesEqual(this.getPageRanges(PageRange.MAX_PAGE_NUMBER_), | |
98 other.getPageRanges(PageRange.MAX_PAGE_NUMBER_)); | |
63 } | 99 } |
64 }; | 100 }; |
65 | 101 |
66 // Export | 102 // Export |
67 return { | 103 return { |
68 PageRange: PageRange | 104 PageRange: PageRange |
69 }; | 105 }; |
70 }); | 106 }); |
OLD | NEW |