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/logging.h" | 10 #include "base/logging.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 !params.supports_alpha_blend; | 68 !params.supports_alpha_blend; |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 73 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
74 const PrintMsg_Print_Params& print_params, | 74 const PrintMsg_Print_Params& print_params, |
75 WebFrame* frame, | 75 WebFrame* frame, |
76 WebNode* node, | 76 WebNode* node, |
77 WebView* web_view) | 77 WebView* web_view) |
78 : frame_(frame), web_view_(web_view), expected_pages_count_(0), | 78 : frame_(frame), |
79 use_browser_overlays_(true) { | 79 web_view_(web_view), |
| 80 expected_pages_count_(0), |
| 81 use_browser_overlays_(true), |
| 82 finished_(false) { |
80 int dpi = GetDPI(&print_params); | 83 int dpi = GetDPI(&print_params); |
81 print_canvas_size_.set_width( | 84 print_canvas_size_.set_width( |
82 ConvertUnit(print_params.printable_size.width(), dpi, | 85 ConvertUnit(print_params.printable_size.width(), dpi, |
83 print_params.desired_dpi)); | 86 print_params.desired_dpi)); |
84 | 87 |
85 print_canvas_size_.set_height( | 88 print_canvas_size_.set_height( |
86 ConvertUnit(print_params.printable_size.height(), dpi, | 89 ConvertUnit(print_params.printable_size.height(), dpi, |
87 print_params.desired_dpi)); | 90 print_params.desired_dpi)); |
88 | 91 |
89 // Layout page according to printer page size. Since WebKit shrinks the | 92 // Layout page according to printer page size. Since WebKit shrinks the |
(...skipping 13 matching lines...) Expand all Loading... |
103 | 106 |
104 WebNode node_to_print; | 107 WebNode node_to_print; |
105 if (node) | 108 if (node) |
106 node_to_print = *node; | 109 node_to_print = *node; |
107 expected_pages_count_ = frame->printBegin( | 110 expected_pages_count_ = frame->printBegin( |
108 print_canvas_size_, node_to_print, static_cast<int>(print_params.dpi), | 111 print_canvas_size_, node_to_print, static_cast<int>(print_params.dpi), |
109 &use_browser_overlays_); | 112 &use_browser_overlays_); |
110 } | 113 } |
111 | 114 |
112 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { | 115 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { |
113 frame_->printEnd(); | 116 FinishPrinting(); |
114 web_view_->resize(prev_view_size_); | |
115 if (WebFrame* web_frame = web_view_->mainFrame()) | |
116 web_frame->setScrollOffset(prev_scroll_offset_); | |
117 } | 117 } |
118 | 118 |
| 119 void PrepareFrameAndViewForPrint::FinishPrinting() { |
| 120 if (!finished_) { |
| 121 finished_ = true; |
| 122 frame_->printEnd(); |
| 123 web_view_->resize(prev_view_size_); |
| 124 if (WebFrame* web_frame = web_view_->mainFrame()) |
| 125 web_frame->setScrollOffset(prev_scroll_offset_); |
| 126 } |
| 127 } |
119 | 128 |
120 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) | 129 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) |
121 : RenderViewObserver(render_view), | 130 : RenderViewObserver(render_view), |
122 RenderViewObserverTracker<PrintWebViewHelper>(render_view), | 131 RenderViewObserverTracker<PrintWebViewHelper>(render_view), |
123 print_web_view_(NULL), | 132 print_web_view_(NULL), |
124 script_initiated_preview_frame_(NULL), | 133 script_initiated_preview_frame_(NULL), |
125 context_menu_preview_node_(NULL), | 134 context_menu_preview_node_(NULL), |
126 user_cancelled_scripted_print_count_(0), | 135 user_cancelled_scripted_print_count_(0), |
127 notify_browser_of_print_failure_(true) { | 136 notify_browser_of_print_failure_(true) { |
128 is_preview_ = switches::IsPrintPreviewEnabled(); | 137 is_preview_ = switches::IsPrintPreviewEnabled(); |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 | 707 |
699 void PrintWebViewHelper::ResetScriptedPrintCount() { | 708 void PrintWebViewHelper::ResetScriptedPrintCount() { |
700 // Reset cancel counter on successful print. | 709 // Reset cancel counter on successful print. |
701 user_cancelled_scripted_print_count_ = 0; | 710 user_cancelled_scripted_print_count_ = 0; |
702 } | 711 } |
703 | 712 |
704 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 713 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
705 ++user_cancelled_scripted_print_count_; | 714 ++user_cancelled_scripted_print_count_; |
706 last_cancelled_script_print_ = base::Time::Now(); | 715 last_cancelled_script_print_ = base::Time::Now(); |
707 } | 716 } |
OLD | NEW |