• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3// found in the LICENSE file.
4
5cr.define('print_preview.ticket_items', function() {
6  'use strict';
7
8  /**
9   * Page range ticket item whose value is a {@code string} that represents
10   * which pages in the document should be printed.
11   * @param {!print_preview.DocumentInfo} documentInfo Information about the
12   *     document to print.
13   * @constructor
14   * @extends {print_preview.ticket_items.TicketItem}
15   */
16  function PageRange(documentInfo) {
17    print_preview.ticket_items.TicketItem.call(
18        this,
19        null /*appState*/,
20        null /*field*/,
21        null /*destinationStore*/,
22        documentInfo);
23  };
24
25  /**
26   * Impossibly large page number.
27   * @type {number}
28   * @const
29   * @private
30   */
31  PageRange.MAX_PAGE_NUMBER_ = 1000000000;
32
33  PageRange.prototype = {
34    __proto__: print_preview.ticket_items.TicketItem.prototype,
35
36    /** @override */
37    wouldValueBeValid: function(value) {
38      return null != pageRangeTextToPageRanges(
39          value, this.getDocumentInfoInternal().pageCount);
40    },
41
42    /**
43     * @return {!print_preview.PageNumberSet} Set of page numbers defined by the
44     *     page range string.
45     */
46    getPageNumberSet: function() {
47      var pageNumberList = pageRangeTextToPageList(
48          this.getValue(), this.getDocumentInfoInternal().pageCount);
49      return new print_preview.PageNumberSet(pageNumberList);
50    },
51
52    /** @override */
53    isCapabilityAvailable: function() {
54      return true;
55    },
56
57    /** @override */
58    getDefaultValueInternal: function() {
59      return '';
60    },
61
62    /** @override */
63    getCapabilityNotAvailableValueInternal: function() {
64      return '';
65    },
66
67    /**
68     * @return {!Array.<Object.<{from: number, to: number}>>} A list of page
69     *     ranges.
70     */
71    getPageRanges: function() {
72      return pageRangeTextToPageRanges(this.getValue()) || [];
73    },
74
75    /**
76     * @return {!Array.<object.<{from: number, to: number}>>} A list of page
77     *     ranges suitable for use in the native layer.
78     * TODO(vitalybuka): this should be removed when native layer switched to
79     *     page ranges.
80     */
81    getDocumentPageRanges: function() {
82      var pageRanges = pageRangeTextToPageRanges(
83          this.getValue(), this.getDocumentInfoInternal().pageCount);
84      return pageRanges || [];
85    },
86  };
87
88  // Export
89  return {
90    PageRange: PageRange
91  };
92});
93