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