[M120 Migration][MM] Fix EME AD insert issue
[platform/framework/web/chromium-efl.git] / printing / page_number.h
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.
4
5 #ifndef PRINTING_PAGE_NUMBER_H_
6 #define PRINTING_PAGE_NUMBER_H_
7
8 #include <ostream>
9 #include <vector>
10
11 #include "base/check_op.h"
12 #include "base/memory/raw_ptr.h"
13 #include "printing/page_range.h"
14
15 namespace printing {
16
17 // Represents a page series using the array of page ranges. Pages are assumed
18 // to be 0-indexed.
19 class COMPONENT_EXPORT(PRINTING) PageNumber {
20  public:
21   // Initializes the page to the first page in the ranges or 0.
22   PageNumber(const PageRanges& ranges, uint32_t document_page_count);
23
24   PageNumber();
25
26   PageNumber(const PageNumber& other);
27   PageNumber& operator=(const PageNumber& other);
28
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);
32
33   // Converts to a page numbers.
34   uint32_t ToUint() const {
35     DCHECK(*this == npos() || page_number_ < document_page_count_);
36     return page_number_;
37   }
38
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++();
42
43   // Returns an instance that represents the end of a series.
44   static const PageNumber npos() { return PageNumber(); }
45
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;
50
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);
55
56  private:
57   // The page range to follow.
58   raw_ptr<const PageRanges> ranges_;
59
60   // The next page to be printed. `kInvalidPageIndex` when not printing.
61   uint32_t page_number_;
62
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_;
66
67   // Total number of pages in the underlying document, including outside of the
68   // specified ranges.
69   uint32_t document_page_count_;
70 };
71
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();
78 }
79
80 }  // namespace printing
81
82 #endif  // PRINTING_PAGE_NUMBER_H_