Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / ui / events / gesture_detection / gesture_event_details.cc
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/gesture_event_details.h"
6
7 namespace ui {
8
9 GestureEventDetails::GestureEventDetails() : type_(ET_UNKNOWN) {}
10
11 GestureEventDetails::GestureEventDetails(ui::EventType type,
12                                          float delta_x,
13                                          float delta_y)
14     : type_(type),
15       touch_points_(1) {
16   switch (type_) {
17     case ui::ET_GESTURE_SCROLL_BEGIN:
18       data.scroll_begin.x_hint = delta_x;
19       data.scroll_begin.y_hint = delta_y;
20       break;
21
22     case ui::ET_GESTURE_SCROLL_UPDATE:
23       data.scroll_update.x = delta_x;
24       data.scroll_update.y = delta_y;
25       data.scroll_update.x_ordinal = delta_x;
26       data.scroll_update.y_ordinal = delta_y;
27       break;
28
29     case ui::ET_SCROLL_FLING_START:
30       data.fling_velocity.x = delta_x;
31       data.fling_velocity.y = delta_y;
32       data.fling_velocity.x_ordinal = delta_x;
33       data.fling_velocity.y_ordinal = delta_y;
34       break;
35
36     case ui::ET_GESTURE_LONG_PRESS:
37       data.touch_id = static_cast<int>(delta_x);
38       CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for long press.";
39       break;
40
41     case ui::ET_GESTURE_TWO_FINGER_TAP:
42       data.first_finger_enclosing_rectangle.width = delta_x;
43       data.first_finger_enclosing_rectangle.height = delta_y;
44       break;
45
46     case ui::ET_GESTURE_PINCH_UPDATE:
47       data.scale = delta_x;
48       CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for pinch";
49       break;
50
51     case ui::ET_GESTURE_MULTIFINGER_SWIPE:
52       data.swipe.left = delta_x < 0;
53       data.swipe.right = delta_x > 0;
54       data.swipe.up = delta_y < 0;
55       data.swipe.down = delta_y > 0;
56       break;
57
58     case ui::ET_GESTURE_TAP:
59       data.tap_count = static_cast<int>(delta_x);
60       CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for tap.";
61       break;
62
63     default:
64       if (delta_x != 0.f || delta_y != 0.f) {
65         DLOG(WARNING) << "A gesture event (" << type << ") had unknown data: ("
66                       << delta_x << "," << delta_y;
67       }
68       break;
69   }
70 }
71
72 GestureEventDetails::GestureEventDetails(ui::EventType type,
73                                          float delta_x,
74                                          float delta_y,
75                                          float delta_x_ordinal,
76                                          float delta_y_ordinal)
77     : type_(type),
78       touch_points_(1) {
79   CHECK(type == ui::ET_GESTURE_SCROLL_UPDATE ||
80         type == ui::ET_SCROLL_FLING_START);
81   switch (type_) {
82     case ui::ET_GESTURE_SCROLL_UPDATE:
83       data.scroll_update.x = delta_x;
84       data.scroll_update.y = delta_y;
85       data.scroll_update.x_ordinal = delta_x_ordinal;
86       data.scroll_update.y_ordinal = delta_y_ordinal;
87       break;
88
89     case ui::ET_SCROLL_FLING_START:
90       data.fling_velocity.x = delta_x;
91       data.fling_velocity.y = delta_y;
92       data.fling_velocity.x_ordinal = delta_x_ordinal;
93       data.fling_velocity.y_ordinal = delta_y_ordinal;
94       break;
95
96     default:
97       break;
98   }
99 }
100
101 void GestureEventDetails::SetScrollVelocity(float velocity_x,
102                                             float velocity_y,
103                                             float velocity_x_ordinal,
104                                             float velocity_y_ordinal) {
105   CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
106   data.scroll_update.velocity_x = velocity_x;
107   data.scroll_update.velocity_y = velocity_y;
108   data.scroll_update.velocity_x_ordinal = velocity_x_ordinal;
109   data.scroll_update.velocity_y_ordinal = velocity_y_ordinal;
110 }
111
112 }  // namespace ui