Flip this back to true. IdleHandlers should certainly be being scheduled when the...
[chromium-blink-merge.git] / printing / page_number.cc
blobdb3861dbdffd453d2b10b4494e917a60e3babbb1
1 // Copyright (c) 2006-2008 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.
5 #include "printing/page_number.h"
7 #include <limits>
9 #include "base/logging.h"
10 #include "printing/print_settings.h"
12 namespace printing {
14 PageNumber::PageNumber(const PrintSettings& settings, int document_page_count) {
15 Init(settings, document_page_count);
18 PageNumber::PageNumber()
19 : ranges_(NULL),
20 page_number_(-1),
21 page_range_index_(-1),
22 document_page_count_(0) {
25 void PageNumber::operator=(const PageNumber& other) {
26 ranges_ = other.ranges_;
27 page_number_ = other.page_number_;
28 page_range_index_ = other.page_range_index_;
29 document_page_count_ = other.document_page_count_;
32 void PageNumber::Init(const PrintSettings& settings, int document_page_count) {
33 DCHECK(document_page_count);
34 ranges_ = settings.ranges().empty() ? NULL : &settings.ranges();
35 document_page_count_ = document_page_count;
36 if (ranges_) {
37 page_range_index_ = 0;
38 page_number_ = (*ranges_)[0].from;
39 } else {
40 if (document_page_count) {
41 page_number_ = 0;
42 } else {
43 page_number_ = -1;
45 page_range_index_ = -1;
49 int PageNumber::operator++() {
50 if (!ranges_) {
51 // Switch to next page.
52 if (++page_number_ == document_page_count_) {
53 // Finished.
54 *this = npos();
56 } else {
57 // Switch to next page.
58 ++page_number_;
59 // Page ranges are inclusive.
60 if (page_number_ > (*ranges_)[page_range_index_].to) {
61 DCHECK(ranges_->size() <= static_cast<size_t>(
62 std::numeric_limits<int>::max()));
63 if (++page_range_index_ == static_cast<int>(ranges_->size())) {
64 // Finished.
65 *this = npos();
66 } else {
67 page_number_ = (*ranges_)[page_range_index_].from;
71 return ToInt();
74 bool PageNumber::operator==(const PageNumber& other) const {
75 return page_number_ == other.page_number_ &&
76 page_range_index_ == other.page_range_index_;
78 bool PageNumber::operator!=(const PageNumber& other) const {
79 return page_number_ != other.page_number_ ||
80 page_range_index_ != other.page_range_index_;
83 } // namespace printing