1010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// found in the LICENSE file. 4010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// MSVC++ requires this to be set before any other includes to get M_PI. 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define _USE_MATH_DEFINES 71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 8010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/events/gestures/motion_event_aura.h" 9010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <cmath> 111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 12010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/logging.h" 13010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/events/gestures/gesture_configuration.h" 14010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)namespace ui { 16010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 17010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)MotionEventAura::MotionEventAura() 18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) : pointer_count_(0), cached_action_index_(-1) { 19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 20010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 21010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)MotionEventAura::MotionEventAura( 22010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) size_t pointer_count, 23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const base::TimeTicks& last_touch_time, 24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) Action cached_action, 25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) int cached_action_index, 261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int flags, 271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const PointData (&active_touches)[MotionEvent::MAX_TOUCH_POINT_COUNT]) 28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) : pointer_count_(pointer_count), 29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) last_touch_time_(last_touch_time), 30010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_(cached_action), 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci cached_action_index_(cached_action_index), 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci flags_(flags) { 33010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) DCHECK(pointer_count_); 34010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) for (size_t i = 0; i < pointer_count; ++i) 35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) active_touches_[i] = active_touches[i]; 36010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 37010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)MotionEventAura::~MotionEventAura() {} 39010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 40010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)MotionEventAura::PointData MotionEventAura::GetPointDataFromTouchEvent( 41010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const TouchEvent& touch) { 42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) PointData point_data; 43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) point_data.x = touch.x(); 44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) point_data.y = touch.y(); 45f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) point_data.raw_x = touch.root_location_f().x(); 46f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) point_data.raw_y = touch.root_location_f().y(); 47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) point_data.touch_id = touch.touch_id(); 48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) point_data.pressure = touch.force(); 49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) point_data.source_device_id = touch.source_device_id(); 50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci float radius_x = touch.radius_x(); 521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci float radius_y = touch.radius_y(); 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f; 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0"; 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0"; 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci << "Unexpected touch rotation angle"; 581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (radius_x > radius_y) { 601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // The case radius_x == radius_y is omitted from here on purpose: for 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // circles, we want to pass the angle (which could be any value in such 621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // cases but always seem to be set to zero) unchanged. 631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.touch_major = 2.f * radius_x; 641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.touch_minor = 2.f * radius_y; 651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.orientation = rotation_angle_rad - M_PI_2; 661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } else { 671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.touch_major = 2.f * radius_y; 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.touch_minor = 2.f * radius_x; 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.orientation = rotation_angle_rad; 701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (!point_data.touch_major) { 731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.touch_major = 2.f * GestureConfiguration::default_radius(); 741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.touch_minor = 2.f * GestureConfiguration::default_radius(); 751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci point_data.orientation = 0; 761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return point_data; 79010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void MotionEventAura::OnTouch(const TouchEvent& touch) { 82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) switch (touch.type()) { 83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_PRESSED: 84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) AddTouch(touch); 85010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 86010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_RELEASED: 87010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_CANCELLED: 88010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Removing these touch points needs to be postponed until after the 89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // MotionEvent has been dispatched. This cleanup occurs in 90010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // CleanupRemovedTouchPoints. 91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) UpdateTouch(touch); 92010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 93010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_MOVED: 94010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) UpdateTouch(touch); 95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) default: 97010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) NOTREACHED(); 98010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 99010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 100010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 101010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) UpdateCachedAction(touch); 1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci flags_ = touch.flags(); 103010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) last_touch_time_ = touch.time_stamp() + base::TimeTicks(); 104010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 105010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 106010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)int MotionEventAura::GetId() const { 107010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return GetPointerId(0); 108010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 109010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 110010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)MotionEvent::Action MotionEventAura::GetAction() const { 111010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return cached_action_; 112010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 113010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 114010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)int MotionEventAura::GetActionIndex() const { 115010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) DCHECK(cached_action_ == ACTION_POINTER_DOWN || 116010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_ == ACTION_POINTER_UP); 117010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) DCHECK_GE(cached_action_index_, 0); 11803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(cached_action_index_, static_cast<int>(pointer_count_)); 119010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return cached_action_index_; 120010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 121010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 122010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)size_t MotionEventAura::GetPointerCount() const { return pointer_count_; } 123010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 124010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)int MotionEventAura::GetPointerId(size_t pointer_index) const { 12503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 126010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return active_touches_[pointer_index].touch_id; 127010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 128010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 129010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)float MotionEventAura::GetX(size_t pointer_index) const { 13003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 131010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return active_touches_[pointer_index].x; 132010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 133010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 134010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)float MotionEventAura::GetY(size_t pointer_index) const { 13503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 136010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return active_touches_[pointer_index].y; 137010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 138010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)float MotionEventAura::GetRawX(size_t pointer_index) const { 14003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 141f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return active_touches_[pointer_index].raw_x; 142f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)float MotionEventAura::GetRawY(size_t pointer_index) const { 14503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return active_touches_[pointer_index].raw_y; 147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 148f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 149010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)float MotionEventAura::GetTouchMajor(size_t pointer_index) const { 15003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return active_touches_[pointer_index].touch_major; 1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccifloat MotionEventAura::GetTouchMinor(size_t pointer_index) const { 1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DCHECK_LE(pointer_index, pointer_count_); 1561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return active_touches_[pointer_index].touch_minor; 1571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 1581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccifloat MotionEventAura::GetOrientation(size_t pointer_index) const { 1601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DCHECK_LE(pointer_index, pointer_count_); 1611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return active_touches_[pointer_index].orientation; 162010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 163010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 164010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)float MotionEventAura::GetPressure(size_t pointer_index) const { 16503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 166010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return active_touches_[pointer_index].pressure; 167010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 168010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 169116680a4aac90f2aa7413d9095a592090648e557Ben MurdochMotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { 17003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. 17103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 172116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return MotionEvent::TOOL_TYPE_UNKNOWN; 173116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 174116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 175116680a4aac90f2aa7413d9095a592090648e557Ben Murdochint MotionEventAura::GetButtonState() const { 176116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NOTIMPLEMENTED(); 177116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return 0; 178116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 179116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciint MotionEventAura::GetFlags() const { 1811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return flags_; 1821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 1831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)base::TimeTicks MotionEventAura::GetEventTime() const { 1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return last_touch_time_; 1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 188010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)scoped_ptr<MotionEvent> MotionEventAura::Clone() const { 189010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return scoped_ptr<MotionEvent>(new MotionEventAura(pointer_count_, 190010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) last_touch_time_, 191010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_, 192010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_index_, 1931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci flags_, 194010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) active_touches_)); 195010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 196010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)scoped_ptr<MotionEvent> MotionEventAura::Cancel() const { 197010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return scoped_ptr<MotionEvent>(new MotionEventAura( 1981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci pointer_count_, last_touch_time_, ACTION_CANCEL, -1, 0, active_touches_)); 199010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 200010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 201010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) { 202010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (event.type() != ET_TOUCH_RELEASED && 203010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) event.type() != ET_TOUCH_CANCELLED) { 204010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return; 205010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 206010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 207010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) int index_to_delete = static_cast<int>(GetIndexFromId(event.touch_id())); 208010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) pointer_count_--; 209010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) active_touches_[index_to_delete] = active_touches_[pointer_count_]; 210010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 211010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 212010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)MotionEventAura::PointData::PointData() 213010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) : x(0), 214010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) y(0), 215f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) raw_x(0), 216f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) raw_y(0), 217010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) touch_id(0), 218010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) pressure(0), 219010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) source_device_id(0), 2201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci touch_major(0), 2211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci touch_minor(0), 2221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci orientation(0) { 223010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 224010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 225010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { 22603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(pointer_index, pointer_count_); 227010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return active_touches_[pointer_index].source_device_id; 228010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 229010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 230010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void MotionEventAura::AddTouch(const TouchEvent& touch) { 2311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) 232010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return; 233010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 234010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) active_touches_[pointer_count_] = GetPointDataFromTouchEvent(touch); 235010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) pointer_count_++; 236010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 237010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 238010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 239010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void MotionEventAura::UpdateTouch(const TouchEvent& touch) { 240010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) active_touches_[GetIndexFromId(touch.touch_id())] = 241010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) GetPointDataFromTouchEvent(touch); 242010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 243010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 244010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) { 245010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) DCHECK(pointer_count_); 246010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) switch (touch.type()) { 247010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_PRESSED: 248010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (pointer_count_ == 1) { 249010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_ = ACTION_DOWN; 250010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } else { 251010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_ = ACTION_POINTER_DOWN; 252010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_index_ = 253010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) static_cast<int>(GetIndexFromId(touch.touch_id())); 254010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 255010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 256010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_RELEASED: 257010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (pointer_count_ == 1) { 258010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_ = ACTION_UP; 259010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } else { 260010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_ = ACTION_POINTER_UP; 261010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_index_ = 262010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) static_cast<int>(GetIndexFromId(touch.touch_id())); 26303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) DCHECK_LT(cached_action_index_, static_cast<int>(pointer_count_)); 264010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 265010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 266010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_CANCELLED: 267010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_ = ACTION_CANCEL; 268010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 269010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) case ET_TOUCH_MOVED: 270010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) cached_action_ = ACTION_MOVE; 271010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 272010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) default: 273010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) NOTREACHED(); 274010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) break; 275010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 276010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 277010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 278010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)size_t MotionEventAura::GetIndexFromId(int id) const { 279010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) for (size_t i = 0; i < pointer_count_; ++i) { 280010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (active_touches_[i].touch_id == id) 281010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return i; 282010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 283010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) NOTREACHED(); 284010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return 0; 285010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} 286010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 287010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)} // namespace ui 288