diff options
author | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-06 15:25:50 +0000 |
---|---|---|
committer | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-06 15:25:50 +0000 |
commit | 0e0fca32b226a29a774728b642848bfdd732f791 (patch) | |
tree | 70547f886163e2a364ed47a8d5c85765d48f0e12 /chrome/browser/printing | |
parent | d09e2889c21d0a420b70680291906e4a17fb8503 (diff) | |
download | chromium_src-0e0fca32b226a29a774728b642848bfdd732f791.zip chromium_src-0e0fca32b226a29a774728b642848bfdd732f791.tar.gz chromium_src-0e0fca32b226a29a774728b642848bfdd732f791.tar.bz2 |
Move Emf class to the printing library. Also creates a platform agnostic NativeMetafile definition to ease platform porting.
BUG=none
TEST=none (No functional change)
Review URL: http://codereview.chromium.org/149181
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19943 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r-- | chrome/browser/printing/print_job_manager.cc | 1 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_worker.cc | 1 | ||||
-rw-r--r-- | chrome/browser/printing/print_view_manager.cc | 18 | ||||
-rw-r--r-- | chrome/browser/printing/printed_document.cc | 15 | ||||
-rw-r--r-- | chrome/browser/printing/printed_document.h | 8 | ||||
-rw-r--r-- | chrome/browser/printing/printed_page.cc | 10 | ||||
-rw-r--r-- | chrome/browser/printing/printed_page.h | 11 | ||||
-rw-r--r-- | chrome/browser/printing/printing_layout_uitest.cc | 16 |
8 files changed, 38 insertions, 42 deletions
diff --git a/chrome/browser/printing/print_job_manager.cc b/chrome/browser/printing/print_job_manager.cc index c6f4ac3..320aa21 100644 --- a/chrome/browser/printing/print_job_manager.cc +++ b/chrome/browser/printing/print_job_manager.cc @@ -8,7 +8,6 @@ #include "chrome/browser/printing/printer_query.h" #include "chrome/browser/printing/printed_document.h" #include "chrome/browser/printing/printed_page.h" -#include "chrome/common/gfx/emf.h" #include "chrome/common/notification_service.h" namespace printing { diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc index af32da0..728ff3d 100644 --- a/chrome/browser/printing/print_job_worker.cc +++ b/chrome/browser/printing/print_job_worker.cc @@ -8,7 +8,6 @@ #include "chrome/browser/printing/print_job.h" #include "chrome/browser/printing/printed_document.h" #include "chrome/browser/printing/printed_page.h" -#include "chrome/common/gfx/emf.h" #include "chrome/common/notification_service.h" namespace printing { diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index d775ff5..1c56d00d 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -5,6 +5,7 @@ #include "chrome/browser/printing/print_view_manager.h" #include "app/l10n_util.h" +#include "base/scoped_ptr.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/printing/print_job.h" #include "chrome/browser/printing/print_job_manager.h" @@ -13,10 +14,10 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/gfx/emf.h" #include "chrome/common/notification_service.h" #include "chrome/common/render_messages.h" #include "grit/generated_resources.h" +#include "printing/native_metafile.h" using base::TimeDelta; @@ -95,23 +96,24 @@ void PrintViewManager::DidPrintPage( return; } - base::SharedMemory shared_buf(params.emf_data_handle, true); + base::SharedMemory shared_buf(params.metafile_data_handle, true); if (!shared_buf.Map(params.data_size)) { NOTREACHED() << "couldn't map"; owner_.Stop(); return; } - gfx::Emf* emf = new gfx::Emf; - if (!emf->CreateFromData(shared_buf.memory(), params.data_size)) { - NOTREACHED() << "Invalid EMF header"; - delete emf; + scoped_ptr<NativeMetafile> metafile(new NativeMetafile()); + if (!metafile->CreateFromData(shared_buf.memory(), params.data_size)) { + NOTREACHED() << "Invalid metafile header"; owner_.Stop(); return; } // Update the rendered document. It will send notifications to the listener. - document->SetPage(params.page_number, emf, params.actual_shrink); + document->SetPage(params.page_number, + metafile.release(), + params.actual_shrink); ShouldQuitFromInnerMessageLoop(); } @@ -301,7 +303,7 @@ void PrintViewManager::TerminatePrintJob(bool cancel) { return; if (cancel) { - // We don't need the EMF data anymore because the printing is canceled. + // We don't need the metafile data anymore because the printing is canceled. print_job_->Cancel(); waiting_to_print_ = false; inside_inner_message_loop_ = false; diff --git a/chrome/browser/printing/printed_document.cc b/chrome/browser/printing/printed_document.cc index a366a95..ac26581 100644 --- a/chrome/browser/printing/printed_document.cc +++ b/chrome/browser/printing/printed_document.cc @@ -18,7 +18,6 @@ #include "chrome/browser/printing/page_overlays.h" #include "chrome/browser/printing/printed_pages_source.h" #include "chrome/browser/printing/printed_page.h" -#include "chrome/common/gfx/emf.h" #include "printing/units.h" #include "skia/ext/platform_device.h" @@ -60,12 +59,14 @@ PrintedDocument::PrintedDocument(const PrintSettings& settings, PrintedDocument::~PrintedDocument() { } -void PrintedDocument::SetPage(int page_number, gfx::Emf* emf, double shrink) { +void PrintedDocument::SetPage(int page_number, + NativeMetafile* metafile, + double shrink) { // Notice the page_number + 1, the reason is that this is the value that will // be shown. Users dislike 0-based counting. scoped_refptr<PrintedPage> page( new PrintedPage(page_number + 1, - emf, immutable_.settings_.page_setup_pixels().physical_size())); + metafile, immutable_.settings_.page_setup_pixels().physical_size())); { AutoLock lock(lock_); mutable_.pages_[page_number] = page; @@ -123,7 +124,7 @@ void PrintedDocument::RenderPrintedPage(const PrintedPage& page, BOOL res = ModifyWorldTransform(context, &xform, MWT_LEFTMULTIPLY); DCHECK_NE(res, 0); - if (!page.emf()->SafePlayback(context)) { + if (!page.native_metafile()->SafePlayback(context)) { NOTREACHED(); } @@ -176,7 +177,7 @@ bool PrintedDocument::IsComplete() const { for (; page != PageNumber::npos(); ++page) { PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt()); if (itr == mutable_.pages_.end() || !itr->second.get() || - !itr->second->emf()) + !itr->second->native_metafile()) return false; } return true; @@ -202,7 +203,7 @@ size_t PrintedDocument::MemoryUsage() const { } size_t total = 0; for (size_t i = 0; i < pages_copy.size(); ++i) { - total += pages_copy[i]->emf()->GetDataSize(); + total += pages_copy[i]->native_metafile()->GetDataSize(); } return total; } @@ -321,7 +322,7 @@ void PrintedDocument::DebugDump(const PrintedPage& page) file_util::ReplaceIllegalCharacters(&filename, '_'); std::wstring path(g_debug_dump_info->debug_dump_path); file_util::AppendToPath(&path, filename); - page.emf()->SaveTo(path); + page.native_metafile()->SaveTo(path); } void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) { diff --git a/chrome/browser/printing/printed_document.h b/chrome/browser/printing/printed_document.h index 5efc415..0d1480d 100644 --- a/chrome/browser/printing/printed_document.h +++ b/chrome/browser/printing/printed_document.h @@ -11,12 +11,12 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "chrome/browser/printing/print_settings.h" +#include "printing/native_metafile.h" #include "googleurl/src/gurl.h" class MessageLoop; namespace gfx { -class Emf; class Font; } @@ -40,9 +40,9 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { int cookie); ~PrintedDocument(); - // Sets a page's data. 0-based. Takes emf ownership. + // Sets a page's data. 0-based. Takes metafile ownership. // Note: locks for a short amount of time. - void SetPage(int page_number, gfx::Emf* emf, double shrink); + void SetPage(int page_number, NativeMetafile* metafile, double shrink); // Retrieves a page. If the page is not available right now, it // requests to have this page be rendered and returns false. @@ -103,7 +103,7 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { static const std::wstring& debug_dump_path(); private: - // Array of EMF data for each print previewed page. + // Array of data for each print previewed page. typedef std::map<int, scoped_refptr<PrintedPage>> PrintedPages; // Contains all the mutable stuff. All this stuff MUST be accessed with the diff --git a/chrome/browser/printing/printed_page.cc b/chrome/browser/printing/printed_page.cc index 1cb5c0d..4c44acc 100644 --- a/chrome/browser/printing/printed_page.cc +++ b/chrome/browser/printing/printed_page.cc @@ -4,23 +4,21 @@ #include "chrome/browser/printing/printed_page.h" -#include "chrome/common/gfx/emf.h" - namespace printing { PrintedPage::PrintedPage(int page_number, - gfx::Emf* emf, + NativeMetafile* native_metafile, const gfx::Size& page_size) : page_number_(page_number), - emf_(emf), + native_metafile_(native_metafile), page_size_(page_size) { } PrintedPage::~PrintedPage() { } -const gfx::Emf* PrintedPage::emf() const { - return emf_.get(); +const NativeMetafile* PrintedPage::native_metafile() const { + return native_metafile_.get(); } } // namespace printing diff --git a/chrome/browser/printing/printed_page.h b/chrome/browser/printing/printed_page.h index 9058d72..b60c93d 100644 --- a/chrome/browser/printing/printed_page.h +++ b/chrome/browser/printing/printed_page.h @@ -9,10 +9,7 @@ #include "base/gfx/size.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" - -namespace gfx { -class Emf; -} +#include "printing/native_metafile.h" namespace printing { @@ -25,13 +22,13 @@ namespace printing { class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> { public: PrintedPage(int page_number, - gfx::Emf* emf, + NativeMetafile* native_metafile, const gfx::Size& page_size); ~PrintedPage(); // Getters int page_number() const { return page_number_; } - const gfx::Emf* emf() const; + const NativeMetafile* native_metafile() const; const gfx::Size& page_size() const { return page_size_; } private: @@ -39,7 +36,7 @@ class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> { const int page_number_; // Actual paint data. - const scoped_ptr<gfx::Emf> emf_; + const scoped_ptr<NativeMetafile> native_metafile_; // The physical page size. To support multiple page formats inside on print // job. diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc index a651a0a..e9f6c27 100644 --- a/chrome/browser/printing/printing_layout_uitest.cc +++ b/chrome/browser/printing/printing_layout_uitest.cc @@ -11,13 +11,13 @@ #include "base/simple_thread.h" #include "base/win_util.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/gfx/emf.h" #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/window_proxy.h" #include "chrome/test/ui/ui_test.h" #include "chrome/browser/printing/printing_test.h" #include "net/url_request/url_request_unittest.h" +#include "printing/native_metafile.h" namespace { @@ -37,7 +37,7 @@ class Image { if (LowerCaseEqualsASCII(ext, "png")) { LoadPng(data); } else if (LowerCaseEqualsASCII(ext, "emf")) { - LoadEmf(data); + LoadMetafile(data); } else { EXPECT_TRUE(false); } @@ -149,11 +149,11 @@ class Image { row_length_ = size_.width() * sizeof(uint32); } - void LoadEmf(const std::string& data) { + void LoadMetafile(const std::string& data) { ASSERT_FALSE(data.empty()); - gfx::Emf emf; - emf.CreateFromData(data.data(), data.size()); - gfx::Rect rect(emf.GetBounds()); + printing::NativeMetafile metafile; + metafile.CreateFromData(data.data(), data.size()); + gfx::Rect rect(metafile.GetBounds()); // Create a temporary HDC and bitmap to retrieve the renderered data. HDC hdc = CreateCompatibleDC(NULL); BITMAPV4HEADER hdr; @@ -170,7 +170,7 @@ class Image { EXPECT_TRUE(bitmap); EXPECT_TRUE(SelectObject(hdc, bitmap)); skia::PlatformDevice::InitializeDC(hdc); - EXPECT_TRUE(emf.Playback(hdc, NULL)); + EXPECT_TRUE(metafile.Playback(hdc, NULL)); row_length_ = size_.width() * sizeof(uint32); size_t bytes = row_length_ * size_.height(); ASSERT_TRUE(bytes); @@ -200,7 +200,7 @@ class PrintingLayoutTest : public PrintingTest<UITest> { public: PrintingLayoutTest() { emf_path_ = browser_directory_.ToWStringHack(); - file_util::AppendToPath(&emf_path_, L"emf_dumps"); + file_util::AppendToPath(&emf_path_, L"metafile_dumps"); launch_arguments_.AppendSwitchWithValue(L"debug-print", L'"' + emf_path_ + L'"'); show_window_ = true; |