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

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) 16 #if defined(OS_LINUX)
(...skipping 21 matching lines...) Expand all
38 // hierarchies. An event has a type, some flags and a time stamp. 38 // hierarchies. An event has a type, some flags and a time stamp.
39 // 39 //
40 // Each major event type has a corresponding Event subclass. 40 // Each major event type has a corresponding Event subclass.
41 // 41 //
42 // Events are immutable but support copy 42 // Events are immutable but support copy
43 // 43 //
44 //////////////////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////////////////
45 class Event { 45 class Event {
46 public: 46 public:
47 const NativeEvent& native_event() const { return native_event_; } 47 const NativeEvent& native_event() const { return native_event_; }
48 const NativeEvent2& native_event_2() const { return native_event_2_; }
48 ui::EventType type() const { return type_; } 49 ui::EventType type() const { return type_; }
49 const base::Time& time_stamp() const { return time_stamp_; } 50 const base::Time& time_stamp() const { return time_stamp_; }
50 int flags() const { return flags_; } 51 int flags() const { return flags_; }
51 void set_flags(int flags) { flags_ = flags; } 52 void set_flags(int flags) { flags_ = flags; }
52 53
53 // The following methods return true if the respective keys were pressed at 54 // The following methods return true if the respective keys were pressed at
54 // the time the event was created. 55 // the time the event was created.
55 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; } 56 bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; }
56 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; } 57 bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; }
57 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; } 58 bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; }
(...skipping 25 matching lines...) Expand all
83 84
84 // Convert windows flags to views::Event flags 85 // Convert windows flags to views::Event flags
85 static int ConvertWindowsFlags(uint32 win_flags); 86 static int ConvertWindowsFlags(uint32 win_flags);
86 #elif defined(OS_LINUX) 87 #elif defined(OS_LINUX)
87 // Convert the state member on a GdkEvent to views::Event flags 88 // Convert the state member on a GdkEvent to views::Event flags
88 static int GetFlagsFromGdkState(int state); 89 static int GetFlagsFromGdkState(int state);
89 #endif 90 #endif
90 91
91 protected: 92 protected:
92 Event(ui::EventType type, int flags); 93 Event(ui::EventType type, int flags);
94 Event(NativeEvent native_event, ui::EventType type, int flags);
95 // Because the world is complicated, sometimes we have two different kinds of
96 // NativeEvent in play in the same executable. See native_types.h for the tale
97 // of woe.
rjkroege 2011/02/10 21:15:26 I'd a TODO here or in native_types.h that was a li
Ben Goodger (Google) 2011/02/10 21:22:37 I rewrote the comment in native_types.h as: // O
98 Event(NativeEvent2 native_event, ui::EventType type, int flags);
93 99
94 Event(const Event& model) 100 Event(const Event& model)
95 : native_event_(model.native_event()), 101 : native_event_(model.native_event()),
96 type_(model.type()), 102 type_(model.type()),
97 time_stamp_(model.time_stamp()), 103 time_stamp_(model.time_stamp()),
98 flags_(model.flags()) { 104 flags_(model.flags()) {
99 } 105 }
100 106
101 private: 107 private:
102 void operator=(const Event&); 108 void operator=(const Event&);
103 109
104 NativeEvent native_event_; 110 NativeEvent native_event_;
111 NativeEvent2 native_event_2_;
105 ui::EventType type_; 112 ui::EventType type_;
106 base::Time time_stamp_; 113 base::Time time_stamp_;
107 int flags_; 114 int flags_;
108 }; 115 };
109 116
110 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
111 // 118 //
112 // LocatedEvent class 119 // LocatedEvent class
113 // 120 //
114 // A generic event that is used for any events that is located at a specific 121 // 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: 246 private:
240 // The identity (typically finger) of the touch starting at 0 and incrementing 247 // The identity (typically finger) of the touch starting at 0 and incrementing
241 // for each separable additional touch that the hardware can detect. 248 // for each separable additional touch that the hardware can detect.
242 const int touch_id_; 249 const int touch_id_;
243 250
244 DISALLOW_COPY_AND_ASSIGN(TouchEvent); 251 DISALLOW_COPY_AND_ASSIGN(TouchEvent);
245 }; 252 };
246 #endif 253 #endif
247 254
248 //////////////////////////////////////////////////////////////////////////////// 255 ////////////////////////////////////////////////////////////////////////////////
249 //
250 // KeyEvent class 256 // KeyEvent class
251 // 257 //
252 // A key event is used for any input event related to the keyboard. 258 // KeyEvent encapsulates keyboard input events - key press and release.
253 // Note: this event is about key pressed, not typed characters.
254 // 259 //
255 ////////////////////////////////////////////////////////////////////////////////
256 class KeyEvent : public Event { 260 class KeyEvent : public Event {
257 public: 261 public:
258 // Create a new key event 262 explicit KeyEvent(NativeEvent native_event);
263 explicit KeyEvent(NativeEvent2 native_event_2);
264
265 // Creates a new KeyEvent synthetically (i.e. not in response to an input
266 // event from the host environment). This is typically only used in testing as
267 // some metadata obtainable from the underlying native event is not present.
268 // TODO(beng): see if we can kill this.
259 KeyEvent(ui::EventType type, 269 KeyEvent(ui::EventType type,
260 ui::KeyboardCode key_code, 270 ui::KeyboardCode key_code,
261 int event_flags, 271 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 272
283 ui::KeyboardCode key_code() const { return key_code_; } 273 ui::KeyboardCode key_code() const { return key_code_; }
284 274
285 #if defined(OS_WIN) 275 private:
286 bool IsExtendedKey() const; 276 ui::KeyboardCode key_code_;
287 277
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); 278 DISALLOW_COPY_AND_ASSIGN(KeyEvent);
308 }; 279 };
309 280
310 //////////////////////////////////////////////////////////////////////////////// 281 ////////////////////////////////////////////////////////////////////////////////
311 // 282 //
312 // MouseWheelEvent class 283 // MouseWheelEvent class
313 // 284 //
314 // A MouseWheelEvent is used to propagate mouse wheel user events. 285 // A MouseWheelEvent is used to propagate mouse wheel user events.
315 // Note: e.GetOffset() > 0 means scroll up. 286 // Note: e.GetOffset() > 0 means scroll up.
316 // 287 //
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 const OSExchangeData& data_; 333 const OSExchangeData& data_;
363 334
364 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. 335 // Bitmask of supported ui::DragDropTypes::DragOperation by the source.
365 int source_operations_; 336 int source_operations_;
366 337
367 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); 338 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
368 }; 339 };
369 340
370 } // namespace views 341 } // namespace views
371 342
372 #endif // VIEWS_EVENT_H_ 343 #endif // VIEWS_EVENTS_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698