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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Bundle; | 8 import android.os.Bundle; |
9 import android.util.Log; | 9 import android.util.Log; |
10 import android.util.Pair; | 10 import android.util.Pair; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 private final MotionEventDelegate mMotionEventDelegate; | 60 private final MotionEventDelegate mMotionEventDelegate; |
61 | 61 |
62 // Queue of motion events. If the boolean value is true, it means | 62 // Queue of motion events. If the boolean value is true, it means |
63 // that the event has been offered to the native side but not yet acknowledg
ed. If the | 63 // that the event has been offered to the native side but not yet acknowledg
ed. If the |
64 // value is false, it means the touch event has not been offered | 64 // value is false, it means the touch event has not been offered |
65 // to the native side and can be immediately processed. | 65 // to the native side and can be immediately processed. |
66 private final Deque<Pair<MotionEvent, Boolean>> mPendingMotionEvents = | 66 private final Deque<Pair<MotionEvent, Boolean>> mPendingMotionEvents = |
67 new ArrayDeque<Pair<MotionEvent, Boolean>>(); | 67 new ArrayDeque<Pair<MotionEvent, Boolean>>(); |
68 | 68 |
69 // Has WebKit told us the current page requires touch events. | 69 // Has WebKit told us the current page requires touch events. |
70 private boolean mNeedTouchEvents = false; | 70 private boolean mHasTouchHandlers = false; |
71 | 71 |
72 // Remember whether onShowPress() is called. If it is not, in onSingleTapCon
firmed() | 72 // Remember whether onShowPress() is called. If it is not, in onSingleTapCon
firmed() |
73 // we will first show the press state, then trigger the click. | 73 // we will first show the press state, then trigger the click. |
74 private boolean mShowPressIsCalled; | 74 private boolean mShowPressIsCalled; |
75 | 75 |
76 // TODO(klobag): this is to avoid a bug in GestureDetector. With multi-touch
, | 76 // TODO(klobag): this is to avoid a bug in GestureDetector. With multi-touch
, |
77 // mAlwaysInTapRegion is not reset. So when the last finger is up, onSingleT
apUp() | 77 // mAlwaysInTapRegion is not reset. So when the last finger is up, onSingleT
apUp() |
78 // will be mistakenly fired. | 78 // will be mistakenly fired. |
79 private boolean mIgnoreSingleTap; | 79 private boolean mIgnoreSingleTap; |
80 | 80 |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 // processTouchEvent asynchronously. | 599 // processTouchEvent asynchronously. |
600 TraceEvent.end("onTouchEvent"); | 600 TraceEvent.end("onTouchEvent"); |
601 return true; | 601 return true; |
602 } | 602 } |
603 return processTouchEvent(event); | 603 return processTouchEvent(event); |
604 } | 604 } |
605 | 605 |
606 /** | 606 /** |
607 * Sets the flag indicating that the content has registered listeners for to
uch events. | 607 * Sets the flag indicating that the content has registered listeners for to
uch events. |
608 */ | 608 */ |
609 void didSetNeedTouchEvents(boolean needTouchEvents) { | 609 void hasTouchEventHandlers(boolean hasTouchHandlers) { |
610 mNeedTouchEvents = needTouchEvents; | 610 mHasTouchHandlers = hasTouchHandlers; |
611 // When mainframe is loading, FrameLoader::transitionToCommitted will | 611 // When mainframe is loading, FrameLoader::transitionToCommitted will |
612 // call this method to set mNeedTouchEvents to false. We use this as | 612 // call this method to set mHasTouchHandlers to false. We use this as |
613 // an indicator to clear the pending motion events so that events from | 613 // an indicator to clear the pending motion events so that events from |
614 // the previous page will not be carried over to the new page. | 614 // the previous page will not be carried over to the new page. |
615 if (!mNeedTouchEvents) mPendingMotionEvents.clear(); | 615 if (!mHasTouchHandlers) mPendingMotionEvents.clear(); |
616 } | 616 } |
617 | 617 |
618 private boolean offerTouchEventToJavaScript(MotionEvent event) { | 618 private boolean offerTouchEventToJavaScript(MotionEvent event) { |
619 mLongPressDetector.onOfferTouchEventToJavaScript(event); | 619 mLongPressDetector.onOfferTouchEventToJavaScript(event); |
620 | 620 |
621 if (!mNeedTouchEvents) return false; | 621 if (!mHasTouchHandlers) return false; |
622 | 622 |
623 if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { | 623 if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { |
624 // Only send move events if the move has exceeded the slop threshold
. | 624 // Only send move events if the move has exceeded the slop threshold
. |
625 if (!mLongPressDetector.confirmOfferMoveEventToJavaScript(event)) { | 625 if (!mLongPressDetector.confirmOfferMoveEventToJavaScript(event)) { |
626 return true; | 626 return true; |
627 } | 627 } |
628 // Avoid flooding the renderer process with move events: if the prev
ious pending | 628 // Avoid flooding the renderer process with move events: if the prev
ious pending |
629 // command is also a move (common case), skip sending this event to
the webkit | 629 // command is also a move (common case), skip sending this event to
the webkit |
630 // side and collapse it into the pending event. | 630 // side and collapse it into the pending event. |
631 Pair<MotionEvent, Boolean> previousEvent = mPendingMotionEvents.peek
Last(); | 631 Pair<MotionEvent, Boolean> previousEvent = mPendingMotionEvents.peek
Last(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 /** | 743 /** |
744 * @return Whether the ContentViewGestureHandler can handle a MotionEvent ri
ght now. True only | 744 * @return Whether the ContentViewGestureHandler can handle a MotionEvent ri
ght now. True only |
745 * if it's the start of a new stream (ACTION_DOWN), or a continuation of the
current stream. | 745 * if it's the start of a new stream (ACTION_DOWN), or a continuation of the
current stream. |
746 */ | 746 */ |
747 boolean canHandle(MotionEvent ev) { | 747 boolean canHandle(MotionEvent ev) { |
748 return ev.getAction() == MotionEvent.ACTION_DOWN || | 748 return ev.getAction() == MotionEvent.ACTION_DOWN || |
749 (mCurrentDownEvent != null && mCurrentDownEvent.getDownTime() ==
ev.getDownTime()); | 749 (mCurrentDownEvent != null && mCurrentDownEvent.getDownTime() ==
ev.getDownTime()); |
750 } | 750 } |
751 | 751 |
752 } | 752 } |
OLD | NEW |