OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/input/stylus_text_selector.h" | 5 #include "content/browser/renderer_host/input/stylus_text_selector.h" |
6 | 6 |
7 #include "ui/events/event_constants.h" | 7 #include "ui/events/event_constants.h" |
8 #include "ui/events/gesture_detection/gesture_detector.h" | 8 #include "ui/events/gesture_detection/gesture_detector.h" |
9 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 9 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
10 #include "ui/events/gesture_detection/motion_event.h" | 10 #include "ui/events/gesture_detection/motion_event.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 bool StylusTextSelector::OnTouchEvent(const MotionEvent& event) { | 51 bool StylusTextSelector::OnTouchEvent(const MotionEvent& event) { |
52 // Only trigger selection on ACTION_DOWN to prevent partial touch or gesture | 52 // Only trigger selection on ACTION_DOWN to prevent partial touch or gesture |
53 // sequences from being forwarded. | 53 // sequences from being forwarded. |
54 if (event.GetAction() == MotionEvent::ACTION_DOWN) | 54 if (event.GetAction() == MotionEvent::ACTION_DOWN) |
55 text_selection_triggered_ = ShouldStartTextSelection(event); | 55 text_selection_triggered_ = ShouldStartTextSelection(event); |
56 | 56 |
57 if (!text_selection_triggered_) | 57 if (!text_selection_triggered_) |
58 return false; | 58 return false; |
59 | 59 |
| 60 // For Android version < M, stylus button pressed state is BUTTON_SECONDARY. |
| 61 // From Android M, this state has changed to BUTTON_STYLUS_PRIMARY. |
60 secondary_button_pressed_ = | 62 secondary_button_pressed_ = |
61 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; | 63 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY || |
| 64 event.GetButtonState() == MotionEvent::BUTTON_STYLUS_PRIMARY; |
62 | 65 |
63 switch (event.GetAction()) { | 66 switch (event.GetAction()) { |
64 case MotionEvent::ACTION_DOWN: | 67 case MotionEvent::ACTION_DOWN: |
65 drag_state_ = NO_DRAG; | 68 drag_state_ = NO_DRAG; |
66 anchor_x_ = event.GetX(); | 69 anchor_x_ = event.GetX(); |
67 anchor_y_ = event.GetY(); | 70 anchor_y_ = event.GetY(); |
68 break; | 71 break; |
69 | 72 |
70 case MotionEvent::ACTION_MOVE: | 73 case MotionEvent::ACTION_MOVE: |
71 if (!secondary_button_pressed_) { | 74 if (!secondary_button_pressed_) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 136 } |
134 | 137 |
135 return true; | 138 return true; |
136 } | 139 } |
137 | 140 |
138 // static | 141 // static |
139 bool StylusTextSelector::ShouldStartTextSelection(const MotionEvent& event) { | 142 bool StylusTextSelector::ShouldStartTextSelection(const MotionEvent& event) { |
140 DCHECK_GT(event.GetPointerCount(), 0u); | 143 DCHECK_GT(event.GetPointerCount(), 0u); |
141 // Currently we are supporting stylus-only cases. | 144 // Currently we are supporting stylus-only cases. |
142 const bool is_stylus = event.GetToolType(0) == MotionEvent::TOOL_TYPE_STYLUS; | 145 const bool is_stylus = event.GetToolType(0) == MotionEvent::TOOL_TYPE_STYLUS; |
| 146 |
| 147 // For Android version < M, stylus button pressed state is BUTTON_SECONDARY. |
| 148 // From Android M, this state has changed to BUTTON_STYLUS_PRIMARY. |
143 const bool is_only_secondary_button_pressed = | 149 const bool is_only_secondary_button_pressed = |
144 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; | 150 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY || |
| 151 event.GetButtonState() == MotionEvent::BUTTON_STYLUS_PRIMARY; |
145 return is_stylus && is_only_secondary_button_pressed; | 152 return is_stylus && is_only_secondary_button_pressed; |
146 } | 153 } |
147 | 154 |
148 } // namespace content | 155 } // namespace content |
OLD | NEW |