Skip to content

Commit

Permalink
PrintPreview: Added a helper function to get print job settings from …
Browse files Browse the repository at this point in the history
…dictionary.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/6758014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80008 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kmadhusu@chromium.org committed Mar 31, 2011
1 parent 92acf34 commit 37a401b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
18 changes: 17 additions & 1 deletion printing/printing_context.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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/printing_context.h"

#include "base/values.h"
#include "printing/print_job_constants.h"

namespace printing {

PrintingContext::PrintingContext(const std::string& app_locale)
Expand All @@ -26,6 +29,19 @@ void PrintingContext::ResetSettings() {
abort_printing_ = false;
}

bool PrintingContext::GetSettingsFromDict(const DictionaryValue& settings,
bool* landscape,
std::string* printerName) {
bool ret = true;
if (landscape)
ret &= settings.GetBoolean(kSettingLandscape, landscape);

if (printerName)
ret &= settings.GetString(kSettingPrinterName, printerName);

return ret;
}

PrintingContext::Result PrintingContext::OnError() {
ResetSettings();
return abort_printing_ ? CANCEL : FAILED;
Expand Down
7 changes: 7 additions & 0 deletions printing/printing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ class PrintingContext {
// Reinitializes the settings for object reuse.
void ResetSettings();

// Extracts print job settings from |settings|. Out parameters can be NULL.
// Returns true if all non-NULL out parameters are successfully extracted
// from |settings| else returns false.
bool GetSettingsFromDict(const DictionaryValue& settings,
bool* landscape,
std::string* printerName);

// Does bookkeeping when an error occurs.
PrintingContext::Result OnError();

Expand Down
5 changes: 2 additions & 3 deletions printing/printing_context_cairo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "base/logging.h"
#include "base/values.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings_initializer_gtk.h"
#include "printing/units.h"

Expand Down Expand Up @@ -154,10 +153,10 @@ PrintingContext::Result PrintingContextCairo::UpdatePrintSettings(
DCHECK(!in_print_job_);

bool landscape;
if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
if (!GetSettingsFromDict(job_settings, &landscape, NULL))
return OnError();
settings_.SetOrientation(landscape);

settings_.SetOrientation(landscape);
settings_.ranges = ranges;

// TODO(kmadhusu): Update other print settings such as number of copies,
Expand Down
9 changes: 3 additions & 6 deletions printing/printing_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/sys_string_conversions.h"
#include "base/values.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings_initializer_mac.h"

namespace printing {
Expand Down Expand Up @@ -93,14 +92,12 @@
print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]);

bool landscape;
if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
return OnError();
settings_.SetOrientation(landscape);

std::string printer_name;
if (!job_settings.GetString(kSettingPrinterName, &printer_name))
if (!GetSettingsFromDict(job_settings, &landscape, &printer_name))
return OnError();

settings_.SetOrientation(landscape);

if (!SetPrinter(printer_name))
return OnError();

Expand Down
4 changes: 2 additions & 2 deletions printing/printing_context_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "printing/print_job_constants.h"
#include "printing/print_settings_initializer_win.h"
#include "printing/printed_document.h"
#include "skia/ext/platform_device_win.h"
Expand Down Expand Up @@ -215,8 +214,9 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings(
DCHECK(!in_print_job_);

bool landscape;
if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
if (!GetSettingsFromDict(job_settings, &landscape, NULL))
return OnError();

settings_.SetOrientation(landscape);

// TODO(kmadhusu): Update other print settings such as number of copies,
Expand Down

0 comments on commit 37a401b

Please sign in to comment.