Commit 59b56e52 authored by hclam@chromium.org's avatar hclam@chromium.org

Revert of Unified Gesture Recognizer (https://codereview.chromium.org/251543003/)

Reason for revert:
Memory leak detected: http://build.chromium.org/p/chromium.memory/builders/Linux%20Chromium%20OS%20ASan%20LSan%20Tests%20%281%29/builds/1239/steps/aura_unittests/logs/stdio

Original issue's description:
> Unified Gesture Recognizer
>
> This adds the unified GR for Aura behind the --use-unified-gesture-detector flag.
>
> BUG=332418
> TEST=GestureRecognizer/GestureRecognizerTest.*
>   MotionEventUITest.*
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=269325

Review URL: https://codereview.chromium.org/278183002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269628 0039d316-1c4b-4281-b951-d872f2087c98
parent 2a321de3
......@@ -876,7 +876,6 @@
'../ui/compositor/compositor.gyp:compositor_test_support',
'../ui/events/events.gyp:events',
'../ui/events/events.gyp:events_test_support',
'../ui/events/events.gyp:gesture_detection',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/keyboard/keyboard.gyp:keyboard',
......
......@@ -24,7 +24,6 @@
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/gestures/gesture_types.h"
#include "ui/events/test/events_test_utils.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/views/test/test_views_delegate.h"
......@@ -283,12 +282,8 @@ void DispatchGesture(ui::EventType gesture_type, gfx::Point location) {
ui::EventTimeForNow(),
ui::GestureEventDetails(gesture_type, 0, 0),
1);
ui::EventSource* event_source =
Shell::GetPrimaryRootWindow()->GetHost()->GetEventSource();
ui::EventSourceTestApi event_source_test(event_source);
ui::EventDispatchDetails details =
event_source_test.SendEventToProcessor(&gesture_event);
CHECK(!details.dispatcher_destroyed);
Shell::GetPrimaryRootWindow()->GetHost()->dispatcher()->DispatchGestureEvent(
&gesture_event);
}
} // namespace
......
......@@ -500,7 +500,7 @@ bool RenderWidgetHostViewGuest::CanDispatchToConsumer(
return true;
}
void RenderWidgetHostViewGuest::DispatchGestureEvent(
void RenderWidgetHostViewGuest::DispatchPostponedGestureEvent(
ui::GestureEvent* event) {
ForwardGestureEventToRenderer(event);
}
......
......@@ -145,7 +145,7 @@ class CONTENT_EXPORT RenderWidgetHostViewGuest
// Overridden from ui::GestureEventHelper.
virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE;
virtual void DispatchGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE;
......
......@@ -54,7 +54,6 @@
'../ui/events/events.gyp:dom4_keycode_converter',
'../ui/events/events.gyp:events_base',
'../ui/events/events.gyp:events_test_support',
'../ui/events/events.gyp:gesture_detection',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gfx/gfx.gyp:gfx_test_support',
......
......@@ -262,7 +262,6 @@
'../compositor/compositor.gyp:compositor_test_support',
'../events/events.gyp:events',
'../events/events.gyp:events_base',
'../events/events.gyp:gesture_detection',
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
'../gl/gl.gyp:gl',
......
......@@ -682,8 +682,9 @@ class GestureRecognizerTest : public AuraTestBase,
virtual void SetUp() OVERRIDE {
// TODO(tdresser): Once unified GR has landed, only run these tests once.
if (UsingUnifiedGR()) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kUseUnifiedGestureDetector);
// TODO(tdresser): use unified GR once it's available.
// CommandLine::ForCurrentProcess()->AppendSwitch(
// switches::kUseUnifiedGestureDetector);
}
AuraTestBase::SetUp();
......@@ -745,11 +746,6 @@ TEST_P(GestureRecognizerTest, GestureEventTap) {
// Check that appropriate touch events generate tap gesture events
// when information about the touch radii are provided.
TEST_P(GestureRecognizerTest, GestureEventTapRegion) {
// TODO(tdresser): enable this test with unified GR once we resolve the
// bounding box differences. See crbug.com/366641.
if (UsingUnifiedGR())
return;
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
......@@ -3713,11 +3709,6 @@ TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) {
TEST_P(GestureRecognizerTest,
TransferEventDispatchesTouchCancel) {
// TODO(tdresser): enable this test with unified GR once two finger tap is
// supported. See crbug.com/354396.
if (UsingUnifiedGR())
return;
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
......
......@@ -495,6 +495,11 @@ bool WindowEventDispatcher::CanDispatchToConsumer(
return (consumer_window && consumer_window->GetRootWindow() == window());
}
void WindowEventDispatcher::DispatchPostponedGestureEvent(
ui::GestureEvent* event) {
DispatchGestureEvent(event);
}
void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) {
DispatchDetails details = OnEventFromSource(event);
if (details.dispatcher_destroyed)
......
......@@ -72,6 +72,11 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
void DispatchCancelModeEvent();
// Handles a gesture event. Returns true if handled. Unlike the other
// event-dispatching function (e.g. for touch/mouse/keyboard events), gesture
// events are dispatched from GestureRecognizer instead of WindowTreeHost.
void DispatchGestureEvent(ui::GestureEvent* event);
// Dispatches a ui::ET_MOUSE_EXITED event at |point|.
// TODO(beng): needed only for WTH::OnCursorVisibilityChanged().
void DispatchMouseExitAtPoint(const gfx::Point& point);
......@@ -179,7 +184,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
// Overridden from ui::GestureEventHelper.
virtual bool CanDispatchToConsumer(ui::GestureConsumer* consumer) OVERRIDE;
virtual void DispatchGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual void DispatchPostponedGestureEvent(ui::GestureEvent* event) OVERRIDE;
virtual void DispatchCancelTouchEvent(ui::TouchEvent* event) OVERRIDE;
// Overridden from WindowObserver:
......
......@@ -19,8 +19,6 @@ const char kTouchEventsAuto[] = "auto";
const char kTouchEventsEnabled[] = "enabled";
// disabled: touch events are disabled.
const char kTouchEventsDisabled[] = "disabled";
// Use the unified gesture detector, instead of the aura gesture detector.
const char kUseUnifiedGestureDetector[] = "use-unified-gesture-detector";
#if defined(OS_LINUX)
// Tells chrome to interpret events from these devices as touch events. Only
......
......@@ -15,7 +15,6 @@ EVENTS_BASE_EXPORT extern const char kTouchEvents[];
EVENTS_BASE_EXPORT extern const char kTouchEventsAuto[];
EVENTS_BASE_EXPORT extern const char kTouchEventsEnabled[];
EVENTS_BASE_EXPORT extern const char kTouchEventsDisabled[];
EVENTS_BASE_EXPORT extern const char kUseUnifiedGestureDetector[];
#if defined(OS_LINUX)
EVENTS_BASE_EXPORT extern const char kTouchDevices[];
......
......@@ -39,8 +39,6 @@
'events_base_export.h',
'gesture_event_details.cc',
'gesture_event_details.h',
'gestures/gesture_configuration.cc',
'gestures/gesture_configuration.h',
'keycodes/keyboard_code_conversion.cc',
'keycodes/keyboard_code_conversion.h',
'keycodes/keyboard_code_conversion_android.cc',
......@@ -80,7 +78,6 @@
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
'events_base',
'gesture_detection',
],
'defines': [
'EVENTS_IMPLEMENTATION',
......@@ -109,18 +106,16 @@
'event_utils.h',
'events_export.h',
'events_stub.cc',
'gestures/gesture_configuration.cc',
'gestures/gesture_configuration.h',
'gestures/gesture_point.cc',
'gestures/gesture_point.h',
'gestures/gesture_provider_aura.cc',
'gestures/gesture_provider_aura.h',
'gestures/gesture_recognizer.h',
'gestures/gesture_recognizer_impl.cc',
'gestures/gesture_recognizer_impl.h',
'gestures/gesture_sequence.cc',
'gestures/gesture_sequence.h',
'gestures/gesture_types.h',
'gestures/motion_event_aura.cc',
'gestures/motion_event_aura.h',
'gestures/velocity_calculator.cc',
'gestures/velocity_calculator.h',
'ozone/device/device_event.cc',
......@@ -176,24 +171,6 @@
'linux/text_edit_key_bindings_delegate_auralinux.h',
],
'conditions': [
['use_aura==0', {
'sources!': [
'gestures/gesture_point.cc',
'gestures/gesture_point.h',
'gestures/gesture_provider_aura.cc',
'gestures/gesture_provider_aura.h',
'gestures/gesture_recognizer.h',
'gestures/gesture_recognizer_impl.cc',
'gestures/gesture_recognizer_impl.h',
'gestures/gesture_sequence.cc',
'gestures/gesture_sequence.h',
'gestures/gesture_types.h',
'gestures/motion_event_aura.cc',
'gestures/motion_event_aura.h',
'gestures/velocity_calculator.cc',
'gestures/velocity_calculator.h',
],
}],
# We explicitly enumerate the platforms we _do_ provide native cracking
# for here.
['OS=="win" or OS=="mac" or use_x11==1 or use_ozone==1', {
......@@ -276,9 +253,6 @@
'gesture_detection/bitset_32.h',
'gesture_detection/filtered_gesture_provider.cc',
'gesture_detection/filtered_gesture_provider.h',
'gesture_detection/gesture_config_helper.h',
'gesture_detection/gesture_config_helper_android.cc',
'gesture_detection/gesture_config_helper_aura.cc',
'gesture_detection/gesture_detection_export.h',
'gesture_detection/gesture_detector.cc',
'gesture_detection/gesture_detector.h',
......@@ -286,6 +260,9 @@
'gesture_detection/gesture_event_data.h',
'gesture_detection/gesture_event_data_packet.cc',
'gesture_detection/gesture_event_data_packet.h',
'gesture_detection/gesture_config_helper.h',
'gesture_detection/gesture_config_helper_aura.cc',
'gesture_detection/gesture_config_helper_android.cc',
'gesture_detection/gesture_provider.cc',
'gesture_detection/gesture_provider.h',
'gesture_detection/motion_event.h',
......@@ -301,6 +278,11 @@
'gesture_detection/velocity_tracker.h',
],
'conditions': [
['use_aura==1', {
'dependencies': [
'events'
],
}],
['use_aura!=1 and OS!="android"', {
'sources': [
'gesture_detection/gesture_config_helper.cc',
......@@ -358,7 +340,7 @@
'events',
'events_base',
'events_test_support',
'gesture_detection',
'gesture_detection'
],
'sources': [
'cocoa/events_mac_unittest.mm',
......@@ -366,7 +348,6 @@
'event_processor_unittest.cc',
'event_rewriter_unittest.cc',
'event_unittest.cc',
'gestures/motion_event_aura_unittest.cc',
'gestures/velocity_calculator_unittest.cc',
'gesture_detection/bitset_32_unittest.cc',
'gesture_detection/gesture_provider_unittest.cc',
......@@ -382,12 +363,6 @@
'x/events_x_unittest.cc',
],
'conditions': [
['use_aura==0', {
'sources!': [
'gestures/motion_event_aura_unittest.cc',
'gestures/velocity_calculator_unittest.cc',
],
}],
['OS=="linux" and use_allocator!="none"', {
'dependencies': [
'<(DEPTH)/base/allocator/allocator.gyp:allocator',
......
......@@ -2,13 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// MSVC++ requires this to be set before any other includes to get M_PI.
#define _USE_MATH_DEFINES
#include "ui/events/gesture_detection/gesture_config_helper.h"
#include <cmath>
#include "ui/events/gestures/gesture_configuration.h"
#include "ui/gfx/screen.h"
......@@ -35,8 +30,7 @@ GestureDetector::Config DefaultGestureDetectorConfig() {
config.swipe_enabled = true;
config.minimum_swipe_velocity = GestureConfiguration::min_swipe_speed();
config.maximum_swipe_deviation_angle =
atan2(1.f, GestureConfiguration::max_swipe_deviation_ratio()) * 180.0f /
static_cast<float>(M_PI);
atan2(1.f, GestureConfiguration::max_swipe_deviation_ratio());
return config;
}
......@@ -46,7 +40,8 @@ ScaleGestureDetector::Config DefaultScaleGestureDetectorConfig() {
config.gesture_detector_config = DefaultGestureDetectorConfig();
config.min_scaling_touch_major = GestureConfiguration::default_radius() * 2;
config.min_scaling_span = GestureConfiguration::min_scaling_span_in_pixels();
config.min_scaling_span =
GestureConfiguration::min_distance_for_pinch_scroll_in_pixels();
return config;
}
......
......@@ -31,8 +31,6 @@ class GESTURE_DETECTION_EXPORT MotionEvent {
virtual int GetId() const = 0;
virtual Action GetAction() const = 0;
// Only valid if |GetAction()| returns ACTION_POINTER_UP or
// ACTION_POINTER_DOWN.
virtual int GetActionIndex() const = 0;
virtual size_t GetPointerCount() const = 0;
virtual int GetPointerId(size_t pointer_index) const = 0;
......
......@@ -34,10 +34,6 @@ double GestureConfiguration::scroll_prediction_seconds_ = 0.03;
double
GestureConfiguration::min_touch_down_duration_in_seconds_for_click_ = 0.01;
// If this is too small, we currently can get single finger pinch zoom. See
// crbug.com/357237 for details.
int GestureConfiguration::min_scaling_span_in_pixels_ = 125;
// The number of points used in the linear regression which determines
// touch velocity. Velocity is reported for 2 or more touch move events.
int GestureConfiguration::points_buffered_for_velocity_ = 8;
......
......@@ -6,7 +6,7 @@
#define UI_EVENTS_GESTURES_GESTURE_CONFIGURATION_H_
#include "base/basictypes.h"
#include "ui/events/events_base_export.h"
#include "ui/events/events_export.h"
namespace ui {
......@@ -14,7 +14,7 @@ namespace ui {
// approaches (windows, chrome, others). This would turn into an
// abstract base class.
class EVENTS_BASE_EXPORT GestureConfiguration {
class EVENTS_EXPORT GestureConfiguration {
public:
// Number of parameters in the array of parameters for the fling acceleration
// curve.
......@@ -143,15 +143,6 @@ class EVENTS_BASE_EXPORT GestureConfiguration {
static void set_min_touch_down_duration_in_seconds_for_click(double val) {
min_touch_down_duration_in_seconds_for_click_ = val;
}
static int min_scaling_span_in_pixels() {
return min_scaling_span_in_pixels_;
};
static void set_min_scaling_span_in_pixels(int val) {
min_scaling_span_in_pixels_ = val;
}
static int points_buffered_for_velocity() {
return points_buffered_for_velocity_;
}
......@@ -244,7 +235,6 @@ class EVENTS_BASE_EXPORT GestureConfiguration {
static float min_scroll_velocity_;
static double min_swipe_speed_;
static double min_touch_down_duration_in_seconds_for_click_;
static int min_scaling_span_in_pixels_;
static int points_buffered_for_velocity_;
static double rail_break_proportion_;
static double rail_start_proportion_;
......
// Copyright 2014 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/gestures/gesture_provider_aura.h"
#include "base/logging.h"
#include "ui/events/event.h"
#include "ui/events/gesture_detection/gesture_config_helper.h"
#include "ui/events/gesture_detection/gesture_event_data.h"
namespace ui {
GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client)
: client_(client),
filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) {
filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false);
}
GestureProviderAura::~GestureProviderAura() {}
bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) {
last_touch_event_flags_ = event.flags();
bool pointer_id_is_active = false;
for (size_t i = 0; i < pointer_state_.GetPointerCount(); ++i) {
if (event.touch_id() != pointer_state_.GetPointerId(i))
continue;
pointer_id_is_active = true;
break;
}
if (event.type() == ET_TOUCH_PRESSED && pointer_id_is_active) {
// Ignore touch press events if we already believe the pointer is down.
return false;
} else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) {
// We could have an active touch stream transfered to us, resulting in touch
// move or touch up events without associated touch down events. Ignore
// them.
return false;
}
pointer_state_.OnTouch(event);
bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_);
pointer_state_.CleanupRemovedTouchPoints(event);
return result;
}
void GestureProviderAura::OnTouchEventAck(bool event_consumed) {
filtered_gesture_provider_.OnTouchEventAck(event_consumed);
}
void GestureProviderAura::OnGestureEvent(
const GestureEventData& gesture) {
ui::GestureEvent event(gesture.type,
gesture.x,
gesture.y,
last_touch_event_flags_,
gesture.time - base::TimeTicks(),
gesture.details,
// ui::GestureEvent stores a bitfield indicating the
// ids of active touch points. This is currently only
// used when one finger is down, and will eventually
// be cleaned up. See crbug.com/366707.
1 << gesture.motion_event_id);
client_->OnGestureEvent(&event);
}
} // namespace content
// Copyright 2014 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_GESTURE_DETECTION_UI_GESTURE_PROVIDER_H_
#define UI_EVENTS_GESTURE_DETECTION_UI_GESTURE_PROVIDER_H_
#include "base/basictypes.h"
#include "ui/events/event.h"
#include "ui/events/events_export.h"
#include "ui/events/gesture_detection/filtered_gesture_provider.h"
#include "ui/events/gesture_detection/gesture_event_data_packet.h"
#include "ui/events/gesture_detection/touch_disposition_gesture_filter.h"
#include "ui/events/gestures/motion_event_aura.h"
namespace ui {
class EVENTS_EXPORT GestureProviderAuraClient {
public:
virtual ~GestureProviderAuraClient() {}
virtual void OnGestureEvent(GestureEvent* event) = 0;
};
// Provides gesture detection and dispatch given a sequence of touch events
// and touch event acks.
class EVENTS_EXPORT GestureProviderAura : public GestureProviderClient {
public:
GestureProviderAura(GestureProviderAuraClient* client);
virtual ~GestureProviderAura();
bool OnTouchEvent(const TouchEvent& event);
void OnTouchEventAck(bool event_consumed);
const MotionEventAura& pointer_state() { return pointer_state_; }
// GestureProviderClient implementation
virtual void OnGestureEvent(const GestureEventData& gesture) OVERRIDE;
private:
GestureProviderAuraClient* client_;
MotionEventAura pointer_state_;
FilteredGestureProvider filtered_gesture_provider_;
int last_touch_event_flags_;
DISALLOW_COPY_AND_ASSIGN(GestureProviderAura);
};
} // namespace ui
#endif // UI_EVENTS_GESTURE_DETECTION_UI_GESTURE_PROVIDER_H_
......@@ -4,16 +4,11 @@
#include "ui/events/gestures/gesture_recognizer_impl.h"
#include <limits>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_switches.h"
#include "ui/events/event_utils.h"
#include "ui/events/gestures/gesture_configuration.h"
#include "ui/events/gestures/gesture_sequence.h"
......@@ -59,23 +54,16 @@ void TransferTouchIdToConsumerMap(
}
}
GestureProviderAura* CreateGestureProvider(GestureProviderAuraClient* client) {
return new GestureProviderAura(client);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
// GestureRecognizerImpl, public:
GestureRecognizerImpl::GestureRecognizerImpl()
: use_unified_gesture_detector_(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseUnifiedGestureDetector)) {
GestureRecognizerImpl::GestureRecognizerImpl() {
}
GestureRecognizerImpl::~GestureRecognizerImpl() {
STLDeleteValues(&consumer_sequence_);
STLDeleteValues(&consumer_gesture_provider_);
}
// Checks if this finger is already down, if so, returns the current target.
......@@ -95,65 +83,34 @@ GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent(
GestureConsumer* GestureRecognizerImpl::GetTargetForLocation(
const gfx::PointF& location, int source_device_id) {
const int max_distance =
GestureConfiguration::max_separation_for_gesture_touches_in_pixels();
if (!use_unified_gesture_detector_) {
const GesturePoint* closest_point = NULL;
int64 closest_distance_squared = 0;
std::map<GestureConsumer*, GestureSequence*>::iterator i;
for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) {
const GesturePoint* points = i->second->points();
for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) {
if (!points[j].in_use() ||
source_device_id != points[j].source_device_id()) {
continue;
}
gfx::Vector2dF delta = points[j].last_touch_position() - location;
// Relative distance is all we need here, so LengthSquared() is
// appropriate, and cheaper than Length().
int64 distance_squared = delta.LengthSquared();
if (!closest_point || distance_squared < closest_distance_squared) {
closest_point = &points[j];
closest_distance_squared = distance_squared;
}
const GesturePoint* closest_point = NULL;
int64 closest_distance_squared = 0;
std::map<GestureConsumer*, GestureSequence*>::iterator i;
for (i = consumer_sequence_.begin(); i != consumer_sequence_.end(); ++i) {
const GesturePoint* points = i->second->points();
for (int j = 0; j < GestureSequence::kMaxGesturePoints; ++j) {
if (!points[j].in_use() ||
source_device_id != points[j].source_device_id()) {
continue;
}
}
if (closest_distance_squared < max_distance * max_distance && closest_point)
return touch_id_target_[closest_point->touch_id()];
else
return NULL;
} else {
gfx::PointF closest_point;
int closest_touch_id;
float closest_distance_squared = std::numeric_limits<float>::infinity();
std::map<GestureConsumer*, GestureProviderAura*>::iterator i;
for (i = consumer_gesture_provider_.begin();
i != consumer_gesture_provider_.end();
++i) {
const MotionEventAura& pointer_state = i->second->pointer_state();
for (size_t j = 0; j < pointer_state.GetPointerCount(); ++j) {
if (source_device_id != pointer_state.GetSourceDeviceId(j))
continue;
gfx::PointF point(pointer_state.GetX(j), pointer_state.GetY(j));
// Relative distance is all we need here, so LengthSquared() is
// appropriate, and cheaper than Length().
float distance_squared = (point - location).LengthSquared();
if (distance_squared < closest_distance_squared) {
closest_point = point;
closest_touch_id = pointer_state.GetPointerId(j);
closest_distance_squared = distance_squared;
}
gfx::Vector2dF delta = points[j].last_touch_position() - location;
// Relative distance is all we need here, so LengthSquared() is
// appropriate, and cheaper than Length().
int64 distance_squared = delta.LengthSquared();
if (!closest_point || distance_squared < closest_distance_squared) {
closest_point = &points[j];
closest_distance_squared = distance_squared;
}
}
if (closest_distance_squared < max_distance * max_distance)
return touch_id_target_[closest_touch_id];
else
return NULL;
}
const int max_distance =
GestureConfiguration::max_separation_for_gesture_touches_in_pixels();
if (closest_distance_squared < max_distance * max_distance && closest_point)
return touch_id_target_[closest_point->touch_id()];
else
return NULL;
}
void GestureRecognizerImpl::TransferEventsTo(GestureConsumer* current_consumer,
......@@ -183,30 +140,18 @@ void GestureRecognizerImpl::TransferEventsTo(GestureConsumer* current_consumer,
&touch_id_target_);
TransferTouchIdToConsumerMap(current_consumer, new_consumer,
&touch_id_target_for_gestures_);
if (!use_unified_gesture_detector_)
TransferConsumer(current_consumer, new_consumer, &consumer_sequence_);
else
TransferConsumer(
current_consumer, new_consumer, &consumer_gesture_provider_);
TransferConsumer(current_consumer, new_consumer, &consumer_sequence_);
}
}
bool GestureRecognizerImpl::GetLastTouchPointForTarget(
GestureConsumer* consumer,
gfx::PointF* point) {
if (!use_unified_gesture_detector_) {
if (consumer_sequence_.count(consumer) == 0)
return false;
*point = consumer_sequence_[consumer]->last_touch_location();
return true;
} else {
if (consumer_gesture_provider_.count(consumer) == 0)
return false;
const MotionEvent& pointer_state =
consumer_gesture_provider_[consumer]->pointer_state();
*point = gfx::PointF(pointer_state.GetX(), pointer_state.GetY());
return true;
}
if (consumer_sequence_.count(consumer) == 0)
return false;
*point = consumer_sequence_[consumer]->last_touch_location();
return true;
}
bool GestureRecognizerImpl::CancelActiveTouches(GestureConsumer* consumer) {
......@@ -242,16 +187,6 @@ GestureSequence* GestureRecognizerImpl::GetGestureSequenceForConsumer(
return gesture_sequence;
}
GestureProviderAura* GestureRecognizerImpl::GetGestureProviderForConsumer(
GestureConsumer* consumer) {
GestureProviderAura* gesture_provider = consumer_gesture_provider_[consumer];
if (!gesture_provider) {
gesture_provider = CreateGestureProvider(this);
consumer_gesture_provider_[consumer] = gesture_provider;
}
return gesture_provider;
}
void GestureRecognizerImpl::SetupTargets(const TouchEvent& event,
GestureConsumer* target) {
if (event.type() == ui::ET_TOUCH_RELEASED ||
......@@ -279,55 +214,22 @@ void GestureRecognizerImpl::CancelTouches(
}
}
void GestureRecognizerImpl::DispatchGestureEvent(GestureEvent* event) {
GestureConsumer* consumer = GetTargetForGestureEvent(*event);
if (consumer) {
GestureEventHelper* helper = FindDispatchHelperForConsumer(consumer);
if (helper)
helper->DispatchGestureEvent(event);
}
}
GestureSequence::Gestures* GestureRecognizerImpl::ProcessTouchEventForGesture(
const TouchEvent& event,
ui::EventResult result,
GestureConsumer* target) {
SetupTargets(event, target);
if (!use_unified_gesture_detector_) {
GestureSequence* gesture_sequence = GetGestureSequenceForConsumer(target);
return gesture_sequence->ProcessTouchEventForGesture(event, result);
} else {
GestureProviderAura* gesture_provider =
GetGestureProviderForConsumer(target);
// TODO(tdresser) - detect gestures eagerly.
if (!(result & ER_CONSUMED)) {
if (gesture_provider->OnTouchEvent(event))
gesture_provider->OnTouchEventAck(result != ER_UNHANDLED);
}
return NULL;
}
GestureSequence* gesture_sequence = GetGestureSequenceForConsumer(target);
return gesture_sequence->ProcessTouchEventForGesture(event, result);
}
bool GestureRecognizerImpl::CleanupStateForConsumer(
GestureConsumer* consumer) {
bool state_cleaned_up = false;
if (!use_unified_gesture_detector_) {
if (consumer_sequence_.count(consumer)) {
state_cleaned_up = true;
delete consumer_sequence_[consumer];
consumer_sequence_.erase(consumer);
}
} else {
if (consumer_gesture_provider_.count(consumer)) {
state_cleaned_up = true;
// Don't immediately delete the GestureProvider, as we could be in the
// middle of dispatching a set of gestures.
base::MessageLoop::current()->DeleteSoon(
FROM_HERE, consumer_gesture_provider_[consumer]);
consumer_gesture_provider_.erase(consumer);
}
if (consumer_sequence_.count(consumer)) {
state_cleaned_up = true;
delete consumer_sequence_[consumer];
consumer_sequence_.erase(consumer);
}
state_cleaned_up |= RemoveConsumerFromMap(consumer, &touch_id_target_);
......@@ -349,11 +251,12 @@ void GestureRecognizerImpl::RemoveGestureEventHelper(
}
void GestureRecognizerImpl::DispatchPostponedGestureEvent(GestureEvent* event) {
DispatchGestureEvent(event);
}
void GestureRecognizerImpl::OnGestureEvent(GestureEvent* event) {
DispatchGestureEvent(event);
GestureConsumer* consumer = GetTargetForGestureEvent(*event);
if (consumer) {
GestureEventHelper* helper = FindDispatchHelperForConsumer(consumer);
if (helper)
helper->DispatchPostponedGestureEvent(event);
}
}
GestureEventHelper* GestureRecognizerImpl::FindDispatchHelperForConsumer(
......
......@@ -12,7 +12,6 @@
#include "base/memory/scoped_ptr.h"
#include "ui/events/event_constants.h"
#include "ui/events/events_export.h"
#include "ui/events/gestures/gesture_provider_aura.h"
#include "ui/events/gestures/gesture_recognizer.h"
#include "ui/events/gestures/gesture_sequence.h"
#include "ui/gfx/point.h"
......@@ -24,12 +23,8 @@ class GestureEventHelper;
class GestureSequence;
class TouchEvent;
// TODO(tdresser): Once the unified gesture recognition process sticks
// (crbug.com/332418), GestureRecognizerImpl can be cleaned up
// significantly.
class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer,
public GestureSequenceDelegate,
public GestureProviderAuraClient {
public GestureSequenceDelegate {
public:
typedef std::map<int, GestureConsumer*> TouchIdToConsumerMap;
......@@ -52,19 +47,14 @@ class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer,
virtual bool CancelActiveTouches(GestureConsumer* consumer) OVERRIDE;
protected:
virtual GestureSequence* CreateSequence(GestureSequenceDelegate* delegate);
virtual GestureSequence* GetGestureSequenceForConsumer(GestureConsumer* c);
virtual GestureProviderAura* GetGestureProviderForConsumer(
GestureConsumer* c);
virtual GestureSequence* CreateSequence(
ui::GestureSequenceDelegate* delegate);
private:
// Sets up the target consumer for gestures based on the touch-event.
void SetupTargets(const TouchEvent& event, GestureConsumer* consumer);
void CancelTouches(std::vector<std::pair<int, GestureConsumer*> >* touches);
void DispatchGestureEvent(GestureEvent* event);
// Overridden from GestureRecognizer
virtual Gestures* ProcessTouchEventForGesture(
const TouchEvent& event,
......@@ -78,15 +68,11 @@ class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer,
// Overridden from ui::GestureSequenceDelegate.
virtual void DispatchPostponedGestureEvent(GestureEvent* event) OVERRIDE;
// Overridden from GestureProviderAuraClient
virtual void OnGestureEvent(GestureEvent* event) OVERRIDE;
// Convenience method to find the GestureEventHelper that can dispatch events
// to a specific |consumer|.
GestureEventHelper* FindDispatchHelperForConsumer(GestureConsumer* consumer);
std::map<GestureConsumer*, GestureSequence*> consumer_sequence_;
std::map<GestureConsumer*, GestureProviderAura*> consumer_gesture_provider_;
// Both |touch_id_target_| and |touch_id_target_for_gestures_| map a touch-id
// to its target window. touch-ids are removed from |touch_id_target_| on
......@@ -97,8 +83,6 @@ class EVENTS_EXPORT GestureRecognizerImpl : public GestureRecognizer,
std::vector<GestureEventHelper*> helpers_;
bool use_unified_gesture_detector_;
DISALLOW_COPY_AND_ASSIGN(GestureRecognizerImpl);
};
......
......@@ -28,7 +28,7 @@ class EVENTS_EXPORT GestureEventHelper {
// Returns true if this helper can dispatch events to |consumer|.
virtual bool CanDispatchToConsumer(GestureConsumer* consumer) = 0;
virtual void DispatchGestureEvent(GestureEvent* event) = 0;
virtual void DispatchPostponedGestureEvent(GestureEvent* event) = 0;
virtual void DispatchCancelTouchEvent(TouchEvent* event) = 0;
};
......
// Copyright 2014 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/gestures/motion_event_aura.h"
#include "base/logging.h"
#include "ui/events/gestures/gesture_configuration.h"
namespace ui {
MotionEventAura::MotionEventAura()
: pointer_count_(0), cached_action_index_(-1) {
}
MotionEventAura::MotionEventAura(
size_t pointer_count,
const base::TimeTicks& last_touch_time,
Action cached_action,
int cached_action_index,
const PointData (&active_touches)[GestureSequence::kMaxGesturePoints])
: pointer_count_(pointer_count),
last_touch_time_(last_touch_time),
cached_action_(cached_action),
cached_action_index_(cached_action_index) {
DCHECK(pointer_count_);
for (size_t i = 0; i < pointer_count; ++i)
active_touches_[i] = active_touches[i];
}
MotionEventAura::~MotionEventAura() {}
MotionEventAura::PointData MotionEventAura::GetPointDataFromTouchEvent(
const TouchEvent& touch) {
PointData point_data;
point_data.x = touch.x();
point_data.y = touch.y();
point_data.touch_id = touch.touch_id();
point_data.pressure = touch.force();
point_data.source_device_id = touch.source_device_id();
// TODO(tdresser): at some point we should start using both radii if they are
// available, but for now we use the max.
point_data.major_radius = std::max(touch.radius_x(), touch.radius_y());
if (!point_data.major_radius)
point_data.major_radius = GestureConfiguration::default_radius();
return point_data;
}
void MotionEventAura::OnTouch(const TouchEvent& touch) {
switch (touch.type()) {
case ET_TOUCH_PRESSED:
AddTouch(touch);
break;
case ET_TOUCH_RELEASED:
case ET_TOUCH_CANCELLED:
// Removing these touch points needs to be postponed until after the
// MotionEvent has been dispatched. This cleanup occurs in
// CleanupRemovedTouchPoints.
UpdateTouch(touch);
break;
case ET_TOUCH_MOVED:
UpdateTouch(touch);
break;
default:
NOTREACHED();
break;
}
UpdateCachedAction(touch);
last_touch_time_ = touch.time_stamp() + base::TimeTicks();
}
int MotionEventAura::GetId() const {
return GetPointerId(0);
}
MotionEvent::Action MotionEventAura::GetAction() const {
return cached_action_;
}
int MotionEventAura::GetActionIndex() const {
DCHECK(cached_action_ == ACTION_POINTER_DOWN ||
cached_action_ == ACTION_POINTER_UP);
DCHECK_GE(cached_action_index_, 0);
DCHECK_LE(cached_action_index_, static_cast<int>(pointer_count_));
return cached_action_index_;
}
size_t MotionEventAura::GetPointerCount() const { return pointer_count_; }
int MotionEventAura::GetPointerId(size_t pointer_index) const {
DCHECK_LE(pointer_index, pointer_count_);
return active_touches_[pointer_index].touch_id;
}
float MotionEventAura::GetX(size_t pointer_index) const {
DCHECK_LE(pointer_index, pointer_count_);
return active_touches_[pointer_index].x;
}
float MotionEventAura::GetY(size_t pointer_index) const {
DCHECK_LE(pointer_index, pointer_count_);
return active_touches_[pointer_index].y;
}
float MotionEventAura::GetTouchMajor(size_t pointer_index) const {
DCHECK_LE(pointer_index, pointer_count_);
return active_touches_[pointer_index].major_radius * 2;
}
float MotionEventAura::GetPressure(size_t pointer_index) const {
DCHECK_LE(pointer_index, pointer_count_);
return active_touches_[pointer_index].pressure;
}
base::TimeTicks MotionEventAura::GetEventTime() const {
return last_touch_time_;
}
size_t MotionEventAura::GetHistorySize() const { return 0; }
base::TimeTicks MotionEventAura::GetHistoricalEventTime(
size_t historical_index) const {
NOTIMPLEMENTED();
return base::TimeTicks();
}
float MotionEventAura::GetHistoricalTouchMajor(size_t pointer_index,
size_t historical_index) const {
NOTIMPLEMENTED();
return 0;
}
float MotionEventAura::GetHistoricalX(size_t pointer_index,
size_t historical_index) const {
NOTIMPLEMENTED();
return 0;
}
float MotionEventAura::GetHistoricalY(size_t pointer_index,
size_t historical_index) const {
NOTIMPLEMENTED();
return 0;
}
scoped_ptr<MotionEvent> MotionEventAura::Clone() const {
return scoped_ptr<MotionEvent>(new MotionEventAura(pointer_count_,
last_touch_time_,
cached_action_,
cached_action_index_,
active_touches_));
}
scoped_ptr<MotionEvent> MotionEventAura::Cancel() const {
return scoped_ptr<MotionEvent>(new MotionEventAura(
pointer_count_, last_touch_time_, ACTION_CANCEL, -1, active_touches_));
}
void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) {
if (event.type() != ET_TOUCH_RELEASED &&
event.type() != ET_TOUCH_CANCELLED) {
return;
}
int index_to_delete = static_cast<int>(GetIndexFromId(event.touch_id()));
pointer_count_--;
active_touches_[index_to_delete] = active_touches_[pointer_count_];
}
MotionEventAura::PointData::PointData()
: x(0),
y(0),
touch_id(0),
pressure(0),
source_device_id(0),
major_radius(0) {
}
int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const {
DCHECK_LE(pointer_index, pointer_count_);
return active_touches_[pointer_index].source_device_id;
}
void MotionEventAura::AddTouch(const TouchEvent& touch) {
if (pointer_count_ == static_cast<size_t>(GestureSequence::kMaxGesturePoints))
return;
active_touches_[pointer_count_] = GetPointDataFromTouchEvent(touch);
pointer_count_++;
}
void MotionEventAura::UpdateTouch(const TouchEvent& touch) {
active_touches_[GetIndexFromId(touch.touch_id())] =
GetPointDataFromTouchEvent(touch);
}
void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) {
DCHECK(pointer_count_);
switch (touch.type()) {
case ET_TOUCH_PRESSED:
if (pointer_count_ == 1) {
cached_action_ = ACTION_DOWN;
} else {
cached_action_ = ACTION_POINTER_DOWN;
cached_action_index_ =
static_cast<int>(GetIndexFromId(touch.touch_id()));
}
break;
case ET_TOUCH_RELEASED:
if (pointer_count_ == 1) {
cached_action_ = ACTION_UP;
} else {
cached_action_ = ACTION_POINTER_UP;
cached_action_index_ =
static_cast<int>(GetIndexFromId(touch.touch_id()));
DCHECK_LE(cached_action_index_, static_cast<int>(pointer_count_));
}
break;
case ET_TOUCH_CANCELLED:
cached_action_ = ACTION_CANCEL;
break;
case ET_TOUCH_MOVED:
cached_action_ = ACTION_MOVE;
break;
default:
NOTREACHED();
break;
}
}
size_t MotionEventAura::GetIndexFromId(int id) const {
for (size_t i = 0; i < pointer_count_; ++i) {
if (active_touches_[i].touch_id == id)
return i;
}
NOTREACHED();
return 0;
}
} // namespace ui
// Copyright 2014 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_GESTURE_DETECTION_UI_MOTION_EVENT_H_
#define UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_
#include "ui/events/gesture_detection/motion_event.h"
#include <map>
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "ui/events/event.h"
#include "ui/events/events_export.h"
#include "ui/events/gestures/gesture_sequence.h"
namespace ui {
// Implementation of MotionEvent which takes a stream of ui::TouchEvents.
class EVENTS_EXPORT MotionEventAura : public MotionEvent {
public:
MotionEventAura();
virtual ~MotionEventAura();
void OnTouch(const TouchEvent& touch);
// MotionEvent implementation.
virtual int GetId() const OVERRIDE;
virtual Action GetAction() const OVERRIDE;
virtual int GetActionIndex() const OVERRIDE;
virtual size_t GetPointerCount() const OVERRIDE;
virtual int GetPointerId(size_t pointer_index) const OVERRIDE;
virtual float GetX(size_t pointer_index) const OVERRIDE;
virtual float GetY(size_t pointer_index) const OVERRIDE;
virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE;
virtual float GetPressure(size_t pointer_index) const OVERRIDE;
virtual base::TimeTicks GetEventTime() const OVERRIDE;
virtual size_t GetHistorySize() const OVERRIDE;
virtual base::TimeTicks GetHistoricalEventTime(size_t historical_index) const
OVERRIDE;
virtual float GetHistoricalTouchMajor(size_t pointer_index,
size_t historical_index) const OVERRIDE;
virtual float GetHistoricalX(size_t pointer_index,
size_t historical_index) const OVERRIDE;
virtual float GetHistoricalY(size_t pointer_index,
size_t historical_index) const OVERRIDE;
virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE;
virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE;
int GetSourceDeviceId(size_t pointer_index) const;
// We can't cleanup removed touch points immediately upon receipt of a
// TouchCancel or TouchRelease, as the MotionEvent needs to be able to report
// information about those touch events. Once the MotionEvent has been
// processed, we call CleanupRemovedTouchPoints to do the required
// book-keeping.
void CleanupRemovedTouchPoints(const TouchEvent& event);
private:
struct PointData {
PointData();
float x;
float y;
int touch_id;
float pressure;
int source_device_id;
float major_radius;
};
MotionEventAura(
size_t pointer_count,
const base::TimeTicks& last_touch_time,
Action cached_action,
int cached_action_index,
const PointData (&active_touches)[GestureSequence::kMaxGesturePoints]);
static PointData GetPointDataFromTouchEvent(const TouchEvent& touch);
void AddTouch(const TouchEvent& touch);
void UpdateTouch(const TouchEvent& touch);
void UpdateCachedAction(const TouchEvent& touch);
size_t GetIndexFromId(int id) const;
size_t pointer_count_;
base::TimeTicks last_touch_time_;
Action cached_action_;
// The index of the touch responsible for last ACTION_POINTER_DOWN or
// ACTION_POINTER_UP. -1 if no such action has occurred.
int cached_action_index_;
// We want constant time indexing by pointer_index, and fast indexing by id.
// TODO(tdresser): figure out which constant to use here.
PointData active_touches_[GestureSequence::kMaxGesturePoints];
DISALLOW_COPY_AND_ASSIGN(MotionEventAura);
};
} // namespace ui
#endif // UI_EVENTS_GESTURE_DETECTION_UI_MOTION_EVENT_H_
// Copyright 2014 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 "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h"
#include "ui/events/gestures/motion_event_aura.h"
namespace {
ui::TouchEvent TouchWithType(ui::EventType type, int id) {
return ui::TouchEvent(
type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(0));
}
ui::TouchEvent TouchWithPosition(ui::EventType type,
int id,
float x,
float y,
float radius,
float pressure) {
return ui::TouchEvent(type,
gfx::PointF(x, y),
0,
id,
base::TimeDelta::FromMilliseconds(0),
radius,
radius,
0,
pressure);
}
ui::TouchEvent TouchWithTime(ui::EventType type, int id, int ms) {
return ui::TouchEvent(
type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(ms));
}
base::TimeTicks MsToTicks(int ms) {
return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms);
}
} // namespace
namespace ui {
TEST(MotionEventAuraTest, PointerCountAndIds) {
// Test that |PointerCount()| returns the correct number of pointers, and ids
// are assigned correctly.
int ids[] = {4, 6, 1};
MotionEventAura event;
EXPECT_EQ(0U, event.GetPointerCount());
TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
event.OnTouch(press0);
EXPECT_EQ(1U, event.GetPointerCount());
EXPECT_EQ(ids[0], event.GetPointerId(0));
TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
event.OnTouch(press1);
EXPECT_EQ(2U, event.GetPointerCount());
EXPECT_EQ(ids[0], event.GetPointerId(0));
EXPECT_EQ(ids[1], event.GetPointerId(1));
TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]);
event.OnTouch(press2);
EXPECT_EQ(3U, event.GetPointerCount());
EXPECT_EQ(ids[0], event.GetPointerId(0));
EXPECT_EQ(ids[1], event.GetPointerId(1));
EXPECT_EQ(ids[2], event.GetPointerId(2));
TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
event.OnTouch(release1);
event.CleanupRemovedTouchPoints(release1);
EXPECT_EQ(2U, event.GetPointerCount());
EXPECT_EQ(ids[0], event.GetPointerId(0));
EXPECT_EQ(ids[2], event.GetPointerId(1));
// Test cloning of pointer count and id information.
scoped_ptr<MotionEvent> clone = event.Clone();
EXPECT_EQ(2U, clone->GetPointerCount());
EXPECT_EQ(ids[0], clone->GetPointerId(0));
EXPECT_EQ(ids[2], clone->GetPointerId(1));
TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
event.OnTouch(release0);
event.CleanupRemovedTouchPoints(release0);
EXPECT_EQ(1U, event.GetPointerCount());
EXPECT_EQ(ids[2], event.GetPointerId(0));
TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]);
event.OnTouch(release2);
event.CleanupRemovedTouchPoints(release2);
EXPECT_EQ(0U, event.GetPointerCount());
}
TEST(MotionEventAuraTest, GetActionIndexAfterRemoval) {
// Test that |GetActionIndex()| returns the correct index when points have
// been removed.
int ids[] = {4, 6, 9};
MotionEventAura event;
EXPECT_EQ(0U, event.GetPointerCount());
TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
event.OnTouch(press0);
TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
event.OnTouch(press1);
TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]);
event.OnTouch(press2);
EXPECT_EQ(3U, event.GetPointerCount());
TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
event.OnTouch(release1);
event.CleanupRemovedTouchPoints(release1);
EXPECT_EQ(1, event.GetActionIndex());
EXPECT_EQ(2U, event.GetPointerCount());
TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
event.OnTouch(release2);
event.CleanupRemovedTouchPoints(release2);
EXPECT_EQ(0, event.GetActionIndex());
EXPECT_EQ(1U, event.GetPointerCount());
TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]);
event.OnTouch(release0);
event.CleanupRemovedTouchPoints(release0);
EXPECT_EQ(0U, event.GetPointerCount());
}
TEST(MotionEventAuraTest, PointerLocations) {
// Test that location information is stored correctly.
MotionEventAura event;
int ids[] = {15, 13};
float x;
float y;
float r;
float p;
x = 14.4f;
y = 17.3f;
r = 25.7f;
p = 48.2f;
TouchEvent press0 = TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, r, p);
event.OnTouch(press0);
EXPECT_EQ(1U, event.GetPointerCount());
EXPECT_FLOAT_EQ(x, event.GetX(0));
EXPECT_FLOAT_EQ(y, event.GetY(0));
EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2);
EXPECT_FLOAT_EQ(p, event.GetPressure(0));
x = 17.8f;
y = 12.1f;
r = 21.2f;
p = 18.4f;
TouchEvent press1 = TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, r, p);
event.OnTouch(press1);
EXPECT_EQ(2U, event.GetPointerCount());
EXPECT_FLOAT_EQ(x, event.GetX(1));
EXPECT_FLOAT_EQ(y, event.GetY(1));
EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
EXPECT_FLOAT_EQ(p, event.GetPressure(1));
// Test cloning of pointer location information.
scoped_ptr<MotionEvent> clone = event.Clone();
EXPECT_EQ(2U, clone->GetPointerCount());
EXPECT_FLOAT_EQ(x, clone->GetX(1));
EXPECT_FLOAT_EQ(y, clone->GetY(1));
EXPECT_FLOAT_EQ(r, clone->GetTouchMajor(1) / 2);
EXPECT_FLOAT_EQ(p, clone->GetPressure(1));
x = 27.9f;
y = 22.3f;
r = 7.6f;
p = 82.1f;
TouchEvent move1 = TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, r, p);
event.OnTouch(move1);
EXPECT_FLOAT_EQ(x, event.GetX(1));
EXPECT_FLOAT_EQ(y, event.GetY(1));
EXPECT_FLOAT_EQ(r, event.GetTouchMajor(1) / 2);
EXPECT_FLOAT_EQ(p, event.GetPressure(1));
x = 34.6f;
y = 23.8f;
r = 12.9f;
p = 14.2f;
TouchEvent move0 = TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, r, p);
event.OnTouch(move0);
EXPECT_FLOAT_EQ(x, event.GetX(0));
EXPECT_FLOAT_EQ(y, event.GetY(0));
EXPECT_FLOAT_EQ(r, event.GetTouchMajor(0) / 2);
EXPECT_FLOAT_EQ(p, event.GetPressure(0));
}
TEST(MotionEventAuraTest, Timestamps) {
// Test that timestamp information is stored and converted correctly.
MotionEventAura event;
int ids[] = {7, 13};
int times_in_ms[] = {59436, 60263, 82175};
TouchEvent press0 = TouchWithTime(
ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]);
event.OnTouch(press0);
EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime());
TouchEvent press1 = TouchWithTime(
ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]);
event.OnTouch(press1);
EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime());
TouchEvent move0 = TouchWithTime(
ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]);
event.OnTouch(move0);
EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime());
// Test cloning of timestamp information.
scoped_ptr<MotionEvent> clone = event.Clone();
EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime());
}
TEST(MotionEventAuraTest, CachedAction) {
// Test that the cached action and cached action index are correct.
int ids[] = {4, 6};
MotionEventAura event;
TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
event.OnTouch(press0);
EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction());
EXPECT_EQ(1U, event.GetPointerCount());
TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
event.OnTouch(press1);
EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
EXPECT_EQ(1, event.GetActionIndex());
EXPECT_EQ(2U, event.GetPointerCount());
// Test cloning of CachedAction information.
scoped_ptr<MotionEvent> clone = event.Clone();
EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction());
EXPECT_EQ(1, clone->GetActionIndex());
TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]);
event.OnTouch(move0);
EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction());
EXPECT_EQ(2U, event.GetPointerCount());
TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]);
event.OnTouch(release0);
EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction());
EXPECT_EQ(2U, event.GetPointerCount());
event.CleanupRemovedTouchPoints(release0);
EXPECT_EQ(1U, event.GetPointerCount());
TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]);
event.OnTouch(release1);
EXPECT_EQ(MotionEvent::ACTION_UP, event.GetAction());
EXPECT_EQ(1U, event.GetPointerCount());
event.CleanupRemovedTouchPoints(release1);
EXPECT_EQ(0U, event.GetPointerCount());
}
TEST(MotionEventAuraTest, Cancel) {
int ids[] = {4, 6};
MotionEventAura event;
TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]);
event.OnTouch(press0);
EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction());
EXPECT_EQ(1U, event.GetPointerCount());
TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]);
event.OnTouch(press1);
EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
EXPECT_EQ(1, event.GetActionIndex());
EXPECT_EQ(2U, event.GetPointerCount());
scoped_ptr<MotionEvent> cancel = event.Cancel();
EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction());
EXPECT_EQ(2U, static_cast<MotionEventAura*>(cancel.get())->GetPointerCount());
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment