Revert 162447 - Temporarily remove "Swap primary monitor" from keyboard overlay for...
[chromium-blink-merge.git] / printing / printing_context.cc
blob09a93ff18e0e44219453984651871457389f8bd5
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/printing_context.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "printing/page_setup.h"
10 #include "printing/page_size_margins.h"
11 #include "printing/print_settings_initializer.h"
13 namespace printing {
15 PrintingContext::PrintingContext(const std::string& app_locale)
16 : dialog_box_dismissed_(false),
17 in_print_job_(false),
18 abort_printing_(false),
19 app_locale_(app_locale) {
22 PrintingContext::~PrintingContext() {
25 void PrintingContext::set_margin_type(MarginType type) {
26 DCHECK(type != CUSTOM_MARGINS);
27 settings_.margin_type = type;
30 void PrintingContext::ResetSettings() {
31 ReleaseContext();
33 settings_.Clear();
35 in_print_job_ = false;
36 dialog_box_dismissed_ = false;
37 abort_printing_ = false;
40 PrintingContext::Result PrintingContext::OnError() {
41 ResetSettings();
42 return abort_printing_ ? CANCEL : FAILED;
45 PrintingContext::Result PrintingContext::UpdatePrintSettings(
46 const base::DictionaryValue& job_settings,
47 const PageRanges& ranges) {
48 ResetSettings();
50 if (!job_settings.GetBoolean(kSettingHeaderFooterEnabled,
51 &settings_.display_header_footer)) {
52 NOTREACHED();
55 int margin_type = DEFAULT_MARGINS;
56 if (!job_settings.GetInteger(kSettingMarginsType, &margin_type) ||
57 (margin_type != DEFAULT_MARGINS &&
58 margin_type != NO_MARGINS &&
59 margin_type != CUSTOM_MARGINS &&
60 margin_type != PRINTABLE_AREA_MARGINS)) {
61 NOTREACHED();
63 settings_.margin_type = static_cast<MarginType>(margin_type);
65 if (margin_type == CUSTOM_MARGINS) {
66 printing::PageSizeMargins page_size_margins;
67 GetCustomMarginsFromJobSettings(job_settings, &page_size_margins);
69 PageMargins margins_in_points;
70 margins_in_points.Clear();
71 margins_in_points.top = page_size_margins.margin_top;
72 margins_in_points.bottom = page_size_margins.margin_bottom;
73 margins_in_points.left = page_size_margins.margin_left;
74 margins_in_points.right = page_size_margins.margin_right;
76 settings_.SetCustomMargins(margins_in_points);
79 PrintingContext::Result result = UpdatePrinterSettings(job_settings, ranges);
80 PrintSettingsInitializer::InitHeaderFooterStrings(job_settings, &settings_);
81 return result;
84 } // namespace printing