longpress_drag_selector.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.
  4. #ifndef UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_
  5. #define UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/time/time.h"
  8. #include "ui/gfx/geometry/point_f.h"
  9. #include "ui/gfx/geometry/vector2d_f.h"
  10. #include "ui/touch_selection/touch_selection_draggable.h"
  11. #include "ui/touch_selection/ui_touch_selection_export.h"
  12. namespace ui {
  13. class MotionEvent;
  14. class UI_TOUCH_SELECTION_EXPORT LongPressDragSelectorClient
  15. : public TouchSelectionDraggableClient {
  16. public:
  17. ~LongPressDragSelectorClient() override {}
  18. virtual void OnLongPressDragActiveStateChanged() = 0;
  19. virtual gfx::PointF GetSelectionStart() const = 0;
  20. virtual gfx::PointF GetSelectionEnd() const = 0;
  21. };
  22. // Supports text selection via touch dragging after a longpress-initiated
  23. // selection.
  24. class UI_TOUCH_SELECTION_EXPORT LongPressDragSelector
  25. : public TouchSelectionDraggable {
  26. public:
  27. explicit LongPressDragSelector(LongPressDragSelectorClient* client);
  28. ~LongPressDragSelector() override;
  29. // TouchSelectionDraggable implementation.
  30. bool WillHandleTouchEvent(const MotionEvent& event) override;
  31. bool IsActive() const override;
  32. // Called just prior to a longpress event being handled.
  33. void OnLongPressEvent(base::TimeTicks event_time,
  34. const gfx::PointF& position);
  35. // Called when a scroll is going to happen to cancel longpress-drag gesture.
  36. void OnScrollBeginEvent();
  37. // Called when the active selection changes.
  38. void OnSelectionActivated();
  39. void OnSelectionDeactivated();
  40. private:
  41. enum SelectionState {
  42. INACTIVE,
  43. LONGPRESS_PENDING,
  44. SELECTION_PENDING,
  45. DRAG_PENDING,
  46. DRAGGING
  47. };
  48. void SetState(SelectionState state);
  49. const raw_ptr<LongPressDragSelectorClient> client_;
  50. SelectionState state_;
  51. base::TimeTicks touch_down_time_;
  52. gfx::PointF touch_down_position_;
  53. gfx::Vector2dF longpress_drag_selection_offset_;
  54. gfx::PointF longpress_drag_start_anchor_;
  55. bool has_longpress_drag_start_anchor_;
  56. };
  57. } // namespace ui
  58. #endif // UI_TOUCH_SELECTION_LONGPRESS_DRAG_SELECTOR_H_