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

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

Issue 2528823002: Separate SwipeRefreshHandler and ContentViewCore (Closed)
Patch Set: Respond to boliu's comments, refactor CreateOverscrollController() function Created 4 years 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_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "content/browser/gpu/gpu_data_manager_impl.h" 48 #include "content/browser/gpu/gpu_data_manager_impl.h"
49 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 49 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
50 #include "content/browser/media/android/media_web_contents_observer_android.h" 50 #include "content/browser/media/android/media_web_contents_observer_android.h"
51 #include "content/browser/renderer_host/compositor_impl_android.h" 51 #include "content/browser/renderer_host/compositor_impl_android.h"
52 #include "content/browser/renderer_host/dip_util.h" 52 #include "content/browser/renderer_host/dip_util.h"
53 #include "content/browser/renderer_host/frame_metadata_util.h" 53 #include "content/browser/renderer_host/frame_metadata_util.h"
54 #include "content/browser/renderer_host/input/input_router_impl.h" 54 #include "content/browser/renderer_host/input/input_router_impl.h"
55 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h " 55 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h "
56 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 56 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
57 #include "content/browser/renderer_host/render_process_host_impl.h" 57 #include "content/browser/renderer_host/render_process_host_impl.h"
58 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
58 #include "content/browser/renderer_host/render_view_host_impl.h" 59 #include "content/browser/renderer_host/render_view_host_impl.h"
59 #include "content/browser/renderer_host/render_widget_host_impl.h" 60 #include "content/browser/renderer_host/render_widget_host_impl.h"
60 #include "content/common/gpu_host_messages.h" 61 #include "content/common/gpu_host_messages.h"
61 #include "content/common/input_messages.h" 62 #include "content/common/input_messages.h"
62 #include "content/common/view_messages.h" 63 #include "content/common/view_messages.h"
63 #include "content/public/browser/android/compositor.h" 64 #include "content/public/browser/android/compositor.h"
64 #include "content/public/browser/android/synchronous_compositor_client.h" 65 #include "content/public/browser/android/synchronous_compositor_client.h"
65 #include "content/public/browser/browser_thread.h" 66 #include "content/public/browser/browser_thread.h"
66 #include "content/public/browser/devtools_agent_host.h" 67 #include "content/public/browser/devtools_agent_host.h"
67 #include "content/public/browser/render_view_host.h" 68 #include "content/public/browser/render_view_host.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 config.tap_slop = gfx::ViewConfiguration::GetTouchSlopInDips(); 330 config.tap_slop = gfx::ViewConfiguration::GetTouchSlopInDips();
330 config.enable_adaptive_handle_orientation = 331 config.enable_adaptive_handle_orientation =
331 base::CommandLine::ForCurrentProcess()->HasSwitch( 332 base::CommandLine::ForCurrentProcess()->HasSwitch(
332 switches::kEnableAdaptiveSelectionHandleOrientation); 333 switches::kEnableAdaptiveSelectionHandleOrientation);
333 config.enable_longpress_drag_selection = 334 config.enable_longpress_drag_selection =
334 base::CommandLine::ForCurrentProcess()->HasSwitch( 335 base::CommandLine::ForCurrentProcess()->HasSwitch(
335 switches::kEnableLongpressDragSelection); 336 switches::kEnableLongpressDragSelection);
336 return base::MakeUnique<ui::TouchSelectionController>(client, config); 337 return base::MakeUnique<ui::TouchSelectionController>(client, config);
337 } 338 }
338 339
339 std::unique_ptr<OverscrollControllerAndroid> CreateOverscrollController(
340 ContentViewCoreImpl* content_view_core,
341 float dpi_scale) {
342 return base::MakeUnique<OverscrollControllerAndroid>(content_view_core,
343 dpi_scale);
344 }
345
346 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { 340 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) {
347 gfx::RectF rect = controller.GetRectBetweenBounds(); 341 gfx::RectF rect = controller.GetRectBetweenBounds();
348 if (rect.IsEmpty()) 342 if (rect.IsEmpty())
349 return rect; 343 return rect;
350 344
351 rect.Union(controller.GetStartHandleRect()); 345 rect.Union(controller.GetStartHandleRect());
352 rect.Union(controller.GetEndHandleRect()); 346 rect.Union(controller.GetEndHandleRect());
353 return rect; 347 return rect;
354 } 348 }
355 349
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 if (using_browser_compositor_) { 456 if (using_browser_compositor_) {
463 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( 457 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid(
464 &view_, cached_background_color_, 458 &view_, cached_background_color_,
465 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, 459 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources,
466 weak_ptr_factory_.GetWeakPtr()))); 460 weak_ptr_factory_.GetWeakPtr())));
467 } 461 }
468 462
469 host_->SetView(this); 463 host_->SetView(this);
470 SetContentViewCore(content_view_core); 464 SetContentViewCore(content_view_core);
471 465
466 CreateOverscrollControllerIfPossible();
467
472 if (GetTextInputManager()) 468 if (GetTextInputManager())
473 GetTextInputManager()->AddObserver(this); 469 GetTextInputManager()->AddObserver(this);
474 } 470 }
475 471
476 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 472 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
477 if (content_view_core_) 473 if (content_view_core_)
478 content_view_core_->RemoveObserver(this); 474 content_view_core_->RemoveObserver(this);
479 SetContentViewCore(NULL); 475 SetContentViewCore(NULL);
480 DCHECK(ack_callbacks_.empty()); 476 DCHECK(ack_callbacks_.empty());
481 DCHECK(!delegated_frame_host_); 477 DCHECK(!delegated_frame_host_);
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1209 }
1214 1210
1215 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient( 1211 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient(
1216 SynchronousCompositorClient* client) { 1212 SynchronousCompositorClient* client) {
1217 synchronous_compositor_client_ = client; 1213 synchronous_compositor_client_ = client;
1218 if (!sync_compositor_ && synchronous_compositor_client_) { 1214 if (!sync_compositor_ && synchronous_compositor_client_) {
1219 sync_compositor_ = SynchronousCompositorHost::Create(this); 1215 sync_compositor_ = SynchronousCompositorHost::Create(this);
1220 } 1216 }
1221 } 1217 }
1222 1218
1219 void RenderWidgetHostViewAndroid::OnOverscrollRefreshHandlerSet() {
1220 overscroll_controller_.reset();
boliu 2016/12/06 23:24:16 this can be set multiple times? did this fix a uni
rlanday 2016/12/07 00:07:48 We were discussing how in the current version of t
boliu 2016/12/07 00:33:15 Wording.. it's not CVC can be set multiple times,
1221 CreateOverscrollControllerIfPossible();
1222 }
1223
1223 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { 1224 bool RenderWidgetHostViewAndroid::SupportsAnimation() const {
1224 // The synchronous (WebView) compositor does not have a proper browser 1225 // The synchronous (WebView) compositor does not have a proper browser
1225 // compositor with which to drive animations. 1226 // compositor with which to drive animations.
1226 return using_browser_compositor_; 1227 return using_browser_compositor_;
1227 } 1228 }
1228 1229
1229 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { 1230 void RenderWidgetHostViewAndroid::SetNeedsAnimate() {
1230 DCHECK(view_.GetWindowAndroid()); 1231 DCHECK(view_.GetWindowAndroid());
1231 DCHECK(using_browser_compositor_); 1232 DCHECK(using_browser_compositor_);
1232 view_.GetWindowAndroid()->SetNeedsAnimate(); 1233 view_.GetWindowAndroid()->SetNeedsAnimate();
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 } 1762 }
1762 1763
1763 void RenderWidgetHostViewAndroid::SetContentViewCore( 1764 void RenderWidgetHostViewAndroid::SetContentViewCore(
1764 ContentViewCoreImpl* content_view_core) { 1765 ContentViewCoreImpl* content_view_core) {
1765 DCHECK(!content_view_core || !content_view_core_ || 1766 DCHECK(!content_view_core || !content_view_core_ ||
1766 (content_view_core_ == content_view_core)); 1767 (content_view_core_ == content_view_core));
1767 StopObservingRootWindow(); 1768 StopObservingRootWindow();
1768 1769
1769 bool resize = false; 1770 bool resize = false;
1770 if (content_view_core != content_view_core_) { 1771 if (content_view_core != content_view_core_) {
1771 overscroll_controller_.reset();
1772 selection_controller_.reset(); 1772 selection_controller_.reset();
1773 ReleaseLocksOnSurface(); 1773 ReleaseLocksOnSurface();
1774 // TODO(yusufo) : Get rid of the below conditions and have a better handling 1774 // TODO(yusufo) : Get rid of the below conditions and have a better handling
1775 // for resizing after crbug.com/628302 is handled. 1775 // for resizing after crbug.com/628302 is handled.
1776 bool is_size_initialized = !content_view_core 1776 bool is_size_initialized = !content_view_core
1777 || content_view_core->GetViewportSizeDip().width() != 0 1777 || content_view_core->GetViewportSizeDip().width() != 0
1778 || content_view_core->GetViewportSizeDip().height() != 0; 1778 || content_view_core->GetViewportSizeDip().height() != 0;
1779 if (content_view_core_ || is_size_initialized) 1779 if (content_view_core_ || is_size_initialized)
1780 resize = true; 1780 resize = true;
1781 if (content_view_core_) { 1781 if (content_view_core_) {
(...skipping 26 matching lines...) Expand all
1808 } 1808 }
1809 1809
1810 if (is_showing_) 1810 if (is_showing_)
1811 StartObservingRootWindow(); 1811 StartObservingRootWindow();
1812 1812
1813 if (resize) 1813 if (resize)
1814 WasResized(); 1814 WasResized();
1815 1815
1816 if (!selection_controller_) 1816 if (!selection_controller_)
1817 selection_controller_ = CreateSelectionController(this, content_view_core_); 1817 selection_controller_ = CreateSelectionController(this, content_view_core_);
1818
1819 if (!overscroll_controller_ &&
1820 view_.GetWindowAndroid()->GetCompositor()) {
1821 overscroll_controller_ = CreateOverscrollController(
1822 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView()));
1823 }
1824 } 1818 }
1825 1819
1826 void RenderWidgetHostViewAndroid::RunAckCallbacks() { 1820 void RenderWidgetHostViewAndroid::RunAckCallbacks() {
1827 while (!ack_callbacks_.empty()) { 1821 while (!ack_callbacks_.empty()) {
1828 ack_callbacks_.front().Run(); 1822 ack_callbacks_.front().Run();
1829 ack_callbacks_.pop(); 1823 ack_callbacks_.pop();
1830 } 1824 }
1831 } 1825 }
1832 1826
1833 void RenderWidgetHostViewAndroid::OnGestureEvent( 1827 void RenderWidgetHostViewAndroid::OnGestureEvent(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 OnAttachCompositor(); 1871 OnAttachCompositor();
1878 } 1872 }
1879 1873
1880 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { 1874 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() {
1881 StopObservingRootWindow(); 1875 StopObservingRootWindow();
1882 OnDetachCompositor(); 1876 OnDetachCompositor();
1883 } 1877 }
1884 1878
1885 void RenderWidgetHostViewAndroid::OnAttachCompositor() { 1879 void RenderWidgetHostViewAndroid::OnAttachCompositor() {
1886 DCHECK(content_view_core_); 1880 DCHECK(content_view_core_);
1887 if (!overscroll_controller_) 1881 CreateOverscrollControllerIfPossible();
1888 overscroll_controller_ = CreateOverscrollController(
1889 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView()));
1890 ui::WindowAndroidCompositor* compositor = 1882 ui::WindowAndroidCompositor* compositor =
1891 view_.GetWindowAndroid()->GetCompositor(); 1883 view_.GetWindowAndroid()->GetCompositor();
1892 delegated_frame_host_->RegisterFrameSinkHierarchy( 1884 delegated_frame_host_->RegisterFrameSinkHierarchy(
1893 compositor->GetFrameSinkId()); 1885 compositor->GetFrameSinkId());
1894 } 1886 }
1895 1887
1896 void RenderWidgetHostViewAndroid::OnDetachCompositor() { 1888 void RenderWidgetHostViewAndroid::OnDetachCompositor() {
1897 DCHECK(content_view_core_); 1889 DCHECK(content_view_core_);
1898 DCHECK(using_browser_compositor_); 1890 DCHECK(using_browser_compositor_);
1899 RunAckCallbacks(); 1891 RunAckCallbacks();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 return; 1985 return;
1994 case ui::MotionEvent::ACTION_UP: 1986 case ui::MotionEvent::ACTION_UP:
1995 case ui::MotionEvent::ACTION_POINTER_UP: 1987 case ui::MotionEvent::ACTION_POINTER_UP:
1996 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 1988 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
1997 delta.InMicroseconds(), 1, 1000000, 50); 1989 delta.InMicroseconds(), 1, 1000000, 50);
1998 default: 1990 default:
1999 return; 1991 return;
2000 } 1992 }
2001 } 1993 }
2002 1994
1995 void RenderWidgetHostViewAndroid::CreateOverscrollControllerIfPossible() {
1996 // an OverscrollController is already set
1997 if (overscroll_controller_) {
boliu 2016/12/06 23:24:16 style: for if blocks where the both the condition
rlanday 2016/12/07 00:07:48 Ok
1998 return;
1999 }
2000
2001 RenderWidgetHostDelegate* delegate = host_->delegate();
2002 if (!delegate) {
2003 return;
2004 }
2005
2006 RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView();
2007 if (!delegate_view) {
boliu 2016/12/06 23:24:16 can this happen? Pretty sure WebContentsImpl alway
rlanday 2016/12/07 00:07:48 This is actually what the test case was failing on
boliu 2016/12/07 00:33:15 Ok.. Do you have the full stack of when that happe
rlanday 2016/12/07 00:46:00 I 8.385s Main signal 11 (SIGSEGV), code 1 (SEG
boliu 2016/12/07 00:50:19 meh, MockRenderWidgetHostDelegate doesn't have a D
2008 return;
2009 }
2010
2011 ui::OverscrollRefreshHandler* overscroll_refresh_handler =
2012 delegate_view->GetOverscrollRefreshHandler();
2013 if (!overscroll_refresh_handler) {
2014 return;
2015 }
2016
2017 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2018 overscroll_refresh_handler,
2019 content_view_core_->GetWindowAndroid()->GetCompositor(),
boliu 2016/12/06 23:24:16 also need to null check GetCompositor
boliu 2016/12/06 23:26:57 actually, need to null check content_view_core_ as
rlanday 2016/12/07 00:07:48 Hmm, this check doesn't already exist in the curre
boliu 2016/12/07 00:33:15 Line 1820 on the left
boliu 2016/12/07 00:35:46 Oh wait you mean null check for CVC? Well, in theo
2020 ui::GetScaleFactorForNativeView(GetNativeView()));
2021 }
2022
2003 } // namespace content 2023 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | content/browser/web_contents/web_contents_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698