Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 5 #include "ui/events/ozone/evdev/touch_noise/touch_noise_remover.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/stl_util.h" | |
| 9 #include "base/strings/stringprintf.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "ui/events/event.h" | |
| 12 #include "ui/events/ozone/evdev/device_event_dispatcher_evdev.h" | |
| 13 #include "ui/events/ozone/evdev/touch_noise/far_apart_taps_touch_noise_filter.h" | |
| 14 #include "ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_fil ter.h" | |
| 15 #include "ui/events/ozone/evdev/touch_noise/single_position_touch_noise_filter.h " | |
| 16 | |
| 17 namespace ui { | |
| 18 | |
| 19 TouchNoiseRemover::TouchNoiseRemover() { | |
| 20 filters_.push_back(new FarApartTapsTouchNoiseFilter); | |
| 21 filters_.push_back(new HorizontallyAlignedTouchNoiseFilter); | |
| 22 filters_.push_back(new SinglePositionTouchNoiseFilter); | |
| 23 } | |
| 24 | |
| 25 TouchNoiseRemover::~TouchNoiseRemover() { | |
| 26 STLDeleteElements(&filters_); | |
| 27 } | |
| 28 | |
| 29 void TouchNoiseRemover::RemoveNoise( | |
| 30 std::vector<ui::TouchEventParams>* touches, | |
| 31 base::TimeDelta timestamp) { | |
| 32 TouchNoiseFilter::Frame prev_frame = frame_; | |
| 33 const int num_slots = static_cast<int>(arraysize(frame_.fingers)); | |
| 34 frame_.timestamp = timestamp; | |
| 35 for (const ui::TouchEventParams& touch : *touches) { | |
| 36 int slot = touch.touch_id; | |
| 37 if (slot < 0 || slot >= num_slots) | |
|
flackr
2015/03/10 05:23:40
Why do we need to check for slot < 0 || slot >= nu
| |
| 38 continue; | |
| 39 | |
| 40 DCHECK_EQ(timestamp, touch.timestamp); | |
| 41 frame_.fingers[slot].location = touch.location; | |
| 42 frame_.fingers[slot].tracking_id = | |
| 43 (touch.type == ET_TOUCH_RELEASED) ? -1 : touch.tracking_id; | |
| 44 | |
| 45 if (touch.type == ET_TOUCH_PRESSED) | |
| 46 frame_.fingers[slot].canceled = false; | |
| 47 } | |
| 48 | |
| 49 for (TouchNoiseFilter* filter : filters_) | |
| 50 filter->FilterFrame(&prev_frame, &frame_); | |
| 51 | |
| 52 for (auto it = touches->begin(); it != touches->end();) { | |
| 53 int slot = it->touch_id; | |
| 54 if (slot < 0 || slot >= num_slots || frame_.fingers[slot].canceled) { | |
|
flackr
2015/03/10 05:23:40
ditto
| |
| 55 VLOG(2) << base::StringPrintf("TrackingID %d cancelled", it->tracking_id); | |
| 56 it = touches->erase(it); | |
|
flackr
2015/03/10 05:23:40
Should use std::remove_if for linear complexity.
| |
| 57 } else { | |
| 58 ++it; | |
| 59 } | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 } // namespace ui | |
| OLD | NEW |