OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "views/events/event.h" | 5 #include "views/events/event.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "views/view.h" | 8 #include "views/view.h" |
9 #include "views/widget/root_view.h" | 9 #include "views/widget/root_view.h" |
10 | 10 |
11 namespace views { | 11 namespace views { |
12 | 12 |
13 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
14 // Event, protected: | 14 // Event, protected: |
15 | 15 |
16 Event::Event(ui::EventType type, int flags) | 16 Event::Event(ui::EventType type, int flags) |
17 : type_(type), | 17 : type_(type), |
18 time_stamp_(base::Time::NowFromSystemTime()), | 18 time_stamp_(base::Time::NowFromSystemTime()), |
19 flags_(flags) { | 19 flags_(flags) { |
20 Init(); | 20 // Safely initialize the pointer/struct to null/empty. |
| 21 memset(&native_event_, 0, sizeof(native_event_)); |
| 22 #if defined(TOOLKIT_USES_GTK) |
| 23 gdk_event_ = NULL; |
| 24 #endif |
21 } | 25 } |
22 | 26 |
23 Event::Event(NativeEvent native_event, ui::EventType type, int flags) | 27 Event::Event(const NativeEvent& native_event, ui::EventType type, int flags) |
24 : type_(type), | 28 : native_event_(native_event), |
25 time_stamp_(base::Time::NowFromSystemTime()), | |
26 flags_(flags) { | |
27 InitWithNativeEvent(native_event); | |
28 } | |
29 | |
30 Event::Event(NativeEvent2 native_event_2, ui::EventType type, int flags, | |
31 FromNativeEvent2 from_native) | |
32 : native_event_2_(native_event_2), | |
33 type_(type), | 29 type_(type), |
34 time_stamp_(base::Time::NowFromSystemTime()), | 30 time_stamp_(base::Time::NowFromSystemTime()), |
35 flags_(flags) { | 31 flags_(flags) { |
36 InitWithNativeEvent2(native_event_2, from_native); | 32 #if defined(TOOLKIT_USES_GTK) |
| 33 gdk_event_ = NULL; |
| 34 #endif |
37 } | 35 } |
38 | 36 |
39 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
40 // LocatedEvent, protected: | 38 // LocatedEvent, protected: |
41 | 39 |
| 40 #if !defined(USE_AURA) |
| 41 LocatedEvent::LocatedEvent(const NativeEvent& native_event) |
| 42 : Event(native_event, |
| 43 ui::EventTypeFromNative(native_event), |
| 44 ui::EventFlagsFromNative(native_event)), |
| 45 location_(ui::EventLocationFromNative(native_event)) { |
| 46 } |
| 47 #endif |
| 48 |
42 // TODO(msw): Kill this legacy constructor when we update uses. | 49 // TODO(msw): Kill this legacy constructor when we update uses. |
43 LocatedEvent::LocatedEvent(ui::EventType type, const gfx::Point& location, | 50 LocatedEvent::LocatedEvent(ui::EventType type, |
| 51 const gfx::Point& location, |
44 int flags) | 52 int flags) |
45 : Event(type, flags), | 53 : Event(type, flags), |
46 location_(location) { | 54 location_(location) { |
47 } | 55 } |
48 | 56 |
49 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* source, | 57 LocatedEvent::LocatedEvent(const LocatedEvent& model, |
| 58 View* source, |
50 View* target) | 59 View* target) |
51 : Event(model), | 60 : Event(model), |
52 location_(model.location_) { | 61 location_(model.location_) { |
53 if (target && target != source) | 62 if (target && target != source) |
54 View::ConvertPointToView(source, target, &location_); | 63 View::ConvertPointToView(source, target, &location_); |
55 } | 64 } |
56 | 65 |
57 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* root) | 66 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* root) |
58 : Event(model), | 67 : Event(model), |
59 location_(model.location_) { | 68 location_(model.location_) { |
60 View::ConvertPointFromWidget(root, &location_); | 69 View::ConvertPointFromWidget(root, &location_); |
61 } | 70 } |
62 | 71 |
63 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
64 // KeyEvent, public: | 73 // KeyEvent, public: |
65 | 74 |
66 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, | 75 #if !defined(USE_AURA) |
| 76 KeyEvent::KeyEvent(const NativeEvent& native_event) |
| 77 : Event(native_event, |
| 78 ui::EventTypeFromNative(native_event), |
| 79 ui::EventFlagsFromNative(native_event)), |
| 80 key_code_(ui::KeyboardCodeFromNative(native_event)), |
| 81 character_(0), |
| 82 unmodified_character_(0) { |
| 83 } |
| 84 #endif |
| 85 |
| 86 KeyEvent::KeyEvent(ui::EventType type, |
| 87 ui::KeyboardCode key_code, |
67 int event_flags) | 88 int event_flags) |
68 : Event(type, event_flags), | 89 : Event(type, event_flags), |
69 key_code_(key_code), | 90 key_code_(key_code), |
70 character_(0), | 91 character_(0), |
71 unmodified_character_(0) { | 92 unmodified_character_(0) { |
72 } | 93 } |
73 | 94 |
74 // KeyEvent, private: --------------------------------------------------------- | 95 // KeyEvent, private: --------------------------------------------------------- |
75 | 96 |
76 // static | 97 // static |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 case ui::VKEY_OEM_7: | 189 case ui::VKEY_OEM_7: |
169 return shift ? '"' : '\''; | 190 return shift ? '"' : '\''; |
170 default: | 191 default: |
171 return 0; | 192 return 0; |
172 } | 193 } |
173 } | 194 } |
174 | 195 |
175 //////////////////////////////////////////////////////////////////////////////// | 196 //////////////////////////////////////////////////////////////////////////////// |
176 // MouseEvent, public: | 197 // MouseEvent, public: |
177 | 198 |
| 199 MouseEvent::MouseEvent(const NativeEvent& native_event) |
| 200 : LocatedEvent(native_event) { |
| 201 } |
| 202 |
178 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) | 203 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) |
179 : LocatedEvent(model, source, target) { | 204 : LocatedEvent(model, source, target) { |
180 } | 205 } |
181 | 206 |
182 MouseEvent::MouseEvent(const TouchEvent& touch, | 207 MouseEvent::MouseEvent(const TouchEvent& touch) |
183 FromNativeEvent2 from_native) | 208 : LocatedEvent(touch.native_event()) { |
184 : LocatedEvent(touch.native_event_2(), from_native) { | |
185 // The location of the event is correctly extracted from the native event. But | 209 // The location of the event is correctly extracted from the native event. But |
186 // it is necessary to update the event type. | 210 // it is necessary to update the event type. |
187 ui::EventType mtype = ui::ET_UNKNOWN; | 211 ui::EventType mtype = ui::ET_UNKNOWN; |
188 switch (touch.type()) { | 212 switch (touch.type()) { |
189 case ui::ET_TOUCH_RELEASED: | 213 case ui::ET_TOUCH_RELEASED: |
190 mtype = ui::ET_MOUSE_RELEASED; | 214 mtype = ui::ET_MOUSE_RELEASED; |
191 break; | 215 break; |
192 case ui::ET_TOUCH_PRESSED: | 216 case ui::ET_TOUCH_PRESSED: |
193 mtype = ui::ET_MOUSE_PRESSED; | 217 mtype = ui::ET_MOUSE_PRESSED; |
194 break; | 218 break; |
(...skipping 14 matching lines...) Expand all Loading... |
209 ui::EF_MIDDLE_BUTTON_DOWN); | 233 ui::EF_MIDDLE_BUTTON_DOWN); |
210 int button = ui::EF_LEFT_BUTTON_DOWN; | 234 int button = ui::EF_LEFT_BUTTON_DOWN; |
211 if (touch.identity() == 1) | 235 if (touch.identity() == 1) |
212 button = ui::EF_RIGHT_BUTTON_DOWN; | 236 button = ui::EF_RIGHT_BUTTON_DOWN; |
213 else if (touch.identity() == 2) | 237 else if (touch.identity() == 2) |
214 button = ui::EF_MIDDLE_BUTTON_DOWN; | 238 button = ui::EF_MIDDLE_BUTTON_DOWN; |
215 set_flags(new_flags | button); | 239 set_flags(new_flags | button); |
216 } | 240 } |
217 | 241 |
218 //////////////////////////////////////////////////////////////////////////////// | 242 //////////////////////////////////////////////////////////////////////////////// |
| 243 // MouseWheelEvent, public: |
| 244 |
| 245 #if !defined(USE_AURA) |
| 246 MouseWheelEvent::MouseWheelEvent(const ui::NativeEvent& native_event) |
| 247 : MouseEvent(native_event), |
| 248 offset_(ui::GetMouseWheelOffset(native_event)) { |
| 249 } |
| 250 #endif |
| 251 |
| 252 //////////////////////////////////////////////////////////////////////////////// |
219 // TouchEvent, public: | 253 // TouchEvent, public: |
220 | 254 |
221 TouchEvent::TouchEvent(ui::EventType type, | 255 TouchEvent::TouchEvent(ui::EventType type, |
222 int x, | 256 int x, |
223 int y, | 257 int y, |
224 int flags, | 258 int flags, |
225 int touch_id, | 259 int touch_id, |
226 float radius_x, | 260 float radius_x, |
227 float radius_y, | 261 float radius_y, |
228 float angle, | 262 float angle, |
(...skipping 28 matching lines...) Expand all Loading... |
257 } | 291 } |
258 | 292 |
259 //////////////////////////////////////////////////////////////////////////////// | 293 //////////////////////////////////////////////////////////////////////////////// |
260 // MouseWheelEvent, public: | 294 // MouseWheelEvent, public: |
261 | 295 |
262 // This value matches windows WHEEL_DELTA. | 296 // This value matches windows WHEEL_DELTA. |
263 // static | 297 // static |
264 const int MouseWheelEvent::kWheelDelta = 120; | 298 const int MouseWheelEvent::kWheelDelta = 120; |
265 | 299 |
266 } // namespace views | 300 } // namespace views |
OLD | NEW |