Home | History | Annotate | Download | only in gesture_detection
      1 // Copyright 2014 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/gesture_detection/motion_event_generic.h"
      6 
      7 #include "base/logging.h"
      8 
      9 namespace ui {
     10 
     11 PointerProperties::PointerProperties()
     12     : id(0),
     13       tool_type(MotionEvent::TOOL_TYPE_UNKNOWN),
     14       x(0),
     15       y(0),
     16       raw_x(0),
     17       raw_y(0),
     18       pressure(0),
     19       touch_major(0),
     20       touch_minor(0),
     21       orientation(0) {
     22 }
     23 
     24 PointerProperties::PointerProperties(float x, float y)
     25     : id(0),
     26       tool_type(MotionEvent::TOOL_TYPE_UNKNOWN),
     27       x(x),
     28       y(y),
     29       raw_x(x),
     30       raw_y(y),
     31       pressure(0),
     32       touch_major(0),
     33       touch_minor(0),
     34       orientation(0) {
     35 }
     36 
     37 MotionEventGeneric::MotionEventGeneric()
     38     : action_(ACTION_CANCEL),
     39       id_(0),
     40       action_index_(0),
     41       button_state_(0),
     42       flags_(0) {
     43 }
     44 
     45 MotionEventGeneric::MotionEventGeneric(Action action,
     46                                        base::TimeTicks event_time,
     47                                        const PointerProperties& pointer)
     48     : action_(action),
     49       event_time_(event_time),
     50       id_(0),
     51       action_index_(0),
     52       button_state_(0),
     53       flags_(0) {
     54   PushPointer(pointer);
     55 }
     56 
     57 MotionEventGeneric::MotionEventGeneric(const MotionEventGeneric& other)
     58     : action_(other.action_),
     59       event_time_(other.event_time_),
     60       id_(other.id_),
     61       action_index_(other.action_index_),
     62       button_state_(other.button_state_),
     63       flags_(other.flags_),
     64       pointers_(other.pointers_) {
     65 }
     66 
     67 MotionEventGeneric::~MotionEventGeneric() {
     68 }
     69 
     70 int MotionEventGeneric::GetId() const {
     71   return id_;
     72 }
     73 
     74 MotionEvent::Action MotionEventGeneric::GetAction() const {
     75   return action_;
     76 }
     77 
     78 int MotionEventGeneric::GetActionIndex() const {
     79   return action_index_;
     80 }
     81 
     82 size_t MotionEventGeneric::GetPointerCount() const {
     83   return pointers_->size();
     84 }
     85 
     86 int MotionEventGeneric::GetPointerId(size_t pointer_index) const {
     87   DCHECK_LT(pointer_index, pointers_->size());
     88   return pointers_[pointer_index].id;
     89 }
     90 
     91 float MotionEventGeneric::GetX(size_t pointer_index) const {
     92   DCHECK_LT(pointer_index, pointers_->size());
     93   return pointers_[pointer_index].x;
     94 }
     95 
     96 float MotionEventGeneric::GetY(size_t pointer_index) const {
     97   DCHECK_LT(pointer_index, pointers_->size());
     98   return pointers_[pointer_index].y;
     99 }
    100 
    101 float MotionEventGeneric::GetRawX(size_t pointer_index) const {
    102   DCHECK_LT(pointer_index, pointers_->size());
    103   return pointers_[pointer_index].raw_x;
    104 }
    105 
    106 float MotionEventGeneric::GetRawY(size_t pointer_index) const {
    107   DCHECK_LT(pointer_index, pointers_->size());
    108   return pointers_[pointer_index].raw_y;
    109 }
    110 
    111 float MotionEventGeneric::GetTouchMajor(size_t pointer_index) const {
    112   DCHECK_LT(pointer_index, pointers_->size());
    113   return pointers_[pointer_index].touch_major;
    114 }
    115 
    116 float MotionEventGeneric::GetTouchMinor(size_t pointer_index) const {
    117   DCHECK_LT(pointer_index, pointers_->size());
    118   return pointers_[pointer_index].touch_minor;
    119 }
    120 
    121 float MotionEventGeneric::GetOrientation(size_t pointer_index) const {
    122   DCHECK_LT(pointer_index, pointers_->size());
    123   return pointers_[pointer_index].orientation;
    124 }
    125 
    126 float MotionEventGeneric::GetPressure(size_t pointer_index) const {
    127   DCHECK_LT(pointer_index, pointers_->size());
    128   return pointers_[pointer_index].pressure;
    129 }
    130 
    131 MotionEvent::ToolType MotionEventGeneric::GetToolType(
    132     size_t pointer_index) const {
    133   DCHECK_LT(pointer_index, pointers_->size());
    134   return pointers_[pointer_index].tool_type;
    135 }
    136 
    137 int MotionEventGeneric::GetButtonState() const {
    138   return button_state_;
    139 }
    140 
    141 int MotionEventGeneric::GetFlags() const {
    142   return flags_;
    143 }
    144 
    145 base::TimeTicks MotionEventGeneric::GetEventTime() const {
    146   return event_time_;
    147 }
    148 
    149 scoped_ptr<MotionEvent> MotionEventGeneric::Clone() const {
    150   return scoped_ptr<MotionEvent>(new MotionEventGeneric(*this));
    151 }
    152 
    153 scoped_ptr<MotionEvent> MotionEventGeneric::Cancel() const {
    154   scoped_ptr<MotionEventGeneric> event(new MotionEventGeneric(*this));
    155   event->set_action(ACTION_CANCEL);
    156   return event.PassAs<MotionEvent>();
    157 }
    158 
    159 void MotionEventGeneric::PushPointer(const PointerProperties& pointer) {
    160   pointers_->push_back(pointer);
    161 }
    162 
    163 void MotionEventGeneric::PopPointer() {
    164   DCHECK_GT(pointers_->size(), 0U);
    165   pointers_->pop_back();
    166 }
    167 
    168 }  // namespace ui
    169