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 DCHECK(!old_resize_params_); | |
590 | |
591 // We don't expect to receive an ACK when the requested size or the physical | |
592 // backing size is empty, or when the main viewport size didn't change. | |
593 if (!resize_params.new_size.IsEmpty() && | |
594 !resize_params.physical_backing_size.IsEmpty()) { | |
595 resize_ack_pending_ = g_check_for_pending_resize_ack; | |
596 } | |
597 | |
598 old_resize_params_ = | |
599 make_scoped_ptr(new ViewMsg_Resize_Params(resize_params)); | |
600 } | |
601 | |
567 void RenderWidgetHostImpl::WasResized() { | 602 void RenderWidgetHostImpl::WasResized() { |
568 // Skip if the |delegate_| has already been detached because | 603 // Skip if the |delegate_| has already been detached because |
569 // it's web contents is being deleted. | 604 // it's web contents is being deleted. |
570 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || | 605 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || |
571 !renderer_initialized_ || should_auto_resize_ || !delegate_) { | 606 !renderer_initialized_ || should_auto_resize_ || !delegate_) { |
572 return; | 607 return; |
573 } | 608 } |
574 | 609 |
575 gfx::Size new_size(view_->GetRequestedRendererSize()); | 610 bool size_changed = false; |
piman
2014/10/31 20:35:52
Default to true?
If we never called SetInitialRend
mkosiba (inactive)
2014/11/06 00:18:29
I was going back and forth between doing that and
| |
611 bool side_payload_changed = screen_info_out_of_date_; | |
612 scoped_ptr<ViewMsg_Resize_Params> params(new ViewMsg_Resize_Params); | |
576 | 613 |
577 gfx::Size old_physical_backing_size = physical_backing_size_; | 614 GetResizeParams(params.get()); |
578 physical_backing_size_ = view_->GetPhysicalBackingSize(); | 615 if (old_resize_params_) { |
579 bool was_fullscreen = is_fullscreen_; | 616 size_changed = old_resize_params_->new_size != params->new_size; |
580 is_fullscreen_ = IsFullscreen(); | 617 side_payload_changed = |
581 float old_top_controls_layout_height = | 618 side_payload_changed || |
582 top_controls_layout_height_; | 619 old_resize_params_->physical_backing_size != |
583 top_controls_layout_height_ = | 620 params->physical_backing_size || |
584 view_->GetTopControlsLayoutHeight(); | 621 old_resize_params_->is_fullscreen != params->is_fullscreen || |
585 gfx::Size old_visible_viewport_size = visible_viewport_size_; | 622 old_resize_params_->top_controls_layout_height != |
586 visible_viewport_size_ = view_->GetVisibleViewportSize(); | 623 params->top_controls_layout_height || |
624 old_resize_params_->visible_viewport_size != | |
625 params->visible_viewport_size; | |
626 } | |
587 | 627 |
588 bool size_changed = new_size != last_requested_size_; | 628 if (!size_changed && !side_payload_changed && old_resize_params_) |
589 bool side_payload_changed = | |
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 | |
597 if (!size_changed && !side_payload_changed) | |
598 return; | 629 return; |
599 | 630 |
600 if (!screen_info_) { | |
601 screen_info_.reset(new blink::WebScreenInfo); | |
602 GetWebScreenInfo(screen_info_.get()); | |
603 } | |
604 | |
605 // We don't expect to receive an ACK when the requested size or the physical | 631 // We don't expect to receive an ACK when the requested size or the physical |
606 // backing size is empty, or when the main viewport size didn't change. | 632 // backing size is empty, or when the main viewport size didn't change. |
607 if (!new_size.IsEmpty() && !physical_backing_size_.IsEmpty() && size_changed) | 633 if (!params->new_size.IsEmpty() && !params->physical_backing_size.IsEmpty() && |
634 size_changed) { | |
608 resize_ack_pending_ = g_check_for_pending_resize_ack; | 635 resize_ack_pending_ = g_check_for_pending_resize_ack; |
636 } | |
609 | 637 |
610 ViewMsg_Resize_Params params; | 638 if (!Send(new ViewMsg_Resize(routing_id_, *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; | 639 resize_ack_pending_ = false; |
620 } else { | 640 } else { |
621 last_requested_size_ = new_size; | 641 old_resize_params_.swap(params); |
622 } | 642 } |
623 } | 643 } |
624 | 644 |
625 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { | 645 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { |
626 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); | 646 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); |
627 } | 647 } |
628 | 648 |
629 void RenderWidgetHostImpl::GotFocus() { | 649 void RenderWidgetHostImpl::GotFocus() { |
630 Focus(); | 650 Focus(); |
631 if (delegate_) | 651 if (delegate_) |
(...skipping 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2399 } | 2419 } |
2400 #endif | 2420 #endif |
2401 | 2421 |
2402 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2422 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
2403 if (view_) | 2423 if (view_) |
2404 return view_->PreferredReadbackFormat(); | 2424 return view_->PreferredReadbackFormat(); |
2405 return kN32_SkColorType; | 2425 return kN32_SkColorType; |
2406 } | 2426 } |
2407 | 2427 |
2408 } // namespace content | 2428 } // namespace content |
OLD | NEW |