1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef VIEWS_EVENT_H_
#define VIEWS_EVENT_H_
#pragma once
#include "base/basictypes.h"
#include "base/time.h"
#include "ui/base/events.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/point.h"
#include "views/native_types.h"
#if defined(OS_LINUX)
typedef struct _GdkEventKey GdkEventKey;
#endif
#if defined(TOUCH_UI)
typedef union _XEvent XEvent;
#endif
namespace ui {
class OSExchangeData;
}
using ui::OSExchangeData;
namespace views {
class View;
////////////////////////////////////////////////////////////////////////////////
//
// Event class
//
// An event encapsulates an input event that can be propagated into view
// hierarchies. An event has a type, some flags and a time stamp.
//
// Each major event type has a corresponding Event subclass.
//
// Events are immutable but support copy
//
////////////////////////////////////////////////////////////////////////////////
class Event {
public:
const NativeEvent& native_event() const { return native_event_; }
ui::EventType type() const { return type_; }
const base::Time& time_stamp() const { return time_stamp_; }
int flags() const { return flags_; }
void set_flags(int flags) { flags_ = flags; }
// The following methods return true if the respective keys were pressed at
// the time the event was created.
bool IsShiftDown() const { return (flags_ & ui::EF_SHIFT_DOWN) != 0; }
bool IsControlDown() const { return (flags_ & ui::EF_CONTROL_DOWN) != 0; }
bool IsCapsLockDown() const { return (flags_ & ui::EF_CAPS_LOCK_DOWN) != 0; }
bool IsAltDown() const { return (flags_ & ui::EF_ALT_DOWN) != 0; }
bool IsMouseEvent() const {
return type_ == ui::ET_MOUSE_PRESSED ||
type_ == ui::ET_MOUSE_DRAGGED ||
type_ == ui::ET_MOUSE_RELEASED ||
type_ == ui::ET_MOUSE_MOVED ||
type_ == ui::ET_MOUSE_ENTERED ||
type_ == ui::ET_MOUSE_EXITED ||
type_ == ui::ET_MOUSEWHEEL;
}
#if defined(TOUCH_UI)
bool IsTouchEvent() const {
return type_ == ui::ET_TOUCH_RELEASED ||
type_ == ui::ET_TOUCH_PRESSED ||
type_ == ui::ET_TOUCH_MOVED ||
type_ == ui::ET_TOUCH_STATIONARY ||
type_ == ui::ET_TOUCH_CANCELLED;
}
#endif
#if defined(OS_WIN)
// Returns the EventFlags in terms of windows flags.
int GetWindowsFlags() const;
// Convert windows flags to views::Event flags
static int ConvertWindowsFlags(uint32 win_flags);
#elif defined(OS_LINUX)
// Convert the state member on a GdkEvent to views::Event flags
static int GetFlagsFromGdkState(int state);
#endif
protected:
Event(ui::EventType type, int flags);
Event(const Event& model)
: native_event_(model.native_event()),
type_(model.type()),
time_stamp_(model.time_stamp()),
flags_(model.flags()) {
}
private:
void operator=(const Event&);
NativeEvent native_event_;
ui::EventType type_;
base::Time time_stamp_;
int flags_;
};
////////////////////////////////////////////////////////////////////////////////
//
// LocatedEvent class
//
// A generic event that is used for any events that is located at a specific
// position in the screen.
//
////////////////////////////////////////////////////////////////////////////////
class LocatedEvent : public Event {
public:
LocatedEvent(ui::EventType type, const gfx::Point& location, int flags)
: Event(type, flags),
location_(location) {
}
// Create a new LocatedEvent which is identical to the provided model.
// If from / to views are provided, the model location will be converted
// from 'from' coordinate system to 'to' coordinate system
LocatedEvent(const LocatedEvent& model, View* from, View* to);
int x() const { return location_.x(); }
int y() const { return location_.y(); }
const gfx::Point& location() const { return location_; }
private:
gfx::Point location_;
};
////////////////////////////////////////////////////////////////////////////////
//
// MouseEvent class
//
// A mouse event is used for any input event related to the mouse.
//
////////////////////////////////////////////////////////////////////////////////
class MouseEvent : public LocatedEvent {
public:
// Create a new mouse event
MouseEvent(ui::EventType type, int x, int y, int flags)
: LocatedEvent(type, gfx::Point(x, y), flags) {
}
// Create a new mouse event from a type and a point. If from / to views
// are provided, the point will be converted from 'from' coordinate system to
// 'to' coordinate system.
MouseEvent(ui::EventType type,
View* from,
View* to,
const gfx::Point &l,
int flags);
// Create a new MouseEvent which is identical to the provided model.
// If from / to views are provided, the model location will be converted
// from 'from' coordinate system to 'to' coordinate system
MouseEvent(const MouseEvent& model, View* from, View* to);
#if defined(TOUCH_UI)
// Create a mouse event from an X mouse event.
explicit MouseEvent(XEvent* xevent);
#endif
// Conveniences to quickly test what button is down
bool IsOnlyLeftMouseButton() const {
return (flags() & ui::EF_LEFT_BUTTON_DOWN) &&
!(flags() & (ui::EF_MIDDLE_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN));
}
bool IsLeftMouseButton() const {
return (flags() & ui::EF_LEFT_BUTTON_DOWN) != 0;
}
bool IsOnlyMiddleMouseButton() const {
return (flags() & ui::EF_MIDDLE_BUTTON_DOWN) &&
!(flags() & (ui::EF_LEFT_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN));
}
bool IsMiddleMouseButton() const {
return (flags() & ui::EF_MIDDLE_BUTTON_DOWN) != 0;
}
bool IsOnlyRightMouseButton() const {
return (flags() & ui::EF_RIGHT_BUTTON_DOWN) &&
!(flags() & (ui::EF_LEFT_BUTTON_DOWN | ui::EF_MIDDLE_BUTTON_DOWN));
}
bool IsRightMouseButton() const {
return (flags() & ui::EF_RIGHT_BUTTON_DOWN) != 0;
}
private:
DISALLOW_COPY_AND_ASSIGN(MouseEvent);
};
#if defined(TOUCH_UI)
////////////////////////////////////////////////////////////////////////////////
//
// TouchEvent class
//
// A touch event is generated by touch screen and advanced track
// pad devices. There is a deliberate direct correspondence between
// TouchEvent and PlatformTouchPoint.
//
////////////////////////////////////////////////////////////////////////////////
class TouchEvent : public LocatedEvent {
public:
// Create a new touch event.
TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id);
// Create a new touch event from a type and a point. If from / to views
// are provided, the point will be converted from 'from' coordinate system to
// 'to' coordinate system.
TouchEvent(ui::EventType type,
View* from,
View* to,
const gfx::Point& l,
int flags,
int touch_id);
// Create a new TouchEvent which is identical to the provided model.
// If from / to views are provided, the model location will be converted
// from 'from' coordinate system to 'to' coordinate system.
TouchEvent(const TouchEvent& model, View* from, View* to);
#if defined(HAVE_XINPUT2)
explicit TouchEvent(XEvent* xev);
#endif
bool identity() const { return touch_id_; }
private:
// The identity (typically finger) of the touch starting at 0 and incrementing
// for each separable additional touch that the hardware can detect.
const int touch_id_;
DISALLOW_COPY_AND_ASSIGN(TouchEvent);
};
#endif
////////////////////////////////////////////////////////////////////////////////
//
// KeyEvent class
//
// A key event is used for any input event related to the keyboard.
// Note: this event is about key pressed, not typed characters.
//
////////////////////////////////////////////////////////////////////////////////
class KeyEvent : public Event {
public:
// Create a new key event
KeyEvent(ui::EventType type,
ui::KeyboardCode key_code,
int event_flags,
int repeat_count,
int message_flags);
#if defined(OS_WIN)
KeyEvent(ui::EventType type,
ui::KeyboardCode key_code,
int event_flags,
int repeat_count,
int message_flags,
UINT message);
#endif
#if defined(OS_LINUX)
explicit KeyEvent(const GdkEventKey* event);
const GdkEventKey* native_event() const { return native_event_; }
#endif
#if defined(TOUCH_UI)
// Create a key event from an X key event.
explicit KeyEvent(XEvent* xevent);
#endif
ui::KeyboardCode key_code() const { return key_code_; }
#if defined(OS_WIN)
bool IsExtendedKey() const;
UINT message() const { return message_; }
#endif
int repeat_count() const { return repeat_count_; }
#if defined(OS_WIN)
static int GetKeyStateFlags();
#endif
private:
ui::KeyboardCode key_code_;
int repeat_count_;
int message_flags_;
#if defined(OS_WIN)
UINT message_;
#elif defined(OS_LINUX)
const GdkEventKey* native_event_;
#endif
DISALLOW_COPY_AND_ASSIGN(KeyEvent);
};
////////////////////////////////////////////////////////////////////////////////
//
// MouseWheelEvent class
//
// A MouseWheelEvent is used to propagate mouse wheel user events.
// Note: e.GetOffset() > 0 means scroll up.
//
////////////////////////////////////////////////////////////////////////////////
class MouseWheelEvent : public LocatedEvent {
public:
// Create a new key event
MouseWheelEvent(int offset, int x, int y, int flags)
: LocatedEvent(ui::ET_MOUSEWHEEL, gfx::Point(x, y), flags),
offset_(offset) {
}
#if defined(TOUCH_UI)
explicit MouseWheelEvent(XEvent* xev);
#endif
int offset() const { return offset_; }
private:
int offset_;
DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent);
};
////////////////////////////////////////////////////////////////////////////////
//
// DropTargetEvent class
//
// A DropTargetEvent is sent to the view the mouse is over during a drag and
// drop operation.
//
////////////////////////////////////////////////////////////////////////////////
class DropTargetEvent : public LocatedEvent {
public:
DropTargetEvent(const OSExchangeData& data,
int x,
int y,
int source_operations)
: LocatedEvent(ui::ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0),
data_(data),
source_operations_(source_operations) {
}
const OSExchangeData& data() const { return data_; }
int source_operations() const { return source_operations_; }
private:
// Data associated with the drag/drop session.
const OSExchangeData& data_;
// Bitmask of supported ui::DragDropTypes::DragOperation by the source.
int source_operations_;
DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
};
} // namespace views
#endif // VIEWS_EVENT_H_
|