| 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_)); |
| 21 } | 22 } |
| 22 | 23 |
| 23 Event::Event(NativeEvent native_event, ui::EventType type, int flags) | 24 Event::Event(const NativeEvent& native_event, ui::EventType type, int flags) |
| 24 : type_(type), | 25 : 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), | 26 type_(type), |
| 34 time_stamp_(base::Time::NowFromSystemTime()), | 27 time_stamp_(base::Time::NowFromSystemTime()), |
| 35 flags_(flags) { | 28 flags_(flags) { |
| 36 InitWithNativeEvent2(native_event_2, from_native); | |
| 37 } | 29 } |
| 38 | 30 |
| 39 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 40 // LocatedEvent, protected: | 32 // LocatedEvent, protected: |
| 41 | 33 |
| 34 #if !defined(USE_AURA) |
| 35 LocatedEvent::LocatedEvent(const NativeEvent& native_event) |
| 36 : Event(native_event, |
| 37 ui::EventTypeFromNative(native_event), |
| 38 ui::EventFlagsFromNative(native_event)), |
| 39 location_(ui::EventLocationFromNative(native_event)) { |
| 40 } |
| 41 #endif |
| 42 |
| 42 // TODO(msw): Kill this legacy constructor when we update uses. | 43 // TODO(msw): Kill this legacy constructor when we update uses. |
| 43 LocatedEvent::LocatedEvent(ui::EventType type, const gfx::Point& location, | 44 LocatedEvent::LocatedEvent(ui::EventType type, |
| 45 const gfx::Point& location, |
| 44 int flags) | 46 int flags) |
| 45 : Event(type, flags), | 47 : Event(type, flags), |
| 46 location_(location) { | 48 location_(location) { |
| 47 } | 49 } |
| 48 | 50 |
| 49 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* source, | 51 LocatedEvent::LocatedEvent(const LocatedEvent& model, |
| 52 View* source, |
| 50 View* target) | 53 View* target) |
| 51 : Event(model), | 54 : Event(model), |
| 52 location_(model.location_) { | 55 location_(model.location_) { |
| 53 if (target && target != source) | 56 if (target && target != source) |
| 54 View::ConvertPointToView(source, target, &location_); | 57 View::ConvertPointToView(source, target, &location_); |
| 55 } | 58 } |
| 56 | 59 |
| 57 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* root) | 60 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* root) |
| 58 : Event(model), | 61 : Event(model), |
| 59 location_(model.location_) { | 62 location_(model.location_) { |
| 60 View::ConvertPointFromWidget(root, &location_); | 63 View::ConvertPointFromWidget(root, &location_); |
| 61 } | 64 } |
| 62 | 65 |
| 63 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
| 64 // KeyEvent, public: | 67 // KeyEvent, public: |
| 65 | 68 |
| 66 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, | 69 #if !defined(USE_AURA) |
| 70 KeyEvent::KeyEvent(const NativeEvent& native_event) |
| 71 : Event(native_event, |
| 72 ui::EventTypeFromNative(native_event), |
| 73 ui::EventFlagsFromNative(native_event)), |
| 74 key_code_(ui::KeyboardCodeFromNative(native_event)), |
| 75 character_(0), |
| 76 unmodified_character_(0) { |
| 77 } |
| 78 #endif |
| 79 |
| 80 KeyEvent::KeyEvent(ui::EventType type, |
| 81 ui::KeyboardCode key_code, |
| 67 int event_flags) | 82 int event_flags) |
| 68 : Event(type, event_flags), | 83 : Event(type, event_flags), |
| 69 key_code_(key_code), | 84 key_code_(key_code), |
| 70 character_(0), | 85 character_(0), |
| 71 unmodified_character_(0) { | 86 unmodified_character_(0) { |
| 72 } | 87 } |
| 73 | 88 |
| 74 // KeyEvent, private: --------------------------------------------------------- | 89 // KeyEvent, private: --------------------------------------------------------- |
| 75 | 90 |
| 76 // static | 91 // static |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 case ui::VKEY_OEM_7: | 183 case ui::VKEY_OEM_7: |
| 169 return shift ? '"' : '\''; | 184 return shift ? '"' : '\''; |
| 170 default: | 185 default: |
| 171 return 0; | 186 return 0; |
| 172 } | 187 } |
| 173 } | 188 } |
| 174 | 189 |
| 175 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
| 176 // MouseEvent, public: | 191 // MouseEvent, public: |
| 177 | 192 |
| 193 MouseEvent::MouseEvent(const NativeEvent& native_event) |
| 194 : LocatedEvent(native_event) { |
| 195 } |
| 196 |
| 178 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) | 197 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) |
| 179 : LocatedEvent(model, source, target) { | 198 : LocatedEvent(model, source, target) { |
| 180 } | 199 } |
| 181 | 200 |
| 182 MouseEvent::MouseEvent(const TouchEvent& touch, | 201 MouseEvent::MouseEvent(const TouchEvent& touch) |
| 183 FromNativeEvent2 from_native) | 202 : 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 | 203 // The location of the event is correctly extracted from the native event. But |
| 186 // it is necessary to update the event type. | 204 // it is necessary to update the event type. |
| 187 ui::EventType mtype = ui::ET_UNKNOWN; | 205 ui::EventType mtype = ui::ET_UNKNOWN; |
| 188 switch (touch.type()) { | 206 switch (touch.type()) { |
| 189 case ui::ET_TOUCH_RELEASED: | 207 case ui::ET_TOUCH_RELEASED: |
| 190 mtype = ui::ET_MOUSE_RELEASED; | 208 mtype = ui::ET_MOUSE_RELEASED; |
| 191 break; | 209 break; |
| 192 case ui::ET_TOUCH_PRESSED: | 210 case ui::ET_TOUCH_PRESSED: |
| 193 mtype = ui::ET_MOUSE_PRESSED; | 211 mtype = ui::ET_MOUSE_PRESSED; |
| 194 break; | 212 break; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 209 ui::EF_MIDDLE_BUTTON_DOWN); | 227 ui::EF_MIDDLE_BUTTON_DOWN); |
| 210 int button = ui::EF_LEFT_BUTTON_DOWN; | 228 int button = ui::EF_LEFT_BUTTON_DOWN; |
| 211 if (touch.identity() == 1) | 229 if (touch.identity() == 1) |
| 212 button = ui::EF_RIGHT_BUTTON_DOWN; | 230 button = ui::EF_RIGHT_BUTTON_DOWN; |
| 213 else if (touch.identity() == 2) | 231 else if (touch.identity() == 2) |
| 214 button = ui::EF_MIDDLE_BUTTON_DOWN; | 232 button = ui::EF_MIDDLE_BUTTON_DOWN; |
| 215 set_flags(new_flags | button); | 233 set_flags(new_flags | button); |
| 216 } | 234 } |
| 217 | 235 |
| 218 //////////////////////////////////////////////////////////////////////////////// | 236 //////////////////////////////////////////////////////////////////////////////// |
| 237 // MouseWheelEvent, public: |
| 238 |
| 239 #if !defined(USE_AURA) |
| 240 MouseWheelEvent::MouseWheelEvent(const ui::NativeEvent& native_event) |
| 241 : MouseEvent(native_event), |
| 242 offset_(ui::GetMouseWheelOffset(native_event)) { |
| 243 } |
| 244 #endif |
| 245 |
| 246 //////////////////////////////////////////////////////////////////////////////// |
| 219 // TouchEvent, public: | 247 // TouchEvent, public: |
| 220 | 248 |
| 221 TouchEvent::TouchEvent(ui::EventType type, | 249 TouchEvent::TouchEvent(ui::EventType type, |
| 222 int x, | 250 int x, |
| 223 int y, | 251 int y, |
| 224 int flags, | 252 int flags, |
| 225 int touch_id, | 253 int touch_id, |
| 226 float radius_x, | 254 float radius_x, |
| 227 float radius_y, | 255 float radius_y, |
| 228 float angle, | 256 float angle, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 257 } | 285 } |
| 258 | 286 |
| 259 //////////////////////////////////////////////////////////////////////////////// | 287 //////////////////////////////////////////////////////////////////////////////// |
| 260 // MouseWheelEvent, public: | 288 // MouseWheelEvent, public: |
| 261 | 289 |
| 262 // This value matches windows WHEEL_DELTA. | 290 // This value matches windows WHEEL_DELTA. |
| 263 // static | 291 // static |
| 264 const int MouseWheelEvent::kWheelDelta = 120; | 292 const int MouseWheelEvent::kWheelDelta = 120; |
| 265 | 293 |
| 266 } // namespace views | 294 } // namespace views |
| OLD | NEW |