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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 | 13 |
Changwan Ryu
2014/10/02 00:39:53
You don't need a blank line here.
jdduke (slow)
2014/10/02 19:30:23
Done.
| |
14 #include "ui/events/gesture_detection/gesture_listeners.h" | |
15 | |
13 namespace ui { | 16 namespace ui { |
14 struct GestureEventData; | 17 class GestureDetector; |
15 class MotionEvent; | 18 class MotionEvent; |
16 } | 19 } |
17 | 20 |
18 namespace content { | 21 namespace content { |
19 class GestureTextSelectorTest; | 22 class GestureTextSelectorTest; |
20 | 23 |
21 // Interface with which GestureTextSelector can select, unselect, show | 24 // Interface with which GestureTextSelector can select, unselect, show |
22 // selection handles, or long press. | 25 // selection handles, or long press. |
23 class CONTENT_EXPORT GestureTextSelectorClient { | 26 class CONTENT_EXPORT GestureTextSelectorClient { |
24 public: | 27 public: |
25 virtual ~GestureTextSelectorClient() {} | 28 virtual ~GestureTextSelectorClient() {} |
26 | 29 |
27 virtual void ShowSelectionHandlesAutomatically() = 0; | 30 virtual void ShowSelectionHandlesAutomatically() = 0; |
28 virtual void SelectRange(float x1, float y1, float x2, float y2) = 0; | 31 virtual void SelectRange(float x1, float y1, float x2, float y2) = 0; |
29 virtual void Unselect() = 0; | |
30 virtual void LongPress(base::TimeTicks time, float x, float y) = 0; | 32 virtual void LongPress(base::TimeTicks time, float x, float y) = 0; |
31 }; | 33 }; |
32 | 34 |
33 // A class to handle gesture-based text selection, such as when clicking first | 35 // A class to handle gesture-based text selection, such as when clicking first |
34 // button on stylus input. It also generates a synthetic long press gesture on | 36 // button on stylus input. It also generates a synthetic long press gesture on |
35 // tap so that a word can be selected or the contextual menu can be shown. | 37 // tap so that a word can be selected or the contextual menu can be shown. |
36 class CONTENT_EXPORT GestureTextSelector { | 38 class CONTENT_EXPORT GestureTextSelector : public ui::SimpleGestureListener { |
37 public: | 39 public: |
38 explicit GestureTextSelector(GestureTextSelectorClient* client); | 40 explicit GestureTextSelector(GestureTextSelectorClient* client); |
39 virtual ~GestureTextSelector(); | 41 virtual ~GestureTextSelector(); |
40 | 42 |
41 // This should be called after gesture detection but before associated | 43 // This should be called before |event| is seen by the platform gesture |
42 // gestures are dispatched. Returns whether it will consume |event|. | 44 // detector or forwarded to web content. |
43 bool OnTouchEvent(const ui::MotionEvent& event); | 45 bool OnTouchEvent(const ui::MotionEvent& event); |
44 | 46 |
45 // Returns whether it will consume the event. | |
46 bool OnGestureEvent(const ui::GestureEventData& gesture); | |
47 | |
48 private: | 47 private: |
49 friend class GestureTextSelectorTest; | 48 friend class GestureTextSelectorTest; |
50 FRIEND_TEST_ALL_PREFIXES(GestureTextSelectorTest, | 49 FRIEND_TEST_ALL_PREFIXES(GestureTextSelectorTest, |
51 ShouldStartTextSelection); | 50 ShouldStartTextSelection); |
52 | 51 |
52 // SimpleGestureListener implementation. | |
53 virtual bool OnSingleTapUp(const ui::MotionEvent& e) override; | |
54 virtual bool OnScroll(const ui::MotionEvent& e1, | |
55 const ui::MotionEvent& e2, | |
56 float distance_x, | |
57 float distance_y) override; | |
58 | |
53 static bool ShouldStartTextSelection(const ui::MotionEvent& event); | 59 static bool ShouldStartTextSelection(const ui::MotionEvent& event); |
54 | 60 |
55 GestureTextSelectorClient* client_; | 61 GestureTextSelectorClient* client_; |
56 bool text_selection_triggered_; | 62 bool text_selection_triggered_; |
57 float anchor_x_; | 63 scoped_ptr<ui::GestureDetector> gesture_detector_; |
58 float anchor_y_; | |
59 | 64 |
60 DISALLOW_COPY_AND_ASSIGN(GestureTextSelector); | 65 DISALLOW_COPY_AND_ASSIGN(GestureTextSelector); |
61 }; | 66 }; |
62 | 67 |
63 } // namespace content | 68 } // namespace content |
64 | 69 |
65 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_ | 70 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_TEXT_SELECTOR_H_ |
OLD | NEW |