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

Side by Side Diff: content/browser/renderer_host/input/gesture_text_selector.cc

Issue 342633003: [Android] Select text when stylus first button is pressed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits and moved mock_motion_event Created 6 years, 6 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
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/input/gesture_text_selector.h"
6
7 #include "ui/events/event_constants.h"
8 #include "ui/events/gesture_detection/gesture_event_data.h"
9 #include "ui/events/gesture_detection/motion_event.h"
10
11 namespace content {
12
13 GestureTextSelector::GestureTextSelector(GestureTextSelectorClient* client)
14 : client_(client),
15 text_selection_triggered_(false),
16 anchor_x_(0.0f),
17 anchor_y_(0.0f) {
18 }
19
20 GestureTextSelector::~GestureTextSelector() {
21 }
22
23 bool GestureTextSelector::OnTouchEvent(const ui::MotionEvent& event) {
24 if (event.GetAction() == ui::MotionEvent::ACTION_DOWN) {
25 // Only trigger selection on ACTION_DOWN to prevent partial touch or gesture
26 // sequences from being forwarded.
27 text_selection_triggered_ = ShouldStartTextSelection(event);
28 }
29 return text_selection_triggered_;
30 }
31
32 bool GestureTextSelector::OnGestureEvent(const ui::GestureEventData& gesture) {
33 if (!text_selection_triggered_)
34 return false;
35
36 switch (gesture.type()) {
37 case ui::ET_GESTURE_TAP: {
38 client_->Unselect();
39 break;
40 }
41 case ui::ET_GESTURE_SCROLL_BEGIN: {
42 client_->Unselect();
43 anchor_x_ = gesture.x;
44 anchor_y_ = gesture.y;
45 break;
46 }
47 case ui::ET_GESTURE_SCROLL_UPDATE: {
48 client_->ShowSelectionHandlesAutomatically();
jdduke (slow) 2014/06/26 00:33:21 I'm curious how the handles look while you're drag
Changwan Ryu 2014/06/26 02:54:10 Moved ShowSelectionHandlesAutomatically to GESTURE
49 client_->SelectRange(anchor_x_, anchor_y_, gesture.x, gesture.y);
50 break;
51 }
52 default:
53 // Suppress all other gestures when we are selecting text.
54 break;
55 }
56 return true;
57 }
58
59 // static
60 bool GestureTextSelector::ShouldStartTextSelection(
61 const ui::MotionEvent& event) {
62 DCHECK_GT(event.GetPointerCount(), 0u);
63 // Currently we are supporting stylus-only cases.
64 const bool is_stylus =
65 event.GetToolType(0) == ui::MotionEvent::TOOL_TYPE_STYLUS;
66 const bool is_only_secondary_button_pressed =
67 event.GetButtonState() == ui::MotionEvent::BUTTON_SECONDARY;
68 return is_stylus && is_only_secondary_button_pressed;
69 }
70
71 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698