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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 DCHECK(!overscroll_controller_); | |
| 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 Loading... | |
| 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 Loading... | |
| 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( |
| 1834 const ui::GestureEventData& gesture) { | 1828 const ui::GestureEventData& gesture) { |
| 1835 blink::WebGestureEvent web_gesture = | 1829 blink::WebGestureEvent web_gesture = |
| 1836 ui::CreateWebGestureEventFromGestureEventData(gesture); | 1830 ui::CreateWebGestureEventFromGestureEventData(gesture); |
| 1837 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to | 1831 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to |
| 1838 // stop providing shift meta values to synthetic MotionEvents. This prevents | 1832 // stop providing shift meta values to synthetic MotionEvents. This prevents |
| 1839 // unintended shift+click interpretation of all accessibility clicks. | 1833 // unintended shift+click interpretation of all accessibility clicks. |
| 1840 // See crbug.com/443247. | 1834 // See crbug.com/443247. |
| 1841 if (web_gesture.type == blink::WebInputEvent::GestureTap && | 1835 if (web_gesture.type == blink::WebInputEvent::GestureTap && |
| 1842 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { | 1836 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { |
| 1843 web_gesture.modifiers = 0; | 1837 web_gesture.modifiers = 0; |
| 1844 } | 1838 } |
| 1845 SendGestureEvent(web_gesture); | 1839 SendGestureEvent(web_gesture); |
| 1846 } | 1840 } |
| 1847 | 1841 |
| 1848 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { | 1842 void RenderWidgetHostViewAndroid::OnContentViewCoreDestroyed() { |
| 1849 SetContentViewCore(NULL); | 1843 SetContentViewCore(NULL); |
| 1844 overscroll_controller_.reset(); | |
| 1850 } | 1845 } |
| 1851 | 1846 |
| 1852 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { | 1847 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { |
| 1853 RunAckCallbacks(); | 1848 RunAckCallbacks(); |
| 1854 } | 1849 } |
| 1855 | 1850 |
| 1856 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { | 1851 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { |
| 1857 TRACE_EVENT1("browser", | 1852 TRACE_EVENT1("browser", |
| 1858 "RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged", | 1853 "RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged", |
| 1859 "visible", visible); | 1854 "visible", visible); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1877 OnAttachCompositor(); | 1872 OnAttachCompositor(); |
| 1878 } | 1873 } |
| 1879 | 1874 |
| 1880 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { | 1875 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { |
| 1881 StopObservingRootWindow(); | 1876 StopObservingRootWindow(); |
| 1882 OnDetachCompositor(); | 1877 OnDetachCompositor(); |
| 1883 } | 1878 } |
| 1884 | 1879 |
| 1885 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1880 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
| 1886 DCHECK(content_view_core_); | 1881 DCHECK(content_view_core_); |
| 1887 if (!overscroll_controller_) | 1882 CreateOverscrollControllerIfPossible(); |
| 1888 overscroll_controller_ = CreateOverscrollController( | |
| 1889 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 1890 ui::WindowAndroidCompositor* compositor = | 1883 ui::WindowAndroidCompositor* compositor = |
| 1891 view_.GetWindowAndroid()->GetCompositor(); | 1884 view_.GetWindowAndroid()->GetCompositor(); |
| 1892 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1885 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1893 compositor->GetFrameSinkId()); | 1886 compositor->GetFrameSinkId()); |
| 1894 } | 1887 } |
| 1895 | 1888 |
| 1896 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1889 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1897 DCHECK(content_view_core_); | 1890 DCHECK(content_view_core_); |
| 1898 DCHECK(using_browser_compositor_); | 1891 DCHECK(using_browser_compositor_); |
| 1899 RunAckCallbacks(); | 1892 RunAckCallbacks(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1993 return; | 1986 return; |
| 1994 case ui::MotionEvent::ACTION_UP: | 1987 case ui::MotionEvent::ACTION_UP: |
| 1995 case ui::MotionEvent::ACTION_POINTER_UP: | 1988 case ui::MotionEvent::ACTION_POINTER_UP: |
| 1996 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1989 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 1997 delta.InMicroseconds(), 1, 1000000, 50); | 1990 delta.InMicroseconds(), 1, 1000000, 50); |
| 1998 default: | 1991 default: |
| 1999 return; | 1992 return; |
| 2000 } | 1993 } |
| 2001 } | 1994 } |
| 2002 | 1995 |
| 1996 void RenderWidgetHostViewAndroid::CreateOverscrollControllerIfPossible() { | |
|
boliu
2016/12/07 21:05:51
also should call this in SetCVC when CVC is not nu
rlanday
2016/12/07 22:13:39
Ok
| |
| 1997 // an OverscrollController is already set | |
| 1998 if (overscroll_controller_) | |
| 1999 return; | |
| 2000 | |
| 2001 RenderWidgetHostDelegate* delegate = host_->delegate(); | |
| 2002 if (!delegate) | |
| 2003 return; | |
| 2004 | |
| 2005 RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView(); | |
| 2006 // render_widget_host_unittest.cc uses an object called | |
| 2007 // MockRenderWidgetHostDelegate that does not have a DelegateView | |
| 2008 if (!delegate_view) | |
| 2009 return; | |
| 2010 | |
| 2011 ui::OverscrollRefreshHandler* overscroll_refresh_handler = | |
| 2012 delegate_view->GetOverscrollRefreshHandler(); | |
| 2013 if (!overscroll_refresh_handler) | |
| 2014 return; | |
| 2015 | |
| 2016 if (!content_view_core_) | |
| 2017 return; | |
| 2018 | |
| 2019 ui::WindowAndroid* window_android = content_view_core_->GetWindowAndroid(); | |
| 2020 if (!window_android) | |
|
boliu
2016/12/07 21:05:52
this one can't happen
rlanday
2016/12/07 22:13:39
Oh, I saw all the "if (GetWindowAndroid())" checks
boliu
2016/12/08 01:05:01
Ohh, you are right. This can be null due to tab re
| |
| 2021 return; | |
| 2022 | |
| 2023 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | |
| 2024 if (!compositor) | |
| 2025 return; | |
| 2026 | |
| 2027 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | |
| 2028 overscroll_refresh_handler, | |
| 2029 compositor, ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 2030 } | |
| 2031 | |
| 2003 } // namespace content | 2032 } // namespace content |
| OLD | NEW |