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 #ifndef UI_AURA_EVENT_H_ | 5 #ifndef UI_AURA_EVENT_H_ |
6 #define UI_AURA_EVENT_H_ | 6 #define UI_AURA_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/aura/aura_export.h" | 11 #include "ui/aura/aura_export.h" |
12 #include "ui/base/events.h" | 12 #include "ui/base/events.h" |
13 #include "ui/base/keycodes/keyboard_codes.h" | 13 #include "ui/base/keycodes/keyboard_codes.h" |
14 #include "ui/gfx/point.h" | 14 #include "ui/gfx/point.h" |
15 | 15 |
16 #if defined(USE_X11) | |
17 typedef union _XEvent XEvent; | |
18 #endif | |
19 | |
20 namespace aura { | 16 namespace aura { |
21 | 17 |
22 #if defined(OS_WIN) | |
23 typedef MSG NativeEvent; | |
24 #elif defined(USE_X11) | |
25 typedef XEvent* NativeEvent; | |
26 #endif | |
27 | |
28 class Window; | 18 class Window; |
29 | 19 |
30 class AURA_EXPORT Event { | 20 class AURA_EXPORT Event { |
31 public: | 21 public: |
32 const NativeEvent& native_event() const { return native_event_; } | 22 const ui::NativeEvent& native_event() const { return native_event_; } |
33 ui::EventType type() const { return type_; } | 23 ui::EventType type() const { return type_; } |
34 const base::Time& time_stamp() const { return time_stamp_; } | 24 const base::Time& time_stamp() const { return time_stamp_; } |
35 int flags() const { return flags_; } | 25 int flags() const { return flags_; } |
36 | 26 |
37 protected: | 27 protected: |
38 Event(ui::EventType type, int flags); | 28 Event(ui::EventType type, int flags); |
39 Event(NativeEvent native_event, ui::EventType type, int flags); | 29 Event(const ui::NativeEvent& native_event, ui::EventType type, int flags); |
40 Event(const Event& copy); | 30 Event(const Event& copy); |
41 void set_type(ui::EventType type) { type_ = type; } | 31 void set_type(ui::EventType type) { type_ = type; } |
42 | 32 |
43 private: | 33 private: |
44 void operator=(const Event&); | 34 void operator=(const Event&); |
45 | 35 |
46 // Safely initializes the native event members of this class. | 36 // Safely initializes the native event members of this class. |
47 void Init(); | 37 void Init(); |
48 void InitWithNativeEvent(NativeEvent native_event); | 38 void InitWithNativeEvent(const ui::NativeEvent& native_event); |
49 | 39 |
50 NativeEvent native_event_; | 40 ui::NativeEvent native_event_; |
51 ui::EventType type_; | 41 ui::EventType type_; |
52 base::Time time_stamp_; | 42 base::Time time_stamp_; |
53 int flags_; | 43 int flags_; |
54 }; | 44 }; |
55 | 45 |
56 class AURA_EXPORT LocatedEvent : public Event { | 46 class AURA_EXPORT LocatedEvent : public Event { |
57 public: | 47 public: |
58 int x() const { return location_.x(); } | 48 int x() const { return location_.x(); } |
59 int y() const { return location_.y(); } | 49 int y() const { return location_.y(); } |
60 gfx::Point location() const { return location_; } | 50 gfx::Point location() const { return location_; } |
61 | 51 |
62 protected: | 52 protected: |
63 explicit LocatedEvent(NativeEvent native_event); | 53 explicit LocatedEvent(const ui::NativeEvent& native_event); |
64 | 54 |
65 // Create a new LocatedEvent which is identical to the provided model. | 55 // Create a new LocatedEvent which is identical to the provided model. |
66 // If source / target windows are provided, the model location will be | 56 // If source / target windows are provided, the model location will be |
67 // converted from |source| coordinate system to |target| coordinate system. | 57 // converted from |source| coordinate system to |target| coordinate system. |
68 LocatedEvent(const LocatedEvent& model, Window* source, Window* target); | 58 LocatedEvent(const LocatedEvent& model, Window* source, Window* target); |
69 | 59 |
70 // Used for synthetic events in testing. | 60 // Used for synthetic events in testing. |
71 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); | 61 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); |
72 | 62 |
73 gfx::Point location_; | 63 gfx::Point location_; |
74 | 64 |
75 private: | 65 private: |
76 DISALLOW_COPY_AND_ASSIGN(LocatedEvent); | 66 DISALLOW_COPY_AND_ASSIGN(LocatedEvent); |
77 }; | 67 }; |
78 | 68 |
79 class AURA_EXPORT MouseEvent : public LocatedEvent { | 69 class AURA_EXPORT MouseEvent : public LocatedEvent { |
80 public: | 70 public: |
81 explicit MouseEvent(NativeEvent native_event); | 71 explicit MouseEvent(const ui::NativeEvent& native_event); |
82 | 72 |
83 // Create a new MouseEvent which is identical to the provided model. | 73 // Create a new MouseEvent which is identical to the provided model. |
84 // If source / target windows are provided, the model location will be | 74 // If source / target windows are provided, the model location will be |
85 // converted from |source| coordinate system to |target| coordinate system. | 75 // converted from |source| coordinate system to |target| coordinate system. |
86 MouseEvent(const MouseEvent& model, Window* source, Window* target); | 76 MouseEvent(const MouseEvent& model, Window* source, Window* target); |
87 MouseEvent(const MouseEvent& model, | 77 MouseEvent(const MouseEvent& model, |
88 Window* source, | 78 Window* source, |
89 Window* target, | 79 Window* target, |
90 ui::EventType type); | 80 ui::EventType type); |
91 | 81 |
92 // Used for synthetic events in testing. | 82 // Used for synthetic events in testing. |
93 MouseEvent(ui::EventType type, const gfx::Point& location, int flags); | 83 MouseEvent(ui::EventType type, const gfx::Point& location, int flags); |
94 | 84 |
95 private: | 85 private: |
96 DISALLOW_COPY_AND_ASSIGN(MouseEvent); | 86 DISALLOW_COPY_AND_ASSIGN(MouseEvent); |
97 }; | 87 }; |
98 | 88 |
99 class AURA_EXPORT KeyEvent : public Event { | 89 class AURA_EXPORT KeyEvent : public Event { |
100 public: | 90 public: |
101 explicit KeyEvent(NativeEvent native_event); | 91 explicit KeyEvent(const ui::NativeEvent& native_event); |
102 | 92 |
103 // Used for synthetic events in testing. | 93 // Used for synthetic events in testing. |
104 KeyEvent(ui::EventType type, | 94 KeyEvent(ui::EventType type, |
105 ui::KeyboardCode key_code, | 95 ui::KeyboardCode key_code, |
106 int flags); | 96 int flags); |
107 | 97 |
108 ui::KeyboardCode key_code() const { return key_code_; } | 98 ui::KeyboardCode key_code() const { return key_code_; } |
109 | 99 |
110 private: | 100 private: |
111 ui::KeyboardCode key_code_; | 101 ui::KeyboardCode key_code_; |
112 }; | 102 }; |
113 | 103 |
114 } // namespace aura | 104 } // namespace aura |
115 | 105 |
116 #endif // UI_AURA_EVENT_H_ | 106 #endif // UI_AURA_EVENT_H_ |
OLD | NEW |