Chromium Code Reviews| 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/print_settings_initializer.h" | 5 #include "printing/print_settings_initializer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "printing/page_size_margins.h" | |
| 15 #include "printing/print_job_constants.h" | 16 #include "printing/print_job_constants.h" |
| 16 #include "printing/print_settings.h" | 17 #include "printing/print_settings.h" |
| 17 #include "printing/units.h" | 18 #include "printing/units.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | |
| 19 #include "ui/gfx/font_list.h" | |
| 20 #include "ui/gfx/text_elider.h" | |
| 21 #include "url/gurl.h" | |
| 22 | 19 |
| 23 namespace printing { | 20 namespace printing { |
| 24 | 21 |
| 25 void PrintSettingsInitializer::InitHeaderFooterStrings( | 22 bool PrintSettingsInitializer::InitSettings( |
| 26 const base::DictionaryValue& job_settings, | 23 const base::DictionaryValue& job_settings, |
| 27 PrintSettings* print_settings) { | 24 const PageRanges& ranges, |
| 28 if (!job_settings.GetBoolean(kSettingHeaderFooterEnabled, | 25 PrintSettings* settings) { |
| 29 &print_settings->display_header_footer)) { | 26 bool display_header_footer = false; |
| 30 NOTREACHED(); | 27 job_settings.GetBoolean(kSettingHeaderFooterEnabled, |
|
Lei Zhang
2013/10/28 23:40:23
Should we save the result and check it with a DCHE
Vitaly Buka (NO REVIEWS)
2013/10/29 00:31:21
Maybe it's better to return error here.
On 2013/1
| |
| 31 } | 28 &display_header_footer); |
| 32 if (!print_settings->display_header_footer) | 29 settings->set_display_header_footer(display_header_footer); |
| 33 return; | |
| 34 | 30 |
| 35 base::string16 title; | 31 if (settings->display_header_footer()) { |
| 36 base::string16 url; | 32 base::string16 title; |
| 37 if (!job_settings.GetString(kSettingHeaderFooterTitle, &title) || | 33 job_settings.GetString(kSettingHeaderFooterTitle, &title); |
| 38 !job_settings.GetString(kSettingHeaderFooterURL, &url)) { | 34 settings->set_title(title); |
| 39 NOTREACHED(); | 35 base::string16 url; |
| 36 job_settings.GetString(kSettingHeaderFooterURL, &url); | |
| 37 settings->set_url(url); | |
| 40 } | 38 } |
| 41 | 39 |
| 42 print_settings->title = title; | 40 bool backgrounds = false; |
| 43 const gfx::FontList& default_fonts = | 41 job_settings.GetBoolean(kSettingShouldPrintBackgrounds, &backgrounds); |
| 44 ui::ResourceBundle::GetSharedInstance().GetFontList( | 42 settings->set_should_print_backgrounds(backgrounds); |
| 45 ui::ResourceBundle::BaseFont); | 43 bool selection_only = false; |
| 46 print_settings->url = gfx::ElideUrl(GURL(url), default_fonts, 0, | 44 job_settings.GetBoolean(kSettingShouldPrintSelectionOnly, &selection_only); |
|
Lei Zhang
2013/10/28 23:40:23
Did the elide functionality move elsewhere or is i
Vitaly Buka (NO REVIEWS)
2013/10/29 00:31:21
It should be removed before when headers/footers s
| |
| 47 std::string()); | 45 settings->set_selection_only(selection_only); |
| 46 | |
| 47 int margin_type = DEFAULT_MARGINS; | |
| 48 if (!job_settings.GetInteger(kSettingMarginsType, &margin_type) || | |
| 49 (margin_type != DEFAULT_MARGINS && | |
| 50 margin_type != NO_MARGINS && | |
| 51 margin_type != CUSTOM_MARGINS && | |
| 52 margin_type != PRINTABLE_AREA_MARGINS)) { | |
| 53 margin_type = DEFAULT_MARGINS; | |
| 54 } | |
| 55 settings->set_margin_type(static_cast<MarginType>(margin_type)); | |
| 56 | |
| 57 if (margin_type == CUSTOM_MARGINS) { | |
| 58 PageSizeMargins page_size_margins; | |
| 59 GetCustomMarginsFromJobSettings(job_settings, &page_size_margins); | |
| 60 | |
| 61 PageMargins margins_in_points; | |
| 62 margins_in_points.Clear(); | |
| 63 margins_in_points.top = page_size_margins.margin_top; | |
| 64 margins_in_points.bottom = page_size_margins.margin_bottom; | |
| 65 margins_in_points.left = page_size_margins.margin_left; | |
| 66 margins_in_points.right = page_size_margins.margin_right; | |
| 67 | |
| 68 settings->SetCustomMargins(margins_in_points); | |
| 69 } | |
| 70 | |
| 71 settings->set_ranges(ranges); | |
| 72 | |
| 73 int color = 0; | |
| 74 bool landscape = false; | |
| 75 int duplex_mode = 0; | |
| 76 base::string16 device_name; | |
| 77 bool collate = false; | |
| 78 int copies = 1; | |
| 79 | |
| 80 if (!job_settings.GetBoolean(kSettingCollate, &collate) || | |
| 81 !job_settings.GetInteger(kSettingCopies, &copies) || | |
| 82 !job_settings.GetInteger(kSettingColor, &color) || | |
| 83 !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || | |
| 84 !job_settings.GetBoolean(kSettingLandscape, &landscape) || | |
| 85 !job_settings.GetString(kSettingDeviceName, &device_name)) { | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 settings->set_collate(collate); | |
| 90 settings->set_copies(copies); | |
| 91 settings->SetOrientation(landscape); | |
| 92 settings->set_device_name(device_name); | |
| 93 settings->set_duplex_mode(static_cast<DuplexMode>(duplex_mode)); | |
| 94 settings->set_color(static_cast<ColorModel>(color)); | |
| 95 | |
| 96 return true; | |
| 48 } | 97 } |
| 49 | 98 |
| 50 } // namespace printing | 99 } // namespace printing |
| OLD | NEW |