Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: views/events/event.cc

Issue 7942004: Consolidate/cleanup event cracking code; single out GdkEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: KeyboardCodeFromNative, Wayland, cleanup and consolidate. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 Init();
21 } 21 }
22 22
23 Event::Event(NativeEvent native_event, ui::EventType type, int flags) 23 Event::Event(const NativeEvent& native_event, ui::EventType type, int flags)
24 : type_(type), 24 : type_(type),
25 time_stamp_(base::Time::NowFromSystemTime()), 25 time_stamp_(base::Time::NowFromSystemTime()),
26 flags_(flags) { 26 flags_(flags) {
27 InitWithNativeEvent(native_event); 27 InitWithNativeEvent(native_event);
28 } 28 }
29 29
30 Event::Event(NativeEvent2 native_event_2, ui::EventType type, int flags, 30 Event::Event(const NativeEvent2& native_event_2,
31 ui::EventType type,
32 int flags,
31 FromNativeEvent2 from_native) 33 FromNativeEvent2 from_native)
32 : native_event_2_(native_event_2), 34 : native_event_2_(native_event_2),
33 type_(type), 35 type_(type),
34 time_stamp_(base::Time::NowFromSystemTime()), 36 time_stamp_(base::Time::NowFromSystemTime()),
35 flags_(flags) { 37 flags_(flags) {
36 InitWithNativeEvent2(native_event_2, from_native); 38 InitWithNativeEvent2(native_event_2, from_native);
37 } 39 }
38 40
41 void Event::InitWithNativeEvent(const NativeEvent& native_event) {
42 native_event_ = native_event;
43 // TODO(beng): remove once we rid views of Gtk/Gdk.
44 native_event_2_ = NULL;
45 }
46
39 //////////////////////////////////////////////////////////////////////////////// 47 ////////////////////////////////////////////////////////////////////////////////
40 // LocatedEvent, protected: 48 // LocatedEvent, protected:
41 49
50 #if !defined(USE_AURA)
51 LocatedEvent::LocatedEvent(const NativeEvent& native_event)
52 : Event(native_event,
53 ui::EventTypeFromNative(native_event),
54 ui::EventFlagsFromNative(native_event)),
55 location_(ui::EventLocationFromNative(native_event)) {
56 }
57 #endif
58
42 // TODO(msw): Kill this legacy constructor when we update uses. 59 // TODO(msw): Kill this legacy constructor when we update uses.
43 LocatedEvent::LocatedEvent(ui::EventType type, const gfx::Point& location, 60 LocatedEvent::LocatedEvent(ui::EventType type,
61 const gfx::Point& location,
44 int flags) 62 int flags)
45 : Event(type, flags), 63 : Event(type, flags),
46 location_(location) { 64 location_(location) {
47 } 65 }
48 66
49 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* source, 67 LocatedEvent::LocatedEvent(const LocatedEvent& model,
68 View* source,
50 View* target) 69 View* target)
51 : Event(model), 70 : Event(model),
52 location_(model.location_) { 71 location_(model.location_) {
53 if (target && target != source) 72 if (target && target != source)
54 View::ConvertPointToView(source, target, &location_); 73 View::ConvertPointToView(source, target, &location_);
55 } 74 }
56 75
57 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* root) 76 LocatedEvent::LocatedEvent(const LocatedEvent& model, View* root)
58 : Event(model), 77 : Event(model),
59 location_(model.location_) { 78 location_(model.location_) {
60 View::ConvertPointFromWidget(root, &location_); 79 View::ConvertPointFromWidget(root, &location_);
61 } 80 }
62 81
63 //////////////////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////////////////
64 // KeyEvent, public: 83 // KeyEvent, public:
65 84
66 KeyEvent::KeyEvent(ui::EventType type, ui::KeyboardCode key_code, 85 #if !defined(USE_AURA)
86 KeyEvent::KeyEvent(const NativeEvent& native_event)
87 : Event(native_event,
88 ui::EventTypeFromNative(native_event),
89 ui::EventFlagsFromNative(native_event)),
90 key_code_(ui::KeyboardCodeFromNative(native_event)),
91 character_(0),
92 unmodified_character_(0) {
93 }
94 #endif
95
96 KeyEvent::KeyEvent(ui::EventType type,
97 ui::KeyboardCode key_code,
67 int event_flags) 98 int event_flags)
68 : Event(type, event_flags), 99 : Event(type, event_flags),
69 key_code_(key_code), 100 key_code_(key_code),
70 character_(0), 101 character_(0),
71 unmodified_character_(0) { 102 unmodified_character_(0) {
72 } 103 }
73 104
74 // KeyEvent, private: --------------------------------------------------------- 105 // KeyEvent, private: ---------------------------------------------------------
75 106
76 // static 107 // static
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 case ui::VKEY_OEM_7: 199 case ui::VKEY_OEM_7:
169 return shift ? '"' : '\''; 200 return shift ? '"' : '\'';
170 default: 201 default:
171 return 0; 202 return 0;
172 } 203 }
173 } 204 }
174 205
175 //////////////////////////////////////////////////////////////////////////////// 206 ////////////////////////////////////////////////////////////////////////////////
176 // MouseEvent, public: 207 // MouseEvent, public:
177 208
209 MouseEvent::MouseEvent(const NativeEvent& native_event)
210 : LocatedEvent(native_event) {
211 }
212
178 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target) 213 MouseEvent::MouseEvent(const MouseEvent& model, View* source, View* target)
179 : LocatedEvent(model, source, target) { 214 : LocatedEvent(model, source, target) {
180 } 215 }
181 216
182 MouseEvent::MouseEvent(const TouchEvent& touch, 217 MouseEvent::MouseEvent(const TouchEvent& touch,
183 FromNativeEvent2 from_native) 218 FromNativeEvent2 from_native)
184 : LocatedEvent(touch.native_event_2(), from_native) { 219 : LocatedEvent(touch.native_event_2(), from_native) {
185 // The location of the event is correctly extracted from the native event. But 220 // The location of the event is correctly extracted from the native event. But
186 // it is necessary to update the event type. 221 // it is necessary to update the event type.
187 ui::EventType mtype = ui::ET_UNKNOWN; 222 ui::EventType mtype = ui::ET_UNKNOWN;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 292 }
258 293
259 //////////////////////////////////////////////////////////////////////////////// 294 ////////////////////////////////////////////////////////////////////////////////
260 // MouseWheelEvent, public: 295 // MouseWheelEvent, public:
261 296
262 // This value matches windows WHEEL_DELTA. 297 // This value matches windows WHEEL_DELTA.
263 // static 298 // static
264 const int MouseWheelEvent::kWheelDelta = 120; 299 const int MouseWheelEvent::kWheelDelta = 120;
265 300
266 } // namespace views 301 } // namespace views
OLDNEW
« ui/base/events.h ('K') | « views/events/event.h ('k') | views/events/event_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698