| 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 "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // too long. This will be removed soon. http://crbug.com/92000 | 157 // too long. This will be removed soon. http://crbug.com/92000 |
| 158 settings->margin_top = 0; | 158 settings->margin_top = 0; |
| 159 settings->margin_left = 0; | 159 settings->margin_left = 0; |
| 160 settings->printable_size.set_width(settings->page_size.width()); | 160 settings->printable_size.set_width(settings->page_size.width()); |
| 161 settings->printable_size.set_height(settings->page_size.height()); | 161 settings->printable_size.set_height(settings->page_size.height()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Get the margins option selected and set custom margins appropriately. | 164 // Get the margins option selected and set custom margins appropriately. |
| 165 void SetCustomMarginsIfSelected(const DictionaryValue& job_settings, | 165 void SetCustomMarginsIfSelected(const DictionaryValue& job_settings, |
| 166 PrintMsg_PrintPages_Params* settings) { | 166 PrintMsg_PrintPages_Params* settings) { |
| 167 bool default_margins_selected; | 167 int margin_type = printing::DEFAULT_MARGINS; |
| 168 if (!job_settings.GetBoolean(printing::kSettingDefaultMarginsSelected, | 168 if (!job_settings.GetInteger(printing::kSettingMarginsType, &margin_type)) { |
| 169 &default_margins_selected)) { | |
| 170 NOTREACHED(); | 169 NOTREACHED(); |
| 171 default_margins_selected = true; | |
| 172 } | 170 } |
| 173 | 171 |
| 174 if (default_margins_selected) | 172 if (margin_type == printing::DEFAULT_MARGINS) |
| 175 return; | 173 return; |
| 176 | 174 |
| 177 DictionaryValue* custom_margins; | |
| 178 if (!job_settings.GetDictionary(printing::kSettingMargins, | |
| 179 &custom_margins)) { | |
| 180 NOTREACHED(); | |
| 181 return; | |
| 182 } | |
| 183 | |
| 184 double custom_margin_top_in_points = 0; | 175 double custom_margin_top_in_points = 0; |
| 185 double custom_margin_left_in_points = 0; | 176 double custom_margin_left_in_points = 0; |
| 186 double custom_margin_right_in_points = 0; | 177 double custom_margin_right_in_points = 0; |
| 187 double custom_margin_bottom_in_points = 0; | 178 double custom_margin_bottom_in_points = 0; |
| 188 if (!custom_margins->GetDouble(printing::kSettingMarginTop, | 179 if (margin_type == printing::CUSTOM_MARGINS) { |
| 189 &custom_margin_top_in_points) || | 180 DictionaryValue* custom_margins; |
| 190 !custom_margins->GetDouble(printing::kSettingMarginLeft, | 181 if (!job_settings.GetDictionary(printing::kSettingMarginsCustom, |
| 191 &custom_margin_left_in_points) || | 182 &custom_margins)) { |
| 192 !custom_margins->GetDouble(printing::kSettingMarginRight, | 183 NOTREACHED(); |
| 193 &custom_margin_right_in_points) || | 184 return; |
| 194 !custom_margins->GetDouble(printing::kSettingMarginBottom, | 185 } |
| 195 &custom_margin_bottom_in_points)) { | 186 if (!custom_margins->GetDouble(printing::kSettingMarginTop, |
| 196 NOTREACHED(); | 187 &custom_margin_top_in_points) || |
| 197 return; | 188 !custom_margins->GetDouble(printing::kSettingMarginLeft, |
| 189 &custom_margin_left_in_points) || |
| 190 !custom_margins->GetDouble(printing::kSettingMarginRight, |
| 191 &custom_margin_right_in_points) || |
| 192 !custom_margins->GetDouble(printing::kSettingMarginBottom, |
| 193 &custom_margin_bottom_in_points)) { |
| 194 NOTREACHED(); |
| 195 return; |
| 196 } |
| 198 } | 197 } |
| 199 | 198 |
| 200 int dpi = GetDPI(&settings->params); | 199 int dpi = GetDPI(&settings->params); |
| 201 double custom_margin_top_in_dots = ConvertUnitDouble( | 200 double custom_margin_top_in_dots = ConvertUnitDouble( |
| 202 custom_margin_top_in_points, printing::kPointsPerInch, dpi); | 201 custom_margin_top_in_points, printing::kPointsPerInch, dpi); |
| 203 double custom_margin_left_in_dots = ConvertUnitDouble( | 202 double custom_margin_left_in_dots = ConvertUnitDouble( |
| 204 custom_margin_left_in_points, printing::kPointsPerInch, dpi); | 203 custom_margin_left_in_points, printing::kPointsPerInch, dpi); |
| 205 double custom_margin_right_in_dots = ConvertUnitDouble( | 204 double custom_margin_right_in_dots = ConvertUnitDouble( |
| 206 custom_margin_right_in_points, printing::kPointsPerInch, dpi); | 205 custom_margin_right_in_points, printing::kPointsPerInch, dpi); |
| 207 double custom_margin_bottom_in_dots = ConvertUnitDouble( | 206 double custom_margin_bottom_in_dots = ConvertUnitDouble( |
| (...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1587 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1589 return prep_frame_view_->GetPrintCanvasSize(); | 1588 return prep_frame_view_->GetPrintCanvasSize(); |
| 1590 } | 1589 } |
| 1591 | 1590 |
| 1592 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1591 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1593 prep_frame_view_.reset(); | 1592 prep_frame_view_.reset(); |
| 1594 metafile_.reset(); | 1593 metafile_.reset(); |
| 1595 pages_to_render_.clear(); | 1594 pages_to_render_.clear(); |
| 1596 error_ = PREVIEW_ERROR_NONE; | 1595 error_ = PREVIEW_ERROR_NONE; |
| 1597 } | 1596 } |
| OLD | NEW |