| 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/browser/renderer_host/render_widget_host.h" | 5 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 6 | 6 |
| 7 #include "app/keyboard_codes.h" | 7 #include "app/keyboard_codes.h" |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 Source<RenderWidgetHost>(this), | 252 Source<RenderWidgetHost>(this), |
| 253 Details<bool>(&is_visible)); | 253 Details<bool>(&is_visible)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void RenderWidgetHost::WasResized() { | 256 void RenderWidgetHost::WasResized() { |
| 257 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || | 257 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || |
| 258 !renderer_initialized_) { | 258 !renderer_initialized_) { |
| 259 return; | 259 return; |
| 260 } | 260 } |
| 261 | 261 |
| 262 gfx::Rect view_bounds = view_->GetViewBounds(); | 262 gfx::Size new_size = view_->GetViewBounds().size(); |
| 263 gfx::Size new_size(view_bounds.width(), view_bounds.height()); | 263 gfx::Rect reserved_rect = view_->reserved_contents_rect(); |
| 264 | 264 |
| 265 // Avoid asking the RenderWidget to resize to its current size, since it | 265 // Avoid asking the RenderWidget to resize to its current size, since it |
| 266 // won't send us a PaintRect message in that case. | 266 // won't send us a PaintRect message in that case, unless reserved area is |
| 267 if (new_size == current_size_) | 267 // changed, but even in this case PaintRect message won't be sent. |
| 268 if (new_size == current_size_ && reserved_rect == current_reserved_rect_) |
| 268 return; | 269 return; |
| 269 | 270 |
| 270 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_) | 271 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_ && |
| 272 in_flight_reserved_rect_ == reserved_rect) { |
| 271 return; | 273 return; |
| 274 } |
| 272 | 275 |
| 273 // We don't expect to receive an ACK when the requested size is empty. | 276 // We don't expect to receive an ACK when the requested size is empty or |
| 274 if (!new_size.IsEmpty()) | 277 // only reserved area is changed. |
| 275 resize_ack_pending_ = true; | 278 resize_ack_pending_ = !new_size.IsEmpty() && new_size != current_size_; |
| 276 | 279 |
| 277 if (!Send(new ViewMsg_Resize(routing_id_, new_size, | 280 if (!Send(new ViewMsg_Resize(routing_id_, new_size, reserved_rect))) { |
| 278 GetRootWindowResizerRect()))) | |
| 279 resize_ack_pending_ = false; | 281 resize_ack_pending_ = false; |
| 280 else | 282 } else { |
| 281 in_flight_size_ = new_size; | 283 if (resize_ack_pending_) { |
| 284 in_flight_size_ = new_size; |
| 285 in_flight_reserved_rect_ = reserved_rect; |
| 286 } else { |
| 287 // Message was sent successfully, but we do not expect to receive an ACK, |
| 288 // so update current values right away. |
| 289 current_size_ = new_size; |
| 290 current_reserved_rect_ = reserved_rect; |
| 291 } |
| 292 } |
| 282 } | 293 } |
| 283 | 294 |
| 284 void RenderWidgetHost::GotFocus() { | 295 void RenderWidgetHost::GotFocus() { |
| 285 Focus(); | 296 Focus(); |
| 286 } | 297 } |
| 287 | 298 |
| 288 void RenderWidgetHost::Focus() { | 299 void RenderWidgetHost::Focus() { |
| 289 Send(new ViewMsg_SetFocus(routing_id_, true)); | 300 Send(new ViewMsg_SetFocus(routing_id_, true)); |
| 290 } | 301 } |
| 291 | 302 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 625 |
| 615 // Must reset these to ensure that keyboard events work with a new renderer. | 626 // Must reset these to ensure that keyboard events work with a new renderer. |
| 616 key_queue_.clear(); | 627 key_queue_.clear(); |
| 617 suppress_next_char_events_ = false; | 628 suppress_next_char_events_ = false; |
| 618 | 629 |
| 619 // Reset some fields in preparation for recovering from a crash. | 630 // Reset some fields in preparation for recovering from a crash. |
| 620 resize_ack_pending_ = false; | 631 resize_ack_pending_ = false; |
| 621 repaint_ack_pending_ = false; | 632 repaint_ack_pending_ = false; |
| 622 | 633 |
| 623 in_flight_size_.SetSize(0, 0); | 634 in_flight_size_.SetSize(0, 0); |
| 635 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); |
| 624 current_size_.SetSize(0, 0); | 636 current_size_.SetSize(0, 0); |
| 637 current_reserved_rect_.SetRect(0, 0, 0, 0); |
| 625 is_hidden_ = false; | 638 is_hidden_ = false; |
| 626 | 639 |
| 627 if (view_) { | 640 if (view_) { |
| 628 view_->RenderViewGone(); | 641 view_->RenderViewGone(); |
| 629 view_ = NULL; // The View should be deleted by RenderViewGone. | 642 view_ = NULL; // The View should be deleted by RenderViewGone. |
| 630 } | 643 } |
| 631 | 644 |
| 632 BackingStoreManager::RemoveBackingStore(this); | 645 BackingStoreManager::RemoveBackingStore(this); |
| 633 } | 646 } |
| 634 | 647 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 685 |
| 673 void RenderWidgetHost::ImeConfirmComposition() { | 686 void RenderWidgetHost::ImeConfirmComposition() { |
| 674 Send(new ViewMsg_ImeConfirmComposition(routing_id())); | 687 Send(new ViewMsg_ImeConfirmComposition(routing_id())); |
| 675 } | 688 } |
| 676 | 689 |
| 677 void RenderWidgetHost::ImeCancelComposition() { | 690 void RenderWidgetHost::ImeCancelComposition() { |
| 678 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(), | 691 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(), |
| 679 std::vector<WebKit::WebCompositionUnderline>(), 0, 0)); | 692 std::vector<WebKit::WebCompositionUnderline>(), 0, 0)); |
| 680 } | 693 } |
| 681 | 694 |
| 682 gfx::Rect RenderWidgetHost::GetRootWindowResizerRect() const { | |
| 683 return gfx::Rect(); | |
| 684 } | |
| 685 | |
| 686 void RenderWidgetHost::SetActive(bool active) { | 695 void RenderWidgetHost::SetActive(bool active) { |
| 687 Send(new ViewMsg_SetActive(routing_id(), active)); | 696 Send(new ViewMsg_SetActive(routing_id(), active)); |
| 688 } | 697 } |
| 689 | 698 |
| 690 void RenderWidgetHost::Destroy() { | 699 void RenderWidgetHost::Destroy() { |
| 691 NotificationService::current()->Notify( | 700 NotificationService::current()->Notify( |
| 692 NotificationType::RENDER_WIDGET_HOST_DESTROYED, | 701 NotificationType::RENDER_WIDGET_HOST_DESTROYED, |
| 693 Source<RenderWidgetHost>(this), | 702 Source<RenderWidgetHost>(this), |
| 694 NotificationService::NoDetails()); | 703 NotificationService::NoDetails()); |
| 695 | 704 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 | 771 |
| 763 void RenderWidgetHost::OnMsgUpdateRect( | 772 void RenderWidgetHost::OnMsgUpdateRect( |
| 764 const ViewHostMsg_UpdateRect_Params& params) { | 773 const ViewHostMsg_UpdateRect_Params& params) { |
| 765 TimeTicks paint_start = TimeTicks::Now(); | 774 TimeTicks paint_start = TimeTicks::Now(); |
| 766 | 775 |
| 767 if (paint_observer_.get()) | 776 if (paint_observer_.get()) |
| 768 paint_observer_->RenderWidgetHostWillPaint(this); | 777 paint_observer_->RenderWidgetHostWillPaint(this); |
| 769 | 778 |
| 770 // Update our knowledge of the RenderWidget's size. | 779 // Update our knowledge of the RenderWidget's size. |
| 771 current_size_ = params.view_size; | 780 current_size_ = params.view_size; |
| 781 current_reserved_rect_ = params.resizer_rect; |
| 772 | 782 |
| 773 bool is_resize_ack = | 783 bool is_resize_ack = |
| 774 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 784 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
| 775 | 785 |
| 776 // resize_ack_pending_ needs to be cleared before we call DidPaintRect, since | 786 // resize_ack_pending_ needs to be cleared before we call DidPaintRect, since |
| 777 // that will end up reaching GetBackingStore. | 787 // that will end up reaching GetBackingStore. |
| 778 if (is_resize_ack) { | 788 if (is_resize_ack) { |
| 779 DCHECK(resize_ack_pending_); | 789 DCHECK(resize_ack_pending_); |
| 780 resize_ack_pending_ = false; | 790 resize_ack_pending_ = false; |
| 781 in_flight_size_.SetSize(0, 0); | 791 in_flight_size_.SetSize(0, 0); |
| 792 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); |
| 782 } | 793 } |
| 783 | 794 |
| 784 bool is_repaint_ack = | 795 bool is_repaint_ack = |
| 785 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); | 796 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); |
| 786 if (is_repaint_ack) { | 797 if (is_repaint_ack) { |
| 787 repaint_ack_pending_ = false; | 798 repaint_ack_pending_ = false; |
| 788 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; | 799 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; |
| 789 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); | 800 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); |
| 790 } | 801 } |
| 791 | 802 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 params.copy_rects); | 860 params.copy_rects); |
| 850 view_being_painted_ = false; | 861 view_being_painted_ = false; |
| 851 } | 862 } |
| 852 } | 863 } |
| 853 | 864 |
| 854 if (paint_observer_.get()) | 865 if (paint_observer_.get()) |
| 855 paint_observer_->RenderWidgetHostDidPaint(this); | 866 paint_observer_->RenderWidgetHostDidPaint(this); |
| 856 | 867 |
| 857 // If we got a resize ack, then perhaps we have another resize to send? | 868 // If we got a resize ack, then perhaps we have another resize to send? |
| 858 if (is_resize_ack && view_) { | 869 if (is_resize_ack && view_) { |
| 859 gfx::Rect view_bounds = view_->GetViewBounds(); | 870 // WasResized checks the current size and sends the resize update only |
| 860 if (current_size_.width() != view_bounds.width() || | 871 // when something was actually changed. |
| 861 current_size_.height() != view_bounds.height()) { | 872 WasResized(); |
| 862 WasResized(); | |
| 863 } | |
| 864 } | 873 } |
| 865 | 874 |
| 866 if (painting_observer_) | 875 if (painting_observer_) |
| 867 painting_observer_->WidgetDidUpdateBackingStore(this); | 876 painting_observer_->WidgetDidUpdateBackingStore(this); |
| 868 | 877 |
| 869 // Log the time delta for processing a paint message. | 878 // Log the time delta for processing a paint message. |
| 870 TimeDelta delta = TimeTicks::Now() - paint_start; | 879 TimeDelta delta = TimeTicks::Now() - paint_start; |
| 871 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta); | 880 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta); |
| 872 } | 881 } |
| 873 | 882 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 // of this key event. | 1223 // of this key event. |
| 1215 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { | 1224 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { |
| 1216 UnhandledKeyboardEvent(front_item); | 1225 UnhandledKeyboardEvent(front_item); |
| 1217 | 1226 |
| 1218 // WARNING: This RenderWidgetHost can be deallocated at this point | 1227 // WARNING: This RenderWidgetHost can be deallocated at this point |
| 1219 // (i.e. in the case of Ctrl+W, where the call to | 1228 // (i.e. in the case of Ctrl+W, where the call to |
| 1220 // UnhandledKeyboardEvent destroys this RenderWidgetHost). | 1229 // UnhandledKeyboardEvent destroys this RenderWidgetHost). |
| 1221 } | 1230 } |
| 1222 } | 1231 } |
| 1223 } | 1232 } |
| OLD | NEW |