OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.chrome.browser.compositor.layouts.eventfilter; | 5 package org.chromium.chrome.browser.compositor.layouts.eventfilter; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Handler; | 8 import android.os.Handler; |
9 import android.view.GestureDetector; | 9 import android.view.GestureDetector; |
10 import android.view.MotionEvent; | 10 import android.view.MotionEvent; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 context.getResources(); | 91 context.getResources(); |
92 | 92 |
93 mDetector = new GestureDetector(context, new GestureDetector.SimpleOnGes tureListener() { | 93 mDetector = new GestureDetector(context, new GestureDetector.SimpleOnGes tureListener() { |
94 | 94 |
95 private float mOnScrollBeginX; | 95 private float mOnScrollBeginX; |
96 private float mOnScrollBeginY; | 96 private float mOnScrollBeginY; |
97 | 97 |
98 @Override | 98 @Override |
99 public boolean onScroll(MotionEvent e1, MotionEvent e2, | 99 public boolean onScroll(MotionEvent e1, MotionEvent e2, |
100 float distanceX, float distanceY) { | 100 float distanceX, float distanceY) { |
101 if (e1 == null || e2 == null) return false; | |
Khushal
2017/04/04 22:10:10
Could we add a comment here that says this should
mdjones
2017/04/04 22:16:24
Done.
| |
102 | |
101 if (!mSeenFirstScrollEvent) { | 103 if (!mSeenFirstScrollEvent) { |
102 // Remove the touch slop region from the first scroll event to avoid a | 104 // Remove the touch slop region from the first scroll event to avoid a |
103 // jump. | 105 // jump. |
104 mSeenFirstScrollEvent = true; | 106 mSeenFirstScrollEvent = true; |
105 float distance = (float) Math.sqrt( | 107 float distance = (float) Math.sqrt( |
106 distanceX * distanceX + distanceY * distanceY); | 108 distanceX * distanceX + distanceY * distanceY); |
107 if (distance > 0.0f) { | 109 if (distance > 0.0f) { |
108 float ratio = Math.max(0, distance - mScaledTouchSlop) / distance; | 110 float ratio = Math.max(0, distance - mScaledTouchSlop) / distance; |
109 mOnScrollBeginX = e1.getX() + distanceX * (1.0f - ratio) ; | 111 mOnScrollBeginX = e1.getX() + distanceX * (1.0f - ratio) ; |
110 mOnScrollBeginY = e1.getY() + distanceY * (1.0f - ratio) ; | 112 mOnScrollBeginY = e1.getY() + distanceY * (1.0f - ratio) ; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 } | 241 } |
240 mDetector.onTouchEvent(e); | 242 mDetector.onTouchEvent(e); |
241 | 243 |
242 // Propagate the up event after any gesture events. | 244 // Propagate the up event after any gesture events. |
243 if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANC EL) { | 245 if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANC EL) { |
244 mHandler.onUpOrCancel(); | 246 mHandler.onUpOrCancel(); |
245 } | 247 } |
246 return true; | 248 return true; |
247 } | 249 } |
248 } | 250 } |
OLD | NEW |