Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1210)

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 659093002: Pass the size to the RenderView on creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java_enum
Patch Set: fix autoresize for guestview/extensions Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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), 173 auto_resize_enabled_(false),
175 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),
185 text_direction_canceled_(false), 183 text_direction_canceled_(false),
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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_ || auto_resize_enabled_ || !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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 // This timeout impacts the "choppiness" of our window resize. 757 // This timeout impacts the "choppiness" of our window resize.
740 const int kPaintMsgTimeoutMS = 50; 758 const int kPaintMsgTimeoutMS = 50;
741 759
742 if (!view_) 760 if (!view_)
743 return; 761 return;
744 762
745 // The view_size will be current_size_ for auto-sized views and otherwise the 763 // The view_size will be current_size_ for auto-sized views and otherwise the
746 // size of the view_. (For auto-sized views, current_size_ is updated during 764 // size of the view_. (For auto-sized views, current_size_ is updated during
747 // UpdateRect messages.) 765 // UpdateRect messages.)
748 gfx::Size view_size = current_size_; 766 gfx::Size view_size = current_size_;
749 if (!should_auto_resize_) { 767 if (!auto_resize_enabled_) {
750 // Get the desired size from the current view bounds. 768 // Get the desired size from the current view bounds.
751 gfx::Rect view_rect = view_->GetViewBounds(); 769 gfx::Rect view_rect = view_->GetViewBounds();
752 if (view_rect.IsEmpty()) 770 if (view_rect.IsEmpty())
753 return; 771 return;
754 view_size = view_rect.size(); 772 view_size = view_rect.size();
755 } 773 }
756 774
757 TRACE_EVENT2("renderer_host", 775 TRACE_EVENT2("renderer_host",
758 "RenderWidgetHostImpl::WaitForBackingStore", 776 "RenderWidgetHostImpl::WaitForBackingStore",
759 "width", 777 "width",
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 TRACE_EVENT0("renderer_host", "WaitForSurface::WaitForUpdate"); 811 TRACE_EVENT0("renderer_host", "WaitForSurface::WaitForUpdate");
794 812
795 // When we have asked the RenderWidget to resize, and we are still waiting 813 // When we have asked the RenderWidget to resize, and we are still waiting
796 // on a response, block for a little while to see if we can't get a response 814 // on a response, block for a little while to see if we can't get a response
797 // before returning the old (incorrectly sized) backing store. 815 // before returning the old (incorrectly sized) backing store.
798 IPC::Message msg; 816 IPC::Message msg;
799 if (RenderWidgetResizeHelper::Get()->WaitForSingleTaskToRun(max_delay)) { 817 if (RenderWidgetResizeHelper::Get()->WaitForSingleTaskToRun(max_delay)) {
800 818
801 // For auto-resized views, current_size_ determines the view_size and it 819 // For auto-resized views, current_size_ determines the view_size and it
802 // may have changed during the handling of an UpdateRect message. 820 // may have changed during the handling of an UpdateRect message.
803 if (should_auto_resize_) 821 if (auto_resize_enabled_)
804 view_size = current_size_; 822 view_size = current_size_;
805 823
806 // Break now if we got a backing store or accelerated surface of the 824 // Break now if we got a backing store or accelerated surface of the
807 // correct size. 825 // correct size.
808 if (view_->HasAcceleratedSurface(view_size)) 826 if (view_->HasAcceleratedSurface(view_size))
809 return; 827 return;
810 } else { 828 } else {
811 TRACE_EVENT0("renderer_host", "WaitForSurface::Timeout"); 829 TRACE_EVENT0("renderer_host", "WaitForSurface::Timeout");
812 break; 830 break;
813 } 831 }
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 } 1391 }
1374 1392
1375 bool RenderWidgetHostImpl::IsMouseLocked() const { 1393 bool RenderWidgetHostImpl::IsMouseLocked() const {
1376 return view_ ? view_->IsMouseLocked() : false; 1394 return view_ ? view_->IsMouseLocked() : false;
1377 } 1395 }
1378 1396
1379 bool RenderWidgetHostImpl::IsFullscreen() const { 1397 bool RenderWidgetHostImpl::IsFullscreen() const {
1380 return false; 1398 return false;
1381 } 1399 }
1382 1400
1383 void RenderWidgetHostImpl::SetShouldAutoResize(bool enable) { 1401 void RenderWidgetHostImpl::SetAutoResize(bool enable,
1384 should_auto_resize_ = enable; 1402 const gfx::Size& min_size,
1403 const gfx::Size& max_size) {
1404 auto_resize_enabled_ = enable;
1405 min_size_for_auto_resize_ = min_size;
1406 max_size_for_auto_resize_ = max_size;
1385 } 1407 }
1386 1408
1387 void RenderWidgetHostImpl::Destroy() { 1409 void RenderWidgetHostImpl::Destroy() {
1388 NotificationService::current()->Notify( 1410 NotificationService::current()->Notify(
1389 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 1411 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1390 Source<RenderWidgetHost>(this), 1412 Source<RenderWidgetHost>(this),
1391 NotificationService::NoDetails()); 1413 NotificationService::NoDetails());
1392 1414
1393 // Tell the view to die. 1415 // Tell the view to die.
1394 // Note that in the process of the view shutting down, it can call a ton 1416 // Note that in the process of the view shutting down, it can call a ton
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); 1596 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this);
1575 repaint_ack_pending_ = false; 1597 repaint_ack_pending_ = false;
1576 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; 1598 TimeDelta delta = TimeTicks::Now() - repaint_start_time_;
1577 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); 1599 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta);
1578 } 1600 }
1579 1601
1580 DCHECK(!params.view_size.IsEmpty()); 1602 DCHECK(!params.view_size.IsEmpty());
1581 1603
1582 DidUpdateBackingStore(params, paint_start); 1604 DidUpdateBackingStore(params, paint_start);
1583 1605
1584 if (should_auto_resize_) { 1606 if (auto_resize_enabled_) {
1585 bool post_callback = new_auto_size_.IsEmpty(); 1607 bool post_callback = new_auto_size_.IsEmpty();
1586 new_auto_size_ = params.view_size; 1608 new_auto_size_ = params.view_size;
1587 if (post_callback) { 1609 if (post_callback) {
1588 base::MessageLoop::current()->PostTask( 1610 base::MessageLoop::current()->PostTask(
1589 FROM_HERE, 1611 FROM_HERE,
1590 base::Bind(&RenderWidgetHostImpl::DelayedAutoResized, 1612 base::Bind(&RenderWidgetHostImpl::DelayedAutoResized,
1591 weak_factory_.GetWeakPtr())); 1613 weak_factory_.GetWeakPtr()));
1592 } 1614 }
1593 } 1615 }
1594 1616
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 host->Send( 2088 host->Send(
2067 new ViewMsg_ReclaimCompositorResources(route_id, output_surface_id, ack)); 2089 new ViewMsg_ReclaimCompositorResources(route_id, output_surface_id, ack));
2068 } 2090 }
2069 2091
2070 void RenderWidgetHostImpl::DelayedAutoResized() { 2092 void RenderWidgetHostImpl::DelayedAutoResized() {
2071 gfx::Size new_size = new_auto_size_; 2093 gfx::Size new_size = new_auto_size_;
2072 // Clear the new_auto_size_ since the empty value is used as a flag to 2094 // Clear the new_auto_size_ since the empty value is used as a flag to
2073 // indicate that no callback is in progress (i.e. without this line 2095 // indicate that no callback is in progress (i.e. without this line
2074 // DelayedAutoResized will not get called again). 2096 // DelayedAutoResized will not get called again).
2075 new_auto_size_.SetSize(0, 0); 2097 new_auto_size_.SetSize(0, 0);
2076 if (!should_auto_resize_) 2098 if (!auto_resize_enabled_)
2077 return; 2099 return;
2078 2100
2079 OnRenderAutoResized(new_size); 2101 OnRenderAutoResized(new_size);
2080 } 2102 }
2081 2103
2082 void RenderWidgetHostImpl::DetachDelegate() { 2104 void RenderWidgetHostImpl::DetachDelegate() {
2083 delegate_ = NULL; 2105 delegate_ = NULL;
2084 } 2106 }
2085 2107
2086 void RenderWidgetHostImpl::ComputeInputLatencyHistograms( 2108 void RenderWidgetHostImpl::ComputeInputLatencyHistograms(
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 } 2443 }
2422 #endif 2444 #endif
2423 2445
2424 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { 2446 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() {
2425 if (view_) 2447 if (view_)
2426 return view_->PreferredReadbackFormat(); 2448 return view_->PreferredReadbackFormat();
2427 return kN32_SkColorType; 2449 return kN32_SkColorType;
2428 } 2450 }
2429 2451
2430 } // namespace content 2452 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698