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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 // By invoking WasResized the renderer is updated as necessary. WasResized | 561 // By invoking WasResized the renderer is updated as necessary. WasResized |
562 // does nothing if the sizes are already in sync. | 562 // does nothing if the sizes are already in sync. |
563 // | 563 // |
564 // TODO: ideally ViewMsg_WasShown would take a size. This way, the renderer | 564 // TODO: ideally ViewMsg_WasShown would take a size. This way, the renderer |
565 // could handle both the restore and resize at once. This isn't that big a | 565 // could handle both the restore and resize at once. This isn't that big a |
566 // deal as RenderWidget::WasShown delays updating, so that the resize from | 566 // deal as RenderWidget::WasShown delays updating, so that the resize from |
567 // WasResized is usually processed before the renderer is painted. | 567 // WasResized is usually processed before the renderer is painted. |
568 WasResized(); | 568 WasResized(); |
569 } | 569 } |
570 | 570 |
571 void RenderWidgetHostImpl::GetResizeParams( | 571 bool RenderWidgetHostImpl::GetResizeParams( |
572 ViewMsg_Resize_Params* resize_params) { | 572 ViewMsg_Resize_Params* resize_params) { |
573 *resize_params = ViewMsg_Resize_Params(); | 573 *resize_params = ViewMsg_Resize_Params(); |
574 | 574 |
575 if (!screen_info_) { | 575 if (!screen_info_) { |
576 screen_info_.reset(new blink::WebScreenInfo); | 576 screen_info_.reset(new blink::WebScreenInfo); |
577 GetWebScreenInfo(screen_info_.get()); | 577 GetWebScreenInfo(screen_info_.get()); |
578 } | 578 } |
579 resize_params->screen_info = *screen_info_; | 579 resize_params->screen_info = *screen_info_; |
580 resize_params->resizer_rect = GetRootWindowResizerRect(); | 580 resize_params->resizer_rect = GetRootWindowResizerRect(); |
581 | 581 |
582 if (view_) { | 582 if (view_) { |
583 resize_params->new_size = view_->GetRequestedRendererSize(); | 583 resize_params->new_size = view_->GetRequestedRendererSize(); |
584 resize_params->physical_backing_size = view_->GetPhysicalBackingSize(); | 584 resize_params->physical_backing_size = view_->GetPhysicalBackingSize(); |
585 resize_params->top_controls_height = view_->GetTopControlsHeight(); | 585 resize_params->top_controls_height = view_->GetTopControlsHeight(); |
586 resize_params->top_controls_shrink_blink_size = | 586 resize_params->top_controls_shrink_blink_size = |
587 view_->DoTopControlsShrinkBlinkSize(); | 587 view_->DoTopControlsShrinkBlinkSize(); |
588 resize_params->visible_viewport_size = view_->GetVisibleViewportSize(); | 588 resize_params->visible_viewport_size = view_->GetVisibleViewportSize(); |
589 resize_params->is_fullscreen = IsFullscreen(); | 589 resize_params->is_fullscreen = IsFullscreen(); |
590 } | 590 } |
| 591 |
| 592 const bool size_changed = |
| 593 !old_resize_params_ || |
| 594 old_resize_params_->new_size != resize_params->new_size; |
| 595 bool dirty = |
| 596 size_changed || screen_info_out_of_date_ || |
| 597 old_resize_params_->physical_backing_size != |
| 598 resize_params->physical_backing_size || |
| 599 old_resize_params_->is_fullscreen != resize_params->is_fullscreen || |
| 600 old_resize_params_->top_controls_height != |
| 601 resize_params->top_controls_height || |
| 602 old_resize_params_->top_controls_shrink_blink_size != |
| 603 resize_params->top_controls_shrink_blink_size || |
| 604 old_resize_params_->visible_viewport_size != |
| 605 resize_params->visible_viewport_size; |
| 606 |
| 607 // We don't expect to receive an ACK when the requested size or the physical |
| 608 // backing size is empty, or when the main viewport size didn't change. |
| 609 resize_params->needs_resize_ack = |
| 610 g_check_for_pending_resize_ack && !resize_params->new_size.IsEmpty() && |
| 611 !resize_params->physical_backing_size.IsEmpty() && size_changed; |
| 612 |
| 613 return dirty; |
591 } | 614 } |
592 | 615 |
593 void RenderWidgetHostImpl::SetInitialRenderSizeParams( | 616 void RenderWidgetHostImpl::SetInitialRenderSizeParams( |
594 const ViewMsg_Resize_Params& resize_params) { | 617 const ViewMsg_Resize_Params& resize_params) { |
595 // We don't expect to receive an ACK when the requested size or the physical | 618 resize_ack_pending_ = resize_params.needs_resize_ack; |
596 // backing size is empty, or when the main viewport size didn't change. | |
597 if (!resize_params.new_size.IsEmpty() && | |
598 !resize_params.physical_backing_size.IsEmpty()) { | |
599 resize_ack_pending_ = g_check_for_pending_resize_ack; | |
600 } | |
601 | 619 |
602 old_resize_params_ = | 620 old_resize_params_ = |
603 make_scoped_ptr(new ViewMsg_Resize_Params(resize_params)); | 621 make_scoped_ptr(new ViewMsg_Resize_Params(resize_params)); |
604 } | 622 } |
605 | 623 |
606 void RenderWidgetHostImpl::WasResized() { | 624 void RenderWidgetHostImpl::WasResized() { |
607 // Skip if the |delegate_| has already been detached because | 625 // Skip if the |delegate_| has already been detached because |
608 // it's web contents is being deleted. | 626 // it's web contents is being deleted. |
609 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || | 627 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || |
610 !renderer_initialized_ || auto_resize_enabled_ || !delegate_) { | 628 !renderer_initialized_ || auto_resize_enabled_ || !delegate_) { |
611 return; | 629 return; |
612 } | 630 } |
613 | 631 |
614 bool size_changed = true; | |
615 bool width_changed = true; | |
616 bool side_payload_changed = screen_info_out_of_date_; | |
617 scoped_ptr<ViewMsg_Resize_Params> params(new ViewMsg_Resize_Params); | 632 scoped_ptr<ViewMsg_Resize_Params> params(new ViewMsg_Resize_Params); |
618 | 633 if (!GetResizeParams(params.get())) |
619 GetResizeParams(params.get()); | |
620 if (old_resize_params_) { | |
621 size_changed = old_resize_params_->new_size != params->new_size; | |
622 width_changed = | |
623 old_resize_params_->new_size.width() != params->new_size.width(); | |
624 side_payload_changed = | |
625 side_payload_changed || | |
626 old_resize_params_->physical_backing_size != | |
627 params->physical_backing_size || | |
628 old_resize_params_->is_fullscreen != params->is_fullscreen || | |
629 old_resize_params_->top_controls_height != | |
630 params->top_controls_height || | |
631 old_resize_params_->top_controls_shrink_blink_size != | |
632 params->top_controls_shrink_blink_size || | |
633 old_resize_params_->visible_viewport_size != | |
634 params->visible_viewport_size; | |
635 } | |
636 | |
637 if (!size_changed && !side_payload_changed) | |
638 return; | 634 return; |
639 | 635 |
640 // We don't expect to receive an ACK when the requested size or the physical | 636 bool width_changed = |
641 // backing size is empty, or when the main viewport size didn't change. | 637 !old_resize_params_ || |
642 if (!params->new_size.IsEmpty() && !params->physical_backing_size.IsEmpty() && | 638 old_resize_params_->new_size.width() != params->new_size.width(); |
643 size_changed) { | 639 if (Send(new ViewMsg_Resize(routing_id_, *params))) { |
644 resize_ack_pending_ = g_check_for_pending_resize_ack; | 640 resize_ack_pending_ = params->needs_resize_ack; |
645 } | |
646 | |
647 if (!Send(new ViewMsg_Resize(routing_id_, *params))) { | |
648 resize_ack_pending_ = false; | |
649 } else { | |
650 old_resize_params_.swap(params); | 641 old_resize_params_.swap(params); |
651 } | 642 } |
652 | 643 |
653 if (delegate_) | 644 if (delegate_) |
654 delegate_->RenderWidgetWasResized(this, width_changed); | 645 delegate_->RenderWidgetWasResized(this, width_changed); |
655 } | 646 } |
656 | 647 |
657 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { | 648 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { |
658 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); | 649 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); |
659 } | 650 } |
(...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2200 } | 2191 } |
2201 #endif | 2192 #endif |
2202 | 2193 |
2203 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2194 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
2204 if (view_) | 2195 if (view_) |
2205 return view_->PreferredReadbackFormat(); | 2196 return view_->PreferredReadbackFormat(); |
2206 return kN32_SkColorType; | 2197 return kN32_SkColorType; |
2207 } | 2198 } |
2208 | 2199 |
2209 } // namespace content | 2200 } // namespace content |
OLD | NEW |