Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "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/i18n/time_formatting.h" | |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/time.h" | |
| 15 #include "base/string_number_conversions.h" | |
|
kmadhusu
2011/07/14 01:50:15
nit: ordering
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 13 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/print_messages.h" | 18 #include "chrome/common/print_messages.h" |
| 16 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
| 17 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/renderer/prerender/prerender_helper.h" | 21 #include "chrome/renderer/prerender/prerender_helper.h" |
| 19 #include "content/renderer/render_view.h" | 22 #include "content/renderer/render_view.h" |
| 20 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 21 #include "printing/metafile.h" | 24 #include "printing/metafile.h" |
| 22 #include "printing/print_job_constants.h" | 25 #include "printing/print_job_constants.h" |
| 23 #include "printing/units.h" | 26 #include "printing/units.h" |
| 27 #include "skia/ext/vector_platform_device_skia.h" | |
| 28 #include "third_party/skia/include/core/SkTypeface.h" | |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/text/text_elider.h" | |
| 35 | 41 |
| 36 #if defined(OS_POSIX) | 42 #if defined(OS_POSIX) |
| 37 #include "content/common/view_messages.h" | 43 #include "content/common/view_messages.h" |
| 38 #endif | 44 #endif |
| 39 | 45 |
| 46 using base::Time; | |
| 40 using printing::ConvertPixelsToPoint; | 47 using printing::ConvertPixelsToPoint; |
| 41 using printing::ConvertPixelsToPointDouble; | 48 using printing::ConvertPixelsToPointDouble; |
| 42 using printing::ConvertUnit; | 49 using printing::ConvertUnit; |
| 43 using printing::ConvertUnitDouble; | 50 using printing::ConvertUnitDouble; |
| 44 using WebKit::WebConsoleMessage; | 51 using WebKit::WebConsoleMessage; |
| 45 using WebKit::WebDocument; | 52 using WebKit::WebDocument; |
| 46 using WebKit::WebElement; | 53 using WebKit::WebElement; |
| 47 using WebKit::WebFrame; | 54 using WebKit::WebFrame; |
| 48 using WebKit::WebNode; | 55 using WebKit::WebNode; |
| 49 using WebKit::WebSize; | 56 using WebKit::WebSize; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 oldParams.params.min_shrink == newParams.params.min_shrink && | 88 oldParams.params.min_shrink == newParams.params.min_shrink && |
| 82 oldParams.params.dpi == newParams.params.dpi && | 89 oldParams.params.dpi == newParams.params.dpi && |
| 83 oldParams.params.printable_size == newParams.params.printable_size && | 90 oldParams.params.printable_size == newParams.params.printable_size && |
| 84 oldParams.params.selection_only == newParams.params.selection_only && | 91 oldParams.params.selection_only == newParams.params.selection_only && |
| 85 oldParams.params.page_size == newParams.params.page_size && | 92 oldParams.params.page_size == newParams.params.page_size && |
| 86 oldParams.params.margin_top == newParams.params.margin_top && | 93 oldParams.params.margin_top == newParams.params.margin_top && |
| 87 oldParams.params.margin_left == newParams.params.margin_left && | 94 oldParams.params.margin_left == newParams.params.margin_left && |
| 88 oldParams.params.supports_alpha_blend == | 95 oldParams.params.supports_alpha_blend == |
| 89 newParams.params.supports_alpha_blend && | 96 newParams.params.supports_alpha_blend && |
| 90 oldParams.pages.size() == newParams.pages.size() && | 97 oldParams.pages.size() == newParams.pages.size() && |
| 98 oldParams.params.header_footer == | |
| 99 newParams.params.header_footer && | |
| 91 std::equal(oldParams.pages.begin(), oldParams.pages.end(), | 100 std::equal(oldParams.pages.begin(), oldParams.pages.end(), |
| 92 newParams.pages.begin()); | 101 newParams.pages.begin()); |
| 93 } | 102 } |
| 94 | 103 |
| 95 } // namespace | 104 } // namespace |
| 96 | 105 |
| 97 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 106 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
| 98 const PrintMsg_Print_Params& print_params, | 107 const PrintMsg_Print_Params& print_params, |
| 99 WebFrame* frame, | 108 WebFrame* frame, |
| 100 WebNode* node, | 109 WebNode* node, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 160 } |
| 152 | 161 |
| 153 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) | 162 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) |
| 154 : RenderViewObserver(render_view), | 163 : RenderViewObserver(render_view), |
| 155 RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 164 RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
| 156 print_web_view_(NULL), | 165 print_web_view_(NULL), |
| 157 script_initiated_preview_frame_(NULL), | 166 script_initiated_preview_frame_(NULL), |
| 158 context_menu_preview_node_(NULL), | 167 context_menu_preview_node_(NULL), |
| 159 user_cancelled_scripted_print_count_(0), | 168 user_cancelled_scripted_print_count_(0), |
| 160 notify_browser_of_print_failure_(true), | 169 notify_browser_of_print_failure_(true), |
| 161 preview_page_count_(0) { | 170 preview_page_count_(0), |
| 171 header_footer_interstice(printing::kSettingHeaderFooterInterstice) { | |
| 162 is_preview_ = switches::IsPrintPreviewEnabled(); | 172 is_preview_ = switches::IsPrintPreviewEnabled(); |
| 163 } | 173 } |
| 164 | 174 |
| 165 PrintWebViewHelper::~PrintWebViewHelper() {} | 175 PrintWebViewHelper::~PrintWebViewHelper() {} |
| 166 | 176 |
| 167 // Prints |frame| which called window.print(). | 177 // Prints |frame| which called window.print(). |
| 168 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) { | 178 void PrintWebViewHelper::PrintPage(WebKit::WebFrame* frame) { |
| 169 DCHECK(frame); | 179 DCHECK(frame); |
| 170 | 180 |
| 171 // Allow Prerendering to cancel this print request if necessary. | 181 // Allow Prerendering to cancel this print request if necessary. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 render_view()->webview()->mainFrame(); | 269 render_view()->webview()->mainFrame(); |
| 260 return true; | 270 return true; |
| 261 } | 271 } |
| 262 | 272 |
| 263 void PrintWebViewHelper::OnPrintPages() { | 273 void PrintWebViewHelper::OnPrintPages() { |
| 264 WebFrame* frame; | 274 WebFrame* frame; |
| 265 if (GetPrintFrame(&frame)) | 275 if (GetPrintFrame(&frame)) |
| 266 Print(frame, NULL); | 276 Print(frame, NULL); |
| 267 } | 277 } |
| 268 | 278 |
| 269 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 279 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings, |
| 280 const DictionaryValue& header_footer_info) { | |
| 270 DCHECK(is_preview_); | 281 DCHECK(is_preview_); |
| 271 DCHECK(!context_menu_preview_node_.get() || !script_initiated_preview_frame_); | 282 DCHECK(!context_menu_preview_node_.get() || !script_initiated_preview_frame_); |
| 272 | 283 |
| 284 header_footer_info_ = header_footer_info.DeepCopy(); | |
| 285 | |
| 273 if (script_initiated_preview_frame_) { | 286 if (script_initiated_preview_frame_) { |
| 274 // Script initiated print preview. | 287 // Script initiated print preview. |
| 275 PrintPreview(script_initiated_preview_frame_, NULL, settings); | 288 PrintPreview(script_initiated_preview_frame_, NULL, settings); |
| 276 } else if (context_menu_preview_node_.get()) { | 289 } else if (context_menu_preview_node_.get()) { |
| 277 // User initiated - print node under context menu. | 290 // User initiated - print node under context menu. |
| 278 PrintPreview(context_menu_preview_node_->document().frame(), | 291 PrintPreview(context_menu_preview_node_->document().frame(), |
| 279 context_menu_preview_node_.get(), settings); | 292 context_menu_preview_node_.get(), settings); |
| 280 } else { | 293 } else { |
| 281 // User initiated - normal print preview. | 294 // User initiated - normal print preview. |
| 282 WebFrame* frame; | 295 WebFrame* frame; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 | 505 |
| 493 void PrintWebViewHelper::didStopLoading() { | 506 void PrintWebViewHelper::didStopLoading() { |
| 494 PrintMsg_PrintPages_Params* params = print_pages_params_.get(); | 507 PrintMsg_PrintPages_Params* params = print_pages_params_.get(); |
| 495 DCHECK(params != NULL); | 508 DCHECK(params != NULL); |
| 496 PrintPages(*params, print_web_view_->mainFrame(), NULL); | 509 PrintPages(*params, print_web_view_->mainFrame(), NULL); |
| 497 } | 510 } |
| 498 | 511 |
| 499 void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( | 512 void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( |
| 500 WebFrame* frame, | 513 WebFrame* frame, |
| 501 int page_index, | 514 int page_index, |
| 502 const PrintMsg_Print_Params& default_params, | 515 const PrintMsg_Print_Params& default_params) { |
| 503 double* content_width_in_points, | |
| 504 double* content_height_in_points, | |
| 505 double* margin_top_in_points, | |
| 506 double* margin_right_in_points, | |
| 507 double* margin_bottom_in_points, | |
| 508 double* margin_left_in_points) { | |
| 509 int dpi = GetDPI(&default_params); | 516 int dpi = GetDPI(&default_params); |
| 510 | 517 |
| 511 WebSize page_size_in_pixels( | 518 WebSize page_size_in_pixels( |
| 512 ConvertUnit(default_params.page_size.width(), | 519 ConvertUnit(default_params.page_size.width(), |
| 513 dpi, printing::kPixelsPerInch), | 520 dpi, printing::kPixelsPerInch), |
| 514 ConvertUnit(default_params.page_size.height(), | 521 ConvertUnit(default_params.page_size.height(), |
| 515 dpi, printing::kPixelsPerInch)); | 522 dpi, printing::kPixelsPerInch)); |
| 516 int margin_top_in_pixels = ConvertUnit( | 523 int margin_top_in_pixels = ConvertUnit( |
| 517 default_params.margin_top, | 524 default_params.margin_top, |
| 518 dpi, printing::kPixelsPerInch); | 525 dpi, printing::kPixelsPerInch); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 530 | 537 |
| 531 if (frame) { | 538 if (frame) { |
| 532 frame->pageSizeAndMarginsInPixels(page_index, | 539 frame->pageSizeAndMarginsInPixels(page_index, |
| 533 page_size_in_pixels, | 540 page_size_in_pixels, |
| 534 margin_top_in_pixels, | 541 margin_top_in_pixels, |
| 535 margin_right_in_pixels, | 542 margin_right_in_pixels, |
| 536 margin_bottom_in_pixels, | 543 margin_bottom_in_pixels, |
| 537 margin_left_in_pixels); | 544 margin_left_in_pixels); |
| 538 } | 545 } |
| 539 | 546 |
| 540 *content_width_in_points = ConvertPixelsToPoint(page_size_in_pixels.width - | 547 content_width_in_points = ConvertPixelsToPoint(page_size_in_pixels.width - |
| 541 margin_left_in_pixels - | 548 margin_left_in_pixels - |
| 542 margin_right_in_pixels); | 549 margin_right_in_pixels); |
| 543 *content_height_in_points = ConvertPixelsToPoint(page_size_in_pixels.height - | 550 content_height_in_points = ConvertPixelsToPoint(page_size_in_pixels.height - |
| 544 margin_top_in_pixels - | 551 margin_top_in_pixels - |
| 545 margin_bottom_in_pixels); | 552 margin_bottom_in_pixels); |
| 546 | 553 |
| 547 // Invalid page size and/or margins. We just use the default setting. | 554 // Invalid page size and/or margins. We just use the default setting. |
| 548 if (*content_width_in_points < 1.0 || *content_height_in_points < 1.0) { | 555 if (content_width_in_points < 1.0 || content_height_in_points < 1.0) { |
| 549 GetPageSizeAndMarginsInPoints(NULL, | 556 GetPageSizeAndMarginsInPoints(NULL, |
| 550 page_index, | 557 page_index, |
| 551 default_params, | 558 default_params); |
| 552 content_width_in_points, | |
| 553 content_height_in_points, | |
| 554 margin_top_in_points, | |
| 555 margin_right_in_points, | |
| 556 margin_bottom_in_points, | |
| 557 margin_left_in_points); | |
| 558 return; | 559 return; |
| 559 } | 560 } |
| 560 | 561 |
| 561 if (margin_top_in_points) | 562 margin_top_in_points = ConvertPixelsToPointDouble(margin_top_in_pixels); |
| 562 *margin_top_in_points = | 563 margin_right_in_points = ConvertPixelsToPointDouble(margin_right_in_pixels); |
| 563 ConvertPixelsToPointDouble(margin_top_in_pixels); | 564 margin_bottom_in_points = |
| 564 if (margin_right_in_points) | |
| 565 *margin_right_in_points = | |
| 566 ConvertPixelsToPointDouble(margin_right_in_pixels); | |
| 567 if (margin_bottom_in_points) | |
| 568 *margin_bottom_in_points = | |
| 569 ConvertPixelsToPointDouble(margin_bottom_in_pixels); | 565 ConvertPixelsToPointDouble(margin_bottom_in_pixels); |
| 570 if (margin_left_in_points) | 566 margin_left_in_points = ConvertPixelsToPointDouble(margin_left_in_pixels); |
| 571 *margin_left_in_points = | |
| 572 ConvertPixelsToPointDouble(margin_left_in_pixels); | |
| 573 } | 567 } |
| 574 | 568 |
| 575 bool PrintWebViewHelper::IsModifiable(WebKit::WebFrame* frame, | 569 bool PrintWebViewHelper::IsModifiable(WebKit::WebFrame* frame, |
| 576 WebKit::WebNode* node) { | 570 WebKit::WebNode* node) { |
| 577 if (node) | 571 if (node) |
| 578 return false; | 572 return false; |
| 579 std::string mime(frame->dataSource()->response().mimeType().utf8()); | 573 std::string mime(frame->dataSource()->response().mimeType().utf8()); |
| 580 if (mime == "application/pdf") | 574 if (mime == "application/pdf") |
| 581 return false; | 575 return false; |
| 582 return true; | 576 return true; |
| 583 } | 577 } |
| 584 | 578 |
| 585 void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( | 579 void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( |
| 586 WebFrame* frame, | 580 WebFrame* frame, |
| 587 WebNode* node, | 581 WebNode* node, |
| 588 PrintMsg_Print_Params* params) { | 582 PrintMsg_Print_Params* params) { |
| 589 double content_width_in_points; | |
| 590 double content_height_in_points; | |
| 591 double margin_top_in_points; | |
| 592 double margin_right_in_points; | |
| 593 double margin_bottom_in_points; | |
| 594 double margin_left_in_points; | |
| 595 PrepareFrameAndViewForPrint prepare(*params, frame, node, frame->view()); | 583 PrepareFrameAndViewForPrint prepare(*params, frame, node, frame->view()); |
| 596 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, | 584 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params); |
| 597 &content_width_in_points, &content_height_in_points, | |
| 598 &margin_top_in_points, &margin_right_in_points, | |
| 599 &margin_bottom_in_points, &margin_left_in_points); | |
| 600 int dpi = GetDPI(params); | 585 int dpi = GetDPI(params); |
| 601 params->printable_size = gfx::Size( | 586 params->printable_size = gfx::Size( |
| 602 static_cast<int>(ConvertUnitDouble(content_width_in_points, | 587 static_cast<int>(ConvertUnitDouble(content_width_in_points, |
| 603 printing::kPointsPerInch, dpi)), | 588 printing::kPointsPerInch, dpi)), |
| 604 static_cast<int>(ConvertUnitDouble(content_height_in_points, | 589 static_cast<int>(ConvertUnitDouble(content_height_in_points, |
| 605 printing::kPointsPerInch, dpi))); | 590 printing::kPointsPerInch, dpi))); |
| 606 | 591 |
| 607 double page_width_in_points = content_width_in_points + | 592 double page_width_in_points = content_width_in_points + |
| 608 margin_left_in_points + margin_right_in_points; | 593 margin_left_in_points + margin_right_in_points; |
| 609 double page_height_in_points = content_height_in_points + | 594 double page_height_in_points = content_height_in_points + |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 PrintMsg_PrintPages_Params settings; | 648 PrintMsg_PrintPages_Params settings; |
| 664 settings.params.page_size = gfx::Size(2550, 3300); | 649 settings.params.page_size = gfx::Size(2550, 3300); |
| 665 settings.params.printable_size = gfx::Size(2250, 3000); | 650 settings.params.printable_size = gfx::Size(2250, 3000); |
| 666 settings.params.margin_top = 150; | 651 settings.params.margin_top = 150; |
| 667 settings.params.margin_left = 150; | 652 settings.params.margin_left = 150; |
| 668 settings.params.dpi = 300.0; | 653 settings.params.dpi = 300.0; |
| 669 settings.params.min_shrink = 1.25; | 654 settings.params.min_shrink = 1.25; |
| 670 settings.params.max_shrink = 2.0; | 655 settings.params.max_shrink = 2.0; |
| 671 settings.params.desired_dpi = 72; | 656 settings.params.desired_dpi = 72; |
| 672 settings.params.selection_only = false; | 657 settings.params.selection_only = false; |
| 673 settings.params.supports_alpha_blend = false; | 658 settings.params.supports_alpha_blend = false; |
|
kmadhusu
2011/07/14 01:50:15
You need to set "settings.header_footer = false;"
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 674 // TODO(abodenha@chromium.org) Parse page ranges from the job_settings. | 659 // TODO(abodenha@chromium.org) Parse page ranges from the job_settings. |
| 675 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 660 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 676 return true; | 661 return true; |
| 677 } | 662 } |
| 678 | 663 |
| 679 bool PrintWebViewHelper::UpdatePrintSettingsLocal( | 664 bool PrintWebViewHelper::UpdatePrintSettingsLocal( |
| 680 const DictionaryValue& job_settings) { | 665 const DictionaryValue& job_settings) { |
| 681 PrintMsg_PrintPages_Params settings; | 666 PrintMsg_PrintPages_Params settings; |
| 682 | 667 |
| 683 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 668 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 684 print_pages_params_->params.document_cookie, job_settings, &settings)); | 669 print_pages_params_->params.document_cookie, job_settings, &settings)); |
| 685 | 670 |
| 686 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) | 671 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) |
| 687 return false; | 672 return false; |
| 688 | 673 |
| 689 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 674 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 675 bool header_footer; | |
| 676 if (!job_settings.GetBoolean(printing::kSettingHeaderFooter, &header_footer)) | |
| 677 NOTREACHED(); | |
| 678 print_pages_params_.get()->params.header_footer = header_footer; | |
|
kmadhusu
2011/07/14 01:50:15
"print_pages_params_.get()" -> "print_pages_params
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 679 | |
| 690 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 680 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 691 settings.params.document_cookie)); | 681 settings.params.document_cookie)); |
| 692 return true; | 682 return true; |
| 693 } | 683 } |
| 694 | 684 |
| 695 bool PrintWebViewHelper::UpdatePrintSettings( | 685 bool PrintWebViewHelper::UpdatePrintSettings( |
| 696 const DictionaryValue& job_settings) { | 686 const DictionaryValue& job_settings) { |
| 697 if (job_settings.HasKey(printing::kSettingCloudPrintId)) { | 687 if (job_settings.HasKey(printing::kSettingCloudPrintId)) { |
| 698 return UpdatePrintSettingsCloud(job_settings); | 688 return UpdatePrintSettingsCloud(job_settings); |
| 699 } else { | 689 } else { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 Send(new PrintHostMsg_RequestPrintPreview(routing_id())); | 846 Send(new PrintHostMsg_RequestPrintPreview(routing_id())); |
| 857 } | 847 } |
| 858 | 848 |
| 859 bool PrintWebViewHelper::PreviewPageRendered(int page_number) { | 849 bool PrintWebViewHelper::PreviewPageRendered(int page_number) { |
| 860 bool cancel = false; | 850 bool cancel = false; |
| 861 Send(new PrintHostMsg_DidPreviewPage(routing_id(), page_number, &cancel)); | 851 Send(new PrintHostMsg_DidPreviewPage(routing_id(), page_number, &cancel)); |
| 862 if (cancel) | 852 if (cancel) |
| 863 notify_browser_of_print_failure_ = false; | 853 notify_browser_of_print_failure_ = false; |
| 864 return !cancel; | 854 return !cancel; |
| 865 } | 855 } |
| 856 | |
| 857 size_t GetString16ByteLength(string16 text) { | |
| 858 return text.length()*sizeof(char16); | |
| 859 } | |
| 860 | |
| 861 SkScalar PrintWebViewHelper::GetHorizontalCoordinate( | |
| 862 string16 text, | |
| 863 SkPaint paint, | |
| 864 HorizontalHeaderFooterPosition pos) { | |
| 865 SkScalar text_width_in_points = paint.measureText(text.c_str(), | |
| 866 GetString16ByteLength(text)); | |
| 867 | |
| 868 switch (pos) { | |
|
kmadhusu
2011/07/14 01:50:15
Why did you use switch() here and if() in GetVerti
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 869 case LEFT: | |
|
kmadhusu
2011/07/14 01:50:15
nit: curly braces.
http://google-styleguide.googl
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 870 return margin_left_in_points*(-1) + header_footer_interstice; | |
| 871 case RIGHT: | |
| 872 return ((content_width_in_points+margin_right_in_points) - | |
|
kmadhusu
2011/07/14 01:50:15
nit: add space before and after '+'
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 873 (header_footer_interstice + text_width_in_points)); | |
| 874 case CENTER: | |
| 875 SkScalar available_width = (margin_left_in_points + | |
| 876 margin_right_in_points + | |
| 877 content_width_in_points - | |
| 878 4*header_footer_interstice)/3; | |
| 879 return (available_width - margin_left_in_points + | |
| 880 (available_width - text_width_in_points)/2); | |
| 881 } | |
| 882 NOTREACHED(); | |
| 883 return 0; | |
| 884 } | |
| 885 | |
| 886 SkScalar PrintWebViewHelper::GetVerticalCoordinate( | |
|
kmadhusu
2011/07/14 01:50:15
Are you planning to call GetHorizontalCoordinate()
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 887 SkPaint paint, | |
| 888 VerticalHeaderFooterPosition pos) { | |
| 889 if (pos == TOP) { | |
| 890 return margin_top_in_points*(-1) + header_footer_interstice + | |
| 891 paint.getTextSize(); | |
| 892 } else if (pos == BOTTOM) { | |
| 893 return margin_bottom_in_points+content_height_in_points - | |
|
kmadhusu
2011/07/14 01:50:15
nit: add space before and after '+'
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 894 header_footer_interstice; | |
| 895 } else { | |
| 896 NOTREACHED(); | |
| 897 return 0; | |
| 898 } | |
| 899 } | |
| 900 | |
| 901 void PrintWebViewHelper::PrintHeaderFooterText( | |
| 902 string16 text, | |
| 903 SkPaint paint, | |
| 904 const SkRefPtr<skia::VectorCanvas>& canvas, | |
| 905 HorizontalHeaderFooterPosition hor_pos, | |
| 906 VerticalHeaderFooterPosition ver_pos, | |
| 907 float webkit_scale_factor) { | |
| 908 SkScalar x_cord = GetHorizontalCoordinate(text, paint, hor_pos) / | |
| 909 webkit_scale_factor; | |
| 910 SkScalar y_cord = GetVerticalCoordinate(paint, ver_pos) / | |
| 911 webkit_scale_factor; | |
| 912 size_t byte_length = GetString16ByteLength(text); | |
| 913 | |
| 914 canvas->drawText(text.c_str(), byte_length, x_cord, y_cord, paint); | |
| 915 } | |
| 916 | |
| 917 void PrintWebViewHelper::PrintHeaderAndFooter(SkDevice *device, | |
| 918 const SkRefPtr<skia::VectorCanvas>& canvas, | |
| 919 int page_number, int total_pages, float webkit_scale_factor) { | |
| 920 | |
| 921 // Set the drawing area to draw in the margins. | |
| 922 ((skia::VectorPlatformDeviceSkia* )device)-> | |
|
kmadhusu
2011/07/14 01:50:15
Remove outer paranthesis "(skia::VectorPlatformDev
Aayush Kumar
2011/07/19 01:20:30
That doesn't work. It tries to call setDrawingAre
| |
| 923 setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | |
| 924 | |
| 925 // Setting up styles for the headers and footers text. | |
| 926 SkPaint paint; | |
| 927 paint.setColor(SK_ColorBLACK); | |
| 928 paint.setTextSize(SkIntToScalar(8)/webkit_scale_factor); | |
|
kmadhusu
2011/07/14 01:50:15
Is there any specific reason to use "8"?
dpapad
2011/07/14 15:59:35
Spaces around /.
Aayush Kumar
2011/07/19 01:20:30
It's what looked good on the page according to me
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 929 paint.setTypeface(SkTypeface::CreateFromName(NULL, SkTypeface::kNormal)); | |
| 930 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); | |
| 931 | |
| 932 // Printing the Date | |
| 933 Time now = Time::Now(); | |
| 934 string16 date = base::TimeFormatShortDateNumeric(now); | |
|
kmadhusu
2011/07/14 01:50:15
|now| is used only once.
Change line 934 to base
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 935 PrintHeaderFooterText(date, paint, canvas, LEFT, TOP, webkit_scale_factor); | |
| 936 | |
| 937 // Printing the title | |
| 938 string16 title; | |
| 939 if (!header_footer_info_->GetString("title", &title)) | |
|
kmadhusu
2011/07/14 01:50:15
"title" -> printing::kSettingHeaderFooterTitle
Aayush Kumar
2011/07/19 01:20:30
Thanks! :)
On 2011/07/14 01:50:15, kmadhusu wrote:
| |
| 940 NOTREACHED(); | |
| 941 | |
| 942 SkScalar maxTitleSize = (margin_left_in_points + | |
| 943 content_width_in_points + | |
| 944 margin_right_in_points - | |
| 945 4*header_footer_interstice)/3; | |
| 946 title = ui::ElideText(title, paint, maxTitleSize, false); | |
| 947 PrintHeaderFooterText(title, paint, canvas, CENTER, TOP, | |
| 948 webkit_scale_factor); | |
|
kmadhusu
2011/07/14 01:50:15
Fix indentation.
PrintHeaderFooterText(title, pai
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 949 | |
| 950 // Printing the URL | |
| 951 std::string url; | |
| 952 if (!header_footer_info_->GetString("url", &url)) | |
|
kmadhusu
2011/07/14 01:50:15
"url" -> printing::kSettingHeaderFooterURL
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 953 NOTREACHED(); | |
| 954 GURL gurl(url); | |
| 955 string16 url_elided = ui::ElideUrl(gurl, paint, maxTitleSize, | |
| 956 std::string()); | |
| 957 PrintHeaderFooterText(url_elided, paint, canvas, LEFT, BOTTOM, | |
| 958 webkit_scale_factor); | |
|
kmadhusu
2011/07/14 01:50:15
Fix indentation
Aayush Kumar
2011/07/19 01:20:30
Done.
| |
| 959 | |
| 960 // Printing the page numbers at the bottom right corner of page. | |
| 961 string16 page_on_page_total = base::IntToString16(page_number) + | |
| 962 UTF8ToUTF16("/") + | |
| 963 base::IntToString16(total_pages); | |
| 964 PrintHeaderFooterText(page_on_page_total, paint, canvas, RIGHT, BOTTOM, | |
| 965 webkit_scale_factor); | |
| 966 | |
| 967 // Restore the drawing area to draw in the content area. | |
| 968 ((skia::VectorPlatformDeviceSkia* )device)-> | |
| 969 setDrawingArea(SkPDFDevice::kContent_DrawingArea); | |
| 970 } | |
| OLD | NEW |