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 22 matching lines...) Expand all Loading... |
33 return detector; | 33 return detector; |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 StylusTextSelector::StylusTextSelector(StylusTextSelectorClient* client) | 38 StylusTextSelector::StylusTextSelector(StylusTextSelectorClient* client) |
39 : client_(client), | 39 : client_(client), |
40 text_selection_triggered_(false), | 40 text_selection_triggered_(false), |
41 secondary_button_pressed_(false), | 41 secondary_button_pressed_(false), |
42 dragging_(false), | 42 dragging_(false), |
43 dragged_(false), | |
44 anchor_x_(0.0f), | 43 anchor_x_(0.0f), |
45 anchor_y_(0.0f) { | 44 anchor_y_(0.0f) { |
46 DCHECK(client); | 45 DCHECK(client); |
47 } | 46 } |
48 | 47 |
49 StylusTextSelector::~StylusTextSelector() { | 48 StylusTextSelector::~StylusTextSelector() { |
50 } | 49 } |
51 | 50 |
52 bool StylusTextSelector::OnTouchEvent(const MotionEvent& event) { | 51 bool StylusTextSelector::OnTouchEvent(const MotionEvent& event) { |
53 // 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 |
54 // sequences from being forwarded. | 53 // sequences from being forwarded. |
55 if (event.GetAction() == MotionEvent::ACTION_DOWN) | 54 if (event.GetAction() == MotionEvent::ACTION_DOWN) |
56 text_selection_triggered_ = ShouldStartTextSelection(event); | 55 text_selection_triggered_ = ShouldStartTextSelection(event); |
57 | 56 |
58 if (!text_selection_triggered_) | 57 if (!text_selection_triggered_) |
59 return false; | 58 return false; |
60 | 59 |
61 secondary_button_pressed_ = | 60 secondary_button_pressed_ = |
62 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; | 61 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; |
63 | 62 |
64 switch (event.GetAction()) { | 63 switch (event.GetAction()) { |
65 case MotionEvent::ACTION_DOWN: | 64 case MotionEvent::ACTION_DOWN: |
66 dragging_ = false; | 65 dragging_ = false; |
67 dragged_ = false; | |
68 anchor_x_ = event.GetX(); | 66 anchor_x_ = event.GetX(); |
69 anchor_y_ = event.GetY(); | 67 anchor_y_ = event.GetY(); |
70 break; | 68 break; |
71 | 69 |
72 case MotionEvent::ACTION_MOVE: | 70 case MotionEvent::ACTION_MOVE: |
73 if (!secondary_button_pressed_) { | 71 if (!secondary_button_pressed_) { |
74 dragging_ = false; | 72 dragging_ = false; |
75 anchor_x_ = event.GetX(); | 73 anchor_x_ = event.GetX(); |
76 anchor_y_ = event.GetY(); | 74 anchor_y_ = event.GetY(); |
77 } | 75 } |
78 break; | 76 break; |
79 | 77 |
80 case MotionEvent::ACTION_UP: | 78 case MotionEvent::ACTION_UP: |
81 case MotionEvent::ACTION_CANCEL: | 79 case MotionEvent::ACTION_CANCEL: |
82 if (dragged_) | |
83 client_->OnStylusSelectEnd(); | |
84 dragged_ = false; | |
85 dragging_ = false; | 80 dragging_ = false; |
86 break; | 81 break; |
87 | 82 |
88 case MotionEvent::ACTION_POINTER_UP: | 83 case MotionEvent::ACTION_POINTER_UP: |
89 case MotionEvent::ACTION_POINTER_DOWN: | 84 case MotionEvent::ACTION_POINTER_DOWN: |
90 break; | 85 break; |
91 case MotionEvent::ACTION_NONE: | 86 case MotionEvent::ACTION_NONE: |
92 NOTREACHED(); | 87 NOTREACHED(); |
93 break; | 88 break; |
94 } | 89 } |
(...skipping 21 matching lines...) Expand all Loading... |
116 float distance_x, | 111 float distance_x, |
117 float distance_y) { | 112 float distance_y) { |
118 DCHECK(text_selection_triggered_); | 113 DCHECK(text_selection_triggered_); |
119 | 114 |
120 // Return if Stylus button is not pressed. | 115 // Return if Stylus button is not pressed. |
121 if (!secondary_button_pressed_) | 116 if (!secondary_button_pressed_) |
122 return true; | 117 return true; |
123 | 118 |
124 if (!dragging_) { | 119 if (!dragging_) { |
125 dragging_ = true; | 120 dragging_ = true; |
126 dragged_ = true; | |
127 client_->OnStylusSelectBegin(anchor_x_, anchor_y_, e2.GetX(), e2.GetY()); | 121 client_->OnStylusSelectBegin(anchor_x_, anchor_y_, e2.GetX(), e2.GetY()); |
128 } else { | 122 } else { |
129 client_->OnStylusSelectUpdate(e2.GetX(), e2.GetY()); | 123 client_->OnStylusSelectUpdate(e2.GetX(), e2.GetY()); |
130 } | 124 } |
131 | 125 |
132 return true; | 126 return true; |
133 } | 127 } |
134 | 128 |
135 // static | 129 // static |
136 bool StylusTextSelector::ShouldStartTextSelection(const MotionEvent& event) { | 130 bool StylusTextSelector::ShouldStartTextSelection(const MotionEvent& event) { |
137 DCHECK_GT(event.GetPointerCount(), 0u); | 131 DCHECK_GT(event.GetPointerCount(), 0u); |
138 // Currently we are supporting stylus-only cases. | 132 // Currently we are supporting stylus-only cases. |
139 const bool is_stylus = event.GetToolType(0) == MotionEvent::TOOL_TYPE_STYLUS; | 133 const bool is_stylus = event.GetToolType(0) == MotionEvent::TOOL_TYPE_STYLUS; |
140 const bool is_only_secondary_button_pressed = | 134 const bool is_only_secondary_button_pressed = |
141 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; | 135 event.GetButtonState() == MotionEvent::BUTTON_SECONDARY; |
142 return is_stylus && is_only_secondary_button_pressed; | 136 return is_stylus && is_only_secondary_button_pressed; |
143 } | 137 } |
144 | 138 |
145 } // namespace content | 139 } // namespace content |
OLD | NEW |