Skip to content

Commit

Permalink
Printing: Refactor a few helper methods implemented per-platform to c…
Browse files Browse the repository at this point in the history
…lean 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
  • Loading branch information
jhawkins@chromium.org committed Oct 7, 2010
1 parent cceaf85 commit e059878
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 40 deletions.
42 changes: 2 additions & 40 deletions printing/printed_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions printing/printed_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions printing/printed_document_cairo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ void PrintedDocument::RenderPrintedPage(
NOTIMPLEMENTED();
}

void PrintedDocument::DrawHeaderFooter(gfx::NativeDrawingContext context,
std::wstring text,
gfx::Rect bounds) const {
NOTIMPLEMENTED();
}

} // namespace printing
6 changes: 6 additions & 0 deletions printing/printed_document_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions printing/printed_document_posix.cc
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions printing/printed_document_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions printing/printing.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e059878

Please sign in to comment.