Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / events / 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_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       break;
26
27     case ui::ET_SCROLL_FLING_START:
28       data.fling_velocity.x = delta_x;
29       data.fling_velocity.y = delta_y;
30       break;
31
32     case ui::ET_GESTURE_TWO_FINGER_TAP:
33       data.first_finger_enclosing_rectangle.width = delta_x;
34       data.first_finger_enclosing_rectangle.height = delta_y;
35       break;
36
37     case ui::ET_GESTURE_PINCH_UPDATE:
38       data.scale = delta_x;
39       CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for pinch";
40       break;
41
42     case ui::ET_GESTURE_MULTIFINGER_SWIPE:
43       data.swipe.left = delta_x < 0;
44       data.swipe.right = delta_x > 0;
45       data.swipe.up = delta_y < 0;
46       data.swipe.down = delta_y > 0;
47       break;
48
49     case ui::ET_GESTURE_TAP:
50     case ui::ET_GESTURE_DOUBLE_TAP:
51     case ui::ET_GESTURE_TAP_UNCONFIRMED:
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::Details::Details() {
66   memset(this, 0, sizeof(Details));
67 }
68
69 }  // namespace ui