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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 std::unique_ptr<OverscrollControllerAndroid> CreateOverscrollController( |
| 341 ui::OverscrollRefreshHandler* overscroll_refresh_handler, | |
| 340 ContentViewCoreImpl* content_view_core, | 342 ContentViewCoreImpl* content_view_core, |
| 341 float dpi_scale) { | 343 float dpi_scale) { |
| 342 return base::MakeUnique<OverscrollControllerAndroid>(content_view_core, | 344 return base::MakeUnique<OverscrollControllerAndroid>( |
| 343 dpi_scale); | 345 overscroll_refresh_handler, |
| 346 content_view_core->GetWindowAndroid()->GetCompositor(), dpi_scale); | |
| 344 } | 347 } |
| 345 | 348 |
| 346 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { | 349 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { |
| 347 gfx::RectF rect = controller.GetRectBetweenBounds(); | 350 gfx::RectF rect = controller.GetRectBetweenBounds(); |
| 348 if (rect.IsEmpty()) | 351 if (rect.IsEmpty()) |
| 349 return rect; | 352 return rect; |
| 350 | 353 |
| 351 rect.Union(controller.GetStartHandleRect()); | 354 rect.Union(controller.GetStartHandleRect()); |
| 352 rect.Union(controller.GetEndHandleRect()); | 355 rect.Union(controller.GetEndHandleRect()); |
| 353 return rect; | 356 return rect; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 if (using_browser_compositor_) { | 465 if (using_browser_compositor_) { |
| 463 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( | 466 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( |
| 464 &view_, cached_background_color_, | 467 &view_, cached_background_color_, |
| 465 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, | 468 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources, |
| 466 weak_ptr_factory_.GetWeakPtr()))); | 469 weak_ptr_factory_.GetWeakPtr()))); |
| 467 } | 470 } |
| 468 | 471 |
| 469 host_->SetView(this); | 472 host_->SetView(this); |
| 470 SetContentViewCore(content_view_core); | 473 SetContentViewCore(content_view_core); |
| 471 | 474 |
| 475 ui::OverscrollRefreshHandler* handler = | |
| 476 host_->delegate()->GetDelegateView()->GetOverscrollRefreshHandler(); | |
|
boliu
2016/12/06 16:06:45
looks like host_->delegate() may be null, so need
rlanday
2016/12/06 19:01:16
I'm not sure what you mean here; this is right aft
boliu
2016/12/06 19:05:17
oh oops, my bad :p
| |
| 477 if (handler) { | |
| 478 overscroll_controller_ = CreateOverscrollController( | |
| 479 handler, content_view_core_, | |
| 480 ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 481 } | |
| 482 | |
| 472 if (GetTextInputManager()) | 483 if (GetTextInputManager()) |
| 473 GetTextInputManager()->AddObserver(this); | 484 GetTextInputManager()->AddObserver(this); |
| 474 } | 485 } |
| 475 | 486 |
| 476 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 487 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
| 477 if (content_view_core_) | 488 if (content_view_core_) |
| 478 content_view_core_->RemoveObserver(this); | 489 content_view_core_->RemoveObserver(this); |
| 479 SetContentViewCore(NULL); | 490 SetContentViewCore(NULL); |
| 480 DCHECK(ack_callbacks_.empty()); | 491 DCHECK(ack_callbacks_.empty()); |
| 481 DCHECK(!delegated_frame_host_); | 492 DCHECK(!delegated_frame_host_); |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 } | 1224 } |
| 1214 | 1225 |
| 1215 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient( | 1226 void RenderWidgetHostViewAndroid::SetSynchronousCompositorClient( |
| 1216 SynchronousCompositorClient* client) { | 1227 SynchronousCompositorClient* client) { |
| 1217 synchronous_compositor_client_ = client; | 1228 synchronous_compositor_client_ = client; |
| 1218 if (!sync_compositor_ && synchronous_compositor_client_) { | 1229 if (!sync_compositor_ && synchronous_compositor_client_) { |
| 1219 sync_compositor_ = SynchronousCompositorHost::Create(this); | 1230 sync_compositor_ = SynchronousCompositorHost::Create(this); |
| 1220 } | 1231 } |
| 1221 } | 1232 } |
| 1222 | 1233 |
| 1234 void RenderWidgetHostViewAndroid::OnOverscrollRefreshHandlerSet() { | |
| 1235 DCHECK(!overscroll_controller_); | |
| 1236 overscroll_controller_ = CreateOverscrollController( | |
| 1237 host_->delegate()->GetDelegateView()->GetOverscrollRefreshHandler(), | |
| 1238 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 1239 } | |
| 1240 | |
| 1223 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { | 1241 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { |
| 1224 // The synchronous (WebView) compositor does not have a proper browser | 1242 // The synchronous (WebView) compositor does not have a proper browser |
| 1225 // compositor with which to drive animations. | 1243 // compositor with which to drive animations. |
| 1226 return using_browser_compositor_; | 1244 return using_browser_compositor_; |
| 1227 } | 1245 } |
| 1228 | 1246 |
| 1229 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { | 1247 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { |
| 1230 DCHECK(view_.GetWindowAndroid()); | 1248 DCHECK(view_.GetWindowAndroid()); |
| 1231 DCHECK(using_browser_compositor_); | 1249 DCHECK(using_browser_compositor_); |
| 1232 view_.GetWindowAndroid()->SetNeedsAnimate(); | 1250 view_.GetWindowAndroid()->SetNeedsAnimate(); |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1761 } | 1779 } |
| 1762 | 1780 |
| 1763 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1781 void RenderWidgetHostViewAndroid::SetContentViewCore( |
| 1764 ContentViewCoreImpl* content_view_core) { | 1782 ContentViewCoreImpl* content_view_core) { |
| 1765 DCHECK(!content_view_core || !content_view_core_ || | 1783 DCHECK(!content_view_core || !content_view_core_ || |
| 1766 (content_view_core_ == content_view_core)); | 1784 (content_view_core_ == content_view_core)); |
| 1767 StopObservingRootWindow(); | 1785 StopObservingRootWindow(); |
| 1768 | 1786 |
| 1769 bool resize = false; | 1787 bool resize = false; |
| 1770 if (content_view_core != content_view_core_) { | 1788 if (content_view_core != content_view_core_) { |
| 1771 overscroll_controller_.reset(); | 1789 overscroll_controller_.reset(); |
|
boliu
2016/12/06 16:06:45
probably this reset should move somewhere else as
rlanday
2016/12/06 19:01:16
Hmm I think we probably need to reset this when th
boliu
2016/12/06 19:05:17
Hmm, if DelegateView is always valid for this life
rlanday
2016/12/06 21:26:28
I agree, I am confused if this is something that c
boliu
2016/12/06 23:24:16
RenderWidgetHostViewAndroid::OnContentViewCoreDest
| |
| 1772 selection_controller_.reset(); | 1790 selection_controller_.reset(); |
| 1773 ReleaseLocksOnSurface(); | 1791 ReleaseLocksOnSurface(); |
| 1774 // TODO(yusufo) : Get rid of the below conditions and have a better handling | 1792 // TODO(yusufo) : Get rid of the below conditions and have a better handling |
| 1775 // for resizing after crbug.com/628302 is handled. | 1793 // for resizing after crbug.com/628302 is handled. |
| 1776 bool is_size_initialized = !content_view_core | 1794 bool is_size_initialized = !content_view_core |
| 1777 || content_view_core->GetViewportSizeDip().width() != 0 | 1795 || content_view_core->GetViewportSizeDip().width() != 0 |
| 1778 || content_view_core->GetViewportSizeDip().height() != 0; | 1796 || content_view_core->GetViewportSizeDip().height() != 0; |
| 1779 if (content_view_core_ || is_size_initialized) | 1797 if (content_view_core_ || is_size_initialized) |
| 1780 resize = true; | 1798 resize = true; |
| 1781 if (content_view_core_) { | 1799 if (content_view_core_) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1808 } | 1826 } |
| 1809 | 1827 |
| 1810 if (is_showing_) | 1828 if (is_showing_) |
| 1811 StartObservingRootWindow(); | 1829 StartObservingRootWindow(); |
| 1812 | 1830 |
| 1813 if (resize) | 1831 if (resize) |
| 1814 WasResized(); | 1832 WasResized(); |
| 1815 | 1833 |
| 1816 if (!selection_controller_) | 1834 if (!selection_controller_) |
| 1817 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1835 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 } | 1836 } |
| 1825 | 1837 |
| 1826 void RenderWidgetHostViewAndroid::RunAckCallbacks() { | 1838 void RenderWidgetHostViewAndroid::RunAckCallbacks() { |
| 1827 while (!ack_callbacks_.empty()) { | 1839 while (!ack_callbacks_.empty()) { |
| 1828 ack_callbacks_.front().Run(); | 1840 ack_callbacks_.front().Run(); |
| 1829 ack_callbacks_.pop(); | 1841 ack_callbacks_.pop(); |
| 1830 } | 1842 } |
| 1831 } | 1843 } |
| 1832 | 1844 |
| 1833 void RenderWidgetHostViewAndroid::OnGestureEvent( | 1845 void RenderWidgetHostViewAndroid::OnGestureEvent( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1877 OnAttachCompositor(); | 1889 OnAttachCompositor(); |
| 1878 } | 1890 } |
| 1879 | 1891 |
| 1880 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { | 1892 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { |
| 1881 StopObservingRootWindow(); | 1893 StopObservingRootWindow(); |
| 1882 OnDetachCompositor(); | 1894 OnDetachCompositor(); |
| 1883 } | 1895 } |
| 1884 | 1896 |
| 1885 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1897 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
| 1886 DCHECK(content_view_core_); | 1898 DCHECK(content_view_core_); |
| 1887 if (!overscroll_controller_) | 1899 if (!overscroll_controller_) { |
| 1888 overscroll_controller_ = CreateOverscrollController( | 1900 ui::OverscrollRefreshHandler* handler = |
| 1889 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | 1901 host_->delegate()->GetDelegateView()->GetOverscrollRefreshHandler(); |
| 1902 if (handler) { | |
| 1903 overscroll_controller_ = CreateOverscrollController( | |
| 1904 handler, content_view_core_, | |
| 1905 ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 1906 } | |
| 1907 } | |
| 1890 ui::WindowAndroidCompositor* compositor = | 1908 ui::WindowAndroidCompositor* compositor = |
| 1891 view_.GetWindowAndroid()->GetCompositor(); | 1909 view_.GetWindowAndroid()->GetCompositor(); |
| 1892 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1910 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1893 compositor->GetFrameSinkId()); | 1911 compositor->GetFrameSinkId()); |
| 1894 } | 1912 } |
| 1895 | 1913 |
| 1896 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1914 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1897 DCHECK(content_view_core_); | 1915 DCHECK(content_view_core_); |
| 1898 DCHECK(using_browser_compositor_); | 1916 DCHECK(using_browser_compositor_); |
| 1899 RunAckCallbacks(); | 1917 RunAckCallbacks(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1994 case ui::MotionEvent::ACTION_UP: | 2012 case ui::MotionEvent::ACTION_UP: |
| 1995 case ui::MotionEvent::ACTION_POINTER_UP: | 2013 case ui::MotionEvent::ACTION_POINTER_UP: |
| 1996 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 2014 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 1997 delta.InMicroseconds(), 1, 1000000, 50); | 2015 delta.InMicroseconds(), 1, 1000000, 50); |
| 1998 default: | 2016 default: |
| 1999 return; | 2017 return; |
| 2000 } | 2018 } |
| 2001 } | 2019 } |
| 2002 | 2020 |
| 2003 } // namespace content | 2021 } // namespace content |
| OLD | NEW |