File: fast_ink_pointer_controller.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (113 lines) | stat: -rw-r--r-- 3,637 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_FAST_INK_FAST_INK_POINTER_CONTROLLER_H_
#define ASH_FAST_INK_FAST_INK_POINTER_CONTROLLER_H_

#include <set>

#include "base/time/time.h"
#include "ui/aura/window_tracker.h"
#include "ui/events/event_handler.h"

class PrefChangeRegistrar;

namespace aura {
class Window;
}  // namespace aura

namespace ui {
class LocatedEvent;
}  // namespace ui

namespace views {
class View;
}  // namespace views

namespace ash {

// Base class for a fast ink based pointer controller. Enables/disables
// the pointer, receives points and passes them off to be rendered.
class FastInkPointerController : public ui::EventHandler {
 public:
  FastInkPointerController();

  FastInkPointerController(const FastInkPointerController&) = delete;
  FastInkPointerController& operator=(const FastInkPointerController&) = delete;

  ~FastInkPointerController() override;

  bool is_enabled() const { return enabled_; }

  // Enables/disables the pointer. The user still has to press to see
  // the pointer.
  virtual void SetEnabled(bool enabled);

  // Add window that should be excluded from handling events.
  void AddExcludedWindow(aura::Window* window);

 protected:
  // Returns the pointer view.
  virtual views::View* GetPointerView() const = 0;

  // Creates the pointer view.
  virtual void CreatePointerView(base::TimeDelta presentation_delay,
                                 aura::Window* root_window) = 0;

  // Updates the pointer view.
  virtual void UpdatePointerView(ui::TouchEvent* event) = 0;
  virtual void UpdatePointerView(ui::MouseEvent* event) = 0;

  // Destroys the pointer view if it exists.
  virtual void DestroyPointerView();

  // Whether the controller is ready to start handling a new gesture.
  virtual bool CanStartNewGesture(ui::LocatedEvent* event);
  // Whether the event should be processed and stop propagation.
  // Default implementation will catch basic mouse events (e.g. mouse clicking)
  // and touch events (e.g. touch pressing) and stop them from being further
  // dispatched, so derived class should override it if the default behavior is
  // not as expected. See b/191044469 as an example.
  virtual bool ShouldProcessEvent(ui::LocatedEvent* event);

  bool IsEnabledForMouseEvent() const;

  // Return true if the location of the event is in one of the excluded windows.
  bool IsPointerInExcludedWindows(ui::LocatedEvent* event);

 private:
  // Creates new pointer view if `can_start_new_gesture` is true. Otherwise, try
  // to re-use existing one. Ends the current pointer session if the pointer
  // widget is no longer valid. Returns true if there is a pointer view
  // available.
  bool MaybeCreatePointerView(ui::LocatedEvent* event,
                              bool can_start_new_gesture);

  // ui::EventHandler:
  void OnTouchEvent(ui::TouchEvent* event) override;
  void OnMouseEvent(ui::MouseEvent* event) override;

  void OnHasSeenStylusPrefChanged();

  // The presentation delay used for pointer location prediction.
  const base::TimeDelta presentation_delay_;

  bool enabled_ = false;
  bool has_seen_stylus_ = false;

  std::optional<bool> pointer_view_created_by_touch_;

  // Set of touch ids.
  std::set<int> touch_ids_;

  // If the pointer event is in the bound of any of the |excluded_windows_|.
  // Skip processing the event.
  aura::WindowTracker excluded_windows_;

  std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_local_;
};

}  // namespace ash

#endif  // ASH_FAST_INK_FAST_INK_POINTER_CONTROLLER_H_