1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PRINTING_PAGE_NUMBER_H_
6 #define PRINTING_PAGE_NUMBER_H_
11 #include "base/check_op.h"
12 #include "base/memory/raw_ptr.h"
13 #include "printing/page_range.h"
17 // Represents a page series using the array of page ranges. Pages are assumed
19 class COMPONENT_EXPORT(PRINTING) PageNumber {
21 // Initializes the page to the first page in the ranges or 0.
22 PageNumber(const PageRanges& ranges, uint32_t document_page_count);
26 PageNumber(const PageNumber& other);
27 PageNumber& operator=(const PageNumber& other);
29 // Initializes the page to the first page in the ranges or 0.
30 // Initializes to npos if the ranges is empty and document_page_count is 0.
31 void Init(const PageRanges& ranges, uint32_t document_page_count);
33 // Converts to a page numbers.
34 uint32_t ToUint() const {
35 DCHECK(*this == npos() || page_number_ < document_page_count_);
39 // Calculates the next page in the series. Sets this PageNumber to
40 // PageNumber::npos() if we reach document_page_count_.
41 uint32_t operator++();
43 // Returns an instance that represents the end of a series.
44 static const PageNumber npos() { return PageNumber(); }
46 // Equality operator. Only the current page number is verified so that
47 // "page != PageNumber::npos()" works.
48 bool operator==(const PageNumber& other) const;
49 bool operator!=(const PageNumber& other) const;
51 // Returns all pages represented by the given PageRanges up to and including
52 // page document_page_count - 1.
53 static std::vector<uint32_t> GetPages(PageRanges ranges,
54 uint32_t document_page_count);
57 // The page range to follow.
58 raw_ptr<const PageRanges> ranges_;
60 // The next page to be printed. `kInvalidPageIndex` when not printing.
61 uint32_t page_number_;
63 // The next page to be printed. `kInvalidPageIndex` when not used. Valid only
64 // if document()->settings().range.empty() is false.
65 uint32_t page_range_index_;
67 // Total number of pages in the underlying document, including outside of the
69 uint32_t document_page_count_;
72 // Debug output support.
73 template <class E, class T>
74 inline typename std::basic_ostream<E, T>& operator<<(
75 typename std::basic_ostream<E, T>& ss,
76 const PageNumber& page) {
77 return ss << page.ToUint();
80 } // namespace printing
82 #endif // PRINTING_PAGE_NUMBER_H_