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

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

Issue 1140693004: [Android] Prevent touch interception for browser-consumed touches (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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 "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 const gfx::Rect rect) { 741 const gfx::Rect rect) {
742 if (content_view_core_) 742 if (content_view_core_)
743 content_view_core_->OnSmartClipDataExtracted(text, html, rect); 743 content_view_core_->OnSmartClipDataExtracted(text, html, rect);
744 } 744 }
745 745
746 bool RenderWidgetHostViewAndroid::OnTouchEvent( 746 bool RenderWidgetHostViewAndroid::OnTouchEvent(
747 const ui::MotionEvent& event) { 747 const ui::MotionEvent& event) {
748 if (!host_) 748 if (!host_)
749 return false; 749 return false;
750 750
751 // If a browser-based widget consumes the touch event, it's critical that
752 // touch event interception be disabled. This avoids issues with
753 // double-handling for embedder-detected gestures like side swipe.
751 if (selection_controller_ && 754 if (selection_controller_ &&
752 selection_controller_->WillHandleTouchEvent(event)) 755 selection_controller_->WillHandleTouchEvent(event)) {
756 RequestDisallowInterceptTouchEvent();
753 return true; 757 return true;
758 }
754 759
755 if (stylus_text_selector_.OnTouchEvent(event)) 760 if (stylus_text_selector_.OnTouchEvent(event)) {
761 RequestDisallowInterceptTouchEvent();
756 return true; 762 return true;
763 }
757 764
758 ui::FilteredGestureProvider::TouchHandlingResult result = 765 ui::FilteredGestureProvider::TouchHandlingResult result =
759 gesture_provider_.OnTouchEvent(event); 766 gesture_provider_.OnTouchEvent(event);
760 if (!result.succeeded) 767 if (!result.succeeded)
761 return false; 768 return false;
762 769
763 blink::WebTouchEvent web_event = 770 blink::WebTouchEvent web_event =
764 ui::CreateWebTouchEventFromMotionEvent(event, result.did_generate_scroll); 771 ui::CreateWebTouchEventFromMotionEvent(event, result.did_generate_scroll);
765 host_->ForwardTouchEventWithLatencyInfo(web_event, ui::LatencyInfo()); 772 host_->ForwardTouchEventWithLatencyInfo(web_event, ui::LatencyInfo());
766 773
767 // Send a proactive BeginFrame on the next vsync to reduce latency. 774 // Send a proactive BeginFrame on the next vsync to reduce latency.
768 // This is good enough as long as the first touch event has Begin semantics 775 // This is good enough as long as the first touch event has Begin semantics
769 // and the actual scroll happens on the next vsync. 776 // and the actual scroll happens on the next vsync.
770 if (observing_root_window_) 777 if (observing_root_window_)
771 RequestVSyncUpdate(BEGIN_FRAME); 778 RequestVSyncUpdate(BEGIN_FRAME);
772 779
773 return true; 780 return true;
774 } 781 }
775 782
776 bool RenderWidgetHostViewAndroid::OnTouchHandleEvent( 783 bool RenderWidgetHostViewAndroid::OnTouchHandleEvent(
777 const ui::MotionEvent& event) { 784 const ui::MotionEvent& event) {
778 return selection_controller_ && 785 return selection_controller_ &&
779 selection_controller_->WillHandleTouchEvent(event); 786 selection_controller_->WillHandleTouchEvent(event);
780 } 787 }
781 788
782 void RenderWidgetHostViewAndroid::ResetGestureDetection() { 789 void RenderWidgetHostViewAndroid::ResetGestureDetection() {
783 const ui::MotionEvent* current_down_event = 790 const ui::MotionEvent* current_down_event =
784 gesture_provider_.GetCurrentDownEvent(); 791 gesture_provider_.GetCurrentDownEvent();
785 if (current_down_event) { 792 if (!current_down_event) {
786 scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel(); 793 // A hard reset ensures prevention of any timer-based events that might fire
787 OnTouchEvent(*cancel_event); 794 // after a touch sequence has ended.
795 gesture_provider_.ResetDetection();
796 return;
788 } 797 }
789 798
790 // A hard reset ensures prevention of any timer-based events. 799 scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel();
791 gesture_provider_.ResetDetection(); 800 if (gesture_provider_.OnTouchEvent(*cancel_event).succeeded) {
801 bool causes_scrolling = false;
802 host_->ForwardTouchEventWithLatencyInfo(
803 ui::CreateWebTouchEventFromMotionEvent(*cancel_event, causes_scrolling),
804 ui::LatencyInfo());
805 }
792 } 806 }
793 807
794 void RenderWidgetHostViewAndroid::OnDidNavigateMainFrameToNewPage() { 808 void RenderWidgetHostViewAndroid::OnDidNavigateMainFrameToNewPage() {
795 ResetGestureDetection(); 809 ResetGestureDetection();
796 } 810 }
797 811
798 void RenderWidgetHostViewAndroid::SetDoubleTapSupportEnabled(bool enabled) { 812 void RenderWidgetHostViewAndroid::SetDoubleTapSupportEnabled(bool enabled) {
799 gesture_provider_.SetDoubleTapSupportForPlatformEnabled(enabled); 813 gesture_provider_.SetDoubleTapSupportForPlatformEnabled(enabled);
800 } 814 }
801 815
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 const gfx::PointF& base, 1270 const gfx::PointF& base,
1257 const gfx::PointF& extent) { 1271 const gfx::PointF& extent) {
1258 DCHECK(content_view_core_); 1272 DCHECK(content_view_core_);
1259 content_view_core_->SelectBetweenCoordinates(base, extent); 1273 content_view_core_->SelectBetweenCoordinates(base, extent);
1260 } 1274 }
1261 1275
1262 void RenderWidgetHostViewAndroid::OnSelectionEvent( 1276 void RenderWidgetHostViewAndroid::OnSelectionEvent(
1263 ui::SelectionEventType event) { 1277 ui::SelectionEventType event) {
1264 DCHECK(content_view_core_); 1278 DCHECK(content_view_core_);
1265 DCHECK(selection_controller_); 1279 DCHECK(selection_controller_);
1266 // Showing the selection action bar can alter the current View coordinates in 1280 // If a selection drag has started, it has taken over the active touch
1267 // such a way that the current MotionEvent stream is suddenly shifted in 1281 // sequence. Immediately cancel gesture detection and any downstream touch
1268 // space. Avoid the associated scroll jump by pre-emptively cancelling gesture 1282 // listeners (e.g., web content) to communicate this transfer.
1269 // detection; scrolling after the selection is activated is unnecessary. 1283 if (event == ui::SELECTION_SHOWN)
1270 if (event == ui::SelectionEventType::SELECTION_SHOWN)
1271 ResetGestureDetection(); 1284 ResetGestureDetection();
1272 content_view_core_->OnSelectionEvent( 1285 content_view_core_->OnSelectionEvent(
1273 event, selection_controller_->GetStartPosition(), 1286 event, selection_controller_->GetStartPosition(),
1274 GetSelectionRect(*selection_controller_)); 1287 GetSelectionRect(*selection_controller_));
1275 } 1288 }
1276 1289
1277 scoped_ptr<ui::TouchHandleDrawable> 1290 scoped_ptr<ui::TouchHandleDrawable>
1278 RenderWidgetHostViewAndroid::CreateDrawable() { 1291 RenderWidgetHostViewAndroid::CreateDrawable() {
1279 DCHECK(content_view_core_); 1292 DCHECK(content_view_core_);
1280 if (!using_browser_compositor_) 1293 if (!using_browser_compositor_)
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 bool needs_animate = false; 1537 bool needs_animate = false;
1525 if (overscroll_controller_) { 1538 if (overscroll_controller_) {
1526 needs_animate |= overscroll_controller_->Animate( 1539 needs_animate |= overscroll_controller_->Animate(
1527 frame_time, content_view_core_->GetLayer().get()); 1540 frame_time, content_view_core_->GetLayer().get());
1528 } 1541 }
1529 if (selection_controller_) 1542 if (selection_controller_)
1530 needs_animate |= selection_controller_->Animate(frame_time); 1543 needs_animate |= selection_controller_->Animate(frame_time);
1531 return needs_animate; 1544 return needs_animate;
1532 } 1545 }
1533 1546
1547 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() {
1548 if (content_view_core_)
1549 content_view_core_->RequestDisallowInterceptTouchEvent();
1550 }
1551
1534 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { 1552 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() {
1535 if (layer_.get()) 1553 if (layer_.get())
1536 DestroyDelegatedContent(); 1554 DestroyDelegatedContent();
1537 frame_evictor_->DiscardedFrame(); 1555 frame_evictor_->DiscardedFrame();
1538 } 1556 }
1539 1557
1540 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( 1558 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface(
1541 const gfx::Size& desired_size) { 1559 const gfx::Size& desired_size) {
1542 NOTREACHED(); 1560 NOTREACHED();
1543 return false; 1561 return false;
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 results->orientationAngle = display.RotationAsDegree(); 2034 results->orientationAngle = display.RotationAsDegree();
2017 results->orientationType = 2035 results->orientationType =
2018 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); 2036 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display);
2019 gfx::DeviceDisplayInfo info; 2037 gfx::DeviceDisplayInfo info;
2020 results->depth = info.GetBitsPerPixel(); 2038 results->depth = info.GetBitsPerPixel();
2021 results->depthPerComponent = info.GetBitsPerComponent(); 2039 results->depthPerComponent = info.GetBitsPerComponent();
2022 results->isMonochrome = (results->depthPerComponent == 0); 2040 results->isMonochrome = (results->depthPerComponent == 0);
2023 } 2041 }
2024 2042
2025 } // namespace content 2043 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698