| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 bool hidden) | 160 bool hidden) |
| 161 : view_(NULL), | 161 : view_(NULL), |
| 162 renderer_initialized_(false), | 162 renderer_initialized_(false), |
| 163 hung_renderer_delay_ms_(kHungRendererDelayMs), | 163 hung_renderer_delay_ms_(kHungRendererDelayMs), |
| 164 delegate_(delegate), | 164 delegate_(delegate), |
| 165 process_(process), | 165 process_(process), |
| 166 routing_id_(routing_id), | 166 routing_id_(routing_id), |
| 167 surface_id_(0), | 167 surface_id_(0), |
| 168 is_loading_(false), | 168 is_loading_(false), |
| 169 is_hidden_(hidden), | 169 is_hidden_(hidden), |
| 170 is_fullscreen_(false), | |
| 171 repaint_ack_pending_(false), | 170 repaint_ack_pending_(false), |
| 172 resize_ack_pending_(false), | 171 resize_ack_pending_(false), |
| 173 screen_info_out_of_date_(false), | 172 screen_info_out_of_date_(false), |
| 174 top_controls_layout_height_(0.f), | |
| 175 should_auto_resize_(false), | 173 should_auto_resize_(false), |
| 176 waiting_for_screen_rects_ack_(false), | 174 waiting_for_screen_rects_ack_(false), |
| 177 needs_repainting_on_restore_(false), | 175 needs_repainting_on_restore_(false), |
| 178 is_unresponsive_(false), | 176 is_unresponsive_(false), |
| 179 in_flight_event_count_(0), | 177 in_flight_event_count_(0), |
| 180 in_get_backing_store_(false), | 178 in_get_backing_store_(false), |
| 181 ignore_input_events_(false), | 179 ignore_input_events_(false), |
| 182 input_method_active_(false), | 180 input_method_active_(false), |
| 183 text_direction_updated_(false), | 181 text_direction_updated_(false), |
| 184 text_direction_(blink::WebTextDirectionLeftToRight), | 182 text_direction_(blink::WebTextDirectionLeftToRight), |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 return gfx::GLSurfaceHandle(); | 353 return gfx::GLSurfaceHandle(); |
| 356 } | 354 } |
| 357 | 355 |
| 358 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() { | 356 void RenderWidgetHostImpl::ResetSizeAndRepaintPendingFlags() { |
| 359 resize_ack_pending_ = false; | 357 resize_ack_pending_ = false; |
| 360 if (repaint_ack_pending_) { | 358 if (repaint_ack_pending_) { |
| 361 TRACE_EVENT_ASYNC_END0( | 359 TRACE_EVENT_ASYNC_END0( |
| 362 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); | 360 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); |
| 363 } | 361 } |
| 364 repaint_ack_pending_ = false; | 362 repaint_ack_pending_ = false; |
| 365 last_requested_size_.SetSize(0, 0); | 363 if (old_resize_params_) |
| 364 old_resize_params_->new_size = gfx::Size(); |
| 366 } | 365 } |
| 367 | 366 |
| 368 void RenderWidgetHostImpl::SendScreenRects() { | 367 void RenderWidgetHostImpl::SendScreenRects() { |
| 369 if (!renderer_initialized_ || waiting_for_screen_rects_ack_) | 368 if (!renderer_initialized_ || waiting_for_screen_rects_ack_) |
| 370 return; | 369 return; |
| 371 | 370 |
| 372 if (is_hidden_) { | 371 if (is_hidden_) { |
| 373 // On GTK, this comes in for backgrounded tabs. Ignore, to match what | 372 // On GTK, this comes in for backgrounded tabs. Ignore, to match what |
| 374 // happens on Win & Mac, and when the view is shown it'll call this again. | 373 // happens on Win & Mac, and when the view is shown it'll call this again. |
| 375 return; | 374 return; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 // By invoking WasResized the renderer is updated as necessary. WasResized | 556 // By invoking WasResized the renderer is updated as necessary. WasResized |
| 558 // does nothing if the sizes are already in sync. | 557 // does nothing if the sizes are already in sync. |
| 559 // | 558 // |
| 560 // TODO: ideally ViewMsg_WasShown would take a size. This way, the renderer | 559 // TODO: ideally ViewMsg_WasShown would take a size. This way, the renderer |
| 561 // could handle both the restore and resize at once. This isn't that big a | 560 // could handle both the restore and resize at once. This isn't that big a |
| 562 // deal as RenderWidget::WasShown delays updating, so that the resize from | 561 // deal as RenderWidget::WasShown delays updating, so that the resize from |
| 563 // WasResized is usually processed before the renderer is painted. | 562 // WasResized is usually processed before the renderer is painted. |
| 564 WasResized(); | 563 WasResized(); |
| 565 } | 564 } |
| 566 | 565 |
| 566 void RenderWidgetHostImpl::GetResizeParams( |
| 567 ViewMsg_Resize_Params* resize_params) { |
| 568 *resize_params = ViewMsg_Resize_Params(); |
| 569 |
| 570 if (!screen_info_) { |
| 571 screen_info_.reset(new blink::WebScreenInfo); |
| 572 GetWebScreenInfo(screen_info_.get()); |
| 573 } |
| 574 resize_params->screen_info = *screen_info_; |
| 575 resize_params->resizer_rect = GetRootWindowResizerRect(); |
| 576 |
| 577 if (view_) { |
| 578 resize_params->new_size = view_->GetRequestedRendererSize(); |
| 579 resize_params->physical_backing_size = view_->GetPhysicalBackingSize(); |
| 580 resize_params->top_controls_layout_height = |
| 581 view_->GetTopControlsLayoutHeight(); |
| 582 resize_params->visible_viewport_size = view_->GetVisibleViewportSize(); |
| 583 resize_params->is_fullscreen = IsFullscreen(); |
| 584 } |
| 585 } |
| 586 |
| 587 void RenderWidgetHostImpl::SetInitialRenderSizeParams( |
| 588 const ViewMsg_Resize_Params& resize_params) { |
| 589 // We don't expect to receive an ACK when the requested size or the physical |
| 590 // backing size is empty, or when the main viewport size didn't change. |
| 591 if (!resize_params.new_size.IsEmpty() && |
| 592 !resize_params.physical_backing_size.IsEmpty()) { |
| 593 resize_ack_pending_ = g_check_for_pending_resize_ack; |
| 594 } |
| 595 |
| 596 old_resize_params_ = |
| 597 make_scoped_ptr(new ViewMsg_Resize_Params(resize_params)); |
| 598 } |
| 599 |
| 567 void RenderWidgetHostImpl::WasResized() { | 600 void RenderWidgetHostImpl::WasResized() { |
| 568 // Skip if the |delegate_| has already been detached because | 601 // Skip if the |delegate_| has already been detached because |
| 569 // it's web contents is being deleted. | 602 // it's web contents is being deleted. |
| 570 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || | 603 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || |
| 571 !renderer_initialized_ || should_auto_resize_ || !delegate_) { | 604 !renderer_initialized_ || should_auto_resize_ || !delegate_) { |
| 572 return; | 605 return; |
| 573 } | 606 } |
| 574 | 607 |
| 575 gfx::Size new_size(view_->GetRequestedRendererSize()); | 608 bool size_changed = true; |
| 609 bool side_payload_changed = screen_info_out_of_date_; |
| 610 scoped_ptr<ViewMsg_Resize_Params> params(new ViewMsg_Resize_Params); |
| 576 | 611 |
| 577 gfx::Size old_physical_backing_size = physical_backing_size_; | 612 GetResizeParams(params.get()); |
| 578 physical_backing_size_ = view_->GetPhysicalBackingSize(); | 613 if (old_resize_params_) { |
| 579 bool was_fullscreen = is_fullscreen_; | 614 size_changed = old_resize_params_->new_size != params->new_size; |
| 580 is_fullscreen_ = IsFullscreen(); | 615 side_payload_changed = |
| 581 float old_top_controls_layout_height = | 616 side_payload_changed || |
| 582 top_controls_layout_height_; | 617 old_resize_params_->physical_backing_size != |
| 583 top_controls_layout_height_ = | 618 params->physical_backing_size || |
| 584 view_->GetTopControlsLayoutHeight(); | 619 old_resize_params_->is_fullscreen != params->is_fullscreen || |
| 585 gfx::Size old_visible_viewport_size = visible_viewport_size_; | 620 old_resize_params_->top_controls_layout_height != |
| 586 visible_viewport_size_ = view_->GetVisibleViewportSize(); | 621 params->top_controls_layout_height || |
| 587 | 622 old_resize_params_->visible_viewport_size != |
| 588 bool size_changed = new_size != last_requested_size_; | 623 params->visible_viewport_size; |
| 589 bool side_payload_changed = | 624 } |
| 590 screen_info_out_of_date_ || | |
| 591 old_physical_backing_size != physical_backing_size_ || | |
| 592 was_fullscreen != is_fullscreen_ || | |
| 593 old_top_controls_layout_height != | |
| 594 top_controls_layout_height_ || | |
| 595 old_visible_viewport_size != visible_viewport_size_; | |
| 596 | 625 |
| 597 if (!size_changed && !side_payload_changed) | 626 if (!size_changed && !side_payload_changed) |
| 598 return; | 627 return; |
| 599 | 628 |
| 600 if (!screen_info_) { | 629 // We don't expect to receive an ACK when the requested size or the physical |
| 601 screen_info_.reset(new blink::WebScreenInfo); | 630 // backing size is empty, or when the main viewport size didn't change. |
| 602 GetWebScreenInfo(screen_info_.get()); | 631 if (!params->new_size.IsEmpty() && !params->physical_backing_size.IsEmpty() && |
| 632 size_changed) { |
| 633 resize_ack_pending_ = g_check_for_pending_resize_ack; |
| 603 } | 634 } |
| 604 | 635 |
| 605 // We don't expect to receive an ACK when the requested size or the physical | 636 if (!Send(new ViewMsg_Resize(routing_id_, *params))) { |
| 606 // backing size is empty, or when the main viewport size didn't change. | |
| 607 if (!new_size.IsEmpty() && !physical_backing_size_.IsEmpty() && size_changed) | |
| 608 resize_ack_pending_ = g_check_for_pending_resize_ack; | |
| 609 | |
| 610 ViewMsg_Resize_Params params; | |
| 611 params.screen_info = *screen_info_; | |
| 612 params.new_size = new_size; | |
| 613 params.physical_backing_size = physical_backing_size_; | |
| 614 params.top_controls_layout_height = top_controls_layout_height_; | |
| 615 params.visible_viewport_size = visible_viewport_size_; | |
| 616 params.resizer_rect = GetRootWindowResizerRect(); | |
| 617 params.is_fullscreen = is_fullscreen_; | |
| 618 if (!Send(new ViewMsg_Resize(routing_id_, params))) { | |
| 619 resize_ack_pending_ = false; | 637 resize_ack_pending_ = false; |
| 620 } else { | 638 } else { |
| 621 last_requested_size_ = new_size; | 639 old_resize_params_.swap(params); |
| 622 } | 640 } |
| 623 } | 641 } |
| 624 | 642 |
| 625 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { | 643 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { |
| 626 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); | 644 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); |
| 627 } | 645 } |
| 628 | 646 |
| 629 void RenderWidgetHostImpl::GotFocus() { | 647 void RenderWidgetHostImpl::GotFocus() { |
| 630 Focus(); | 648 Focus(); |
| 631 if (delegate_) | 649 if (delegate_) |
| (...skipping 1789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2421 } | 2439 } |
| 2422 #endif | 2440 #endif |
| 2423 | 2441 |
| 2424 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2442 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
| 2425 if (view_) | 2443 if (view_) |
| 2426 return view_->PreferredReadbackFormat(); | 2444 return view_->PreferredReadbackFormat(); |
| 2427 return kN32_SkColorType; | 2445 return kN32_SkColorType; |
| 2428 } | 2446 } |
| 2429 | 2447 |
| 2430 } // namespace content | 2448 } // namespace content |
| OLD | NEW |