Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 text_selection_triggered_ = ShouldStartTextSelection(event); | |
|
jdduke (slow)
2014/06/25 14:54:19
Maybe add a comment here along the lines of "// On
Changwan Ryu
2014/06/26 00:05:27
Done.
| |
| 26 } | |
| 27 return text_selection_triggered_; | |
| 28 } | |
| 29 | |
| 30 bool GestureTextSelector::OnGestureEvent(const ui::GestureEventData& gesture) { | |
| 31 if (!text_selection_triggered_) | |
| 32 return false; | |
| 33 | |
| 34 switch (gesture.type()) { | |
| 35 case ui::ET_GESTURE_TAP: { | |
| 36 client_->Unselect(); | |
| 37 break; | |
| 38 } | |
| 39 case ui::ET_GESTURE_SCROLL_BEGIN: { | |
| 40 client_->Unselect(); | |
| 41 anchor_x_ = gesture.x; | |
| 42 anchor_y_ = gesture.y; | |
| 43 break; | |
| 44 } | |
| 45 case ui::ET_GESTURE_SCROLL_UPDATE: { | |
| 46 client_->ShowSelectionHandlesAutomatically(); | |
| 47 client_->SelectRange(anchor_x_, anchor_y_, gesture.x, gesture.y); | |
| 48 break; | |
| 49 } | |
| 50 default: | |
| 51 // Suppress all other gestures when we are selecting text. | |
| 52 break; | |
| 53 } | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 bool GestureTextSelector::ShouldStartTextSelection( | |
| 59 const ui::MotionEvent& event) { | |
| 60 DCHECK_GT(event.GetPointerCount(), 0u); | |
| 61 // Currently we are supporting stylus-only cases. | |
| 62 const bool is_stylus = | |
| 63 event.GetToolType(0) == ui::MotionEvent::TOOL_TYPE_STYLUS; | |
| 64 const bool is_only_secondary_button_pressed = | |
| 65 event.GetButtonState() == ui::MotionEvent::BUTTON_SECONDARY; | |
| 66 return is_stylus && is_only_secondary_button_pressed; | |
| 67 } | |
| 68 | |
| 69 } // namespace content | |
| OLD | NEW |