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

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

Issue 6487002: Add a new constructor to KeyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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) 2006-2008 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 #ifndef VIEWS_EVENT_H_ 5 #ifndef VIEWS_EVENTS_EVENT_H_
6 #define VIEWS_EVENT_H_ 6 #define VIEWS_EVENTS_EVENT_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "ui/base/events.h" 11 #include "ui/base/events.h"
12 #include "ui/base/keycodes/keyboard_codes.h" 12 #include "ui/base/keycodes/keyboard_codes.h"
13 #include "ui/gfx/point.h" 13 #include "ui/gfx/point.h"
14 #include "views/native_types.h" 14 #include "views/native_types.h"
15 15
16 #if defined(OS_LINUX)
17 typedef struct _GdkEventKey GdkEventKey;
18 #endif
19
20 #if defined(TOUCH_UI) 16 #if defined(TOUCH_UI)
21 typedef union _XEvent XEvent; 17 typedef union _XEvent XEvent;
22 #endif 18 #endif
23 19
24 namespace ui { 20 namespace ui {
25 class OSExchangeData; 21 class OSExchangeData;
26 } 22 }
27 using ui::OSExchangeData; 23 using ui::OSExchangeData;
28 24
29 namespace views { 25 namespace views {
30 26
31 class View; 27 class View;
32 28
33 //////////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////////
34 // 30 //
35 // Event class 31 // Event class
36 // 32 //
37 // An event encapsulates an input event that can be propagated into view 33 // An event encapsulates an input event that can be propagated into view
38 // hierarchies. An event has a type, some flags and a time stamp. 34 // hierarchies. An event has a type, some flags and a time stamp.
39 // 35 //
40 // Each major event type has a corresponding Event subclass. 36 // Each major event type has a corresponding Event subclass.
41 // 37 //
42 // Events are immutable but support copy 38 // Events are immutable but support copy
43 // 39 //
44 //////////////////////////////////////////////////////////////////////////////// 40 ////////////////////////////////////////////////////////////////////////////////
45 class Event { 41 class Event {
46 public: 42 public:
47 const NativeEvent& native_event() const { return native_event_; } 43 const NativeEvent& native_event() const { return native_event_; }
44 const NativeEvent2& native_event_2() const { return native_event_2_; }
48 ui::EventType type() const { return type_; } 45 ui::EventType type() const { return type_; }
49 const base::Time& time_stamp() const { return time_stamp_; } 46 const base::Time& time_stamp() const { return time_stamp_; }
50 int flags() const { return flags_; } 47 int flags() const { return flags_; }
51 void set_flags(int flags) { flags_ = flags; } 48 void set_flags(int flags) { flags_ = flags; }
52 49
53 // The following methods return true if the respective keys were pressed at 50 // The following methods return true if the respective keys were pressed at
54 // the time the event was created. 51 // the time the event was created.
55 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; } 52 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; }
56 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; } 53 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; }
57 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; } 54 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; }
(...skipping 25 matching lines...) Expand all
83 80
84 // Convert windows flags to views::Event flags 81 // Convert windows flags to views::Event flags
85 static int ConvertWindowsFlags(uint32 win_flags); 82 static int ConvertWindowsFlags(uint32 win_flags);
86 #elif defined(OS_LINUX) 83 #elif defined(OS_LINUX)
87 // Convert the state member on a GdkEvent to views::Event flags 84 // Convert the state member on a GdkEvent to views::Event flags
88 static int GetFlagsFromGdkState(int state); 85 static int GetFlagsFromGdkState(int state);
89 #endif 86 #endif
90 87
91 protected: 88 protected:
92 Event(ui::EventType type, int flags); 89 Event(ui::EventType type, int flags);
90 Event(NativeEvent native_event, ui::EventType type, int flags);
91 // Because the world is complicated, sometimes we have two different kinds of
92 // NativeEvent in play in the same executable. See native_types.h for the tale
93 // of woe.
94 Event(NativeEvent2 native_event, ui::EventType type, int flags);
93 95
94 Event(const Event& model) 96 Event(const Event& model)
95 : native_event_(model.native_event()), 97 : native_event_(model.native_event()),
96 type_(model.type()), 98 type_(model.type()),
97 time_stamp_(model.time_stamp()), 99 time_stamp_(model.time_stamp()),
98 flags_(model.flags()) { 100 flags_(model.flags()) {
99 } 101 }
100 102
101 private: 103 private:
102 void operator=(const Event&); 104 void operator=(const Event&);
103 105
106 // Safely initializes the native event members of this class.
107 void Init();
108 void InitWithNativeEvent(NativeEvent native_event);
109 void InitWithNativeEvent2(NativeEvent2 native_event_2);
110
104 NativeEvent native_event_; 111 NativeEvent native_event_;
112 NativeEvent2 native_event_2_;
105 ui::EventType type_; 113 ui::EventType type_;
106 base::Time time_stamp_; 114 base::Time time_stamp_;
107 int flags_; 115 int flags_;
108 }; 116 };
109 117
110 //////////////////////////////////////////////////////////////////////////////// 118 ////////////////////////////////////////////////////////////////////////////////
111 // 119 //
112 // LocatedEvent class 120 // LocatedEvent class
113 // 121 //
114 // A generic event that is used for any events that is located at a specific 122 // A generic event that is used for any events that is located at a specific
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 private: 247 private:
240 // The identity (typically finger) of the touch starting at 0 and incrementing 248 // The identity (typically finger) of the touch starting at 0 and incrementing
241 // for each separable additional touch that the hardware can detect. 249 // for each separable additional touch that the hardware can detect.
242 const int touch_id_; 250 const int touch_id_;
243 251
244 DISALLOW_COPY_AND_ASSIGN(TouchEvent); 252 DISALLOW_COPY_AND_ASSIGN(TouchEvent);
245 }; 253 };
246 #endif 254 #endif
247 255
248 //////////////////////////////////////////////////////////////////////////////// 256 ////////////////////////////////////////////////////////////////////////////////
249 //
250 // KeyEvent class 257 // KeyEvent class
251 // 258 //
252 // A key event is used for any input event related to the keyboard. 259 // KeyEvent encapsulates keyboard input events - key press and release.
253 // Note: this event is about key pressed, not typed characters.
254 // 260 //
255 ////////////////////////////////////////////////////////////////////////////////
256 class KeyEvent : public Event { 261 class KeyEvent : public Event {
257 public: 262 public:
258 // Create a new key event 263 explicit KeyEvent(NativeEvent native_event);
264 explicit KeyEvent(NativeEvent2 native_event_2);
265
266 // Creates a new KeyEvent synthetically (i.e. not in response to an input
267 // event from the host environment). This is typically only used in testing as
268 // some metadata obtainable from the underlying native event is not present.
269 // TODO(beng): see if we can kill this.
259 KeyEvent(ui::EventType type, 270 KeyEvent(ui::EventType type,
260 ui::KeyboardCode key_code, 271 ui::KeyboardCode key_code,
261 int event_flags, 272 int event_flags);
262 int repeat_count,
263 int message_flags);
264
265 #if defined(OS_WIN)
266 KeyEvent(ui::EventType type,
267 ui::KeyboardCode key_code,
268 int event_flags,
269 int repeat_count,
270 int message_flags,
271 UINT message);
272 #endif
273 #if defined(OS_LINUX)
274 explicit KeyEvent(const GdkEventKey* event);
275
276 const GdkEventKey* native_event() const { return native_event_; }
277 #endif
278 #if defined(TOUCH_UI)
279 // Create a key event from an X key event.
280 explicit KeyEvent(XEvent* xevent);
281 #endif
282 273
283 ui::KeyboardCode key_code() const { return key_code_; } 274 ui::KeyboardCode key_code() const { return key_code_; }
284 275
285 #if defined(OS_WIN) 276 private:
286 bool IsExtendedKey() const; 277 ui::KeyboardCode key_code_;
287 278
288 UINT message() const { return message_; }
289 #endif
290
291 int repeat_count() const { return repeat_count_; }
292
293 #if defined(OS_WIN)
294 static int GetKeyStateFlags();
295 #endif
296
297 private:
298
299 ui::KeyboardCode key_code_;
300 int repeat_count_;
301 int message_flags_;
302 #if defined(OS_WIN)
303 UINT message_;
304 #elif defined(OS_LINUX)
305 const GdkEventKey* native_event_;
306 #endif
307 DISALLOW_COPY_AND_ASSIGN(KeyEvent); 279 DISALLOW_COPY_AND_ASSIGN(KeyEvent);
308 }; 280 };
309 281
310 //////////////////////////////////////////////////////////////////////////////// 282 ////////////////////////////////////////////////////////////////////////////////
311 // 283 //
312 // MouseWheelEvent class 284 // MouseWheelEvent class
313 // 285 //
314 // A MouseWheelEvent is used to propagate mouse wheel user events. 286 // A MouseWheelEvent is used to propagate mouse wheel user events.
315 // Note: e.GetOffset() > 0 means scroll up. 287 // Note: e.GetOffset() > 0 means scroll up.
316 // 288 //
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 const OSExchangeData& data_; 334 const OSExchangeData& data_;
363 335
364 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. 336 // Bitmask of supported ui::DragDropTypes::DragOperation by the source.
365 int source_operations_; 337 int source_operations_;
366 338
367 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); 339 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
368 }; 340 };
369 341
370 } // namespace views 342 } // namespace views
371 343
372 #endif // VIEWS_EVENT_H_ 344 #endif // VIEWS_EVENTS_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698