Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: chrome/browser/printing/printed_document.cc

Issue 125082: Add Print Selection support to Chrome. This change is fairly involved since ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/printing/printed_document.h" 5 #include "chrome/browser/printing/printed_document.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/gfx/font.h" 9 #include "app/gfx/font.h"
10 #include "app/gfx/text_elider.h" 10 #include "app/gfx/text_elider.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 } 61 }
62 NotificationService::current()->Notify( 62 NotificationService::current()->Notify(
63 NotificationType::PRINTED_DOCUMENT_UPDATED, 63 NotificationType::PRINTED_DOCUMENT_UPDATED,
64 Source<PrintedDocument>(this), 64 Source<PrintedDocument>(this),
65 Details<PrintedPage>(page)); 65 Details<PrintedPage>(page));
66 } 66 }
67 67
68 bool PrintedDocument::GetPage(int page_number, 68 bool PrintedDocument::GetPage(int page_number,
69 scoped_refptr<PrintedPage>* page) { 69 scoped_refptr<PrintedPage>* page) {
70 bool request = false; 70 AutoLock lock(lock_);
71 { 71 PrintedPages::const_iterator itr = mutable_.pages_.find(page_number);
72 AutoLock lock(lock_); 72 if (itr != mutable_.pages_.end()) {
73 PrintedPages::const_iterator itr = mutable_.pages_.find(page_number); 73 if (itr->second.get()) {
74 if (itr != mutable_.pages_.end()) { 74 *page = itr->second;
75 if (itr->second.get()) { 75 return true;
76 *page = itr->second;
77 return true;
78 }
79 request = false;
80 } else {
81 request = true;
82 // Force the creation to not repeatedly request the same page.
83 mutable_.pages_[page_number];
84 } 76 }
85 } 77 }
86 if (request) {
87 PrintPage_ThreadJump(page_number);
88 }
89 return false; 78 return false;
90 } 79 }
91 80
92 void PrintedDocument::RenderPrintedPage(const PrintedPage& page, 81 void PrintedDocument::RenderPrintedPage(const PrintedPage& page,
93 HDC context) const { 82 HDC context) const {
94 #ifndef NDEBUG 83 #ifndef NDEBUG
95 { 84 {
96 // Make sure the page is from our list. 85 // Make sure the page is from our list.
97 AutoLock lock(lock_); 86 AutoLock lock(lock_);
98 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); 87 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return false; 162 return false;
174 for (; page != PageNumber::npos(); ++page) { 163 for (; page != PageNumber::npos(); ++page) {
175 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); 164 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt());
176 if (itr == mutable_.pages_.end() || !itr->second.get() || 165 if (itr == mutable_.pages_.end() || !itr->second.get() ||
177 !itr->second->emf()) 166 !itr->second->emf())
178 return false; 167 return false;
179 } 168 }
180 return true; 169 return true;
181 } 170 }
182 171
183 bool PrintedDocument::RequestMissingPages() {
184 typedef std::set<int> PageNumbers;
185 PageNumbers missing_pages;
186 {
187 AutoLock lock(lock_);
188 PageNumber page(immutable_.settings_, mutable_.page_count_);
189 if (page == PageNumber::npos())
190 return false;
191 for (; page != PageNumber::npos(); ++page) {
192 PrintedPage* printed_page = mutable_.pages_[page.ToInt()].get();
193 if (!printed_page || !printed_page->emf())
194 missing_pages.insert(page.ToInt());
195 }
196 }
197 if (!missing_pages.size())
198 return true;
199 PageNumbers::const_iterator end = missing_pages.end();
200 for (PageNumbers::const_iterator itr = missing_pages.begin();
201 itr != end;
202 ++itr) {
203 int page_number = *itr;
204 PrintPage_ThreadJump(page_number);
205 }
206 return true;
207 }
208
209 void PrintedDocument::DisconnectSource() { 172 void PrintedDocument::DisconnectSource() {
210 AutoLock lock(lock_); 173 AutoLock lock(lock_);
211 mutable_.source_ = NULL; 174 mutable_.source_ = NULL;
212 } 175 }
213 176
214 size_t PrintedDocument::MemoryUsage() const { 177 size_t PrintedDocument::MemoryUsage() const {
215 std::vector<scoped_refptr<PrintedPage>> pages_copy; 178 std::vector<scoped_refptr<PrintedPage>> pages_copy;
216 { 179 {
217 AutoLock lock(lock_); 180 AutoLock lock(lock_);
218 pages_copy.reserve(mutable_.pages_.size()); 181 pages_copy.reserve(mutable_.pages_.size());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 bounding.right() + 1, bounding.bottom() + 1); 290 bounding.right() + 1, bounding.bottom() + 1);
328 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION); 291 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION);
329 TextOut(context, 292 TextOut(context,
330 bounding.x(), bounding.y(), 293 bounding.x(), bounding.y(),
331 output.c_str(), 294 output.c_str(),
332 static_cast<int>(output.size())); 295 static_cast<int>(output.size()));
333 int res = RestoreDC(context, saved_state); 296 int res = RestoreDC(context, saved_state);
334 DCHECK_NE(res, 0); 297 DCHECK_NE(res, 0);
335 } 298 }
336 299
337 void PrintedDocument::PrintPage_ThreadJump(int page_number) {
338 if (MessageLoop::current() != immutable_.source_message_loop_) {
339 immutable_.source_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
340 this, &PrintedDocument::PrintPage_ThreadJump, page_number));
341 } else {
342 PrintedPagesSource* source = NULL;
343 {
344 AutoLock lock(lock_);
345 source = mutable_.source_;
346 }
347 NOTREACHED();
348 }
349 }
350
351 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source) 300 PrintedDocument::Mutable::Mutable(PrintedPagesSource* source)
352 : source_(source), 301 : source_(source),
353 expected_page_count_(0), 302 expected_page_count_(0),
354 page_count_(0), 303 page_count_(0),
355 shrink_factor(0) { 304 shrink_factor(0) {
356 } 305 }
357 306
358 PrintedDocument::Immutable::Immutable(const PrintSettings& settings, 307 PrintedDocument::Immutable::Immutable(const PrintSettings& settings,
359 PrintedPagesSource* source, 308 PrintedPagesSource* source,
360 int cookie) 309 int cookie)
(...skipping 10 matching lines...) Expand all
371 date_ = win_util::FormatSystemDate(systemtime, std::wstring()); 320 date_ = win_util::FormatSystemDate(systemtime, std::wstring());
372 time_ = win_util::FormatSystemTime(systemtime, std::wstring()); 321 time_ = win_util::FormatSystemTime(systemtime, std::wstring());
373 #else 322 #else
374 Time now = Time::Now(); 323 Time now = Time::Now();
375 date_ = TimeFormat::ShortDateNumeric(now); 324 date_ = TimeFormat::ShortDateNumeric(now);
376 time_ = TimeFormat::TimeOfDay(now); 325 time_ = TimeFormat::TimeOfDay(now);
377 #endif // WIN32 326 #endif // WIN32
378 } 327 }
379 328
380 } // namespace printing 329 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/printed_document.h ('k') | chrome/browser/printing/win_printing_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698