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/string_number_conversions.h" | |
| 15 #include "base/time.h" | |
| 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_impl.h" | 24 #include "printing/metafile_impl.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.display_header_footer == | |
| 99 newParams.params.display_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 |
| 104 // Gets the byte length of the |text|. | |
| 105 size_t GetString16ByteLength(string16 text) { | |
| 106 return text.length() * sizeof(char16); | |
| 107 } | |
| 108 | |
| 109 // Gets the (x,y) coordinate from where we want to start printing the current | |
| 110 // text depending on the alignment horizontal alignment (LEFT, RIGHT, CENTER) | |
| 111 // and vertical alignment (TOP, BOTTOM). | |
| 112 SkPoint GetHeaderFooterPosition( | |
| 113 string16 text, | |
| 114 SkPaint paint, | |
| 115 printing::HorizontalHeaderFooterPosition hor_pos, | |
| 116 printing::VerticalHeaderFooterPosition ver_pos, | |
| 117 PageSizeMargins& page_size_margins) { | |
| 118 | |
| 119 SkScalar text_width_in_points = paint.measureText( | |
| 120 text.c_str(), GetString16ByteLength(text)); | |
| 121 | |
| 122 SkScalar x; | |
|
dpapad
2011/07/19 15:38:04
SkScalar x(0); Otherwise I am getting compilation
Aayush Kumar
2011/07/19 18:37:19
Done.
Aayush Kumar
2011/07/19 18:37:19
Thanks for pointing it out - it's weird that I did
| |
| 123 switch (hor_pos) { | |
| 124 case printing::LEFT: { | |
| 125 x = page_size_margins.margin_left * (-1) + | |
| 126 printing::kSettingHeaderFooterInterstice; | |
| 127 break; | |
| 128 } | |
| 129 case printing::RIGHT: { | |
| 130 x = ((page_size_margins.content_width + page_size_margins.margin_right) - | |
| 131 (printing::kSettingHeaderFooterInterstice + text_width_in_points)); | |
| 132 break; | |
| 133 } | |
| 134 case printing::CENTER: { | |
| 135 SkScalar available_width = (page_size_margins.margin_left + | |
| 136 page_size_margins.margin_right + | |
| 137 page_size_margins.content_width - | |
| 138 (printing::kSettingHeaderFooterHorizontalRegions + 1) * | |
| 139 printing::kSettingHeaderFooterInterstice) / | |
| 140 printing::kSettingHeaderFooterHorizontalRegions; | |
| 141 x = (available_width - page_size_margins.margin_left + | |
| 142 (available_width - text_width_in_points) / 2); | |
| 143 break; | |
| 144 } | |
| 145 default: { | |
| 146 NOTREACHED(); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 SkScalar y; | |
|
dpapad
2011/07/19 15:38:04
Same here.
Aayush Kumar
2011/07/19 18:37:19
Done.
| |
| 151 switch (ver_pos) { | |
| 152 case printing::TOP: { | |
| 153 y = page_size_margins.margin_top * (-1) + | |
| 154 printing::kSettingHeaderFooterInterstice + | |
| 155 paint.getTextSize(); | |
| 156 break; | |
| 157 } | |
| 158 case printing::BOTTOM: { | |
| 159 y = page_size_margins.margin_bottom + page_size_margins.content_height - | |
| 160 printing::kSettingHeaderFooterInterstice; | |
| 161 break; | |
| 162 } | |
| 163 default: { | |
| 164 NOTREACHED(); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 SkPoint point; | |
| 169 point.set(x, y); | |
| 170 return point; | |
| 171 } | |
| 172 | |
| 173 // Given a text, the positions and the paint object, this method gets the | |
| 174 // coordinates and prints the text at those co-ordinates on the canvas. | |
| 175 void PrintHeaderFooterText( | |
| 176 string16 text, | |
| 177 SkPaint paint, | |
| 178 const SkRefPtr<skia::VectorCanvas>& canvas, | |
| 179 printing::HorizontalHeaderFooterPosition hor_pos, | |
| 180 printing::VerticalHeaderFooterPosition ver_pos, | |
| 181 float webkit_scale_factor, | |
| 182 PageSizeMargins& page_size_margins) { | |
| 183 SkPoint point = GetHeaderFooterPosition(text, paint, hor_pos, ver_pos, | |
| 184 page_size_margins); | |
| 185 point.set(point.x() / webkit_scale_factor, point.y() / webkit_scale_factor); | |
| 186 size_t byte_length = GetString16ByteLength(text); | |
| 187 | |
| 188 canvas->drawText(text.c_str(), byte_length, point.x(), point.y(), paint); | |
| 189 } | |
| 190 | |
| 95 } // namespace | 191 } // namespace |
| 96 | 192 |
| 193 // Given the device and canvas to draw on, prints the appropriate headers | |
| 194 // and footers on to the canvas. | |
| 195 void PrintHeaderAndFooter(SkDevice *device, | |
| 196 const SkRefPtr<skia::VectorCanvas>& canvas, | |
| 197 int page_number, int total_pages, float webkit_scale_factor, | |
| 198 PageSizeMargins& page_size_margins, | |
| 199 const DictionaryValue* header_footer_info) { | |
| 200 // Set the drawing area to draw in the margins. | |
| 201 ((skia::VectorPlatformDeviceSkia* )device) -> | |
| 202 setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | |
| 203 | |
| 204 // Setting up styles for the headers and footers text. | |
| 205 SkPaint paint; | |
| 206 paint.setColor(SK_ColorBLACK); | |
| 207 paint.setTextSize(SkIntToScalar(printing::kSettingHeaderFooterFontSize) / | |
| 208 webkit_scale_factor); | |
| 209 paint.setTypeface(SkTypeface::CreateFromName(NULL, SkTypeface::kNormal)); | |
| 210 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); | |
| 211 | |
| 212 // Ensuring we have enough space to print above and below the page to print | |
| 213 // headers and footers. | |
| 214 if (GetHeaderFooterPosition(UTF8ToUTF16("dummy_string"), paint, | |
| 215 printing::LEFT, printing::TOP, page_size_margins).y() > 0) { | |
| 216 return; | |
| 217 } | |
| 218 if (page_size_margins.margin_bottom - paint.getTextSize() - | |
| 219 printing::kSettingHeaderFooterInterstice < 0) { | |
| 220 return; | |
| 221 } | |
| 222 | |
| 223 // Printing the Date. | |
|
dpapad
2011/07/19 15:38:04
nit: Comments should end with a period, here and e
Aayush Kumar
2011/07/19 18:37:19
Done.
| |
| 224 string16 date = base::TimeFormatShortDateNumeric(Time::Now()); | |
| 225 PrintHeaderFooterText(date, paint, canvas, printing::LEFT, printing::TOP, | |
| 226 webkit_scale_factor, page_size_margins); | |
| 227 | |
| 228 // Printing the title | |
| 229 string16 title; | |
| 230 if (!header_footer_info->GetString(printing::kSettingHeaderFooterTitle, | |
| 231 &title)) { | |
| 232 NOTREACHED(); | |
| 233 } | |
| 234 | |
| 235 SkScalar maxTitleSize = (page_size_margins.margin_left + | |
| 236 page_size_margins.content_width + | |
| 237 page_size_margins.margin_right - | |
| 238 (printing::kSettingHeaderFooterHorizontalRegions + 1) * | |
| 239 printing::kSettingHeaderFooterInterstice) / | |
| 240 printing::kSettingHeaderFooterHorizontalRegions; | |
| 241 title = ui::ElideText(title, paint, maxTitleSize, false); | |
| 242 PrintHeaderFooterText(title, paint, canvas, printing::CENTER, | |
| 243 printing::TOP, webkit_scale_factor, | |
| 244 page_size_margins); | |
| 245 | |
| 246 // Printing the URL | |
| 247 std::string url; | |
| 248 if (!header_footer_info->GetString(printing::kSettingHeaderFooterURL, | |
| 249 &url)) { | |
| 250 NOTREACHED(); | |
| 251 } | |
| 252 GURL gurl(url); | |
| 253 string16 url_elided = ui::ElideUrl(gurl, paint, maxTitleSize, | |
| 254 std::string()); | |
| 255 PrintHeaderFooterText(url_elided, paint, canvas, printing::LEFT, | |
| 256 printing::BOTTOM, webkit_scale_factor, | |
| 257 page_size_margins); | |
| 258 | |
| 259 // Printing the page numbers at the bottom right corner of page. | |
| 260 string16 page_on_page_total = base::IntToString16(page_number) + | |
| 261 UTF8ToUTF16("/") + | |
| 262 base::IntToString16(total_pages); | |
| 263 PrintHeaderFooterText(page_on_page_total, paint, canvas, printing::RIGHT, | |
| 264 printing::BOTTOM, webkit_scale_factor, | |
| 265 page_size_margins); | |
| 266 | |
| 267 // Restore the drawing area to draw in the content area. | |
| 268 ((skia::VectorPlatformDeviceSkia* )device)-> | |
| 269 setDrawingArea(SkPDFDevice::kContent_DrawingArea); | |
| 270 } | |
| 271 | |
| 97 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 272 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
| 98 const PrintMsg_Print_Params& print_params, | 273 const PrintMsg_Print_Params& print_params, |
| 99 WebFrame* frame, | 274 WebFrame* frame, |
| 100 WebNode* node) | 275 WebNode* node) |
| 101 : frame_(frame), | 276 : frame_(frame), |
| 102 web_view_(frame->view()), | 277 web_view_(frame->view()), |
| 103 expected_pages_count_(0), | 278 expected_pages_count_(0), |
| 104 use_browser_overlays_(true), | 279 use_browser_overlays_(true), |
| 105 finished_(false) { | 280 finished_(false) { |
| 106 int dpi = GetDPI(&print_params); | 281 int dpi = GetDPI(&print_params); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 render_view()->webview()->mainFrame(); | 429 render_view()->webview()->mainFrame(); |
| 255 return true; | 430 return true; |
| 256 } | 431 } |
| 257 | 432 |
| 258 void PrintWebViewHelper::OnPrintPages() { | 433 void PrintWebViewHelper::OnPrintPages() { |
| 259 WebFrame* frame; | 434 WebFrame* frame; |
| 260 if (GetPrintFrame(&frame)) | 435 if (GetPrintFrame(&frame)) |
| 261 Print(frame, NULL); | 436 Print(frame, NULL); |
| 262 } | 437 } |
| 263 | 438 |
| 264 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 439 void PrintWebViewHelper::OnPrintPreview( |
| 440 const DictionaryValue& settings, | |
| 441 const DictionaryValue& header_footer_info) { | |
| 265 DCHECK(is_preview_); | 442 DCHECK(is_preview_); |
| 266 print_preview_context_.OnPrintPreview(); | 443 print_preview_context_.OnPrintPreview(); |
| 444 header_footer_info_ = header_footer_info.DeepCopy(); | |
| 267 | 445 |
| 268 if (!InitPrintSettings(print_preview_context_.frame(), | 446 if (!InitPrintSettings(print_preview_context_.frame(), |
| 269 print_preview_context_.node())) { | 447 print_preview_context_.node())) { |
| 270 NOTREACHED(); | 448 NOTREACHED(); |
| 271 return; | 449 return; |
| 272 } | 450 } |
| 273 | 451 |
| 274 if (!UpdatePrintSettings(settings)) { | 452 if (!UpdatePrintSettings(settings)) { |
| 275 DidFinishPrinting(FAIL_PREVIEW); | 453 DidFinishPrinting(FAIL_PREVIEW); |
| 276 return; | 454 return; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 return true; | 723 return true; |
| 546 } | 724 } |
| 547 #endif // OS_MACOSX || OS_WIN | 725 #endif // OS_MACOSX || OS_WIN |
| 548 | 726 |
| 549 void PrintWebViewHelper::didStopLoading() { | 727 void PrintWebViewHelper::didStopLoading() { |
| 550 PrintMsg_PrintPages_Params* params = print_pages_params_.get(); | 728 PrintMsg_PrintPages_Params* params = print_pages_params_.get(); |
| 551 DCHECK(params != NULL); | 729 DCHECK(params != NULL); |
| 552 PrintPages(*params, print_web_view_->mainFrame(), NULL); | 730 PrintPages(*params, print_web_view_->mainFrame(), NULL); |
| 553 } | 731 } |
| 554 | 732 |
| 555 void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( | 733 PageSizeMargins PrintWebViewHelper::GetPageSizeAndMarginsInPoints( |
| 556 WebFrame* frame, | 734 WebFrame* frame, |
| 557 int page_index, | 735 int page_index, |
| 558 const PrintMsg_Print_Params& default_params, | 736 const PrintMsg_Print_Params& default_params) { |
| 559 double* content_width_in_points, | |
| 560 double* content_height_in_points, | |
| 561 double* margin_top_in_points, | |
| 562 double* margin_right_in_points, | |
| 563 double* margin_bottom_in_points, | |
| 564 double* margin_left_in_points) { | |
| 565 int dpi = GetDPI(&default_params); | 737 int dpi = GetDPI(&default_params); |
| 566 | 738 |
| 567 WebSize page_size_in_pixels( | 739 WebSize page_size_in_pixels( |
| 568 ConvertUnit(default_params.page_size.width(), | 740 ConvertUnit(default_params.page_size.width(), |
| 569 dpi, printing::kPixelsPerInch), | 741 dpi, printing::kPixelsPerInch), |
| 570 ConvertUnit(default_params.page_size.height(), | 742 ConvertUnit(default_params.page_size.height(), |
| 571 dpi, printing::kPixelsPerInch)); | 743 dpi, printing::kPixelsPerInch)); |
| 572 int margin_top_in_pixels = ConvertUnit( | 744 int margin_top_in_pixels = ConvertUnit( |
| 573 default_params.margin_top, | 745 default_params.margin_top, |
| 574 dpi, printing::kPixelsPerInch); | 746 dpi, printing::kPixelsPerInch); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 586 | 758 |
| 587 if (frame) { | 759 if (frame) { |
| 588 frame->pageSizeAndMarginsInPixels(page_index, | 760 frame->pageSizeAndMarginsInPixels(page_index, |
| 589 page_size_in_pixels, | 761 page_size_in_pixels, |
| 590 margin_top_in_pixels, | 762 margin_top_in_pixels, |
| 591 margin_right_in_pixels, | 763 margin_right_in_pixels, |
| 592 margin_bottom_in_pixels, | 764 margin_bottom_in_pixels, |
| 593 margin_left_in_pixels); | 765 margin_left_in_pixels); |
| 594 } | 766 } |
| 595 | 767 |
| 596 *content_width_in_points = ConvertPixelsToPoint(page_size_in_pixels.width - | 768 PageSizeMargins page_size_margins_in_points; |
| 597 margin_left_in_pixels - | 769 page_size_margins_in_points.content_width = ConvertPixelsToPoint( |
| 598 margin_right_in_pixels); | 770 page_size_in_pixels.width - margin_left_in_pixels - |
| 599 *content_height_in_points = ConvertPixelsToPoint(page_size_in_pixels.height - | 771 margin_right_in_pixels); |
| 600 margin_top_in_pixels - | 772 page_size_margins_in_points.content_height = ConvertPixelsToPoint( |
| 601 margin_bottom_in_pixels); | 773 page_size_in_pixels.height - margin_top_in_pixels - |
| 774 margin_bottom_in_pixels); | |
| 602 | 775 |
| 603 // Invalid page size and/or margins. We just use the default setting. | 776 // Invalid page size and/or margins. We just use the default setting. |
| 604 if (*content_width_in_points < 1.0 || *content_height_in_points < 1.0) { | 777 if (page_size_margins_in_points.content_width < 1.0 || |
| 605 GetPageSizeAndMarginsInPoints(NULL, | 778 page_size_margins_in_points.content_height < 1.0) { |
| 606 page_index, | 779 return GetPageSizeAndMarginsInPoints(NULL, page_index, default_params); |
| 607 default_params, | |
| 608 content_width_in_points, | |
| 609 content_height_in_points, | |
| 610 margin_top_in_points, | |
| 611 margin_right_in_points, | |
| 612 margin_bottom_in_points, | |
| 613 margin_left_in_points); | |
| 614 return; | |
| 615 } | 780 } |
| 616 | 781 |
| 617 if (margin_top_in_points) | 782 page_size_margins_in_points.margin_top = |
| 618 *margin_top_in_points = | 783 ConvertPixelsToPointDouble(margin_top_in_pixels); |
| 619 ConvertPixelsToPointDouble(margin_top_in_pixels); | 784 page_size_margins_in_points.margin_right = |
| 620 if (margin_right_in_points) | 785 ConvertPixelsToPointDouble(margin_right_in_pixels); |
| 621 *margin_right_in_points = | 786 page_size_margins_in_points.margin_bottom = |
| 622 ConvertPixelsToPointDouble(margin_right_in_pixels); | 787 ConvertPixelsToPointDouble(margin_bottom_in_pixels); |
| 623 if (margin_bottom_in_points) | 788 page_size_margins_in_points.margin_left = |
| 624 *margin_bottom_in_points = | 789 ConvertPixelsToPointDouble(margin_left_in_pixels); |
| 625 ConvertPixelsToPointDouble(margin_bottom_in_pixels); | 790 return page_size_margins_in_points; |
| 626 if (margin_left_in_points) | |
| 627 *margin_left_in_points = | |
| 628 ConvertPixelsToPointDouble(margin_left_in_pixels); | |
| 629 } | 791 } |
| 630 | 792 |
| 631 void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( | 793 void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( |
| 632 WebFrame* frame, | 794 WebFrame* frame, |
| 633 WebNode* node, | 795 WebNode* node, |
| 634 PrintMsg_Print_Params* params) { | 796 PrintMsg_Print_Params* params) { |
| 635 double content_width_in_points; | |
| 636 double content_height_in_points; | |
| 637 double margin_top_in_points; | |
| 638 double margin_right_in_points; | |
| 639 double margin_bottom_in_points; | |
| 640 double margin_left_in_points; | |
| 641 PrepareFrameAndViewForPrint prepare(*params, frame, node); | 797 PrepareFrameAndViewForPrint prepare(*params, frame, node); |
| 642 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, | 798 PageSizeMargins page_size_margins_in_points = |
| 643 &content_width_in_points, &content_height_in_points, | 799 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params); |
| 644 &margin_top_in_points, &margin_right_in_points, | |
| 645 &margin_bottom_in_points, &margin_left_in_points); | |
| 646 int dpi = GetDPI(params); | 800 int dpi = GetDPI(params); |
| 647 params->printable_size = gfx::Size( | 801 params->printable_size = gfx::Size( |
| 648 static_cast<int>(ConvertUnitDouble(content_width_in_points, | 802 static_cast<int>(ConvertUnitDouble( |
| 803 page_size_margins_in_points.content_width, | |
| 649 printing::kPointsPerInch, dpi)), | 804 printing::kPointsPerInch, dpi)), |
| 650 static_cast<int>(ConvertUnitDouble(content_height_in_points, | 805 static_cast<int>(ConvertUnitDouble( |
| 806 page_size_margins_in_points.content_height, | |
| 651 printing::kPointsPerInch, dpi))); | 807 printing::kPointsPerInch, dpi))); |
| 652 | 808 |
| 653 double page_width_in_points = content_width_in_points + | 809 double page_width_in_points = page_size_margins_in_points.content_width + |
| 654 margin_left_in_points + margin_right_in_points; | 810 page_size_margins_in_points.margin_left + |
| 655 double page_height_in_points = content_height_in_points + | 811 page_size_margins_in_points.margin_right; |
| 656 margin_top_in_points + margin_bottom_in_points; | 812 double page_height_in_points = page_size_margins_in_points.content_height + |
| 813 page_size_margins_in_points.margin_top + | |
| 814 page_size_margins_in_points.margin_bottom; | |
| 657 | 815 |
| 658 params->page_size = gfx::Size( | 816 params->page_size = gfx::Size( |
| 659 static_cast<int>(ConvertUnitDouble( | 817 static_cast<int>(ConvertUnitDouble( |
| 660 page_width_in_points, printing::kPointsPerInch, dpi)), | 818 page_width_in_points, printing::kPointsPerInch, dpi)), |
| 661 static_cast<int>(ConvertUnitDouble( | 819 static_cast<int>(ConvertUnitDouble( |
| 662 page_height_in_points, printing::kPointsPerInch, dpi))); | 820 page_height_in_points, printing::kPointsPerInch, dpi))); |
| 663 | 821 |
| 664 params->margin_top = static_cast<int>(ConvertUnitDouble( | 822 params->margin_top = static_cast<int>(ConvertUnitDouble( |
| 665 margin_top_in_points, printing::kPointsPerInch, dpi)); | 823 page_size_margins_in_points.margin_top, printing::kPointsPerInch, dpi)); |
| 666 params->margin_left = static_cast<int>(ConvertUnitDouble( | 824 params->margin_left = static_cast<int>(ConvertUnitDouble( |
| 667 margin_left_in_points, printing::kPointsPerInch, dpi)); | 825 page_size_margins_in_points.margin_left, printing::kPointsPerInch, dpi)); |
| 668 } | 826 } |
| 669 | 827 |
| 670 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, | 828 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, |
| 671 WebKit::WebNode* node) { | 829 WebKit::WebNode* node) { |
| 672 DCHECK(frame); | 830 DCHECK(frame); |
| 673 PrintMsg_PrintPages_Params settings; | 831 PrintMsg_PrintPages_Params settings; |
| 674 | 832 |
| 675 // TODO(abodenha@chromium.org) It doesn't make sense to do this if our | 833 // TODO(abodenha@chromium.org) It doesn't make sense to do this if our |
| 676 // "default" is a cloud based printer. Split InitPrintSettings up | 834 // "default" is a cloud based printer. Split InitPrintSettings up |
| 677 // so that we can avoid the overhead of unneeded calls into the native | 835 // so that we can avoid the overhead of unneeded calls into the native |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 settings.params.margin_top = 150; | 871 settings.params.margin_top = 150; |
| 714 settings.params.margin_left = 150; | 872 settings.params.margin_left = 150; |
| 715 settings.params.dpi = 300.0; | 873 settings.params.dpi = 300.0; |
| 716 settings.params.min_shrink = 1.25; | 874 settings.params.min_shrink = 1.25; |
| 717 settings.params.max_shrink = 2.0; | 875 settings.params.max_shrink = 2.0; |
| 718 settings.params.desired_dpi = 72; | 876 settings.params.desired_dpi = 72; |
| 719 settings.params.selection_only = false; | 877 settings.params.selection_only = false; |
| 720 settings.params.supports_alpha_blend = false; | 878 settings.params.supports_alpha_blend = false; |
| 721 // TODO(abodenha@chromium.org) Parse page ranges from the job_settings. | 879 // TODO(abodenha@chromium.org) Parse page ranges from the job_settings. |
| 722 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 880 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 881 print_pages_params_->params.display_header_footer = false; | |
| 723 return true; | 882 return true; |
| 724 } | 883 } |
| 725 | 884 |
| 726 bool PrintWebViewHelper::UpdatePrintSettingsLocal( | 885 bool PrintWebViewHelper::UpdatePrintSettingsLocal( |
| 727 const DictionaryValue& job_settings) { | 886 const DictionaryValue& job_settings) { |
| 728 PrintMsg_PrintPages_Params settings; | 887 PrintMsg_PrintPages_Params settings; |
| 729 | 888 |
| 730 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 889 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 731 print_pages_params_->params.document_cookie, job_settings, &settings)); | 890 print_pages_params_->params.document_cookie, job_settings, &settings)); |
| 732 | 891 |
| 733 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) | 892 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) |
| 734 return false; | 893 return false; |
| 735 | 894 |
| 736 if (!job_settings.GetInteger(printing::kPreviewRequestID, | 895 if (!job_settings.GetInteger(printing::kPreviewRequestID, |
| 737 &settings.params.preview_request_id)) { | 896 &settings.params.preview_request_id)) { |
| 738 NOTREACHED(); | 897 NOTREACHED(); |
| 739 return false; | 898 return false; |
| 740 } | 899 } |
| 741 | 900 |
| 742 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 901 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 902 bool header_footer; | |
| 903 if (!job_settings.GetBoolean(printing::kSettingHeaderFooter, &header_footer)) | |
| 904 NOTREACHED(); | |
| 905 print_pages_params_->params.display_header_footer = header_footer; | |
| 906 | |
| 743 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 907 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 744 settings.params.document_cookie)); | 908 settings.params.document_cookie)); |
| 745 return true; | 909 return true; |
| 746 } | 910 } |
| 747 | 911 |
| 748 bool PrintWebViewHelper::UpdatePrintSettings( | 912 bool PrintWebViewHelper::UpdatePrintSettings( |
| 749 const DictionaryValue& job_settings) { | 913 const DictionaryValue& job_settings) { |
| 750 if (job_settings.HasKey(printing::kSettingCloudPrintId)) { | 914 if (job_settings.HasKey(printing::kSettingCloudPrintId)) { |
| 751 return UpdatePrintSettingsCloud(job_settings); | 915 return UpdatePrintSettingsCloud(job_settings); |
| 752 } else { | 916 } else { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 const gfx::Size& | 1218 const gfx::Size& |
| 1055 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1219 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1056 return prep_frame_view_->GetPrintCanvasSize(); | 1220 return prep_frame_view_->GetPrintCanvasSize(); |
| 1057 } | 1221 } |
| 1058 | 1222 |
| 1059 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1223 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1060 prep_frame_view_.reset(); | 1224 prep_frame_view_.reset(); |
| 1061 metafile_.reset(); | 1225 metafile_.reset(); |
| 1062 rendered_pages_.clear(); | 1226 rendered_pages_.clear(); |
| 1063 } | 1227 } |
| OLD | NEW |