Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 params.document_cookie != 0; | 119 params.document_cookie != 0; |
| 120 } | 120 } |
| 121 | 121 |
| 122 PrintMsg_Print_Params GetCssPrintParams( | 122 PrintMsg_Print_Params GetCssPrintParams( |
| 123 blink::WebFrame* frame, | 123 blink::WebFrame* frame, |
| 124 int page_index, | 124 int page_index, |
| 125 const PrintMsg_Print_Params& page_params) { | 125 const PrintMsg_Print_Params& page_params) { |
| 126 PrintMsg_Print_Params page_css_params = page_params; | 126 PrintMsg_Print_Params page_css_params = page_params; |
| 127 int dpi = GetDPI(&page_params); | 127 int dpi = GetDPI(&page_params); |
| 128 | 128 |
| 129 blink::WebSize page_size_in_pixels( | 129 blink::WebFloatSize page_size_in_pixels( |
| 130 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch), | 130 ConvertUnitDouble(page_params.page_size.width(), dpi, kPixelsPerInch), |
| 131 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch)); | 131 ConvertUnitDouble(page_params.page_size.height(), dpi, kPixelsPerInch)); |
| 132 int margin_top_in_pixels = | 132 int margin_top_in_pixels = |
| 133 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); | 133 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); |
| 134 int margin_right_in_pixels = ConvertUnit( | 134 int margin_right_in_pixels = ConvertUnit( |
| 135 page_params.page_size.width() - | 135 page_params.page_size.width() - |
| 136 page_params.content_size.width() - page_params.margin_left, | 136 page_params.content_size.width() - page_params.margin_left, |
| 137 dpi, kPixelsPerInch); | 137 dpi, kPixelsPerInch); |
| 138 int margin_bottom_in_pixels = ConvertUnit( | 138 int margin_bottom_in_pixels = ConvertUnit( |
| 139 page_params.page_size.height() - | 139 page_params.page_size.height() - |
| 140 page_params.content_size.height() - page_params.margin_top, | 140 page_params.content_size.height() - page_params.margin_top, |
| 141 dpi, kPixelsPerInch); | 141 dpi, kPixelsPerInch); |
| 142 int margin_left_in_pixels = ConvertUnit( | 142 int margin_left_in_pixels = ConvertUnit( |
| 143 page_params.margin_left, | 143 page_params.margin_left, |
| 144 dpi, kPixelsPerInch); | 144 dpi, kPixelsPerInch); |
| 145 | 145 |
| 146 blink::WebSize original_page_size_in_pixels = page_size_in_pixels; | |
| 147 | |
| 148 if (frame) { | 146 if (frame) { |
| 149 frame->pageSizeAndMarginsInPixels(page_index, | 147 frame->pageSizeAndMarginsInPixels(page_index, |
| 150 page_size_in_pixels, | 148 page_size_in_pixels, |
| 151 margin_top_in_pixels, | 149 margin_top_in_pixels, |
| 152 margin_right_in_pixels, | 150 margin_right_in_pixels, |
| 153 margin_bottom_in_pixels, | 151 margin_bottom_in_pixels, |
| 154 margin_left_in_pixels); | 152 margin_left_in_pixels); |
| 155 } | 153 } |
| 156 | 154 |
| 157 int new_content_width = page_size_in_pixels.width - | 155 float new_content_width = page_size_in_pixels.width - |
| 158 margin_left_in_pixels - margin_right_in_pixels; | 156 margin_left_in_pixels - margin_right_in_pixels; |
| 159 int new_content_height = page_size_in_pixels.height - | 157 float new_content_height = page_size_in_pixels.height - |
| 160 margin_top_in_pixels - margin_bottom_in_pixels; | 158 margin_top_in_pixels - margin_bottom_in_pixels; |
| 161 | 159 |
| 162 // Invalid page size and/or margins. We just use the default setting. | 160 // Invalid page size and/or margins. We just use the default setting. |
| 163 if (new_content_width < 1 || new_content_height < 1) { | 161 if (new_content_width < 1 || new_content_height < 1) { |
| 164 CHECK(frame != NULL); | 162 CHECK(frame != NULL); |
| 165 page_css_params = GetCssPrintParams(NULL, page_index, page_params); | 163 page_css_params = GetCssPrintParams(NULL, page_index, page_params); |
| 166 return page_css_params; | 164 return page_css_params; |
| 167 } | 165 } |
| 168 | 166 |
| 167 page_css_params.page_size = | |
| 168 gfx::Size(ConvertUnit(page_size_in_pixels.width, | |
| 169 kPixelsPerInch, dpi), | |
| 170 ConvertUnit(page_size_in_pixels.height, | |
|
Lei Zhang
2016/07/06 18:26:45
Just run: clang-format -i -style=Chromium $file, a
| |
| 171 kPixelsPerInch, dpi)); | |
| 169 page_css_params.content_size = | 172 page_css_params.content_size = |
| 170 gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi), | 173 gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi), |
| 171 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); | 174 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); |
| 172 | |
| 173 if (original_page_size_in_pixels != page_size_in_pixels) { | |
| 174 page_css_params.page_size = | |
| 175 gfx::Size(ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi), | |
| 176 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi)); | |
| 177 } else { | |
| 178 // Printing frame doesn't have any page size css. Pixels to dpi conversion | |
| 179 // causes rounding off errors. Therefore use the default page size values | |
| 180 // directly. | |
| 181 page_css_params.page_size = page_params.page_size; | |
| 182 } | |
| 183 | 175 |
| 184 page_css_params.margin_top = | 176 page_css_params.margin_top = |
| 185 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); | 177 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); |
| 186 page_css_params.margin_left = | 178 page_css_params.margin_left = |
| 187 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi); | 179 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi); |
| 188 return page_css_params; | 180 return page_css_params; |
| 189 } | 181 } |
| 190 | 182 |
| 191 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, | 183 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, |
| 192 PrintMsg_Print_Params* params_to_fit) { | 184 PrintMsg_Print_Params* params_to_fit) { |
| (...skipping 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2250 blink::WebConsoleMessage::LevelWarning, message)); | 2242 blink::WebConsoleMessage::LevelWarning, message)); |
| 2251 return false; | 2243 return false; |
| 2252 } | 2244 } |
| 2253 | 2245 |
| 2254 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2246 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2255 // Reset counter on successful print. | 2247 // Reset counter on successful print. |
| 2256 count_ = 0; | 2248 count_ = 0; |
| 2257 } | 2249 } |
| 2258 | 2250 |
| 2259 } // namespace printing | 2251 } // namespace printing |
| OLD | NEW |