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

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

Issue 2528823002: Separate SwipeRefreshHandler and ContentViewCore (Closed)
Patch Set: tedchoc's requested changes 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (using_browser_compositor_) { 457 if (using_browser_compositor_) {
464 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( 458 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid(
465 &view_, cached_background_color_, 459 &view_, cached_background_color_,
466 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, 460 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources,
467 weak_ptr_factory_.GetWeakPtr()))); 461 weak_ptr_factory_.GetWeakPtr())));
468 } 462 }
469 463
470 host_->SetView(this); 464 host_->SetView(this);
471 SetContentViewCore(content_view_core); 465 SetContentViewCore(content_view_core);
472 466
467 CreateOverscrollControllerIfPossible();
468
473 if (GetTextInputManager()) 469 if (GetTextInputManager())
474 GetTextInputManager()->AddObserver(this); 470 GetTextInputManager()->AddObserver(this);
475 } 471 }
476 472
477 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 473 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
478 if (content_view_core_) 474 if (content_view_core_)
479 content_view_core_->RemoveObserver(this); 475 content_view_core_->RemoveObserver(this);
480 SetContentViewCore(NULL); 476 SetContentViewCore(NULL);
481 DCHECK(ack_callbacks_.empty()); 477 DCHECK(ack_callbacks_.empty());
482 DCHECK(!delegated_frame_host_); 478 DCHECK(!delegated_frame_host_);
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 } 1205 }
1210 1206
1211 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient( 1207 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient(
1212 SynchronousCompositorClient* client) { 1208 SynchronousCompositorClient* client) {
1213 synchronous_compositor_client_ = client; 1209 synchronous_compositor_client_ = client;
1214 if (!sync_compositor_ && synchronous_compositor_client_) { 1210 if (!sync_compositor_ && synchronous_compositor_client_) {
1215 sync_compositor_ = SynchronousCompositorHost::Create(this); 1211 sync_compositor_ = SynchronousCompositorHost::Create(this);
1216 } 1212 }
1217 } 1213 }
1218 1214
1215 void RenderWidgetHostViewAndroid::OnOverscrollRefreshHandlerAvailable() {
1216 DCHECK(!overscroll_controller_);
1217 CreateOverscrollControllerIfPossible();
1218 }
1219
1219 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { 1220 bool RenderWidgetHostViewAndroid::SupportsAnimation() const {
1220 // The synchronous (WebView) compositor does not have a proper browser 1221 // The synchronous (WebView) compositor does not have a proper browser
1221 // compositor with which to drive animations. 1222 // compositor with which to drive animations.
1222 return using_browser_compositor_; 1223 return using_browser_compositor_;
1223 } 1224 }
1224 1225
1225 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { 1226 void RenderWidgetHostViewAndroid::SetNeedsAnimate() {
1226 DCHECK(view_.GetWindowAndroid()); 1227 DCHECK(view_.GetWindowAndroid());
1227 DCHECK(using_browser_compositor_); 1228 DCHECK(using_browser_compositor_);
1228 view_.GetWindowAndroid()->SetNeedsAnimate(); 1229 view_.GetWindowAndroid()->SetNeedsAnimate();
(...skipping 532 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 27 matching lines...) Expand all
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 1818
1819 if (!overscroll_controller_ && 1819 if (content_view_core_)
1820 view_.GetWindowAndroid()->GetCompositor()) { 1820 CreateOverscrollControllerIfPossible();
1821 overscroll_controller_ = CreateOverscrollController(
1822 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView()));
1823 is_showing_overscroll_glow_ = true;
1824 }
1825 } 1821 }
1826 1822
1827 void RenderWidgetHostViewAndroid::RunAckCallbacks() { 1823 void RenderWidgetHostViewAndroid::RunAckCallbacks() {
1828 while (!ack_callbacks_.empty()) { 1824 while (!ack_callbacks_.empty()) {
1829 ack_callbacks_.front().Run(); 1825 ack_callbacks_.front().Run();
1830 ack_callbacks_.pop(); 1826 ack_callbacks_.pop();
1831 } 1827 }
1832 } 1828 }
1833 1829
1834 void RenderWidgetHostViewAndroid::OnGestureEvent( 1830 void RenderWidgetHostViewAndroid::OnGestureEvent(
1835 const ui::GestureEventData& gesture) { 1831 const ui::GestureEventData& gesture) {
1836 blink::WebGestureEvent web_gesture = 1832 blink::WebGestureEvent web_gesture =
1837 ui::CreateWebGestureEventFromGestureEventData(gesture); 1833 ui::CreateWebGestureEventFromGestureEventData(gesture);
1838 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to 1834 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to
1839 // stop providing shift meta values to synthetic MotionEvents. This prevents 1835 // stop providing shift meta values to synthetic MotionEvents. This prevents
1840 // unintended shift+click interpretation of all accessibility clicks. 1836 // unintended shift+click interpretation of all accessibility clicks.
1841 // See crbug.com/443247. 1837 // See crbug.com/443247.
1842 if (web_gesture.type == blink::WebInputEvent::GestureTap && 1838 if (web_gesture.type == blink::WebInputEvent::GestureTap &&
1843 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { 1839 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) {
1844 web_gesture.modifiers = 0; 1840 web_gesture.modifiers = 0;
1845 } 1841 }
1846 SendGestureEvent(web_gesture); 1842 SendGestureEvent(web_gesture);
1847 } 1843 }
1848 1844
1849 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { 1845 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() {
1850 SetContentViewCore(NULL); 1846 SetContentViewCore(NULL);
1847 overscroll_controller_.reset();
1851 } 1848 }
1852 1849
1853 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { 1850 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() {
1854 RunAckCallbacks(); 1851 RunAckCallbacks();
1855 } 1852 }
1856 1853
1857 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { 1854 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) {
1858 TRACE_EVENT1("browser", 1855 TRACE_EVENT1("browser",
1859 "RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged", 1856 "RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged",
1860 "visible", visible); 1857 "visible", visible);
(...skipping 17 matching lines...) Expand all
1878 OnAttachCompositor(); 1875 OnAttachCompositor();
1879 } 1876 }
1880 1877
1881 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { 1878 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() {
1882 StopObservingRootWindow(); 1879 StopObservingRootWindow();
1883 OnDetachCompositor(); 1880 OnDetachCompositor();
1884 } 1881 }
1885 1882
1886 void RenderWidgetHostViewAndroid::OnAttachCompositor() { 1883 void RenderWidgetHostViewAndroid::OnAttachCompositor() {
1887 DCHECK(content_view_core_); 1884 DCHECK(content_view_core_);
1888 if (!overscroll_controller_) 1885 CreateOverscrollControllerIfPossible();
1889 overscroll_controller_ = CreateOverscrollController(
1890 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView()));
1891 ui::WindowAndroidCompositor* compositor = 1886 ui::WindowAndroidCompositor* compositor =
1892 view_.GetWindowAndroid()->GetCompositor(); 1887 view_.GetWindowAndroid()->GetCompositor();
1893 delegated_frame_host_->RegisterFrameSinkHierarchy( 1888 delegated_frame_host_->RegisterFrameSinkHierarchy(
1894 compositor->GetFrameSinkId()); 1889 compositor->GetFrameSinkId());
1895 } 1890 }
1896 1891
1897 void RenderWidgetHostViewAndroid::OnDetachCompositor() { 1892 void RenderWidgetHostViewAndroid::OnDetachCompositor() {
1898 DCHECK(content_view_core_); 1893 DCHECK(content_view_core_);
1899 DCHECK(using_browser_compositor_); 1894 DCHECK(using_browser_compositor_);
1900 RunAckCallbacks(); 1895 RunAckCallbacks();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 return; 1989 return;
1995 case ui::MotionEvent::ACTION_UP: 1990 case ui::MotionEvent::ACTION_UP:
1996 case ui::MotionEvent::ACTION_POINTER_UP: 1991 case ui::MotionEvent::ACTION_POINTER_UP:
1997 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 1992 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
1998 delta.InMicroseconds(), 1, 1000000, 50); 1993 delta.InMicroseconds(), 1, 1000000, 50);
1999 default: 1994 default:
2000 return; 1995 return;
2001 } 1996 }
2002 } 1997 }
2003 1998
1999 void RenderWidgetHostViewAndroid::CreateOverscrollControllerIfPossible() {
2000 // an OverscrollController is already set
2001 if (overscroll_controller_)
2002 return;
2003
2004 RenderWidgetHostDelegate* delegate = host_->delegate();
2005 if (!delegate)
2006 return;
2007
2008 RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView();
2009 // render_widget_host_unittest.cc uses an object called
2010 // MockRenderWidgetHostDelegate that does not have a DelegateView
2011 if (!delegate_view)
2012 return;
2013
2014 ui::OverscrollRefreshHandler* overscroll_refresh_handler =
2015 delegate_view->GetOverscrollRefreshHandler();
2016 if (!overscroll_refresh_handler)
2017 return;
2018
2019 if (!content_view_core_)
2020 return;
2021
2022 // If window_android is null here, this is bad because we don't listen for it
2023 // being set, so we won't be able to construct the OverscrollController at the
2024 // proper time.
2025 // TODO(rlanday): once we get WindowAndroid from ViewAndroid instead of
2026 // ContentViewCore, listen for WindowAndroid being set and create the
2027 // OverscrollController.
2028 ui::WindowAndroid* window_android = content_view_core_->GetWindowAndroid();
2029 if (!window_android)
2030 return;
2031
2032 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2033 if (!compositor)
2034 return;
2035
2036 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2037 overscroll_refresh_handler, compositor,
2038 ui::GetScaleFactorForNativeView(GetNativeView()));
2039 is_showing_overscroll_glow_ = true;
2040 }
2041
2004 } // namespace content 2042 } // 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