diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-29 02:36:26 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-29 02:36:26 +0000 |
commit | c48bee274f6c6869430bdda4ce771c8cdabf736f (patch) | |
tree | 7ce89dceab0e9dd2d2a7f7426a429f68201a8782 /printing | |
parent | e555f205eb8931da7fdf0f4cb4a01a24c3e2bf8a (diff) | |
download | chromium_src-c48bee274f6c6869430bdda4ce771c8cdabf736f.zip chromium_src-c48bee274f6c6869430bdda4ce771c8cdabf736f.tar.gz chromium_src-c48bee274f6c6869430bdda4ce771c8cdabf736f.tar.bz2 |
Print Preview: Implement basic settings.
BUG=57902
TEST=Run with --enable-print-preview, make sure orientation and color settings work.
Review URL: http://codereview.chromium.org/6736014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/page_setup.cc | 17 | ||||
-rw-r--r-- | printing/page_setup.h | 5 | ||||
-rw-r--r-- | printing/print_job_constants.cc | 15 | ||||
-rw-r--r-- | printing/print_job_constants.h | 15 | ||||
-rw-r--r-- | printing/print_settings.cc | 9 | ||||
-rw-r--r-- | printing/print_settings.h | 5 | ||||
-rw-r--r-- | printing/printing.gyp | 2 | ||||
-rw-r--r-- | printing/printing_context_cairo.cc | 8 | ||||
-rw-r--r-- | printing/printing_context_mac.mm | 6 | ||||
-rw-r--r-- | printing/printing_context_win.cc | 6 |
10 files changed, 83 insertions, 5 deletions
diff --git a/printing/page_setup.cc b/printing/page_setup.cc index 6d4ef1d..9ac3e520 100644 --- a/printing/page_setup.cc +++ b/printing/page_setup.cc @@ -1,9 +1,11 @@ -// Copyright (c) 2006-2008 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/page_setup.h" +#include <algorithm> + #include "base/logging.h" namespace printing { @@ -125,4 +127,17 @@ void PageSetup::SetRequestedMargins(const PageMargins& requested_margins) { Init(physical_size_, printable_area_, text_height_); } +void PageSetup::FlipOrientation() { + if (physical_size_.width() && physical_size_.height()) { + gfx::Size new_size(physical_size_.height(), physical_size_.width()); + int new_y = physical_size_.width() - + (printable_area_.width() + printable_area_.x()); + gfx::Rect new_printable_area(printable_area_.y(), + new_y, + printable_area_.height(), + printable_area_.width()); + Init(new_size, new_printable_area, text_height_); + } +} + } // namespace printing diff --git a/printing/page_setup.h b/printing/page_setup.h index d96980f..0ca1f789 100644 --- a/printing/page_setup.h +++ b/printing/page_setup.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 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. @@ -47,6 +47,9 @@ class PageSetup { void SetRequestedMargins(const PageMargins& requested_margins); + // Flips the orientation of the page and recalculates all page areas. + void FlipOrientation(); + const gfx::Size& physical_size() const { return physical_size_; } const gfx::Rect& overlay_area() const { return overlay_area_; } const gfx::Rect& content_area() const { return content_area_; } diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc new file mode 100644 index 0000000..f4eb542 --- /dev/null +++ b/printing/print_job_constants.cc @@ -0,0 +1,15 @@ +// 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/print_job_constants.h" + +namespace printing { + +// Print out color: true for color, false for grayscale. +const char kSettingColor[] = "color"; + +// Page orientation: true for landscape, false for portrait. +const char kSettingLandscape[] = "landscape"; + +} // namespace printing diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h new file mode 100644 index 0000000..ce224af --- /dev/null +++ b/printing/print_job_constants.h @@ -0,0 +1,15 @@ +// 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. + +#ifndef PRINTING_PRINT_JOB_CONSTANTS_H_ +#define PRINTING_PRINT_JOB_CONSTANTS_H_ + +namespace printing { + +extern const char kSettingColor[]; +extern const char kSettingLandscape[]; + +} // namespace printing + +#endif // PRINTING_PRINT_JOB_CONSTANTS_H_ diff --git a/printing/print_settings.cc b/printing/print_settings.cc index 3f0f842..92f3560 100644 --- a/printing/print_settings.cc +++ b/printing/print_settings.cc @@ -1,4 +1,4 @@ -// 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. @@ -94,4 +94,11 @@ int PrintSettings::NewCookie() { return cookie_seq.GetNext() + 1; } +void PrintSettings::SetOrientation(bool landscape) { + if (landscape_ != landscape) { + landscape_ = landscape; + page_setup_device_units_.FlipOrientation(); + } +} + } // namespace printing diff --git a/printing/print_settings.h b/printing/print_settings.h index 2ec5462..fbd37f4 100644 --- a/printing/print_settings.h +++ b/printing/print_settings.h @@ -1,4 +1,4 @@ -// 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. @@ -94,6 +94,9 @@ class PrintSettings { // correctly associated with its corresponding PrintedDocument. static int NewCookie(); + // Updates the orientation and flip the page if needed. + void SetOrientation(bool landscape); + private: ////////////////////////////////////////////////////////////////////////////// // Settings that can't be changed without side-effects. diff --git a/printing/printing.gyp b/printing/printing.gyp index 0e504c4..94c90a6 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -68,6 +68,8 @@ 'printing_context_mac.h', 'printing_context_win.cc', 'printing_context_win.h', + 'print_job_constants.cc', + 'print_job_constants.h', 'print_settings.cc', 'print_settings.h', 'print_settings_initializer_gtk.cc', diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc index 5687fff..c721e3d 100644 --- a/printing/printing_context_cairo.cc +++ b/printing/printing_context_cairo.cc @@ -6,8 +6,9 @@ #include "base/logging.h" #include "base/values.h" -#include "printing/units.h" +#include "printing/print_job_constants.h" #include "printing/print_settings_initializer_gtk.h" +#include "printing/units.h" #if defined(OS_CHROMEOS) #include <unicode/ulocdata.h> @@ -152,6 +153,11 @@ PrintingContext::Result PrintingContextCairo::UpdatePrintSettings( const DictionaryValue& job_settings, const PageRanges& ranges) { DCHECK(!in_print_job_); + bool landscape; + if (!job_settings.GetBoolean(kSettingLandscape, &landscape)) + return OnError(); + settings_.SetOrientation(landscape); + settings_.ranges = ranges; // TODO(kmadhusu): Update other print settings such as number of copies, diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index 47ccb72..65e707f 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -11,6 +11,7 @@ #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 { @@ -91,6 +92,11 @@ PrintingContext::Result PrintingContextMac::UpdatePrintSettings( ResetSettings(); 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("printerName", &printer_name)) return OnError(); diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 1b62c44..d410f31 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -12,6 +12,7 @@ #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" @@ -213,6 +214,11 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings( const DictionaryValue& job_settings, const PageRanges& ranges) { DCHECK(!in_print_job_); + bool landscape; + if (!job_settings.GetBoolean(kSettingLandscape, &landscape)) + return OnError(); + settings_.SetOrientation(landscape); + // TODO(kmadhusu): Update other print settings such as number of copies, // collate, duplex printing, job title, etc., |