OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/render_widget.h" | 5 #include "chrome/renderer/render_widget.h" |
6 | 6 |
7 #include "app/surface/transport_dib.h" | 7 #include "app/surface/transport_dib.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) | 142 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
143 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) | 143 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) |
144 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) | 144 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) |
145 IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck) | 145 IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck) |
146 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck) | 146 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck) |
147 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) | 147 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
148 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) | 148 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
149 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) | 149 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
150 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode) | 150 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode) |
151 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) | 151 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
| 152 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) |
152 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) | 153 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
153 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 154 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
154 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 155 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
155 IPC_MESSAGE_UNHANDLED_ERROR() | 156 IPC_MESSAGE_UNHANDLED_ERROR() |
156 IPC_END_MESSAGE_MAP() | 157 IPC_END_MESSAGE_MAP() |
157 | 158 |
158 bool RenderWidget::Send(IPC::Message* message) { | 159 bool RenderWidget::Send(IPC::Message* message) { |
159 // Don't send any messages after the browser has told us to close. | 160 // Don't send any messages after the browser has told us to close. |
160 if (closing_) { | 161 if (closing_) { |
161 delete message; | 162 delete message; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 if (!webwidget_) | 244 if (!webwidget_) |
244 return; | 245 return; |
245 | 246 |
246 // See OnWasHidden | 247 // See OnWasHidden |
247 SetHidden(false); | 248 SetHidden(false); |
248 | 249 |
249 if (!needs_repainting && !needs_repainting_on_restore_) | 250 if (!needs_repainting && !needs_repainting_on_restore_) |
250 return; | 251 return; |
251 needs_repainting_on_restore_ = false; | 252 needs_repainting_on_restore_ = false; |
252 | 253 |
253 // Tag the next paint as a restore ack, which is picked up by DoDeferredUpdate | 254 // Tag the next paint as a restore ack, which is picked up by |
254 // when it sends out the next PaintRect message. | 255 // DoDeferredUpdate when it sends out the next PaintRect message. |
255 set_next_paint_is_restore_ack(); | 256 set_next_paint_is_restore_ack(); |
256 | 257 |
257 // Generate a full repaint. | 258 // Generate a full repaint. |
258 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 259 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
259 } | 260 } |
260 | 261 |
261 void RenderWidget::OnRequestMoveAck() { | 262 void RenderWidget::OnRequestMoveAck() { |
262 DCHECK(pending_window_rect_count_); | 263 DCHECK(pending_window_rect_count_); |
263 pending_window_rect_count_--; | 264 pending_window_rect_count_--; |
264 } | 265 } |
265 | 266 |
266 void RenderWidget::OnUpdateRectAck() { | 267 void RenderWidget::OnUpdateRectAck() { |
267 DCHECK(update_reply_pending()); | 268 DCHECK(update_reply_pending()); |
268 update_reply_pending_ = false; | 269 update_reply_pending_ = false; |
269 | 270 |
270 // If we sent an UpdateRect message with a zero-sized bitmap, then we should | 271 // If we sent an UpdateRect message with a zero-sized bitmap, then we should |
271 // have no current update buf. | 272 // have no current paint buffer. |
272 if (current_paint_buf_) { | 273 if (current_paint_buf_) { |
273 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 274 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
274 current_paint_buf_ = NULL; | 275 current_paint_buf_ = NULL; |
275 } | 276 } |
276 | 277 |
277 // Notify subclasses. | 278 // Notify subclasses. |
278 DidFlushPaint(); | 279 DidFlushPaint(); |
279 | 280 |
280 // Continue painting if necessary... | 281 // Continue painting if necessary... |
281 CallDoDeferredUpdate(); | 282 CallDoDeferredUpdate(); |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 if (!webwidget_->handleCompositionEvent(command, cursor_position, | 714 if (!webwidget_->handleCompositionEvent(command, cursor_position, |
714 target_start, target_end, ime_string)) { | 715 target_start, target_end, ime_string)) { |
715 // If the composition event can't be handled, let the browser process | 716 // If the composition event can't be handled, let the browser process |
716 // know so it can update it's state. | 717 // know so it can update it's state. |
717 Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_CANCEL_COMPOSITION, | 718 Send(new ViewHostMsg_ImeUpdateStatus(routing_id(), IME_CANCEL_COMPOSITION, |
718 WebRect())); | 719 WebRect())); |
719 } | 720 } |
720 ime_control_busy_ = false; | 721 ime_control_busy_ = false; |
721 } | 722 } |
722 | 723 |
| 724 // Forces a repaint even if we're hidden, so we can update backing |
| 725 // store even before a tab has been shown for the first time, and it |
| 726 // does it synchronously. |
| 727 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, |
| 728 const gfx::Size& desired_size) { |
| 729 if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue()) |
| 730 return; |
| 731 |
| 732 if (webwidget_->size().isEmpty() || |
| 733 desired_size.IsEmpty()) { |
| 734 // If one of these is empty, then we just return the dib we were |
| 735 // given, to avoid leaking it. |
| 736 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, |
| 737 dib_handle, |
| 738 desired_size)); |
| 739 return; |
| 740 } |
| 741 |
| 742 // Map the given DIB ID into this process, and unmap it at the end |
| 743 // of this function. |
| 744 scoped_ptr<TransportDIB> paint_at_scale_buffer(TransportDIB::Map(dib_handle)); |
| 745 |
| 746 DCHECK(paint_at_scale_buffer.get()); |
| 747 if (!paint_at_scale_buffer.get()) |
| 748 return; |
| 749 |
| 750 // Have to make sure we're laid out before rendering. |
| 751 webwidget_->layout(); |
| 752 |
| 753 gfx::Size canvas_size = webwidget_->size(); |
| 754 float x_scale = static_cast<float>(desired_size.width()) / |
| 755 static_cast<float>(canvas_size.width()); |
| 756 float y_scale = static_cast<float>(desired_size.height()) / |
| 757 static_cast<float>(canvas_size.height()); |
| 758 |
| 759 gfx::Rect orig_bounds(gfx::Point(0,0), canvas_size); |
| 760 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale)); |
| 761 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale)); |
| 762 gfx::Rect bounds(gfx::Point(0,0), canvas_size); |
| 763 |
| 764 scoped_ptr<skia::PlatformCanvas> canvas( |
| 765 paint_at_scale_buffer->GetPlatformCanvas(canvas_size.width(), |
| 766 canvas_size.height())); |
| 767 if (!canvas.get()) { |
| 768 NOTREACHED(); |
| 769 return; |
| 770 } |
| 771 |
| 772 // Reset bounds to what we actually received, but they should be the |
| 773 // same. |
| 774 DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); |
| 775 DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); |
| 776 bounds.set_width(canvas->getDevice()->width()); |
| 777 bounds.set_height(canvas->getDevice()->height()); |
| 778 |
| 779 canvas->save(); |
| 780 // Add the scale factor to the canvas, so that we'll get what we expect. |
| 781 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale)); |
| 782 |
| 783 // Paint the entire thing (using original bounds, not scaled bounds). |
| 784 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); |
| 785 canvas->restore(); |
| 786 |
| 787 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, dib_handle, bounds.size())); |
| 788 } |
| 789 |
723 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { | 790 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { |
724 // During shutdown we can just ignore this message. | 791 // During shutdown we can just ignore this message. |
725 if (!webwidget_) | 792 if (!webwidget_) |
726 return; | 793 return; |
727 | 794 |
728 set_next_paint_is_repaint_ack(); | 795 set_next_paint_is_repaint_ack(); |
729 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); | 796 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
730 didInvalidateRect(repaint_rect); | 797 didInvalidateRect(repaint_rect); |
731 } | 798 } |
732 | 799 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 | 938 |
872 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 939 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
873 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 940 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
874 i != plugin_window_moves_.end(); ++i) { | 941 i != plugin_window_moves_.end(); ++i) { |
875 if (i->window == window) { | 942 if (i->window == window) { |
876 plugin_window_moves_.erase(i); | 943 plugin_window_moves_.erase(i); |
877 break; | 944 break; |
878 } | 945 } |
879 } | 946 } |
880 } | 947 } |
881 | |
OLD | NEW |