OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/printing_context.h" | 5 #include "printing/printing_context.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "printing/page_setup.h" | 9 #include "printing/page_setup.h" |
10 #include "printing/page_size_margins.h" | 10 #include "printing/page_size_margins.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 PrintingContext::Result PrintingContext::OnError() { | 40 PrintingContext::Result PrintingContext::OnError() { |
41 ResetSettings(); | 41 ResetSettings(); |
42 return abort_printing_ ? CANCEL : FAILED; | 42 return abort_printing_ ? CANCEL : FAILED; |
43 } | 43 } |
44 | 44 |
45 PrintingContext::Result PrintingContext::UpdatePrintSettings( | 45 PrintingContext::Result PrintingContext::UpdatePrintSettings( |
46 const base::DictionaryValue& job_settings, | 46 const base::DictionaryValue& job_settings, |
47 const PageRanges& ranges) { | 47 const PageRanges& ranges) { |
48 ResetSettings(); | 48 ResetSettings(); |
49 | 49 |
50 if (!job_settings.GetBoolean(kSettingHeaderFooterEnabled, | 50 job_settings.GetBoolean(kSettingHeaderFooterEnabled, |
51 &settings_.display_header_footer)) { | 51 &settings_.display_header_footer); |
52 NOTREACHED(); | |
53 } | |
54 | 52 |
55 int margin_type = DEFAULT_MARGINS; | 53 int margin_type = DEFAULT_MARGINS; |
56 if (!job_settings.GetInteger(kSettingMarginsType, &margin_type) || | 54 if (!job_settings.GetInteger(kSettingMarginsType, &margin_type) || |
57 (margin_type != DEFAULT_MARGINS && | 55 (margin_type != DEFAULT_MARGINS && |
58 margin_type != NO_MARGINS && | 56 margin_type != NO_MARGINS && |
59 margin_type != CUSTOM_MARGINS && | 57 margin_type != CUSTOM_MARGINS && |
60 margin_type != PRINTABLE_AREA_MARGINS)) { | 58 margin_type != PRINTABLE_AREA_MARGINS)) { |
61 NOTREACHED(); | 59 margin_type = DEFAULT_MARGINS; |
62 } | 60 } |
63 settings_.margin_type = static_cast<MarginType>(margin_type); | 61 settings_.margin_type = static_cast<MarginType>(margin_type); |
64 | 62 |
65 if (margin_type == CUSTOM_MARGINS) { | 63 if (margin_type == CUSTOM_MARGINS) { |
66 printing::PageSizeMargins page_size_margins; | 64 printing::PageSizeMargins page_size_margins; |
67 GetCustomMarginsFromJobSettings(job_settings, &page_size_margins); | 65 GetCustomMarginsFromJobSettings(job_settings, &page_size_margins); |
68 | 66 |
69 PageMargins margins_in_points; | 67 PageMargins margins_in_points; |
70 margins_in_points.Clear(); | 68 margins_in_points.Clear(); |
71 margins_in_points.top = page_size_margins.margin_top; | 69 margins_in_points.top = page_size_margins.margin_top; |
72 margins_in_points.bottom = page_size_margins.margin_bottom; | 70 margins_in_points.bottom = page_size_margins.margin_bottom; |
73 margins_in_points.left = page_size_margins.margin_left; | 71 margins_in_points.left = page_size_margins.margin_left; |
74 margins_in_points.right = page_size_margins.margin_right; | 72 margins_in_points.right = page_size_margins.margin_right; |
75 | 73 |
76 settings_.SetCustomMargins(margins_in_points); | 74 settings_.SetCustomMargins(margins_in_points); |
77 } | 75 } |
78 | 76 |
79 PrintingContext::Result result = UpdatePrinterSettings(job_settings, ranges); | 77 PrintingContext::Result result = UpdatePrinterSettings(job_settings, ranges); |
80 PrintSettingsInitializer::InitHeaderFooterStrings(job_settings, &settings_); | 78 PrintSettingsInitializer::InitHeaderFooterStrings(job_settings, &settings_); |
81 | 79 |
82 if (!job_settings.GetBoolean(kSettingShouldPrintBackgrounds, | 80 job_settings.GetBoolean(kSettingShouldPrintBackgrounds, |
83 &settings_.should_print_backgrounds)) { | 81 &settings_.should_print_backgrounds); |
84 NOTREACHED(); | 82 job_settings.GetBoolean(kSettingShouldPrintSelectionOnly, |
85 } | 83 &settings_.selection_only); |
86 | |
87 if (!job_settings.GetBoolean(kSettingShouldPrintSelectionOnly, | |
88 &settings_.selection_only)) { | |
89 NOTREACHED(); | |
90 } | |
91 | |
92 return result; | 84 return result; |
93 } | 85 } |
94 | 86 |
95 } // namespace printing | 87 } // namespace printing |
OLD | NEW |