Chromium Code Reviews| 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_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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 } | 1210 } |
| 1215 | 1211 |
| 1216 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient( | 1212 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient( |
| 1217 SynchronousCompositorClient* client) { | 1213 SynchronousCompositorClient* client) { |
| 1218 synchronous_compositor_client_ = client; | 1214 synchronous_compositor_client_ = client; |
| 1219 if (!sync_compositor_ && synchronous_compositor_client_) { | 1215 if (!sync_compositor_ && synchronous_compositor_client_) { |
| 1220 sync_compositor_ = SynchronousCompositorHost::Create(this); | 1216 sync_compositor_ = SynchronousCompositorHost::Create(this); |
| 1221 } | 1217 } |
| 1222 } | 1218 } |
| 1223 | 1219 |
| 1220 void RenderWidgetHostViewAndroid::OnOverscrollRefreshHandlerSet() { | |
|
Ted C
2016/12/13 21:09:48
I would probably use Available instead of Set, but
rlanday
2016/12/14 01:11:15
I think that fits
| |
| 1221 DCHECK(!overscroll_controller_); | |
| 1222 CreateOverscrollControllerIfPossible(); | |
| 1223 } | |
| 1224 | |
| 1224 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { | 1225 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { |
| 1225 // The synchronous (WebView) compositor does not have a proper browser | 1226 // The synchronous (WebView) compositor does not have a proper browser |
| 1226 // compositor with which to drive animations. | 1227 // compositor with which to drive animations. |
| 1227 return using_browser_compositor_; | 1228 return using_browser_compositor_; |
| 1228 } | 1229 } |
| 1229 | 1230 |
| 1230 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { | 1231 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { |
| 1231 DCHECK(view_.GetWindowAndroid()); | 1232 DCHECK(view_.GetWindowAndroid()); |
| 1232 DCHECK(using_browser_compositor_); | 1233 DCHECK(using_browser_compositor_); |
| 1233 view_.GetWindowAndroid()->SetNeedsAnimate(); | 1234 view_.GetWindowAndroid()->SetNeedsAnimate(); |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1766 } | 1767 } |
| 1767 | 1768 |
| 1768 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1769 void RenderWidgetHostViewAndroid::SetContentViewCore( |
| 1769 ContentViewCoreImpl* content_view_core) { | 1770 ContentViewCoreImpl* content_view_core) { |
| 1770 DCHECK(!content_view_core || !content_view_core_ || | 1771 DCHECK(!content_view_core || !content_view_core_ || |
| 1771 (content_view_core_ == content_view_core)); | 1772 (content_view_core_ == content_view_core)); |
| 1772 StopObservingRootWindow(); | 1773 StopObservingRootWindow(); |
| 1773 | 1774 |
| 1774 bool resize = false; | 1775 bool resize = false; |
| 1775 if (content_view_core != content_view_core_) { | 1776 if (content_view_core != content_view_core_) { |
| 1776 overscroll_controller_.reset(); | |
| 1777 selection_controller_.reset(); | 1777 selection_controller_.reset(); |
| 1778 ReleaseLocksOnSurface(); | 1778 ReleaseLocksOnSurface(); |
| 1779 // TODO(yusufo) : Get rid of the below conditions and have a better handling | 1779 // TODO(yusufo) : Get rid of the below conditions and have a better handling |
| 1780 // for resizing after crbug.com/628302 is handled. | 1780 // for resizing after crbug.com/628302 is handled. |
| 1781 bool is_size_initialized = !content_view_core | 1781 bool is_size_initialized = !content_view_core |
| 1782 || content_view_core->GetViewportSizeDip().width() != 0 | 1782 || content_view_core->GetViewportSizeDip().width() != 0 |
| 1783 || content_view_core->GetViewportSizeDip().height() != 0; | 1783 || content_view_core->GetViewportSizeDip().height() != 0; |
| 1784 if (content_view_core_ || is_size_initialized) | 1784 if (content_view_core_ || is_size_initialized) |
| 1785 resize = true; | 1785 resize = true; |
| 1786 if (content_view_core_) { | 1786 if (content_view_core_) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1814 | 1814 |
| 1815 if (is_showing_) | 1815 if (is_showing_) |
| 1816 StartObservingRootWindow(); | 1816 StartObservingRootWindow(); |
| 1817 | 1817 |
| 1818 if (resize) | 1818 if (resize) |
| 1819 WasResized(); | 1819 WasResized(); |
| 1820 | 1820 |
| 1821 if (!selection_controller_) | 1821 if (!selection_controller_) |
| 1822 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1822 selection_controller_ = CreateSelectionController(this, content_view_core_); |
| 1823 | 1823 |
| 1824 if (!overscroll_controller_ && | 1824 if (content_view_core_) |
| 1825 view_.GetWindowAndroid()->GetCompositor()) { | 1825 CreateOverscrollControllerIfPossible(); |
| 1826 overscroll_controller_ = CreateOverscrollController( | |
| 1827 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 1828 is_showing_overscroll_glow_ = true; | |
| 1829 } | |
| 1830 } | 1826 } |
| 1831 | 1827 |
| 1832 void RenderWidgetHostViewAndroid::RunAckCallbacks() { | 1828 void RenderWidgetHostViewAndroid::RunAckCallbacks() { |
| 1833 while (!ack_callbacks_.empty()) { | 1829 while (!ack_callbacks_.empty()) { |
| 1834 ack_callbacks_.front().Run(); | 1830 ack_callbacks_.front().Run(); |
| 1835 ack_callbacks_.pop(); | 1831 ack_callbacks_.pop(); |
| 1836 } | 1832 } |
| 1837 } | 1833 } |
| 1838 | 1834 |
| 1839 void RenderWidgetHostViewAndroid::OnGestureEvent( | 1835 void RenderWidgetHostViewAndroid::OnGestureEvent( |
| 1840 const ui::GestureEventData& gesture) { | 1836 const ui::GestureEventData& gesture) { |
| 1841 blink::WebGestureEvent web_gesture = | 1837 blink::WebGestureEvent web_gesture = |
| 1842 ui::CreateWebGestureEventFromGestureEventData(gesture); | 1838 ui::CreateWebGestureEventFromGestureEventData(gesture); |
| 1843 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to | 1839 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to |
| 1844 // stop providing shift meta values to synthetic MotionEvents. This prevents | 1840 // stop providing shift meta values to synthetic MotionEvents. This prevents |
| 1845 // unintended shift+click interpretation of all accessibility clicks. | 1841 // unintended shift+click interpretation of all accessibility clicks. |
| 1846 // See crbug.com/443247. | 1842 // See crbug.com/443247. |
| 1847 if (web_gesture.type == blink::WebInputEvent::GestureTap && | 1843 if (web_gesture.type == blink::WebInputEvent::GestureTap && |
| 1848 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { | 1844 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { |
| 1849 web_gesture.modifiers = 0; | 1845 web_gesture.modifiers = 0; |
| 1850 } | 1846 } |
| 1851 SendGestureEvent(web_gesture); | 1847 SendGestureEvent(web_gesture); |
| 1852 } | 1848 } |
| 1853 | 1849 |
| 1854 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { | 1850 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { |
| 1855 SetContentViewCore(NULL); | 1851 SetContentViewCore(NULL); |
| 1852 overscroll_controller_.reset(); | |
| 1856 } | 1853 } |
| 1857 | 1854 |
| 1858 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { | 1855 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { |
| 1859 RunAckCallbacks(); | 1856 RunAckCallbacks(); |
| 1860 } | 1857 } |
| 1861 | 1858 |
| 1862 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { | 1859 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { |
| 1863 TRACE_EVENT1("browser", | 1860 TRACE_EVENT1("browser", |
| 1864 "RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged", | 1861 "RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged", |
| 1865 "visible", visible); | 1862 "visible", visible); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1883 OnAttachCompositor(); | 1880 OnAttachCompositor(); |
| 1884 } | 1881 } |
| 1885 | 1882 |
| 1886 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { | 1883 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { |
| 1887 StopObservingRootWindow(); | 1884 StopObservingRootWindow(); |
| 1888 OnDetachCompositor(); | 1885 OnDetachCompositor(); |
| 1889 } | 1886 } |
| 1890 | 1887 |
| 1891 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1888 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
| 1892 DCHECK(content_view_core_); | 1889 DCHECK(content_view_core_); |
| 1893 if (!overscroll_controller_) | 1890 CreateOverscrollControllerIfPossible(); |
| 1894 overscroll_controller_ = CreateOverscrollController( | |
| 1895 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 1896 ui::WindowAndroidCompositor* compositor = | 1891 ui::WindowAndroidCompositor* compositor = |
| 1897 view_.GetWindowAndroid()->GetCompositor(); | 1892 view_.GetWindowAndroid()->GetCompositor(); |
| 1898 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1893 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1899 compositor->GetFrameSinkId()); | 1894 compositor->GetFrameSinkId()); |
| 1900 } | 1895 } |
| 1901 | 1896 |
| 1902 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1897 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1903 DCHECK(content_view_core_); | 1898 DCHECK(content_view_core_); |
| 1904 DCHECK(using_browser_compositor_); | 1899 DCHECK(using_browser_compositor_); |
| 1905 RunAckCallbacks(); | 1900 RunAckCallbacks(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1999 return; | 1994 return; |
| 2000 case ui::MotionEvent::ACTION_UP: | 1995 case ui::MotionEvent::ACTION_UP: |
| 2001 case ui::MotionEvent::ACTION_POINTER_UP: | 1996 case ui::MotionEvent::ACTION_POINTER_UP: |
| 2002 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1997 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 2003 delta.InMicroseconds(), 1, 1000000, 50); | 1998 delta.InMicroseconds(), 1, 1000000, 50); |
| 2004 default: | 1999 default: |
| 2005 return; | 2000 return; |
| 2006 } | 2001 } |
| 2007 } | 2002 } |
| 2008 | 2003 |
| 2004 void RenderWidgetHostViewAndroid::CreateOverscrollControllerIfPossible() { | |
| 2005 // an OverscrollController is already set | |
| 2006 if (overscroll_controller_) | |
| 2007 return; | |
| 2008 | |
| 2009 RenderWidgetHostDelegate* delegate = host_->delegate(); | |
| 2010 if (!delegate) | |
| 2011 return; | |
| 2012 | |
| 2013 RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView(); | |
| 2014 // render_widget_host_unittest.cc uses an object called | |
| 2015 // MockRenderWidgetHostDelegate that does not have a DelegateView | |
| 2016 if (!delegate_view) | |
| 2017 return; | |
| 2018 | |
| 2019 ui::OverscrollRefreshHandler* overscroll_refresh_handler = | |
| 2020 delegate_view->GetOverscrollRefreshHandler(); | |
| 2021 if (!overscroll_refresh_handler) | |
| 2022 return; | |
| 2023 | |
| 2024 if (!content_view_core_) | |
| 2025 return; | |
| 2026 | |
| 2027 // If window_android is null here, this is bad because we don't listen for it | |
| 2028 // being set, so we won't be able to construct the OverscrollController at the | |
| 2029 // proper time. | |
| 2030 // TODO(rlanday): once we get WindowAndroid from ViewAndroid instead of | |
| 2031 // ContentViewCore, listen for WindowAndroid being set and create the | |
| 2032 // OverscrollController. | |
| 2033 ui::WindowAndroid* window_android = content_view_core_->GetWindowAndroid(); | |
| 2034 if (!window_android) | |
| 2035 return; | |
| 2036 | |
| 2037 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | |
| 2038 if (!compositor) | |
| 2039 return; | |
| 2040 | |
| 2041 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | |
|
Ted C
2016/12/13 21:09:48
I guess we could also have the RenderViewHostDeleg
rlanday
2016/12/14 01:11:15
I added a note here about how we hope to someday g
| |
| 2042 overscroll_refresh_handler, compositor, | |
| 2043 ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 2044 is_showing_overscroll_glow_ = true; | |
|
rlanday
2016/12/08 19:29:14
This is the new thing that was added in https://co
boliu
2016/12/08 19:32:29
lgtm
| |
| 2045 } | |
| 2046 | |
| 2009 } // namespace content | 2047 } // namespace content |
| OLD | NEW |