diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 22:01:52 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 22:01:52 +0000 |
commit | e059878de96a6fcdc70dfc3bf13d37be6d1a697a (patch) | |
tree | 4387419d69b2946a556e43d52596c78c07582e17 | |
parent | cceaf8512b4cb70a81db1f371ae094e2f2d3f645 (diff) | |
download | chromium_src-e059878de96a6fcdc70dfc3bf13d37be6d1a697a.zip chromium_src-e059878de96a6fcdc70dfc3bf13d37be6d1a697a.tar.gz chromium_src-e059878de96a6fcdc70dfc3bf13d37be6d1a697a.tar.bz2 |
Printing: Refactor a few helper methods implemented per-platform to clean up
ifdef mess in PrintedDocument implementation.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3564016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61865 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | printing/printed_document.cc | 42 | ||||
-rw-r--r-- | printing/printed_document.h | 12 | ||||
-rw-r--r-- | printing/printed_document_cairo.cc | 6 | ||||
-rw-r--r-- | printing/printed_document_mac.cc | 6 | ||||
-rw-r--r-- | printing/printed_document_posix.cc | 21 | ||||
-rw-r--r-- | printing/printed_document_win.cc | 30 | ||||
-rw-r--r-- | printing/printing.gyp | 1 |
7 files changed, 78 insertions, 40 deletions
diff --git a/printing/printed_document.cc b/printing/printed_document.cc index f5989f6..2dad1a0 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -17,7 +17,6 @@ #include "base/singleton.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "base/time.h" #include "base/i18n/time_formatting.h" #include "gfx/font.h" #include "printing/page_number.h" @@ -27,12 +26,6 @@ #include "printing/units.h" #include "skia/ext/platform_device.h" -#if defined(OS_WIN) -#include "app/win_util.h" -#endif - -using base::Time; - namespace { struct PrintDebugDumpPath { @@ -245,25 +238,7 @@ void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context, } } - // TODO(stuartmorgan): Factor out this platform-specific part into another - // method that can be moved into the platform files. -#if defined(OS_WIN) - // Save the state (again) for the clipping region. - int saved_state = SaveDC(context); - DCHECK_NE(saved_state, 0); - - int result = IntersectClipRect(context, bounding.x(), bounding.y(), - bounding.right() + 1, bounding.bottom() + 1); - DCHECK(result == SIMPLEREGION || result == COMPLEXREGION); - TextOut(context, - bounding.x(), bounding.y(), - output.c_str(), - static_cast<int>(output.size())); - int res = RestoreDC(context, saved_state); - DCHECK_NE(res, 0); -#else // OS_WIN - NOTIMPLEMENTED(); -#endif // OS_WIN + DrawHeaderFooter(context, output, bounding); } void PrintedDocument::DebugDump(const PrintedPage& page) { @@ -314,20 +289,7 @@ PrintedDocument::Immutable::Immutable(const PrintSettings& settings, name_(source->RenderSourceName()), url_(source->RenderSourceUrl()), cookie_(cookie) { - // Setup the document's date. -#if defined(OS_WIN) - // On Windows, use the native time formatting for printing. - SYSTEMTIME systemtime; - GetLocalTime(&systemtime); - date_ = - WideToUTF16Hack(win_util::FormatSystemDate(systemtime, std::wstring())); - time_ = - WideToUTF16Hack(win_util::FormatSystemTime(systemtime, std::wstring())); -#else // OS_WIN - Time now = Time::Now(); - date_ = WideToUTF16Hack(base::TimeFormatShortDateNumeric(now)); - time_ = WideToUTF16Hack(base::TimeFormatTimeOfDay(now)); -#endif // OS_WIN + SetDocumentDate(); } PrintedDocument::Immutable::~Immutable() { diff --git a/printing/printed_document.h b/printing/printed_document.h index dfab7a5..f42e075 100644 --- a/printing/printed_document.h +++ b/printing/printed_document.h @@ -149,6 +149,9 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { int cookie); ~Immutable(); + // Sets the document's |date_| and |time_|. + void SetDocumentDate(); + // Print settings used to generate this document. Immutable. PrintSettings settings_; @@ -184,6 +187,15 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { PageOverlays::VerticalPosition y, const gfx::Font& font) const; + // Draws the computed |text| into |context| taking into account the bounding + // region |bounds|. |bounds| is the position in which to draw |text| and + // the minimum area needed to contain |text| which may not be larger than the + // header or footer itself. + // TODO(jhawkins): string16. + void DrawHeaderFooter(gfx::NativeDrawingContext context, + std::wstring text, + gfx::Rect bounds) const; + void DebugDump(const PrintedPage& page); // All writable data member access must be guarded by this lock. Needs to be diff --git a/printing/printed_document_cairo.cc b/printing/printed_document_cairo.cc index fb996db..76085e1 100644 --- a/printing/printed_document_cairo.cc +++ b/printing/printed_document_cairo.cc @@ -27,4 +27,10 @@ void PrintedDocument::RenderPrintedPage( NOTIMPLEMENTED(); } +void PrintedDocument::DrawHeaderFooter(gfx::NativeDrawingContext context, + std::wstring text, + gfx::Rect bounds) const { + NOTIMPLEMENTED(); +} + } // namespace printing diff --git a/printing/printed_document_mac.cc b/printing/printed_document_mac.cc index f729215..8ba8b813 100644 --- a/printing/printed_document_mac.cc +++ b/printing/printed_document_mac.cc @@ -40,4 +40,10 @@ void PrintedDocument::RenderPrintedPage( // TODO(stuartmorgan): Print the header and footer. } +void PrintedDocument::DrawHeaderFooter(gfx::NativeDrawingContext context, + std::wstring text, + gfx::Rect bounds) const { + NOTIMPLEMENTED(); +} + } // namespace printing diff --git a/printing/printed_document_posix.cc b/printing/printed_document_posix.cc new file mode 100644 index 0000000..9a37f2c --- /dev/null +++ b/printing/printed_document_posix.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "printing/printed_document.h" + +#include "base/i18n/time_formatting.h" +#include "base/time.h" +#include "base/utf_string_conversions.h" + +using base::Time; + +namespace printing { + +void PrintedDocument::Immutable::SetDocumentDate() { + Time now = Time::Now(); + date_ = WideToUTF16Hack(base::TimeFormatShortDateNumeric(now)); + time_ = WideToUTF16Hack(base::TimeFormatTimeOfDay(now)); +} + +} // namespace printing diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc index e6a1126..d157aef 100644 --- a/printing/printed_document_win.cc +++ b/printing/printed_document_win.cc @@ -4,8 +4,10 @@ #include "printing/printed_document.h" +#include "app/win_util.h" #include "base/logging.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "gfx/font.h" #include "printing/page_number.h" #include "printing/page_overlays.h" @@ -114,4 +116,32 @@ void PrintedDocument::RenderPrintedPage( DCHECK_NE(res, 0); } +void PrintedDocument::Immutable::SetDocumentDate() { + // Use the native time formatting for printing on Windows. + SYSTEMTIME systemtime; + GetLocalTime(&systemtime); + date_ = + WideToUTF16Hack(win_util::FormatSystemDate(systemtime, std::wstring())); + time_ = + WideToUTF16Hack(win_util::FormatSystemTime(systemtime, std::wstring())); +} + +void PrintedDocument::DrawHeaderFooter(gfx::NativeDrawingContext context, + std::wstring text, + gfx::Rect bounds) const { + // Save the state for the clipping region. + int saved_state = SaveDC(context); + DCHECK_NE(saved_state, 0); + + int result = IntersectClipRect(context, bounds.x(), bounds.y(), + bounds.right() + 1, bounds.bottom() + 1); + DCHECK(result == SIMPLEREGION || result == COMPLEXREGION); + TextOut(context, + bounds.x(), bounds.y(), + text.c_str(), + static_cast<int>(text.size())); + int res = RestoreDC(context, saved_state); + DCHECK_NE(res, 0); +} + } // namespace printing diff --git a/printing/printing.gyp b/printing/printing.gyp index be84caf..3b37771 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -46,6 +46,7 @@ 'printed_document.cc', 'printed_document_cairo.cc', 'printed_document_mac.cc', + 'printed_document_posix.cc', 'printed_document_win.cc', 'printed_document.h', 'printed_page.cc', |