| 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 14 matching lines...) Expand all Loading... |
| 25 #include "components/printing/common/print_messages.h" | 25 #include "components/printing/common/print_messages.h" |
| 26 #include "content/public/common/web_preferences.h" | 26 #include "content/public/common/web_preferences.h" |
| 27 #include "content/public/renderer/render_frame.h" | 27 #include "content/public/renderer/render_frame.h" |
| 28 #include "content/public/renderer/render_thread.h" | 28 #include "content/public/renderer/render_thread.h" |
| 29 #include "content/public/renderer/render_view.h" | 29 #include "content/public/renderer/render_view.h" |
| 30 #include "grit/components_resources.h" | 30 #include "grit/components_resources.h" |
| 31 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
| 32 #include "printing/metafile_skia_wrapper.h" | 32 #include "printing/metafile_skia_wrapper.h" |
| 33 #include "printing/pdf_metafile_skia.h" | 33 #include "printing/pdf_metafile_skia.h" |
| 34 #include "printing/units.h" | 34 #include "printing/units.h" |
| 35 #include "third_party/WebKit/public/platform/WebDoubleSize.h" |
| 35 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 36 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 36 #include "third_party/WebKit/public/platform/WebSize.h" | 37 #include "third_party/WebKit/public/platform/WebSize.h" |
| 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 38 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 38 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 39 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 39 #include "third_party/WebKit/public/web/WebDocument.h" | 40 #include "third_party/WebKit/public/web/WebDocument.h" |
| 40 #include "third_party/WebKit/public/web/WebElement.h" | 41 #include "third_party/WebKit/public/web/WebElement.h" |
| 41 #include "third_party/WebKit/public/web/WebFrameClient.h" | 42 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 42 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" | 43 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" |
| 43 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 44 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| 44 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 45 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 params.document_cookie != 0; | 122 params.document_cookie != 0; |
| 122 } | 123 } |
| 123 | 124 |
| 124 PrintMsg_Print_Params GetCssPrintParams( | 125 PrintMsg_Print_Params GetCssPrintParams( |
| 125 blink::WebLocalFrame* frame, | 126 blink::WebLocalFrame* frame, |
| 126 int page_index, | 127 int page_index, |
| 127 const PrintMsg_Print_Params& page_params) { | 128 const PrintMsg_Print_Params& page_params) { |
| 128 PrintMsg_Print_Params page_css_params = page_params; | 129 PrintMsg_Print_Params page_css_params = page_params; |
| 129 int dpi = GetDPI(&page_params); | 130 int dpi = GetDPI(&page_params); |
| 130 | 131 |
| 131 blink::WebSize page_size_in_pixels( | 132 blink::WebDoubleSize page_size_in_pixels( |
| 132 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch), | 133 ConvertUnitDouble(page_params.page_size.width(), dpi, kPixelsPerInch), |
| 133 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch)); | 134 ConvertUnitDouble(page_params.page_size.height(), dpi, kPixelsPerInch)); |
| 134 int margin_top_in_pixels = | 135 int margin_top_in_pixels = |
| 135 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); | 136 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); |
| 136 int margin_right_in_pixels = ConvertUnit( | 137 int margin_right_in_pixels = ConvertUnit( |
| 137 page_params.page_size.width() - | 138 page_params.page_size.width() - |
| 138 page_params.content_size.width() - page_params.margin_left, | 139 page_params.content_size.width() - page_params.margin_left, |
| 139 dpi, kPixelsPerInch); | 140 dpi, kPixelsPerInch); |
| 140 int margin_bottom_in_pixels = ConvertUnit( | 141 int margin_bottom_in_pixels = ConvertUnit( |
| 141 page_params.page_size.height() - | 142 page_params.page_size.height() - |
| 142 page_params.content_size.height() - page_params.margin_top, | 143 page_params.content_size.height() - page_params.margin_top, |
| 143 dpi, kPixelsPerInch); | 144 dpi, kPixelsPerInch); |
| 144 int margin_left_in_pixels = ConvertUnit( | 145 int margin_left_in_pixels = ConvertUnit( |
| 145 page_params.margin_left, | 146 page_params.margin_left, |
| 146 dpi, kPixelsPerInch); | 147 dpi, kPixelsPerInch); |
| 147 | 148 |
| 148 blink::WebSize original_page_size_in_pixels = page_size_in_pixels; | |
| 149 | |
| 150 if (frame) { | 149 if (frame) { |
| 151 frame->pageSizeAndMarginsInPixels(page_index, | 150 frame->pageSizeAndMarginsInPixels(page_index, |
| 152 page_size_in_pixels, | 151 page_size_in_pixels, |
| 153 margin_top_in_pixels, | 152 margin_top_in_pixels, |
| 154 margin_right_in_pixels, | 153 margin_right_in_pixels, |
| 155 margin_bottom_in_pixels, | 154 margin_bottom_in_pixels, |
| 156 margin_left_in_pixels); | 155 margin_left_in_pixels); |
| 157 } | 156 } |
| 158 | 157 |
| 159 int new_content_width = page_size_in_pixels.width - | 158 double new_content_width = page_size_in_pixels.width() - |
| 160 margin_left_in_pixels - margin_right_in_pixels; | 159 margin_left_in_pixels - margin_right_in_pixels; |
| 161 int new_content_height = page_size_in_pixels.height - | 160 double new_content_height = page_size_in_pixels.height() - |
| 162 margin_top_in_pixels - margin_bottom_in_pixels; | 161 margin_top_in_pixels - margin_bottom_in_pixels; |
| 163 | 162 |
| 164 // Invalid page size and/or margins. We just use the default setting. | 163 // Invalid page size and/or margins. We just use the default setting. |
| 165 if (new_content_width < 1 || new_content_height < 1) { | 164 if (new_content_width < 1 || new_content_height < 1) { |
| 166 CHECK(frame != NULL); | 165 CHECK(frame != NULL); |
| 167 page_css_params = GetCssPrintParams(NULL, page_index, page_params); | 166 page_css_params = GetCssPrintParams(NULL, page_index, page_params); |
| 168 return page_css_params; | 167 return page_css_params; |
| 169 } | 168 } |
| 170 | 169 |
| 170 page_css_params.page_size = |
| 171 gfx::Size(ConvertUnit(page_size_in_pixels.width(), kPixelsPerInch, dpi), |
| 172 ConvertUnit(page_size_in_pixels.height(), kPixelsPerInch, dpi)); |
| 171 page_css_params.content_size = | 173 page_css_params.content_size = |
| 172 gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi), | 174 gfx::Size(ConvertUnit(new_content_width, kPixelsPerInch, dpi), |
| 173 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); | 175 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); |
| 174 | |
| 175 if (original_page_size_in_pixels != page_size_in_pixels) { | |
| 176 page_css_params.page_size = | |
| 177 gfx::Size(ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi), | |
| 178 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi)); | |
| 179 } else { | |
| 180 // Printing frame doesn't have any page size css. Pixels to dpi conversion | |
| 181 // causes rounding off errors. Therefore use the default page size values | |
| 182 // directly. | |
| 183 page_css_params.page_size = page_params.page_size; | |
| 184 } | |
| 185 | 176 |
| 186 page_css_params.margin_top = | 177 page_css_params.margin_top = |
| 187 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); | 178 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); |
| 188 page_css_params.margin_left = | 179 page_css_params.margin_left = |
| 189 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi); | 180 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi); |
| 190 return page_css_params; | 181 return page_css_params; |
| 191 } | 182 } |
| 192 | 183 |
| 193 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, | 184 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, |
| 194 PrintMsg_Print_Params* params_to_fit) { | 185 PrintMsg_Print_Params* params_to_fit) { |
| (...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2261 blink::WebConsoleMessage::LevelWarning, message)); | 2252 blink::WebConsoleMessage::LevelWarning, message)); |
| 2262 return false; | 2253 return false; |
| 2263 } | 2254 } |
| 2264 | 2255 |
| 2265 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2256 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2266 // Reset counter on successful print. | 2257 // Reset counter on successful print. |
| 2267 count_ = 0; | 2258 count_ = 0; |
| 2268 } | 2259 } |
| 2269 | 2260 |
| 2270 } // namespace printing | 2261 } // namespace printing |
| OLD | NEW |