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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_STYLUS_TEXT_SELECTOR_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_STYLUS_TEXT_SELECTOR_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "content/common/content_export.h"
13 #include "ui/events/gesture_detection/gesture_listeners.h"
16 class GestureDetector
;
21 class StylusTextSelectorTest
;
23 // Interface with which the StylusTextSelector conveys drag and tap gestures
24 // when the activating button is pressed.
25 // selection handles, or long press.
26 class CONTENT_EXPORT StylusTextSelectorClient
{
28 virtual ~StylusTextSelectorClient() {}
30 // (x0, y0) and (x1, y1) indicate the bounds of the initial selection.
31 virtual void OnStylusSelectBegin(float x0
, float y0
, float x1
, float y1
) = 0;
32 virtual void OnStylusSelectUpdate(float x
, float y
) = 0;
33 virtual void OnStylusSelectEnd() = 0;
34 virtual void OnStylusSelectTap(base::TimeTicks time
, float x
, float y
) = 0;
37 // Provides stylus-based text selection and interaction, including:
38 // * Selection manipulation when an activating stylus button is pressed and
39 // the stylus is dragged.
40 // * Word selection and context menu activation when the when an activating
41 // stylus button is pressed and the stylus is tapped.
42 class CONTENT_EXPORT StylusTextSelector
: public ui::SimpleGestureListener
{
44 explicit StylusTextSelector(StylusTextSelectorClient
* client
);
45 ~StylusTextSelector() override
;
47 // This should be called before |event| is seen by the platform gesture
48 // detector or forwarded to web content.
49 bool OnTouchEvent(const ui::MotionEvent
& event
);
52 friend class StylusTextSelectorTest
;
53 FRIEND_TEST_ALL_PREFIXES(StylusTextSelectorTest
, ShouldStartTextSelection
);
55 // SimpleGestureListener implementation.
56 bool OnSingleTapUp(const ui::MotionEvent
& e
) override
;
57 bool OnScroll(const ui::MotionEvent
& e1
,
58 const ui::MotionEvent
& e2
,
60 float distance_y
) override
;
62 static bool ShouldStartTextSelection(const ui::MotionEvent
& event
);
64 StylusTextSelectorClient
* client_
;
65 bool text_selection_triggered_
;
66 bool secondary_button_pressed_
;
71 scoped_ptr
<ui::GestureDetector
> gesture_detector_
;
73 DISALLOW_COPY_AND_ASSIGN(StylusTextSelector
);
76 } // namespace content
78 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_STYLUS_TEXT_SELECTOR_H_