OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "printing/printed_document.h" | 5 #include "printing/printed_document.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 base::LazyInstance<PrintDebugDumpPath> g_debug_dump_info = | 40 base::LazyInstance<PrintDebugDumpPath> g_debug_dump_info = |
41 LAZY_INSTANCE_INITIALIZER; | 41 LAZY_INSTANCE_INITIALIZER; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 namespace printing { | 45 namespace printing { |
46 | 46 |
47 PrintedDocument::PrintedDocument(const PrintSettings& settings, | 47 PrintedDocument::PrintedDocument(const PrintSettings& settings, |
48 PrintedPagesSource* source, | 48 PrintedPagesSource* source, |
49 Delegate* delegate, | |
49 int cookie) | 50 int cookie) |
50 : mutable_(source), | 51 : mutable_(source), |
51 immutable_(settings, source, cookie) { | 52 immutable_(settings, source, delegate, cookie) { |
52 | 53 |
54 #if !defined(OS_WIN) | |
55 DCHECK(immutable_.delegate_ == NULL) << | |
56 "Delegate is only supported on Windows for now"; | |
Albert Bodenhamer
2012/06/15 18:41:24
Is there any reason you need this? The basic dele
MAD
2012/06/19 14:24:10
Yeah, I wanted to avoid people trying to use it on
MAD
2012/06/28 15:48:14
Done.
| |
57 #endif | |
53 // Records the expected page count if a range is setup. | 58 // Records the expected page count if a range is setup. |
54 if (!settings.ranges.empty()) { | 59 if (!settings.ranges.empty()) { |
55 // If there is a range, set the number of page | 60 // If there is a range, set the number of page |
56 for (unsigned i = 0; i < settings.ranges.size(); ++i) { | 61 for (unsigned i = 0; i < settings.ranges.size(); ++i) { |
57 const PageRange& range = settings.ranges[i]; | 62 const PageRange& range = settings.ranges[i]; |
58 mutable_.expected_page_count_ += range.to - range.from + 1; | 63 mutable_.expected_page_count_ += range.to - range.from + 1; |
64 if (immutable_.delegate_) | |
65 immutable_.delegate_->SetPageCount(mutable_.expected_page_count_); | |
59 } | 66 } |
60 } | 67 } |
61 } | 68 } |
62 | 69 |
63 PrintedDocument::~PrintedDocument() { | 70 PrintedDocument::~PrintedDocument() { |
64 } | 71 } |
65 | 72 |
66 void PrintedDocument::SetPage(int page_number, | 73 void PrintedDocument::SetPage(int page_number, |
67 Metafile* metafile, | 74 Metafile* metafile, |
68 double shrink, | 75 double shrink, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 } | 155 } |
149 return total; | 156 return total; |
150 } | 157 } |
151 | 158 |
152 void PrintedDocument::set_page_count(int max_page) { | 159 void PrintedDocument::set_page_count(int max_page) { |
153 base::AutoLock lock(lock_); | 160 base::AutoLock lock(lock_); |
154 DCHECK_EQ(0, mutable_.page_count_); | 161 DCHECK_EQ(0, mutable_.page_count_); |
155 mutable_.page_count_ = max_page; | 162 mutable_.page_count_ = max_page; |
156 if (immutable_.settings_.ranges.empty()) { | 163 if (immutable_.settings_.ranges.empty()) { |
157 mutable_.expected_page_count_ = max_page; | 164 mutable_.expected_page_count_ = max_page; |
165 if (immutable_.delegate_) | |
166 immutable_.delegate_->SetPageCount(mutable_.expected_page_count_); | |
158 } else { | 167 } else { |
159 // If there is a range, don't bother since expected_page_count_ is already | 168 // If there is a range, don't bother since expected_page_count_ is already |
160 // initialized. | 169 // initialized. |
161 DCHECK_NE(mutable_.expected_page_count_, 0); | 170 DCHECK_NE(mutable_.expected_page_count_, 0); |
162 } | 171 } |
163 } | 172 } |
164 | 173 |
165 int PrintedDocument::page_count() const { | 174 int PrintedDocument::page_count() const { |
166 base::AutoLock lock(lock_); | 175 base::AutoLock lock(lock_); |
167 return mutable_.page_count_; | 176 return mutable_.page_count_; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 216 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
208 first_page = INT_MAX; | 217 first_page = INT_MAX; |
209 #endif | 218 #endif |
210 } | 219 } |
211 | 220 |
212 PrintedDocument::Mutable::~Mutable() { | 221 PrintedDocument::Mutable::~Mutable() { |
213 } | 222 } |
214 | 223 |
215 PrintedDocument::Immutable::Immutable(const PrintSettings& settings, | 224 PrintedDocument::Immutable::Immutable(const PrintSettings& settings, |
216 PrintedPagesSource* source, | 225 PrintedPagesSource* source, |
226 Delegate* delegate, | |
217 int cookie) | 227 int cookie) |
218 : settings_(settings), | 228 : settings_(settings), |
219 source_message_loop_(MessageLoop::current()), | 229 source_message_loop_(MessageLoop::current()), |
220 name_(source->RenderSourceName()), | 230 name_(source->RenderSourceName()), |
231 delegate_(delegate), | |
221 cookie_(cookie) { | 232 cookie_(cookie) { |
222 } | 233 } |
223 | 234 |
224 PrintedDocument::Immutable::~Immutable() { | 235 PrintedDocument::Immutable::~Immutable() { |
225 } | 236 } |
226 | 237 |
227 #if defined(OS_POSIX) && defined(USE_AURA) | 238 #if defined(OS_POSIX) && defined(USE_AURA) |
228 // This function is not used on aura linux/chromeos. | 239 // This function is not used on aura linux/chromeos. |
229 void PrintedDocument::RenderPrintedPage(const PrintedPage& page, | 240 void PrintedDocument::RenderPrintedPage(const PrintedPage& page, |
230 PrintingContext* context) const { | 241 PrintingContext* context) const { |
231 } | 242 } |
232 #endif | 243 #endif |
233 | 244 |
234 } // namespace printing | 245 } // namespace printing |
OLD | NEW |