Index: ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_filter.cc |
diff --git a/ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_filter.cc b/ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_filter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0c0e7bad7065610e72043c406440f4585da2a9ed |
--- /dev/null |
+++ b/ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_filter.cc |
@@ -0,0 +1,49 @@ |
+// Copyright 2015 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. |
+ |
+#include "ui/events/ozone/evdev/touch_noise/horizontally_aligned_touch_noise_filter.h" |
+ |
+#include <cmath> |
+ |
+#include "base/logging.h" |
+#include "base/strings/stringprintf.h" |
+#include "ui/gfx/geometry/point_f.h" |
+ |
+namespace ui { |
+ |
+namespace { |
+ |
+// The maximum horizontal distance between touches considered aligned. |
+int kMaxDistance = 3; |
+ |
+} // namespace |
+ |
+void HorizontallyAlignedTouchNoiseFilter::FilterFrame(Frame* previous, |
+ Frame* current) { |
+ for (size_t slot = 0; slot < kNumSlots; ++slot) { |
+ Finger* cur = ¤t->fingers[slot]; |
+ Finger* prev = &previous->fingers[slot]; |
+ |
+ bool arrived = prev->tracking_id == -1 && cur->tracking_id >= 0; |
+ if (!arrived) |
+ continue; |
+ |
+ // Check if within kMaxDistance of an existing touch. |
+ for (size_t i = 0; i < kNumSlots; ++i) { |
+ if (i == slot || current->fingers[i].tracking_id == -1) |
+ continue; |
+ if (std::abs(current->fingers[i].location.x() - cur->location.x()) <= |
+ kMaxDistance) { |
+ VLOG(2) << base::StringPrintf( |
+ "Cancel tracking id %d, down at %ld at %s near touch %d at %s", |
+ cur->tracking_id, current->timestamp.ToInternalValue(), |
+ cur->location.ToString().c_str(), current->fingers[i].tracking_id, |
+ current->fingers[i].location.ToString().c_str()); |
+ cur->canceled = true; |
+ } |
+ } |
+ } |
+} |
+ |
+} // namespace ui |