summaryrefslogtreecommitdiff
path: root/ui/events/ozone/evdev/touch_filter/palm_detection_filter.h
blob: 5cf07e0308162d41e851602fca2e4b85cf3740a7 (plain)
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
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_H_
#define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_H_

#if defined(__ANDROID__) || defined(__ANDROID_HOST__)
#include "chrome_to_android_compatibility.h"
#endif

#include <bitset>
#include <vector>

#include "base/time/time.h"
#include "ui/events/ozone/evdev/touch_evdev_types.h"
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"

namespace ui {

// An abstract palm detection filter. It has two functions:
// 1. To decide which touches to "hold"
// 2. To decide which touches to suppress / "cancel".
// Interface is similar to that of TouchFilter but enshrines the "hold" as a
// first class citizen.
class COMPONENT_EXPORT(EVDEV) PalmDetectionFilter {
 public:
  // shared_palm_state is not owned!
  explicit PalmDetectionFilter(
      SharedPalmDetectionFilterState* shared_palm_state);
  virtual ~PalmDetectionFilter();

  // Execute a filter event. Expected to be executed on every update to touches.
  // Arguments are:
  // 1. touches: a vector of kNumTouchEvdevSlots touches.
  // 2. time: the latest event time in touches.
  // 3. slots_to_hold: output bitset of slots to hold. Must not be null.
  // 4. slots_to_suppress: output bitset of slots to suppress/cancel. Must not
  // be null.
  //
  // Note that if a slot is marked as both suppress and hold, we expect the
  // suppress to override the hold.
  virtual void Filter(const std::vector<InProgressTouchEvdev>& touches,
                      base::TimeTicks time,
                      std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
                      std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) = 0;

  // The name of this filter, for testing purposes.
  virtual std::string FilterNameForTesting() const = 0;

 protected:
  // Not owned!
  SharedPalmDetectionFilterState* const shared_palm_state_;
};

}  // namespace ui

#endif  // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_H_