MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / ui / touch_selection / longpress_drag_selector.h
blobf6e84ecf1cd7463786720c79dd3779f383134cb3
1 // Copyright 2015 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 UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_
6 #define UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_
8 #include "base/time/time.h"
9 #include "ui/gfx/geometry/point_f.h"
10 #include "ui/gfx/geometry/vector2d_f.h"
11 #include "ui/touch_selection/touch_selection_draggable.h"
12 #include "ui/touch_selection/ui_touch_selection_export.h"
14 namespace ui {
16 class MotionEvent;
18 class UI_TOUCH_SELECTION_EXPORT LongPressDragSelectorClient
19 : public TouchSelectionDraggableClient {
20 public:
21 ~LongPressDragSelectorClient() override {}
22 virtual void OnLongPressDragActiveStateChanged() = 0;
23 virtual gfx::PointF GetSelectionStart() const = 0;
24 virtual gfx::PointF GetSelectionEnd() const = 0;
27 // Supports text selection via touch dragging after a longpress-initiated
28 // selection.
29 class UI_TOUCH_SELECTION_EXPORT LongPressDragSelector
30 : public TouchSelectionDraggable {
31 public:
32 explicit LongPressDragSelector(LongPressDragSelectorClient* client);
33 ~LongPressDragSelector() override;
35 // TouchSelectionDraggable implementation.
36 bool WillHandleTouchEvent(const MotionEvent& event) override;
37 bool IsActive() const override;
39 // Called just prior to a longpress event being handled.
40 void OnLongPressEvent(base::TimeTicks event_time,
41 const gfx::PointF& position);
43 // Called when the active selection changes.
44 void OnSelectionActivated();
45 void OnSelectionDeactivated();
47 private:
48 enum SelectionState {
49 INACTIVE,
50 LONGPRESS_PENDING,
51 SELECTION_PENDING,
52 DRAG_PENDING,
53 DRAGGING
56 void SetState(SelectionState state);
58 LongPressDragSelectorClient* const client_;
60 SelectionState state_;
62 base::TimeTicks touch_down_time_;
63 gfx::PointF touch_down_position_;
65 gfx::Vector2dF longpress_drag_selection_offset_;
66 gfx::PointF longpress_drag_start_anchor_;
67 bool has_longpress_drag_start_anchor_;
70 } // namespace ui
72 #endif // UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_