| 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 "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/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 #if defined(OS_WIN) || defined(OS_MACOSX) | 54 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 55 #define USE_RENDER_TEXT | 55 #define USE_RENDER_TEXT |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 #if defined(USE_RENDER_TEXT) | 58 #if defined(USE_RENDER_TEXT) |
| 59 #include "ui/gfx/canvas.h" | 59 #include "ui/gfx/canvas.h" |
| 60 #include "ui/gfx/render_text.h" | 60 #include "ui/gfx/render_text.h" |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 using printing::ConvertPixelsToPoint; | |
| 64 using printing::ConvertPixelsToPointDouble; | |
| 65 using printing::ConvertPointsToPixelDouble; | |
| 66 using printing::ConvertUnit; | |
| 67 using printing::ConvertUnitDouble; | |
| 68 using printing::GetHeaderFooterSegmentWidth; | |
| 69 using printing::PageSizeMargins; | |
| 70 using WebKit::WebConsoleMessage; | |
| 71 using WebKit::WebDocument; | |
| 72 using WebKit::WebElement; | |
| 73 using WebKit::WebFrame; | |
| 74 using WebKit::WebNode; | |
| 75 using WebKit::WebPlugin; | |
| 76 using WebKit::WebPluginDocument; | |
| 77 using WebKit::WebPrintParams; | |
| 78 using WebKit::WebSize; | |
| 79 using WebKit::WebString; | |
| 80 using WebKit::WebURLRequest; | |
| 81 using WebKit::WebView; | |
| 82 | |
| 83 namespace { | 63 namespace { |
| 84 | 64 |
| 85 #if defined(USE_RENDER_TEXT) | 65 #if defined(USE_RENDER_TEXT) |
| 86 typedef gfx::RenderText* HeaderFooterPaint; | 66 typedef gfx::RenderText* HeaderFooterPaint; |
| 87 #else | 67 #else |
| 88 typedef SkPaint HeaderFooterPaint; | 68 typedef SkPaint HeaderFooterPaint; |
| 89 #endif | 69 #endif |
| 90 | 70 |
| 91 const double kMinDpi = 1.0; | 71 const double kMinDpi = 1.0; |
| 92 | 72 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 oldParams.params.display_header_footer == | 114 oldParams.params.display_header_footer == |
| 135 newParams.params.display_header_footer && | 115 newParams.params.display_header_footer && |
| 136 oldParams.params.date == newParams.params.date && | 116 oldParams.params.date == newParams.params.date && |
| 137 oldParams.params.title == newParams.params.title && | 117 oldParams.params.title == newParams.params.title && |
| 138 oldParams.params.url == newParams.params.url && | 118 oldParams.params.url == newParams.params.url && |
| 139 std::equal(oldParams.pages.begin(), oldParams.pages.end(), | 119 std::equal(oldParams.pages.begin(), oldParams.pages.end(), |
| 140 newParams.pages.begin()); | 120 newParams.pages.begin()); |
| 141 } | 121 } |
| 142 | 122 |
| 143 PrintMsg_Print_Params GetCssPrintParams( | 123 PrintMsg_Print_Params GetCssPrintParams( |
| 144 WebFrame* frame, | 124 WebKit::WebFrame* frame, |
| 145 int page_index, | 125 int page_index, |
| 146 const PrintMsg_Print_Params& page_params) { | 126 const PrintMsg_Print_Params& page_params) { |
| 147 PrintMsg_Print_Params page_css_params = page_params; | 127 PrintMsg_Print_Params page_css_params = page_params; |
| 148 int dpi = GetDPI(&page_params); | 128 int dpi = GetDPI(&page_params); |
| 149 WebSize page_size_in_pixels( | 129 |
| 150 ConvertUnit(page_params.page_size.width(), | 130 using printing::ConvertUnit; |
| 151 dpi, printing::kPixelsPerInch), | 131 using printing::kPixelsPerInch; |
| 152 ConvertUnit(page_params.page_size.height(), | 132 WebKit::WebSize page_size_in_pixels( |
| 153 dpi, printing::kPixelsPerInch)); | 133 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch), |
| 154 int margin_top_in_pixels = ConvertUnit( | 134 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch)); |
| 155 page_params.margin_top, | 135 int margin_top_in_pixels = |
| 156 dpi, printing::kPixelsPerInch); | 136 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); |
| 157 int margin_right_in_pixels = ConvertUnit( | 137 int margin_right_in_pixels = ConvertUnit( |
| 158 page_params.page_size.width() - | 138 page_params.page_size.width() - |
| 159 page_params.content_size.width() - page_params.margin_left, | 139 page_params.content_size.width() - page_params.margin_left, |
| 160 dpi, printing::kPixelsPerInch); | 140 dpi, kPixelsPerInch); |
| 161 int margin_bottom_in_pixels = ConvertUnit( | 141 int margin_bottom_in_pixels = ConvertUnit( |
| 162 page_params.page_size.height() - | 142 page_params.page_size.height() - |
| 163 page_params.content_size.height() - page_params.margin_top, | 143 page_params.content_size.height() - page_params.margin_top, |
| 164 dpi, printing::kPixelsPerInch); | 144 dpi, kPixelsPerInch); |
| 165 int margin_left_in_pixels = ConvertUnit( | 145 int margin_left_in_pixels = ConvertUnit( |
| 166 page_params.margin_left, | 146 page_params.margin_left, |
| 167 dpi, printing::kPixelsPerInch); | 147 dpi, kPixelsPerInch); |
| 168 | 148 |
| 169 WebSize original_page_size_in_pixels = page_size_in_pixels; | 149 WebKit::WebSize original_page_size_in_pixels = page_size_in_pixels; |
| 170 | 150 |
| 171 if (frame) { | 151 if (frame) { |
| 172 frame->pageSizeAndMarginsInPixels(page_index, | 152 frame->pageSizeAndMarginsInPixels(page_index, |
| 173 page_size_in_pixels, | 153 page_size_in_pixels, |
| 174 margin_top_in_pixels, | 154 margin_top_in_pixels, |
| 175 margin_right_in_pixels, | 155 margin_right_in_pixels, |
| 176 margin_bottom_in_pixels, | 156 margin_bottom_in_pixels, |
| 177 margin_left_in_pixels); | 157 margin_left_in_pixels); |
| 178 } | 158 } |
| 179 | 159 |
| 180 int new_content_width = page_size_in_pixels.width - | 160 int new_content_width = page_size_in_pixels.width - |
| 181 margin_left_in_pixels - margin_right_in_pixels; | 161 margin_left_in_pixels - margin_right_in_pixels; |
| 182 int new_content_height = page_size_in_pixels.height - | 162 int new_content_height = page_size_in_pixels.height - |
| 183 margin_top_in_pixels - margin_bottom_in_pixels; | 163 margin_top_in_pixels - margin_bottom_in_pixels; |
| 184 | 164 |
| 185 // Invalid page size and/or margins. We just use the default setting. | 165 // Invalid page size and/or margins. We just use the default setting. |
| 186 if (new_content_width < 1 || new_content_height < 1) { | 166 if (new_content_width < 1 || new_content_height < 1) { |
| 187 CHECK(frame != NULL); | 167 CHECK(frame != NULL); |
| 188 page_css_params = GetCssPrintParams(NULL, page_index, page_params); | 168 page_css_params = GetCssPrintParams(NULL, page_index, page_params); |
| 189 return page_css_params; | 169 return page_css_params; |
| 190 } | 170 } |
| 191 | 171 |
| 192 page_css_params.content_size = gfx::Size( | 172 page_css_params.content_size = gfx::Size( |
| 193 static_cast<int>(ConvertUnit(new_content_width, | 173 ConvertUnit(new_content_width, kPixelsPerInch, dpi), |
| 194 printing::kPixelsPerInch, dpi)), | 174 ConvertUnit(new_content_height, kPixelsPerInch, dpi)); |
| 195 static_cast<int>(ConvertUnit(new_content_height, | |
| 196 printing::kPixelsPerInch, dpi))); | |
| 197 | 175 |
| 198 if (original_page_size_in_pixels != page_size_in_pixels) { | 176 if (original_page_size_in_pixels != page_size_in_pixels) { |
| 199 page_css_params.page_size = gfx::Size( | 177 page_css_params.page_size = gfx::Size( |
| 200 static_cast<int>(ConvertUnit(page_size_in_pixels.width, | 178 ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi), |
| 201 printing::kPixelsPerInch, dpi)), | 179 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi)); |
| 202 static_cast<int>(ConvertUnit(page_size_in_pixels.height, | |
| 203 printing::kPixelsPerInch, dpi))); | |
| 204 } else { | 180 } else { |
| 205 // Printing frame doesn't have any page size css. Pixels to dpi conversion | 181 // Printing frame doesn't have any page size css. Pixels to dpi conversion |
| 206 // causes rounding off errors. Therefore use the default page size values | 182 // causes rounding off errors. Therefore use the default page size values |
| 207 // directly. | 183 // directly. |
| 208 page_css_params.page_size = page_params.page_size; | 184 page_css_params.page_size = page_params.page_size; |
| 209 } | 185 } |
| 210 | 186 |
| 211 page_css_params.margin_top = | 187 page_css_params.margin_top = |
| 212 static_cast<int>(ConvertUnit(margin_top_in_pixels, | 188 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi); |
| 213 printing::kPixelsPerInch, dpi)); | |
| 214 | |
| 215 page_css_params.margin_left = | 189 page_css_params.margin_left = |
| 216 static_cast<int>(ConvertUnit(margin_left_in_pixels, | 190 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi); |
| 217 printing::kPixelsPerInch, dpi)); | |
| 218 return page_css_params; | 191 return page_css_params; |
| 219 } | 192 } |
| 220 | 193 |
| 221 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, | 194 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, |
| 222 PrintMsg_Print_Params* params_to_fit) { | 195 PrintMsg_Print_Params* params_to_fit) { |
| 223 double content_width = | 196 double content_width = |
| 224 static_cast<double>(params_to_fit->content_size.width()); | 197 static_cast<double>(params_to_fit->content_size.width()); |
| 225 double content_height = | 198 double content_height = |
| 226 static_cast<double>(params_to_fit->content_size.height()); | 199 static_cast<double>(params_to_fit->content_size.height()); |
| 227 int default_page_size_height = page_params.page_size.height(); | 200 int default_page_size_height = page_params.page_size.height(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 250 (default_page_size_width - css_page_size_width * scale_factor) / 2 + | 223 (default_page_size_width - css_page_size_width * scale_factor) / 2 + |
| 251 (params_to_fit->margin_left * scale_factor)); | 224 (params_to_fit->margin_left * scale_factor)); |
| 252 params_to_fit->content_size = gfx::Size( | 225 params_to_fit->content_size = gfx::Size( |
| 253 static_cast<int>(content_width), static_cast<int>(content_height)); | 226 static_cast<int>(content_width), static_cast<int>(content_height)); |
| 254 params_to_fit->page_size = page_params.page_size; | 227 params_to_fit->page_size = page_params.page_size; |
| 255 return scale_factor; | 228 return scale_factor; |
| 256 } | 229 } |
| 257 | 230 |
| 258 void CalculatePageLayoutFromPrintParams( | 231 void CalculatePageLayoutFromPrintParams( |
| 259 const PrintMsg_Print_Params& params, | 232 const PrintMsg_Print_Params& params, |
| 260 PageSizeMargins* page_layout_in_points) { | 233 printing::PageSizeMargins* page_layout_in_points) { |
| 261 int dpi = GetDPI(¶ms); | 234 int dpi = GetDPI(¶ms); |
| 262 int content_width = params.content_size.width(); | 235 int content_width = params.content_size.width(); |
| 263 int content_height = params.content_size.height(); | 236 int content_height = params.content_size.height(); |
| 264 | 237 |
| 265 int margin_bottom = params.page_size.height() - | 238 int margin_bottom = params.page_size.height() - |
| 266 content_height - params.margin_top; | 239 content_height - params.margin_top; |
| 267 int margin_right = params.page_size.width() - | 240 int margin_right = params.page_size.width() - |
| 268 content_width - params.margin_left; | 241 content_width - params.margin_left; |
| 269 | 242 |
| 270 page_layout_in_points->content_width = ConvertUnit( | 243 using printing::ConvertUnit; |
| 271 content_width, dpi, printing::kPointsPerInch); | 244 using printing::kPointsPerInch; |
| 272 page_layout_in_points->content_height = ConvertUnit( | 245 page_layout_in_points->content_width = |
| 273 content_height, dpi, printing::kPointsPerInch); | 246 ConvertUnit(content_width, dpi, kPointsPerInch); |
| 274 page_layout_in_points->margin_top = ConvertUnit( | 247 page_layout_in_points->content_height = |
| 275 params.margin_top, dpi, printing::kPointsPerInch); | 248 ConvertUnit(content_height, dpi, kPointsPerInch); |
| 276 page_layout_in_points->margin_right = ConvertUnit( | 249 page_layout_in_points->margin_top = |
| 277 margin_right, dpi, printing::kPointsPerInch); | 250 ConvertUnit(params.margin_top, dpi, kPointsPerInch); |
| 278 page_layout_in_points->margin_bottom = ConvertUnit( | 251 page_layout_in_points->margin_right = |
| 279 margin_bottom, dpi, printing::kPointsPerInch); | 252 ConvertUnit(margin_right, dpi, kPointsPerInch); |
| 280 page_layout_in_points->margin_left = ConvertUnit( | 253 page_layout_in_points->margin_bottom = |
| 281 params.margin_left, dpi, printing::kPointsPerInch); | 254 ConvertUnit(margin_bottom, dpi, kPointsPerInch); |
| 255 page_layout_in_points->margin_left = |
| 256 ConvertUnit(params.margin_left, dpi, kPointsPerInch); |
| 282 } | 257 } |
| 283 | 258 |
| 284 void EnsureOrientationMatches(const PrintMsg_Print_Params& css_params, | 259 void EnsureOrientationMatches(const PrintMsg_Print_Params& css_params, |
| 285 PrintMsg_Print_Params* page_params) { | 260 PrintMsg_Print_Params* page_params) { |
| 286 if ((page_params->page_size.width() > page_params->page_size.height()) == | 261 if ((page_params->page_size.width() > page_params->page_size.height()) == |
| 287 (css_params.page_size.width() > css_params.page_size.height())) { | 262 (css_params.page_size.width() > css_params.page_size.height())) { |
| 288 return; | 263 return; |
| 289 } | 264 } |
| 290 | 265 |
| 291 // Swap the |width| and |height| values. | 266 // Swap the |width| and |height| values. |
| 292 page_params->page_size.SetSize(page_params->page_size.height(), | 267 page_params->page_size.SetSize(page_params->page_size.height(), |
| 293 page_params->page_size.width()); | 268 page_params->page_size.width()); |
| 294 page_params->content_size.SetSize(page_params->content_size.height(), | 269 page_params->content_size.SetSize(page_params->content_size.height(), |
| 295 page_params->content_size.width()); | 270 page_params->content_size.width()); |
| 296 page_params->printable_area.set_size( | 271 page_params->printable_area.set_size( |
| 297 gfx::Size(page_params->printable_area.height(), | 272 gfx::Size(page_params->printable_area.height(), |
| 298 page_params->printable_area.width())); | 273 page_params->printable_area.width())); |
| 299 } | 274 } |
| 300 | 275 |
| 301 void ComputeWebKitPrintParamsInDesiredDpi( | 276 void ComputeWebKitPrintParamsInDesiredDpi( |
| 302 const PrintMsg_Print_Params& print_params, | 277 const PrintMsg_Print_Params& print_params, |
| 303 WebPrintParams* webkit_print_params) { | 278 WebKit::WebPrintParams* webkit_print_params) { |
| 304 int dpi = GetDPI(&print_params); | 279 int dpi = GetDPI(&print_params); |
| 305 webkit_print_params->printerDPI = dpi; | 280 webkit_print_params->printerDPI = dpi; |
| 306 webkit_print_params->printScalingOption = print_params.print_scaling_option; | 281 webkit_print_params->printScalingOption = print_params.print_scaling_option; |
| 307 | 282 |
| 283 using printing::ConvertUnit; |
| 308 webkit_print_params->printContentArea.width = | 284 webkit_print_params->printContentArea.width = |
| 309 ConvertUnit(print_params.content_size.width(), dpi, | 285 ConvertUnit(print_params.content_size.width(), dpi, |
| 310 print_params.desired_dpi); | 286 print_params.desired_dpi); |
| 311 webkit_print_params->printContentArea.height = | 287 webkit_print_params->printContentArea.height = |
| 312 ConvertUnit(print_params.content_size.height(), dpi, | 288 ConvertUnit(print_params.content_size.height(), dpi, |
| 313 print_params.desired_dpi); | 289 print_params.desired_dpi); |
| 314 | 290 |
| 315 webkit_print_params->printableArea.x = | 291 webkit_print_params->printableArea.x = |
| 316 ConvertUnit(print_params.printable_area.x(), dpi, | 292 ConvertUnit(print_params.printable_area.x(), dpi, |
| 317 print_params.desired_dpi); | 293 print_params.desired_dpi); |
| 318 webkit_print_params->printableArea.y = | 294 webkit_print_params->printableArea.y = |
| 319 ConvertUnit(print_params.printable_area.y(), dpi, | 295 ConvertUnit(print_params.printable_area.y(), dpi, |
| 320 print_params.desired_dpi); | 296 print_params.desired_dpi); |
| 321 webkit_print_params->printableArea.width = | 297 webkit_print_params->printableArea.width = |
| 322 ConvertUnit(print_params.printable_area.width(), dpi, | 298 ConvertUnit(print_params.printable_area.width(), dpi, |
| 323 print_params.desired_dpi); | 299 print_params.desired_dpi); |
| 324 webkit_print_params->printableArea.height = | 300 webkit_print_params->printableArea.height = |
| 325 ConvertUnit(print_params.printable_area.height(), | 301 ConvertUnit(print_params.printable_area.height(), |
| 326 dpi, print_params.desired_dpi); | 302 dpi, print_params.desired_dpi); |
| 327 | 303 |
| 328 webkit_print_params->paperSize.width = | 304 webkit_print_params->paperSize.width = |
| 329 ConvertUnit(print_params.page_size.width(), dpi, | 305 ConvertUnit(print_params.page_size.width(), dpi, |
| 330 print_params.desired_dpi); | 306 print_params.desired_dpi); |
| 331 webkit_print_params->paperSize.height = | 307 webkit_print_params->paperSize.height = |
| 332 ConvertUnit(print_params.page_size.height(), dpi, | 308 ConvertUnit(print_params.page_size.height(), dpi, |
| 333 print_params.desired_dpi); | 309 print_params.desired_dpi); |
| 334 } | 310 } |
| 335 | 311 |
| 336 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { | 312 bool PrintingNodeOrPdfFrame(const WebKit::WebFrame* frame, |
| 313 const WebKit::WebNode& node) { |
| 337 if (!node.isNull()) | 314 if (!node.isNull()) |
| 338 return true; | 315 return true; |
| 339 if (!frame->document().isPluginDocument()) | 316 if (!frame->document().isPluginDocument()) |
| 340 return false; | 317 return false; |
| 341 WebPlugin* plugin = frame->document().to<WebPluginDocument>().plugin(); | 318 WebKit::WebPlugin* plugin = |
| 319 frame->document().to<WebKit::WebPluginDocument>().plugin(); |
| 342 return plugin && plugin->supportsPaginatedPrint(); | 320 return plugin && plugin->supportsPaginatedPrint(); |
| 343 } | 321 } |
| 344 | 322 |
| 345 bool PrintingFrameHasPageSizeStyle(WebFrame* frame, int total_page_count) { | 323 bool PrintingFrameHasPageSizeStyle(WebKit::WebFrame* frame, |
| 324 int total_page_count) { |
| 346 if (!frame) | 325 if (!frame) |
| 347 return false; | 326 return false; |
| 348 bool frame_has_custom_page_size_style = false; | 327 bool frame_has_custom_page_size_style = false; |
| 349 for (int i = 0; i < total_page_count; ++i) { | 328 for (int i = 0; i < total_page_count; ++i) { |
| 350 if (frame->hasCustomPageSizeStyle(i)) { | 329 if (frame->hasCustomPageSizeStyle(i)) { |
| 351 frame_has_custom_page_size_style = true; | 330 frame_has_custom_page_size_style = true; |
| 352 break; | 331 break; |
| 353 } | 332 } |
| 354 } | 333 } |
| 355 return frame_has_custom_page_size_style; | 334 return frame_has_custom_page_size_style; |
| 356 } | 335 } |
| 357 | 336 |
| 358 printing::MarginType GetMarginsForPdf(WebFrame* frame, const WebNode& node) { | 337 printing::MarginType GetMarginsForPdf(WebKit::WebFrame* frame, |
| 338 const WebKit::WebNode& node) { |
| 359 if (frame->isPrintScalingDisabledForPlugin(node)) | 339 if (frame->isPrintScalingDisabledForPlugin(node)) |
| 360 return printing::NO_MARGINS; | 340 return printing::NO_MARGINS; |
| 361 else | 341 else |
| 362 return printing::PRINTABLE_AREA_MARGINS; | 342 return printing::PRINTABLE_AREA_MARGINS; |
| 363 } | 343 } |
| 364 | 344 |
| 365 bool FitToPageEnabled(const DictionaryValue& job_settings) { | 345 bool FitToPageEnabled(const DictionaryValue& job_settings) { |
| 366 bool fit_to_paper_size = false; | 346 bool fit_to_paper_size = false; |
| 367 if (!job_settings.GetBoolean(printing::kSettingFitToPageEnabled, | 347 if (!job_settings.GetBoolean(printing::kSettingFitToPageEnabled, |
| 368 &fit_to_paper_size)) { | 348 &fit_to_paper_size)) { |
| 369 NOTREACHED(); | 349 NOTREACHED(); |
| 370 } | 350 } |
| 371 return fit_to_paper_size; | 351 return fit_to_paper_size; |
| 372 } | 352 } |
| 373 | 353 |
| 374 // Get the (x, y) coordinate from where printing of the current text should | 354 // Get the (x, y) coordinate from where printing of the current text should |
| 375 // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and | 355 // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and |
| 376 // vertical alignment (TOP, BOTTOM). | 356 // vertical alignment (TOP, BOTTOM). |
| 377 SkPoint GetHeaderFooterPosition( | 357 SkPoint GetHeaderFooterPosition( |
| 378 float webkit_scale_factor, | 358 float webkit_scale_factor, |
| 379 const PageSizeMargins& page_layout, | 359 const printing::PageSizeMargins& page_layout, |
| 380 printing::HorizontalHeaderFooterPosition horizontal_position, | 360 printing::HorizontalHeaderFooterPosition horizontal_position, |
| 381 printing::VerticalHeaderFooterPosition vertical_position, | 361 printing::VerticalHeaderFooterPosition vertical_position, |
| 382 double offset_to_baseline, | 362 double offset_to_baseline, |
| 383 double text_width_in_points) { | 363 double text_width_in_points) { |
| 384 SkScalar x = 0; | 364 SkScalar x = 0; |
| 385 switch (horizontal_position) { | 365 switch (horizontal_position) { |
| 386 case printing::LEFT: { | 366 case printing::LEFT: { |
| 387 x = printing::kSettingHeaderFooterInterstice - page_layout.margin_left; | 367 x = printing::kSettingHeaderFooterInterstice - page_layout.margin_left; |
| 388 break; | 368 break; |
| 389 } | 369 } |
| 390 case printing::RIGHT: { | 370 case printing::RIGHT: { |
| 391 x = page_layout.content_width + page_layout.margin_right - | 371 x = page_layout.content_width + page_layout.margin_right - |
| 392 printing::kSettingHeaderFooterInterstice - text_width_in_points; | 372 printing::kSettingHeaderFooterInterstice - text_width_in_points; |
| 393 break; | 373 break; |
| 394 } | 374 } |
| 395 case printing::CENTER: { | 375 case printing::CENTER: { |
| 396 SkScalar available_width = GetHeaderFooterSegmentWidth( | 376 SkScalar available_width = printing::GetHeaderFooterSegmentWidth( |
| 397 page_layout.margin_left + page_layout.margin_right + | 377 page_layout.margin_left + page_layout.margin_right + |
| 398 page_layout.content_width); | 378 page_layout.content_width); |
| 399 x = available_width - page_layout.margin_left + | 379 x = available_width - page_layout.margin_left + |
| 400 (available_width - text_width_in_points) / 2; | 380 (available_width - text_width_in_points) / 2; |
| 401 break; | 381 break; |
| 402 } | 382 } |
| 403 default: { | 383 default: { |
| 404 NOTREACHED(); | 384 NOTREACHED(); |
| 405 } | 385 } |
| 406 } | 386 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 424 return point; | 404 return point; |
| 425 } | 405 } |
| 426 | 406 |
| 427 // Given a text, the positions, and the paint object, this method gets the | 407 // Given a text, the positions, and the paint object, this method gets the |
| 428 // coordinates and prints the text at those coordinates on the canvas. | 408 // coordinates and prints the text at those coordinates on the canvas. |
| 429 void PrintHeaderFooterText( | 409 void PrintHeaderFooterText( |
| 430 const string16& text, | 410 const string16& text, |
| 431 WebKit::WebCanvas* canvas, | 411 WebKit::WebCanvas* canvas, |
| 432 HeaderFooterPaint paint, | 412 HeaderFooterPaint paint, |
| 433 float webkit_scale_factor, | 413 float webkit_scale_factor, |
| 434 const PageSizeMargins& page_layout, | 414 const printing::PageSizeMargins& page_layout, |
| 435 printing::HorizontalHeaderFooterPosition horizontal_position, | 415 printing::HorizontalHeaderFooterPosition horizontal_position, |
| 436 printing::VerticalHeaderFooterPosition vertical_position, | 416 printing::VerticalHeaderFooterPosition vertical_position, |
| 437 double offset_to_baseline) { | 417 double offset_to_baseline) { |
| 438 #if defined(USE_RENDER_TEXT) | 418 #if defined(USE_RENDER_TEXT) |
| 439 paint->SetText(text); | 419 paint->SetText(text); |
| 440 paint->SetFontSize(printing::kSettingHeaderFooterFontSize); | 420 paint->SetFontSize(printing::kSettingHeaderFooterFontSize); |
| 441 double text_width_in_points = paint->GetStringSize().width(); | 421 double text_width_in_points = paint->GetStringSize().width(); |
| 442 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, | 422 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, |
| 443 horizontal_position, | 423 horizontal_position, |
| 444 vertical_position, offset_to_baseline, | 424 vertical_position, offset_to_baseline, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 473 vertical_position, offset_to_baseline, | 453 vertical_position, offset_to_baseline, |
| 474 text_width_in_points); | 454 text_width_in_points); |
| 475 paint.setTextSize(SkDoubleToScalar( | 455 paint.setTextSize(SkDoubleToScalar( |
| 476 paint.getTextSize() / webkit_scale_factor)); | 456 paint.getTextSize() / webkit_scale_factor)); |
| 477 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), | 457 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), |
| 478 paint); | 458 paint); |
| 479 #endif | 459 #endif |
| 480 } | 460 } |
| 481 | 461 |
| 482 PrintMsg_Print_Params CalculatePrintParamsForCss( | 462 PrintMsg_Print_Params CalculatePrintParamsForCss( |
| 483 WebFrame* frame, | 463 WebKit::WebFrame* frame, |
| 484 int page_index, | 464 int page_index, |
| 485 const PrintMsg_Print_Params& page_params, | 465 const PrintMsg_Print_Params& page_params, |
| 486 bool ignore_css_margins, | 466 bool ignore_css_margins, |
| 487 bool fit_to_page, | 467 bool fit_to_page, |
| 488 double* scale_factor) { | 468 double* scale_factor) { |
| 489 PrintMsg_Print_Params css_params = GetCssPrintParams(frame, page_index, | 469 PrintMsg_Print_Params css_params = GetCssPrintParams(frame, page_index, |
| 490 page_params); | 470 page_params); |
| 491 | 471 |
| 492 PrintMsg_Print_Params params = page_params; | 472 PrintMsg_Print_Params params = page_params; |
| 493 EnsureOrientationMatches(css_params, ¶ms); | 473 EnsureOrientationMatches(css_params, ¶ms); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 513 } |
| 534 | 514 |
| 535 } // namespace | 515 } // namespace |
| 536 | 516 |
| 537 // static - Not anonymous so that platform implementations can use it. | 517 // static - Not anonymous so that platform implementations can use it. |
| 538 void PrintWebViewHelper::PrintHeaderAndFooter( | 518 void PrintWebViewHelper::PrintHeaderAndFooter( |
| 539 WebKit::WebCanvas* canvas, | 519 WebKit::WebCanvas* canvas, |
| 540 int page_number, | 520 int page_number, |
| 541 int total_pages, | 521 int total_pages, |
| 542 float webkit_scale_factor, | 522 float webkit_scale_factor, |
| 543 const PageSizeMargins& page_layout, | 523 const printing::PageSizeMargins& page_layout, |
| 544 const DictionaryValue& header_footer_info) { | 524 const DictionaryValue& header_footer_info, |
| 525 const PrintMsg_Print_Params& params) { |
| 545 skia::VectorPlatformDeviceSkia* device = | 526 skia::VectorPlatformDeviceSkia* device = |
| 546 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); | 527 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); |
| 547 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | 528 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); |
| 548 | 529 |
| 549 #if defined(USE_RENDER_TEXT) | 530 #if defined(USE_RENDER_TEXT) |
| 550 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); | 531 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); |
| 551 // TODO(asvitkine): The below line is to workaround http://crbug.com/133548. | 532 // TODO(asvitkine): The below line is to workaround http://crbug.com/133548. |
| 552 // Remove it when the underlying Skia bug has been fixed. | 533 // Remove it when the underlying Skia bug has been fixed. |
| 553 render_text->set_clip_to_display_rect(false); | 534 render_text->set_clip_to_display_rect(false); |
| 554 gfx::FontList font_list( | 535 gfx::FontList font_list( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 page_layout, printing::CENTER, printing::TOP, | 582 page_layout, printing::CENTER, printing::TOP, |
| 602 header_vertical_bounds.top()); | 583 header_vertical_bounds.top()); |
| 603 } | 584 } |
| 604 | 585 |
| 605 // Prints the footers onto the |canvas| if there is enough space to print | 586 // Prints the footers onto the |canvas| if there is enough space to print |
| 606 // them. | 587 // them. |
| 607 string16 page_of_total_pages = base::IntToString16(page_number) + | 588 string16 page_of_total_pages = base::IntToString16(page_number) + |
| 608 UTF8ToUTF16("/") + | 589 UTF8ToUTF16("/") + |
| 609 base::IntToString16(total_pages); | 590 base::IntToString16(total_pages); |
| 610 string16 url; | 591 string16 url; |
| 611 if (!header_footer_info.GetString(printing::kSettingHeaderFooterURL, | 592 if (!header_footer_info.GetString(printing::kSettingHeaderFooterURL, &url)) { |
| 612 &url)) { | |
| 613 NOTREACHED(); | 593 NOTREACHED(); |
| 614 } | 594 } |
| 615 string16 footer_text = page_of_total_pages + url; | 595 string16 footer_text = page_of_total_pages + url; |
| 616 | 596 |
| 617 // Used for height calculations. Note that the width may be undefined. | 597 // Used for height calculations. Note that the width may be undefined. |
| 618 SkRect footer_vertical_bounds; | 598 SkRect footer_vertical_bounds; |
| 619 #if defined(USE_RENDER_TEXT) | 599 #if defined(USE_RENDER_TEXT) |
| 620 paint->SetFontList(font_list); | 600 paint->SetFontList(font_list); |
| 621 paint->SetText(footer_text); | 601 paint->SetText(footer_text); |
| 622 { | 602 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 638 PrintHeaderFooterText(url, canvas, paint, webkit_scale_factor, page_layout, | 618 PrintHeaderFooterText(url, canvas, paint, webkit_scale_factor, page_layout, |
| 639 printing::LEFT, printing::BOTTOM, | 619 printing::LEFT, printing::BOTTOM, |
| 640 footer_vertical_bounds.bottom()); | 620 footer_vertical_bounds.bottom()); |
| 641 } | 621 } |
| 642 | 622 |
| 643 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | 623 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); |
| 644 } | 624 } |
| 645 | 625 |
| 646 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 626 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
| 647 const PrintMsg_Print_Params& print_params, | 627 const PrintMsg_Print_Params& print_params, |
| 648 WebFrame* frame, | 628 WebKit::WebFrame* frame, |
| 649 const WebNode& node) | 629 const WebKit::WebNode& node) |
| 650 : frame_(frame), | 630 : frame_(frame), |
| 651 node_to_print_(node), | 631 node_to_print_(node), |
| 652 web_view_(frame->view()), | 632 web_view_(frame->view()), |
| 653 expected_pages_count_(0), | 633 expected_pages_count_(0), |
| 654 use_browser_overlays_(true), | 634 use_browser_overlays_(true), |
| 655 finished_(false) { | 635 finished_(false) { |
| 656 WebPrintParams webkit_print_params; | 636 WebKit::WebPrintParams webkit_print_params; |
| 657 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); | 637 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); |
| 658 | 638 |
| 659 if (WebFrame* web_frame = web_view_->mainFrame()) | 639 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) |
| 660 prev_scroll_offset_ = web_frame->scrollOffset(); | 640 prev_scroll_offset_ = web_frame->scrollOffset(); |
| 661 prev_view_size_ = web_view_->size(); | 641 prev_view_size_ = web_view_->size(); |
| 662 | 642 |
| 663 StartPrinting(webkit_print_params); | 643 StartPrinting(webkit_print_params); |
| 664 } | 644 } |
| 665 | 645 |
| 666 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 646 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
| 667 FinishPrinting(); | 647 FinishPrinting(); |
| 668 } | 648 } |
| 669 | 649 |
| 670 void PrepareFrameAndViewForPrint::UpdatePrintParams( | 650 void PrepareFrameAndViewForPrint::UpdatePrintParams( |
| 671 const PrintMsg_Print_Params& print_params) { | 651 const PrintMsg_Print_Params& print_params) { |
| 672 DCHECK(!finished_); | 652 DCHECK(!finished_); |
| 673 WebPrintParams webkit_print_params; | 653 WebKit::WebPrintParams webkit_print_params; |
| 674 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); | 654 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); |
| 675 | 655 |
| 676 if (webkit_print_params.printContentArea == | 656 if (webkit_print_params.printContentArea == |
| 677 web_print_params_.printContentArea && | 657 web_print_params_.printContentArea && |
| 678 webkit_print_params.printableArea == web_print_params_.printableArea && | 658 webkit_print_params.printableArea == web_print_params_.printableArea && |
| 679 webkit_print_params.paperSize == web_print_params_.paperSize && | 659 webkit_print_params.paperSize == web_print_params_.paperSize && |
| 680 webkit_print_params.printScalingOption == | 660 webkit_print_params.printScalingOption == |
| 681 web_print_params_.printScalingOption) { | 661 web_print_params_.printScalingOption) { |
| 682 return; | 662 return; |
| 683 } | 663 } |
| 684 | 664 |
| 685 frame_->printEnd(); | 665 frame_->printEnd(); |
| 686 StartPrinting(webkit_print_params); | 666 StartPrinting(webkit_print_params); |
| 687 } | 667 } |
| 688 | 668 |
| 669 gfx::Size PrepareFrameAndViewForPrint::GetPrintCanvasSize() const { |
| 670 return gfx::Size(web_print_params_.printContentArea.width, |
| 671 web_print_params_.printContentArea.height); |
| 672 } |
| 673 |
| 689 void PrepareFrameAndViewForPrint::StartPrinting( | 674 void PrepareFrameAndViewForPrint::StartPrinting( |
| 690 const WebPrintParams& webkit_print_params) { | 675 const WebKit::WebPrintParams& webkit_print_params) { |
| 691 web_print_params_ = webkit_print_params; | 676 web_print_params_ = webkit_print_params; |
| 692 | 677 |
| 693 // Layout page according to printer page size. Since WebKit shrinks the | 678 // Layout page according to printer page size. Since WebKit shrinks the |
| 694 // size of the page automatically (from 125% to 200%) we trick it to | 679 // size of the page automatically (from 125% to 200%) we trick it to |
| 695 // think the page is 125% larger so the size of the page is correct for | 680 // think the page is 125% larger so the size of the page is correct for |
| 696 // minimum (default) scaling. | 681 // minimum (default) scaling. |
| 697 // This is important for sites that try to fill the page. | 682 // This is important for sites that try to fill the page. |
| 698 gfx::Size print_layout_size(web_print_params_.printContentArea.width, | 683 gfx::Size print_layout_size(web_print_params_.printContentArea.width, |
| 699 web_print_params_.printContentArea.height); | 684 web_print_params_.printContentArea.height); |
| 700 print_layout_size.set_height(static_cast<int>( | 685 print_layout_size.set_height(static_cast<int>( |
| 701 static_cast<double>(print_layout_size.height()) * 1.25)); | 686 static_cast<double>(print_layout_size.height()) * 1.25)); |
| 702 | 687 |
| 703 web_view_->resize(print_layout_size); | 688 web_view_->resize(print_layout_size); |
| 704 | 689 |
| 705 expected_pages_count_ = frame_->printBegin(web_print_params_, | 690 expected_pages_count_ = frame_->printBegin(web_print_params_, |
| 706 node_to_print_, | 691 node_to_print_, |
| 707 &use_browser_overlays_); | 692 &use_browser_overlays_); |
| 708 } | 693 } |
| 709 | 694 |
| 710 void PrepareFrameAndViewForPrint::FinishPrinting() { | 695 void PrepareFrameAndViewForPrint::FinishPrinting() { |
| 711 if (!finished_) { | 696 if (!finished_) { |
| 712 finished_ = true; | 697 finished_ = true; |
| 713 frame_->printEnd(); | 698 frame_->printEnd(); |
| 714 web_view_->resize(prev_view_size_); | 699 web_view_->resize(prev_view_size_); |
| 715 if (WebFrame* web_frame = web_view_->mainFrame()) | 700 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) |
| 716 web_frame->setScrollOffset(prev_scroll_offset_); | 701 web_frame->setScrollOffset(prev_scroll_offset_); |
| 717 } | 702 } |
| 718 } | 703 } |
| 719 | 704 |
| 720 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) | 705 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) |
| 721 : content::RenderViewObserver(render_view), | 706 : content::RenderViewObserver(render_view), |
| 722 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 707 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
| 723 print_web_view_(NULL), | 708 print_web_view_(NULL), |
| 724 is_preview_enabled_(IsPrintPreviewEnabled()), | 709 is_preview_enabled_(IsPrintPreviewEnabled()), |
| 725 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), | 710 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 } | 746 } |
| 762 | 747 |
| 763 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 748 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
| 764 return; | 749 return; |
| 765 IncrementScriptedPrintCount(); | 750 IncrementScriptedPrintCount(); |
| 766 | 751 |
| 767 if (is_preview_enabled_) { | 752 if (is_preview_enabled_) { |
| 768 print_preview_context_.InitWithFrame(frame); | 753 print_preview_context_.InitWithFrame(frame); |
| 769 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 754 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
| 770 } else { | 755 } else { |
| 771 Print(frame, WebNode()); | 756 Print(frame, WebKit::WebNode()); |
| 772 } | 757 } |
| 773 } | 758 } |
| 774 | 759 |
| 775 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 760 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
| 776 bool handled = true; | 761 bool handled = true; |
| 777 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 762 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
| 778 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 763 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
| 779 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 764 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
| 780 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 765 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
| 781 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, | 766 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 794 | 779 |
| 795 void PrintWebViewHelper::OnPrintForPrintPreview( | 780 void PrintWebViewHelper::OnPrintForPrintPreview( |
| 796 const DictionaryValue& job_settings) { | 781 const DictionaryValue& job_settings) { |
| 797 DCHECK(is_preview_enabled_); | 782 DCHECK(is_preview_enabled_); |
| 798 // If still not finished with earlier print request simply ignore. | 783 // If still not finished with earlier print request simply ignore. |
| 799 if (print_web_view_) | 784 if (print_web_view_) |
| 800 return; | 785 return; |
| 801 | 786 |
| 802 if (!render_view()->GetWebView()) | 787 if (!render_view()->GetWebView()) |
| 803 return; | 788 return; |
| 804 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 789 WebKit::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
| 805 if (!main_frame) | 790 if (!main_frame) |
| 806 return; | 791 return; |
| 807 | 792 |
| 808 WebDocument document = main_frame->document(); | 793 WebKit::WebDocument document = main_frame->document(); |
| 809 // <object> with id="pdf-viewer" is created in | 794 // <object> with id="pdf-viewer" is created in |
| 810 // chrome/browser/resources/print_preview/print_preview.js | 795 // chrome/browser/resources/print_preview/print_preview.js |
| 811 WebElement pdf_element = document.getElementById("pdf-viewer"); | 796 WebKit::WebElement pdf_element = document.getElementById("pdf-viewer"); |
| 812 if (pdf_element.isNull()) { | 797 if (pdf_element.isNull()) { |
| 813 NOTREACHED(); | 798 NOTREACHED(); |
| 814 return; | 799 return; |
| 815 } | 800 } |
| 816 | 801 |
| 817 // Set |print_for_preview_| flag and autoreset it to back to original | 802 // Set |print_for_preview_| flag and autoreset it to back to original |
| 818 // on return. | 803 // on return. |
| 819 AutoReset<bool> set_printing_flag(&print_for_preview_, true); | 804 AutoReset<bool> set_printing_flag(&print_for_preview_, true); |
| 820 | 805 |
| 821 WebFrame* pdf_frame = pdf_element.document().frame(); | 806 WebKit::WebFrame* pdf_frame = pdf_element.document().frame(); |
| 822 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) { | 807 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) { |
| 823 LOG(ERROR) << "UpdatePrintSettings failed"; | 808 LOG(ERROR) << "UpdatePrintSettings failed"; |
| 824 DidFinishPrinting(FAIL_PRINT); | 809 DidFinishPrinting(FAIL_PRINT); |
| 825 return; | 810 return; |
| 826 } | 811 } |
| 827 | 812 |
| 828 // Print page onto entire page not just printable area. Preview PDF already | 813 // Print page onto entire page not just printable area. Preview PDF already |
| 829 // has content in correct position taking into account page size and printable | 814 // has content in correct position taking into account page size and printable |
| 830 // area. | 815 // area. |
| 831 // TODO(vitalybuka) : Make this consistent on all platform. This change | 816 // TODO(vitalybuka) : Make this consistent on all platform. This change |
| (...skipping 20 matching lines...) Expand all Loading... |
| 852 | 837 |
| 853 // If the user has selected text in the currently focused frame we print | 838 // If the user has selected text in the currently focused frame we print |
| 854 // only that frame (this makes print selection work for multiple frames). | 839 // only that frame (this makes print selection work for multiple frames). |
| 855 *frame = render_view()->GetWebView()->focusedFrame()->hasSelection() ? | 840 *frame = render_view()->GetWebView()->focusedFrame()->hasSelection() ? |
| 856 render_view()->GetWebView()->focusedFrame() : | 841 render_view()->GetWebView()->focusedFrame() : |
| 857 render_view()->GetWebView()->mainFrame(); | 842 render_view()->GetWebView()->mainFrame(); |
| 858 return true; | 843 return true; |
| 859 } | 844 } |
| 860 | 845 |
| 861 void PrintWebViewHelper::OnPrintPages() { | 846 void PrintWebViewHelper::OnPrintPages() { |
| 862 WebFrame* frame; | 847 WebKit::WebFrame* frame; |
| 863 if (GetPrintFrame(&frame)) | 848 if (GetPrintFrame(&frame)) |
| 864 Print(frame, WebNode()); | 849 Print(frame, WebKit::WebNode()); |
| 865 } | 850 } |
| 866 | 851 |
| 867 void PrintWebViewHelper::OnPrintForSystemDialog() { | 852 void PrintWebViewHelper::OnPrintForSystemDialog() { |
| 868 WebFrame* frame = print_preview_context_.frame(); | 853 WebKit::WebFrame* frame = print_preview_context_.frame(); |
| 869 if (!frame) { | 854 if (!frame) { |
| 870 NOTREACHED(); | 855 NOTREACHED(); |
| 871 return; | 856 return; |
| 872 } | 857 } |
| 873 | 858 |
| 874 Print(frame, print_preview_context_.node()); | 859 Print(frame, print_preview_context_.node()); |
| 875 } | 860 } |
| 876 | 861 |
| 877 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 862 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
| 878 const printing::PageSizeMargins& page_layout_in_points, | 863 const printing::PageSizeMargins& page_layout_in_points, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 889 page_layout_in_points.margin_top, | 874 page_layout_in_points.margin_top, |
| 890 page_layout_in_points.content_width, | 875 page_layout_in_points.content_width, |
| 891 page_layout_in_points.content_height); | 876 page_layout_in_points.content_height); |
| 892 } | 877 } |
| 893 | 878 |
| 894 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( | 879 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( |
| 895 const DictionaryValue& settings) { | 880 const DictionaryValue& settings) { |
| 896 int margins_type = 0; | 881 int margins_type = 0; |
| 897 if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type)) | 882 if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type)) |
| 898 margins_type = printing::DEFAULT_MARGINS; | 883 margins_type = printing::DEFAULT_MARGINS; |
| 899 ignore_css_margins_ = margins_type != printing::DEFAULT_MARGINS; | 884 ignore_css_margins_ = (margins_type != printing::DEFAULT_MARGINS); |
| 900 } | 885 } |
| 901 | 886 |
| 902 bool PrintWebViewHelper::IsPrintToPdfRequested( | 887 bool PrintWebViewHelper::IsPrintToPdfRequested( |
| 903 const DictionaryValue& job_settings) { | 888 const DictionaryValue& job_settings) { |
| 904 bool print_to_pdf = false; | 889 bool print_to_pdf = false; |
| 905 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) | 890 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) |
| 906 NOTREACHED(); | 891 NOTREACHED(); |
| 907 return print_to_pdf; | 892 return print_to_pdf; |
| 908 } | 893 } |
| 909 | 894 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 if (CreatePreviewDocument()) { | 975 if (CreatePreviewDocument()) { |
| 991 DidFinishPrinting(OK); | 976 DidFinishPrinting(OK); |
| 992 } else { | 977 } else { |
| 993 if (notify_browser_of_print_failure_) | 978 if (notify_browser_of_print_failure_) |
| 994 LOG(ERROR) << "CreatePreviewDocument failed"; | 979 LOG(ERROR) << "CreatePreviewDocument failed"; |
| 995 DidFinishPrinting(FAIL_PREVIEW); | 980 DidFinishPrinting(FAIL_PREVIEW); |
| 996 } | 981 } |
| 997 } | 982 } |
| 998 | 983 |
| 999 bool PrintWebViewHelper::CreatePreviewDocument() { | 984 bool PrintWebViewHelper::CreatePreviewDocument() { |
| 1000 PrintMsg_Print_Params print_params = print_pages_params_->params; | 985 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
| 1001 const std::vector<int>& pages = print_pages_params_->pages; | 986 const std::vector<int>& pages = print_pages_params_->pages; |
| 1002 if (!print_preview_context_.CreatePreviewDocument(&print_params, pages, | 987 if (!print_preview_context_.CreatePreviewDocument(print_params, pages, |
| 1003 ignore_css_margins_)) { | 988 ignore_css_margins_)) { |
| 1004 return false; | 989 return false; |
| 1005 } | 990 } |
| 1006 | 991 |
| 1007 PageSizeMargins default_page_layout; | 992 printing::PageSizeMargins default_page_layout; |
| 1008 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, | 993 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, |
| 1009 print_params, ignore_css_margins_, NULL, | 994 print_params, ignore_css_margins_, NULL, |
| 1010 &default_page_layout); | 995 &default_page_layout); |
| 1011 | 996 |
| 1012 if (!old_print_pages_params_.get() || | 997 if (!old_print_pages_params_.get() || |
| 1013 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { | 998 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { |
| 1014 bool has_page_size_style = PrintingFrameHasPageSizeStyle( | 999 bool has_page_size_style = PrintingFrameHasPageSizeStyle( |
| 1015 print_preview_context_.frame(), | 1000 print_preview_context_.frame(), |
| 1016 print_preview_context_.total_page_count()); | 1001 print_preview_context_.total_page_count()); |
| 1017 int dpi = GetDPI(&print_params); | 1002 int dpi = GetDPI(&print_params); |
| 1003 |
| 1004 using printing::ConvertUnit; |
| 1005 using printing::kPointsPerInch; |
| 1018 gfx::Rect printable_area_in_points( | 1006 gfx::Rect printable_area_in_points( |
| 1019 ConvertUnit(print_pages_params_->params.printable_area.x(), | 1007 ConvertUnit(print_params.printable_area.x(), dpi, kPointsPerInch), |
| 1020 dpi, printing::kPointsPerInch), | 1008 ConvertUnit(print_params.printable_area.y(), dpi, kPointsPerInch), |
| 1021 ConvertUnit(print_pages_params_->params.printable_area.y(), | 1009 ConvertUnit(print_params.printable_area.width(), dpi, kPointsPerInch), |
| 1022 dpi, printing::kPointsPerInch), | 1010 ConvertUnit(print_params.printable_area.height(), dpi, kPointsPerInch)); |
| 1023 ConvertUnit(print_pages_params_->params.printable_area.width(), | |
| 1024 dpi, printing::kPointsPerInch), | |
| 1025 ConvertUnit(print_pages_params_->params.printable_area.height(), | |
| 1026 dpi, printing::kPointsPerInch)); | |
| 1027 | 1011 |
| 1028 // Margins: Send default page layout to browser process. | 1012 // Margins: Send default page layout to browser process. |
| 1029 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), | 1013 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), |
| 1030 default_page_layout, | 1014 default_page_layout, |
| 1031 printable_area_in_points, | 1015 printable_area_in_points, |
| 1032 has_page_size_style)); | 1016 has_page_size_style)); |
| 1033 } | 1017 } |
| 1034 | 1018 |
| 1035 PrintHostMsg_DidGetPreviewPageCount_Params params; | 1019 PrintHostMsg_DidGetPreviewPageCount_Params params; |
| 1036 params.page_count = print_preview_context_.total_page_count(); | 1020 params.page_count = print_preview_context_.total_page_count(); |
| 1037 params.is_modifiable = print_preview_context_.IsModifiable(); | 1021 params.is_modifiable = print_preview_context_.IsModifiable(); |
| 1038 params.document_cookie = print_pages_params_->params.document_cookie; | 1022 params.document_cookie = print_params.document_cookie; |
| 1039 params.preview_request_id = print_pages_params_->params.preview_request_id; | 1023 params.preview_request_id = print_params.preview_request_id; |
| 1040 params.clear_preview_data = print_preview_context_.generate_draft_pages(); | 1024 params.clear_preview_data = print_preview_context_.generate_draft_pages(); |
| 1041 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params)); | 1025 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params)); |
| 1042 if (CheckForCancel()) | 1026 if (CheckForCancel()) |
| 1043 return false; | 1027 return false; |
| 1044 | 1028 |
| 1045 while (!print_preview_context_.IsFinalPageRendered()) { | 1029 while (!print_preview_context_.IsFinalPageRendered()) { |
| 1046 int page_number = print_preview_context_.GetNextPageNumber(); | 1030 int page_number = print_preview_context_.GetNextPageNumber(); |
| 1047 DCHECK_GE(page_number, 0); | 1031 DCHECK_GE(page_number, 0); |
| 1048 if (!RenderPreviewPage(page_number)) | 1032 if (!RenderPreviewPage(page_number, print_params)) |
| 1049 return false; | 1033 return false; |
| 1050 | 1034 |
| 1051 if (CheckForCancel()) | 1035 if (CheckForCancel()) |
| 1052 return false; | 1036 return false; |
| 1053 | 1037 |
| 1054 // We must call PrepareFrameAndViewForPrint::FinishPrinting() (by way of | 1038 // We must call PrepareFrameAndViewForPrint::FinishPrinting() (by way of |
| 1055 // print_preview_context_.AllPagesRendered()) before calling | 1039 // print_preview_context_.AllPagesRendered()) before calling |
| 1056 // FinalizePrintReadyDocument() when printing a PDF because the plugin | 1040 // FinalizePrintReadyDocument() when printing a PDF because the plugin |
| 1057 // code does not generate output until we call FinishPrinting(). We do not | 1041 // code does not generate output until we call FinishPrinting(). We do not |
| 1058 // generate draft pages for PDFs, so IsFinalPageRendered() and | 1042 // generate draft pages for PDFs, so IsFinalPageRendered() and |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 if (!success) | 1093 if (!success) |
| 1110 LOG(ERROR) << "Failure in OnPrintingDone"; | 1094 LOG(ERROR) << "Failure in OnPrintingDone"; |
| 1111 DidFinishPrinting(success ? OK : FAIL_PRINT); | 1095 DidFinishPrinting(success ? OK : FAIL_PRINT); |
| 1112 } | 1096 } |
| 1113 | 1097 |
| 1114 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { | 1098 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { |
| 1115 is_scripted_printing_blocked_ = blocked; | 1099 is_scripted_printing_blocked_ = blocked; |
| 1116 } | 1100 } |
| 1117 | 1101 |
| 1118 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { | 1102 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { |
| 1119 const WebNode& context_menu_node = render_view()->GetContextMenuNode(); | 1103 PrintNode(render_view()->GetContextMenuNode()); |
| 1120 PrintNode(context_menu_node); | |
| 1121 } | 1104 } |
| 1122 | 1105 |
| 1123 void PrintWebViewHelper::OnInitiatePrintPreview() { | 1106 void PrintWebViewHelper::OnInitiatePrintPreview() { |
| 1124 DCHECK(is_preview_enabled_); | 1107 DCHECK(is_preview_enabled_); |
| 1125 WebFrame* frame; | 1108 WebKit::WebFrame* frame; |
| 1126 if (GetPrintFrame(&frame)) { | 1109 if (GetPrintFrame(&frame)) { |
| 1127 print_preview_context_.InitWithFrame(frame); | 1110 print_preview_context_.InitWithFrame(frame); |
| 1128 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); | 1111 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); |
| 1129 } else { | 1112 } else { |
| 1130 // This should not happen. Let's add a CHECK here to see how often this | 1113 // This should not happen. Let's add a CHECK here to see how often this |
| 1131 // gets hit. | 1114 // gets hit. |
| 1132 // TODO(thestig) Remove this later when we have sufficient usage of this | 1115 // TODO(thestig) Remove this later when we have sufficient usage of this |
| 1133 // code on the M19 stable channel. | 1116 // code on the M19 stable channel. |
| 1134 CHECK(false); | 1117 CHECK(false); |
| 1135 } | 1118 } |
| 1136 } | 1119 } |
| 1137 | 1120 |
| 1138 void PrintWebViewHelper::PrintNode(const WebNode& node) { | 1121 void PrintWebViewHelper::PrintNode(const WebKit::WebNode& node) { |
| 1139 if (node.isNull() || !node.document().frame()) { | 1122 if (node.isNull() || !node.document().frame()) { |
| 1140 // This can occur when the context menu refers to an invalid WebNode. | 1123 // This can occur when the context menu refers to an invalid WebNode. |
| 1141 // See http://crbug.com/100890#c17 for a repro case. | 1124 // See http://crbug.com/100890#c17 for a repro case. |
| 1142 return; | 1125 return; |
| 1143 } | 1126 } |
| 1144 | 1127 |
| 1145 if (print_node_in_progress_) { | 1128 if (print_node_in_progress_) { |
| 1146 // This can happen as a result of processing sync messages when printing | 1129 // This can happen as a result of processing sync messages when printing |
| 1147 // from ppapi plugins. It's a rare case, so its OK to just fail here. | 1130 // from ppapi plugins. It's a rare case, so its OK to just fail here. |
| 1148 // See http://crbug.com/159165. | 1131 // See http://crbug.com/159165. |
| 1149 return; | 1132 return; |
| 1150 } | 1133 } |
| 1151 | 1134 |
| 1152 print_node_in_progress_ = true; | 1135 print_node_in_progress_ = true; |
| 1153 | 1136 |
| 1154 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets | 1137 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets |
| 1155 // its |context_menu_node_|. | 1138 // its |context_menu_node_|. |
| 1156 if (is_preview_enabled_) { | 1139 if (is_preview_enabled_) { |
| 1157 print_preview_context_.InitWithNode(node); | 1140 print_preview_context_.InitWithNode(node); |
| 1158 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1141 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
| 1159 } else { | 1142 } else { |
| 1160 WebNode duplicate_node(node); | 1143 WebKit::WebNode duplicate_node(node); |
| 1161 Print(duplicate_node.document().frame(), duplicate_node); | 1144 Print(duplicate_node.document().frame(), duplicate_node); |
| 1162 } | 1145 } |
| 1163 | 1146 |
| 1164 print_node_in_progress_ = false; | 1147 print_node_in_progress_ = false; |
| 1165 } | 1148 } |
| 1166 | 1149 |
| 1167 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, | 1150 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, |
| 1168 const WebKit::WebNode& node) { | 1151 const WebKit::WebNode& node) { |
| 1169 // If still not finished with earlier print request simply ignore. | 1152 // If still not finished with earlier print request simply ignore. |
| 1170 if (print_web_view_) | 1153 if (print_web_view_) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 } | 1238 } |
| 1256 | 1239 |
| 1257 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { | 1240 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { |
| 1258 // Create a new WebView with the same settings as the current display one. | 1241 // Create a new WebView with the same settings as the current display one. |
| 1259 // Except that we disable javascript (don't want any active content running | 1242 // Except that we disable javascript (don't want any active content running |
| 1260 // on the page). | 1243 // on the page). |
| 1261 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); | 1244 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); |
| 1262 prefs.javascript_enabled = false; | 1245 prefs.javascript_enabled = false; |
| 1263 prefs.java_enabled = false; | 1246 prefs.java_enabled = false; |
| 1264 | 1247 |
| 1265 print_web_view_ = WebView::create(this); | 1248 print_web_view_ = WebKit::WebView::create(this); |
| 1266 prefs.Apply(print_web_view_); | 1249 prefs.Apply(print_web_view_); |
| 1267 print_web_view_->initializeMainFrame(this); | 1250 print_web_view_->initializeMainFrame(this); |
| 1268 | 1251 |
| 1269 print_pages_params_->pages.clear(); // Print all pages of selection. | 1252 print_pages_params_->pages.clear(); // Print all pages of selection. |
| 1270 | 1253 |
| 1271 std::string html = web_frame->selectionAsMarkup().utf8(); | 1254 std::string html = web_frame->selectionAsMarkup().utf8(); |
| 1272 std::string url_str = "data:text/html;charset=utf-8,"; | 1255 std::string url_str = "data:text/html;charset=utf-8,"; |
| 1273 url_str.append(html); | 1256 url_str.append(html); |
| 1274 GURL url(url_str); | 1257 GURL url(url_str); |
| 1275 | 1258 |
| 1276 // When loading is done this will call didStopLoading() and that will do the | 1259 // When loading is done this will call didStopLoading() and that will do the |
| 1277 // actual printing. | 1260 // actual printing. |
| 1278 print_web_view_->mainFrame()->loadRequest(WebURLRequest(url)); | 1261 print_web_view_->mainFrame()->loadRequest(WebKit::WebURLRequest(url)); |
| 1279 | 1262 |
| 1280 return true; | 1263 return true; |
| 1281 } | 1264 } |
| 1282 | 1265 |
| 1283 #if defined(OS_MACOSX) || defined(OS_WIN) | 1266 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 1284 bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { | 1267 bool PrintWebViewHelper::PrintPages(WebKit::WebFrame* frame, |
| 1268 const WebKit::WebNode& node) { |
| 1285 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1269 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
| 1286 const PrintMsg_Print_Params& print_params = params.params; | 1270 const PrintMsg_Print_Params& print_params = params.params; |
| 1287 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node); | 1271 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node); |
| 1288 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view, | 1272 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view, |
| 1289 print_params, ignore_css_margins_); | 1273 print_params, ignore_css_margins_); |
| 1290 | 1274 |
| 1291 int page_count = prep_frame_view.GetExpectedPageCount(); | 1275 int page_count = prep_frame_view.GetExpectedPageCount(); |
| 1292 if (!page_count) | 1276 if (!page_count) |
| 1293 return false; | 1277 return false; |
| 1294 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), | 1278 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1309 break; | 1293 break; |
| 1310 page_params.page_number = params.pages[i]; | 1294 page_params.page_number = params.pages[i]; |
| 1311 PrintPageInternal(page_params, canvas_size, frame); | 1295 PrintPageInternal(page_params, canvas_size, frame); |
| 1312 } | 1296 } |
| 1313 } | 1297 } |
| 1314 return true; | 1298 return true; |
| 1315 } | 1299 } |
| 1316 #endif // OS_MACOSX || OS_WIN | 1300 #endif // OS_MACOSX || OS_WIN |
| 1317 | 1301 |
| 1318 void PrintWebViewHelper::didStopLoading() { | 1302 void PrintWebViewHelper::didStopLoading() { |
| 1319 PrintPages(print_web_view_->mainFrame(), WebNode()); | 1303 PrintPages(print_web_view_->mainFrame(), WebKit::WebNode()); |
| 1320 } | 1304 } |
| 1321 | 1305 |
| 1322 // static - Not anonymous so that platform implementations can use it. | 1306 // static - Not anonymous so that platform implementations can use it. |
| 1323 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( | 1307 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( |
| 1324 WebFrame* frame, | 1308 WebKit::WebFrame* frame, |
| 1325 int page_index, | 1309 int page_index, |
| 1326 const PrintMsg_Print_Params& page_params, | 1310 const PrintMsg_Print_Params& page_params, |
| 1327 bool ignore_css_margins, | 1311 bool ignore_css_margins, |
| 1328 double* scale_factor, | 1312 double* scale_factor, |
| 1329 PageSizeMargins* page_layout_in_points) { | 1313 printing::PageSizeMargins* page_layout_in_points) { |
| 1330 PrintMsg_Print_Params params = CalculatePrintParamsForCss( | 1314 PrintMsg_Print_Params params = CalculatePrintParamsForCss( |
| 1331 frame, page_index, page_params, ignore_css_margins, | 1315 frame, page_index, page_params, ignore_css_margins, |
| 1332 page_params.print_scaling_option == | 1316 page_params.print_scaling_option == |
| 1333 WebKit::WebPrintScalingOptionFitToPrintableArea, | 1317 WebKit::WebPrintScalingOptionFitToPrintableArea, |
| 1334 scale_factor); | 1318 scale_factor); |
| 1335 CalculatePageLayoutFromPrintParams(params, page_layout_in_points); | 1319 CalculatePageLayoutFromPrintParams(params, page_layout_in_points); |
| 1336 } | 1320 } |
| 1337 | 1321 |
| 1338 // static - Not anonymous so that platform implementations can use it. | 1322 // static - Not anonymous so that platform implementations can use it. |
| 1339 void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout( | 1323 void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout( |
| 1340 WebFrame* frame, | 1324 WebKit::WebFrame* frame, |
| 1341 const WebNode& node, | 1325 const WebKit::WebNode& node, |
| 1342 PrepareFrameAndViewForPrint* prepare, | 1326 PrepareFrameAndViewForPrint* prepare, |
| 1343 const PrintMsg_Print_Params& params, | 1327 const PrintMsg_Print_Params& params, |
| 1344 bool ignore_css_margins) { | 1328 bool ignore_css_margins) { |
| 1345 if (PrintingNodeOrPdfFrame(frame, node)) | 1329 if (PrintingNodeOrPdfFrame(frame, node)) |
| 1346 return; | 1330 return; |
| 1347 bool fit_to_page = ignore_css_margins && | 1331 bool fit_to_page = ignore_css_margins && |
| 1348 params.print_scaling_option == | 1332 params.print_scaling_option == |
| 1349 WebKit::WebPrintScalingOptionFitToPrintableArea; | 1333 WebKit::WebPrintScalingOptionFitToPrintableArea; |
| 1350 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss( | 1334 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss( |
| 1351 frame, 0, params, ignore_css_margins, fit_to_page, NULL); | 1335 frame, 0, params, ignore_css_margins, fit_to_page, NULL); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1379 if (fit_to_paper_size) { | 1363 if (fit_to_paper_size) { |
| 1380 settings.params.print_scaling_option = | 1364 settings.params.print_scaling_option = |
| 1381 WebKit::WebPrintScalingOptionFitToPrintableArea; | 1365 WebKit::WebPrintScalingOptionFitToPrintableArea; |
| 1382 } | 1366 } |
| 1383 | 1367 |
| 1384 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1368 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1385 return result; | 1369 return result; |
| 1386 } | 1370 } |
| 1387 | 1371 |
| 1388 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( | 1372 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( |
| 1389 WebKit::WebFrame* frame, const WebKit::WebNode& node, | 1373 WebKit::WebFrame* frame, |
| 1374 const WebKit::WebNode& node, |
| 1390 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { | 1375 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { |
| 1391 DCHECK(frame); | 1376 DCHECK(frame); |
| 1392 | 1377 |
| 1393 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); | 1378 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); |
| 1394 if (!InitPrintSettings(fit_to_paper_size)) { | 1379 if (!InitPrintSettings(fit_to_paper_size)) { |
| 1395 notify_browser_of_print_failure_ = false; | 1380 notify_browser_of_print_failure_ = false; |
| 1396 render_view()->RunModalAlertDialog( | 1381 render_view()->RunModalAlertDialog( |
| 1397 frame, | 1382 frame, |
| 1398 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | 1383 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); |
| 1399 return false; | 1384 return false; |
| 1400 } | 1385 } |
| 1401 | 1386 |
| 1402 DCHECK(!prepare->get()); | 1387 DCHECK(!prepare->get()); |
| 1403 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, | 1388 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, |
| 1404 frame, node)); | 1389 frame, node)); |
| 1405 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(), | 1390 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(), |
| 1406 print_pages_params_->params, | 1391 print_pages_params_->params, |
| 1407 ignore_css_margins_); | 1392 ignore_css_margins_); |
| 1408 Send(new PrintHostMsg_DidGetDocumentCookie( | 1393 Send(new PrintHostMsg_DidGetDocumentCookie( |
| 1409 routing_id(), print_pages_params_->params.document_cookie)); | 1394 routing_id(), print_pages_params_->params.document_cookie)); |
| 1410 return true; | 1395 return true; |
| 1411 } | 1396 } |
| 1412 | 1397 |
| 1413 bool PrintWebViewHelper::UpdatePrintSettings( | 1398 bool PrintWebViewHelper::UpdatePrintSettings( |
| 1414 WebKit::WebFrame* frame, const WebKit::WebNode& node, | 1399 WebKit::WebFrame* frame, |
| 1400 const WebKit::WebNode& node, |
| 1415 const DictionaryValue& passed_job_settings) { | 1401 const DictionaryValue& passed_job_settings) { |
| 1416 DCHECK(is_preview_enabled_); | 1402 DCHECK(is_preview_enabled_); |
| 1417 const DictionaryValue* job_settings = &passed_job_settings; | 1403 const DictionaryValue* job_settings = &passed_job_settings; |
| 1418 DictionaryValue modified_job_settings; | 1404 DictionaryValue modified_job_settings; |
| 1419 if (job_settings->empty()) { | 1405 if (job_settings->empty()) { |
| 1420 if (!print_for_preview_) | 1406 if (!print_for_preview_) |
| 1421 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1407 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
| 1422 return false; | 1408 return false; |
| 1423 } | 1409 } |
| 1424 | 1410 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 kMaxSecondsToIgnoreJavascriptInitiatedPrint); | 1580 kMaxSecondsToIgnoreJavascriptInitiatedPrint); |
| 1595 } | 1581 } |
| 1596 if (diff.InSeconds() < min_wait_seconds) { | 1582 if (diff.InSeconds() < min_wait_seconds) { |
| 1597 too_frequent = true; | 1583 too_frequent = true; |
| 1598 } | 1584 } |
| 1599 } | 1585 } |
| 1600 | 1586 |
| 1601 if (!too_frequent) | 1587 if (!too_frequent) |
| 1602 return false; | 1588 return false; |
| 1603 | 1589 |
| 1604 WebString message(WebString::fromUTF8( | 1590 WebKit::WebString message( |
| 1605 "Ignoring too frequent calls to print().")); | 1591 WebKit::WebString::fromUTF8("Ignoring too frequent calls to print().")); |
| 1606 frame->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelWarning, | 1592 frame->addMessageToConsole( |
| 1607 message)); | 1593 WebKit::WebConsoleMessage( |
| 1594 WebKit::WebConsoleMessage::LevelWarning, message)); |
| 1608 return true; | 1595 return true; |
| 1609 } | 1596 } |
| 1610 | 1597 |
| 1611 void PrintWebViewHelper::ResetScriptedPrintCount() { | 1598 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 1612 // Reset cancel counter on successful print. | 1599 // Reset cancel counter on successful print. |
| 1613 user_cancelled_scripted_print_count_ = 0; | 1600 user_cancelled_scripted_print_count_ = 0; |
| 1614 } | 1601 } |
| 1615 | 1602 |
| 1616 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 1603 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 1617 ++user_cancelled_scripted_print_count_; | 1604 ++user_cancelled_scripted_print_count_; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 frame_ = web_node.document().frame(); | 1715 frame_ = web_node.document().frame(); |
| 1729 node_ = web_node; | 1716 node_ = web_node; |
| 1730 } | 1717 } |
| 1731 | 1718 |
| 1732 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { | 1719 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { |
| 1733 DCHECK_EQ(INITIALIZED, state_); | 1720 DCHECK_EQ(INITIALIZED, state_); |
| 1734 ClearContext(); | 1721 ClearContext(); |
| 1735 } | 1722 } |
| 1736 | 1723 |
| 1737 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( | 1724 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( |
| 1738 PrintMsg_Print_Params* print_params, | 1725 const PrintMsg_Print_Params& print_params, |
| 1739 const std::vector<int>& pages, | 1726 const std::vector<int>& pages, |
| 1740 bool ignore_css_margins) { | 1727 bool ignore_css_margins) { |
| 1741 DCHECK_EQ(INITIALIZED, state_); | 1728 DCHECK_EQ(INITIALIZED, state_); |
| 1742 state_ = RENDERING; | 1729 state_ = RENDERING; |
| 1743 | 1730 |
| 1744 metafile_.reset(new printing::PreviewMetafile); | 1731 metafile_.reset(new printing::PreviewMetafile); |
| 1745 if (!metafile_->Init()) { | 1732 if (!metafile_->Init()) { |
| 1746 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); | 1733 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); |
| 1747 LOG(ERROR) << "PreviewMetafile Init failed"; | 1734 LOG(ERROR) << "PreviewMetafile Init failed"; |
| 1748 return false; | 1735 return false; |
| 1749 } | 1736 } |
| 1750 | 1737 |
| 1751 // Need to make sure old object gets destroyed first. | 1738 // Need to make sure old object gets destroyed first. |
| 1752 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(*print_params, frame(), | 1739 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(print_params, frame(), |
| 1753 node())); | 1740 node())); |
| 1754 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(), | 1741 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(), |
| 1755 *print_params, ignore_css_margins); | 1742 print_params, ignore_css_margins); |
| 1756 | |
| 1757 print_params_.reset(new PrintMsg_Print_Params(*print_params)); | |
| 1758 | 1743 |
| 1759 total_page_count_ = prep_frame_view_->GetExpectedPageCount(); | 1744 total_page_count_ = prep_frame_view_->GetExpectedPageCount(); |
| 1760 if (total_page_count_ == 0) { | 1745 if (total_page_count_ == 0) { |
| 1761 LOG(ERROR) << "CreatePreviewDocument got 0 page count"; | 1746 LOG(ERROR) << "CreatePreviewDocument got 0 page count"; |
| 1762 set_error(PREVIEW_ERROR_ZERO_PAGES); | 1747 set_error(PREVIEW_ERROR_ZERO_PAGES); |
| 1763 return false; | 1748 return false; |
| 1764 } | 1749 } |
| 1765 | 1750 |
| 1766 int selected_page_count = pages.size(); | 1751 int selected_page_count = pages.size(); |
| 1767 current_page_index_ = 0; | 1752 current_page_index_ = 0; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1898 | 1883 |
| 1899 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() const { | 1884 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() const { |
| 1900 return generate_draft_pages_; | 1885 return generate_draft_pages_; |
| 1901 } | 1886 } |
| 1902 | 1887 |
| 1903 printing::PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() { | 1888 printing::PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() { |
| 1904 DCHECK(IsRendering()); | 1889 DCHECK(IsRendering()); |
| 1905 return metafile_.get(); | 1890 return metafile_.get(); |
| 1906 } | 1891 } |
| 1907 | 1892 |
| 1908 const PrintMsg_Print_Params& | |
| 1909 PrintWebViewHelper::PrintPreviewContext::print_params() const { | |
| 1910 DCHECK(state_ != UNINITIALIZED); | |
| 1911 return *print_params_; | |
| 1912 } | |
| 1913 | |
| 1914 int PrintWebViewHelper::PrintPreviewContext::last_error() const { | 1893 int PrintWebViewHelper::PrintPreviewContext::last_error() const { |
| 1915 return error_; | 1894 return error_; |
| 1916 } | 1895 } |
| 1917 | 1896 |
| 1918 gfx::Size PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1897 gfx::Size PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1919 DCHECK(IsRendering()); | 1898 DCHECK(IsRendering()); |
| 1920 return prep_frame_view_->GetPrintCanvasSize(); | 1899 return prep_frame_view_->GetPrintCanvasSize(); |
| 1921 } | 1900 } |
| 1922 | 1901 |
| 1923 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1902 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1924 prep_frame_view_.reset(); | 1903 prep_frame_view_.reset(); |
| 1925 metafile_.reset(); | 1904 metafile_.reset(); |
| 1926 pages_to_render_.clear(); | 1905 pages_to_render_.clear(); |
| 1927 error_ = PREVIEW_ERROR_NONE; | 1906 error_ = PREVIEW_ERROR_NONE; |
| 1928 } | 1907 } |
| OLD | NEW |