summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authordpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 07:56:18 +0000
committerdpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 07:56:18 +0000
commit61c1046892028090afc10fd0e58d992e739c3b31 (patch)
treed83317a5074baaeed44994d0853e2d69b18ff1f1 /printing
parent73c2f6a71887dcf9ad7948dd74c84beba4ad1c55 (diff)
downloadchromium_src-61c1046892028090afc10fd0e58d992e739c3b31.zip
chromium_src-61c1046892028090afc10fd0e58d992e739c3b31.tar.gz
chromium_src-61c1046892028090afc10fd0e58d992e739c3b31.tar.bz2
Print Preview: Making margin selection sticky (part 2/2, again)
This is a reland of http://codereview.chromium.org/8351048/ with minor changes to fix the compilation errors on the shared builders. BUG=102446 TEST=See bug description. Review URL: http://codereview.chromium.org/8528053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110055 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/page_size_margins.cc29
-rw-r--r--printing/page_size_margins.h10
-rw-r--r--printing/printing.gyp1
-rw-r--r--printing/printing_context.cc27
4 files changed, 47 insertions, 20 deletions
diff --git a/printing/page_size_margins.cc b/printing/page_size_margins.cc
new file mode 100644
index 0000000..8a6b48b
--- /dev/null
+++ b/printing/page_size_margins.cc
@@ -0,0 +1,29 @@
+// 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_size_margins.h"
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "printing/print_job_constants.h"
+
+namespace printing {
+
+void GetCustomMarginsFromJobSettings(const base::DictionaryValue& settings,
+ PageSizeMargins* page_size_margins) {
+ DictionaryValue* custom_margins;
+ if (!settings.GetDictionary(kSettingMarginsCustom, &custom_margins) ||
+ !custom_margins->GetDouble(kSettingMarginTop,
+ &page_size_margins->margin_top) ||
+ !custom_margins->GetDouble(kSettingMarginBottom,
+ &page_size_margins->margin_bottom) ||
+ !custom_margins->GetDouble(kSettingMarginLeft,
+ &page_size_margins->margin_left) ||
+ !custom_margins->GetDouble(kSettingMarginRight,
+ &page_size_margins->margin_right)) {
+ NOTREACHED();
+ }
+}
+
+} // namespace printing
diff --git a/printing/page_size_margins.h b/printing/page_size_margins.h
index 4f74c297..b6913724 100644
--- a/printing/page_size_margins.h
+++ b/printing/page_size_margins.h
@@ -5,6 +5,12 @@
#ifndef PRINTING_PAGE_SIZE_MARGINS_H_
#define PRINTING_PAGE_SIZE_MARGINS_H_
+#include "printing/printing_export.h"
+
+namespace base {
+class DictionaryValue;
+}
+
namespace printing {
// Struct that holds margin and content area sizes of a page. Units are
@@ -18,7 +24,9 @@ struct PageSizeMargins {
double margin_left;
};
+PRINTING_EXPORT void GetCustomMarginsFromJobSettings(
+ const base::DictionaryValue& settings, PageSizeMargins* page_size_margins);
+
} // namespace printing
#endif // PRINTING_PAGE_SIZE_MARGINS_H_
-
diff --git a/printing/printing.gyp b/printing/printing.gyp
index 0cb2c06..34e3b4e 100644
--- a/printing/printing.gyp
+++ b/printing/printing.gyp
@@ -50,6 +50,7 @@
'page_range.h',
'page_setup.cc',
'page_setup.h',
+ 'page_size_margins.cc',
'page_size_margins.h',
'pdf_metafile_cg_mac.cc',
'pdf_metafile_cg_mac.h',
diff --git a/printing/printing_context.cc b/printing/printing_context.cc
index cc39e6c..09a93ff 100644
--- a/printing/printing_context.cc
+++ b/printing/printing_context.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/values.h"
#include "printing/page_setup.h"
+#include "printing/page_size_margins.h"
#include "printing/print_settings_initializer.h"
namespace printing {
@@ -62,27 +63,15 @@ PrintingContext::Result PrintingContext::UpdatePrintSettings(
settings_.margin_type = static_cast<MarginType>(margin_type);
if (margin_type == CUSTOM_MARGINS) {
- double top_margin_in_points = 0;
- double bottom_margin_in_points = 0;
- double left_margin_in_points = 0;
- double right_margin_in_points = 0;
- DictionaryValue* custom_margins;
- if (!job_settings.GetDictionary(kSettingMarginsCustom, &custom_margins) ||
- !custom_margins->GetDouble(kSettingMarginTop, &top_margin_in_points) ||
- !custom_margins->GetDouble(kSettingMarginBottom,
- &bottom_margin_in_points) ||
- !custom_margins->GetDouble(kSettingMarginLeft,
- &left_margin_in_points) ||
- !custom_margins->GetDouble(kSettingMarginRight,
- &right_margin_in_points)) {
- NOTREACHED();
- }
+ printing::PageSizeMargins page_size_margins;
+ GetCustomMarginsFromJobSettings(job_settings, &page_size_margins);
+
PageMargins margins_in_points;
margins_in_points.Clear();
- margins_in_points.top = top_margin_in_points;
- margins_in_points.bottom = bottom_margin_in_points;
- margins_in_points.left = left_margin_in_points;
- margins_in_points.right = right_margin_in_points;
+ margins_in_points.top = page_size_margins.margin_top;
+ margins_in_points.bottom = page_size_margins.margin_bottom;
+ margins_in_points.left = page_size_margins.margin_left;
+ margins_in_points.right = page_size_margins.margin_right;
settings_.SetCustomMargins(margins_in_points);
}