| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 bool has_visible_overlays) { | 71 bool has_visible_overlays) { |
| 72 // Notice the page_number + 1, the reason is that this is the value that will | 72 // Notice the page_number + 1, the reason is that this is the value that will |
| 73 // be shown. Users dislike 0-based counting. | 73 // be shown. Users dislike 0-based counting. |
| 74 scoped_refptr<PrintedPage> page( | 74 scoped_refptr<PrintedPage> page( |
| 75 new PrintedPage(page_number + 1, | 75 new PrintedPage(page_number + 1, |
| 76 metafile, | 76 metafile, |
| 77 paper_size, | 77 paper_size, |
| 78 page_rect, | 78 page_rect, |
| 79 has_visible_overlays)); | 79 has_visible_overlays)); |
| 80 { | 80 { |
| 81 AutoLock lock(lock_); | 81 base::AutoLock lock(lock_); |
| 82 mutable_.pages_[page_number] = page; | 82 mutable_.pages_[page_number] = page; |
| 83 if (mutable_.shrink_factor == 0) { | 83 if (mutable_.shrink_factor == 0) { |
| 84 mutable_.shrink_factor = shrink; | 84 mutable_.shrink_factor = shrink; |
| 85 } else { | 85 } else { |
| 86 DCHECK_EQ(mutable_.shrink_factor, shrink); | 86 DCHECK_EQ(mutable_.shrink_factor, shrink); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 DebugDump(*page); | 89 DebugDump(*page); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool PrintedDocument::GetPage(int page_number, | 92 bool PrintedDocument::GetPage(int page_number, |
| 93 scoped_refptr<PrintedPage>* page) { | 93 scoped_refptr<PrintedPage>* page) { |
| 94 AutoLock lock(lock_); | 94 base::AutoLock lock(lock_); |
| 95 PrintedPages::const_iterator itr = mutable_.pages_.find(page_number); | 95 PrintedPages::const_iterator itr = mutable_.pages_.find(page_number); |
| 96 if (itr != mutable_.pages_.end()) { | 96 if (itr != mutable_.pages_.end()) { |
| 97 if (itr->second.get()) { | 97 if (itr->second.get()) { |
| 98 *page = itr->second; | 98 *page = itr->second; |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool PrintedDocument::IsComplete() const { | 105 bool PrintedDocument::IsComplete() const { |
| 106 AutoLock lock(lock_); | 106 base::AutoLock lock(lock_); |
| 107 if (!mutable_.page_count_) | 107 if (!mutable_.page_count_) |
| 108 return false; | 108 return false; |
| 109 PageNumber page(immutable_.settings_, mutable_.page_count_); | 109 PageNumber page(immutable_.settings_, mutable_.page_count_); |
| 110 if (page == PageNumber::npos()) | 110 if (page == PageNumber::npos()) |
| 111 return false; | 111 return false; |
| 112 for (; page != PageNumber::npos(); ++page) { | 112 for (; page != PageNumber::npos(); ++page) { |
| 113 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); | 113 PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); |
| 114 if (itr == mutable_.pages_.end() || !itr->second.get() || | 114 if (itr == mutable_.pages_.end() || !itr->second.get() || |
| 115 !itr->second->native_metafile()) | 115 !itr->second->native_metafile()) |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void PrintedDocument::DisconnectSource() { | 121 void PrintedDocument::DisconnectSource() { |
| 122 AutoLock lock(lock_); | 122 base::AutoLock lock(lock_); |
| 123 mutable_.source_ = NULL; | 123 mutable_.source_ = NULL; |
| 124 } | 124 } |
| 125 | 125 |
| 126 uint32 PrintedDocument::MemoryUsage() const { | 126 uint32 PrintedDocument::MemoryUsage() const { |
| 127 std::vector< scoped_refptr<PrintedPage> > pages_copy; | 127 std::vector< scoped_refptr<PrintedPage> > pages_copy; |
| 128 { | 128 { |
| 129 AutoLock lock(lock_); | 129 base::AutoLock lock(lock_); |
| 130 pages_copy.reserve(mutable_.pages_.size()); | 130 pages_copy.reserve(mutable_.pages_.size()); |
| 131 PrintedPages::const_iterator end = mutable_.pages_.end(); | 131 PrintedPages::const_iterator end = mutable_.pages_.end(); |
| 132 for (PrintedPages::const_iterator itr = mutable_.pages_.begin(); | 132 for (PrintedPages::const_iterator itr = mutable_.pages_.begin(); |
| 133 itr != end; ++itr) { | 133 itr != end; ++itr) { |
| 134 if (itr->second.get()) { | 134 if (itr->second.get()) { |
| 135 pages_copy.push_back(itr->second); | 135 pages_copy.push_back(itr->second); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 uint32 total = 0; | 139 uint32 total = 0; |
| 140 for (size_t i = 0; i < pages_copy.size(); ++i) { | 140 for (size_t i = 0; i < pages_copy.size(); ++i) { |
| 141 total += pages_copy[i]->native_metafile()->GetDataSize(); | 141 total += pages_copy[i]->native_metafile()->GetDataSize(); |
| 142 } | 142 } |
| 143 return total; | 143 return total; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void PrintedDocument::set_page_count(int max_page) { | 146 void PrintedDocument::set_page_count(int max_page) { |
| 147 AutoLock lock(lock_); | 147 base::AutoLock lock(lock_); |
| 148 DCHECK_EQ(0, mutable_.page_count_); | 148 DCHECK_EQ(0, mutable_.page_count_); |
| 149 mutable_.page_count_ = max_page; | 149 mutable_.page_count_ = max_page; |
| 150 if (immutable_.settings_.ranges.empty()) { | 150 if (immutable_.settings_.ranges.empty()) { |
| 151 mutable_.expected_page_count_ = max_page; | 151 mutable_.expected_page_count_ = max_page; |
| 152 } else { | 152 } else { |
| 153 // If there is a range, don't bother since expected_page_count_ is already | 153 // If there is a range, don't bother since expected_page_count_ is already |
| 154 // initialized. | 154 // initialized. |
| 155 DCHECK_NE(mutable_.expected_page_count_, 0); | 155 DCHECK_NE(mutable_.expected_page_count_, 0); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 int PrintedDocument::page_count() const { | 159 int PrintedDocument::page_count() const { |
| 160 AutoLock lock(lock_); | 160 base::AutoLock lock(lock_); |
| 161 return mutable_.page_count_; | 161 return mutable_.page_count_; |
| 162 } | 162 } |
| 163 | 163 |
| 164 int PrintedDocument::expected_page_count() const { | 164 int PrintedDocument::expected_page_count() const { |
| 165 AutoLock lock(lock_); | 165 base::AutoLock lock(lock_); |
| 166 return mutable_.expected_page_count_; | 166 return mutable_.expected_page_count_; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context, | 169 void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context, |
| 170 const PrintedPage& page, | 170 const PrintedPage& page, |
| 171 PageOverlays::HorizontalPosition x, | 171 PageOverlays::HorizontalPosition x, |
| 172 PageOverlays::VerticalPosition y, | 172 PageOverlays::VerticalPosition y, |
| 173 const gfx::Font& font) const { | 173 const gfx::Font& font) const { |
| 174 const PrintSettings& settings = immutable_.settings_; | 174 const PrintSettings& settings = immutable_.settings_; |
| 175 if (!settings.use_overlays || !page.has_visible_overlays()) { | 175 if (!settings.use_overlays || !page.has_visible_overlays()) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 name_(source->RenderSourceName()), | 284 name_(source->RenderSourceName()), |
| 285 url_(source->RenderSourceUrl()), | 285 url_(source->RenderSourceUrl()), |
| 286 cookie_(cookie) { | 286 cookie_(cookie) { |
| 287 SetDocumentDate(); | 287 SetDocumentDate(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 PrintedDocument::Immutable::~Immutable() { | 290 PrintedDocument::Immutable::~Immutable() { |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace printing | 293 } // namespace printing |
| OLD | NEW |