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
|
// Copyright (c) 2011 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 UI_VIEWS_EVENTS_EVENT_H_
#define UI_VIEWS_EVENTS_EVENT_H_
#pragma once
#include "base/basictypes.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/point.h"
#include "ui/views/native_types.h"
class OSExchangeData;
namespace ui {
class View;
class Event {
public:
// Event types.
enum EventType { ET_UNKNOWN = 0,
ET_MOUSE_PRESSED,
ET_MOUSE_DRAGGED,
ET_MOUSE_RELEASED,
ET_MOUSE_MOVED,
ET_MOUSE_ENTERED,
ET_MOUSE_EXITED,
ET_KEY_PRESSED,
ET_KEY_RELEASED,
ET_MOUSEWHEEL,
ET_DROP_TARGET_EVENT,
ET_FOCUS_CHANGE };
// Event flags currently supported. Although this is a "views"
// file, this header is used on non-views platforms (e.g. OSX). For
// example, these EventFlags are used by the automation provider for
// all platforms.
enum EventFlags { EF_CAPS_LOCK_DOWN = 1 << 0,
EF_SHIFT_DOWN = 1 << 1,
EF_CONTROL_DOWN = 1 << 2,
EF_ALT_DOWN = 1 << 3,
EF_LEFT_BUTTON_DOWN = 1 << 4,
EF_MIDDLE_BUTTON_DOWN = 1 << 5,
EF_RIGHT_BUTTON_DOWN = 1 << 6,
EF_COMMAND_DOWN = 1 << 7, // Only useful on OSX
};
EventType type() const { return type_; }
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_ & EF_SHIFT_DOWN) != 0; }
bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; }
bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; }
bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; }
// Return a mask of active modifier keycodes from
// ui/base/keycodes/keyboard_codes.h
int GetModifiers() const;
// Returns true if the event is any kind of mouse event.
bool IsMouseEvent() const {
return type_ == ET_MOUSE_PRESSED ||
type_ == ET_MOUSE_RELEASED ||
type_ == ET_MOUSE_MOVED ||
type_ == ET_MOUSE_EXITED ||
type_ == ET_MOUSEWHEEL;
}
protected:
Event(EventType type, int flags);
private:
EventType type_;
int flags_;
DISALLOW_COPY_AND_ASSIGN(Event);
};
class LocatedEvent : public Event {
public:
int x() const { return location_.x(); }
int y() const { return location_.y(); }
const gfx::Point& location() const { return location_; }
protected:
// Constructors called from subclasses.
// Simple initialization from cracked metadata.
LocatedEvent(EventType type, const gfx::Point& location, int flags);
// During event processing, event locations are translated from the
// coordinates of a source View to a target as the tree is descended. This
// translation occurs by constructing a new event from another event object,
// specifying a |source| and |target| View to facilitate coordinate
// conversion. Events that are processed in this manner will have a similar
// constructor that calls into this one.
LocatedEvent(const LocatedEvent& other, View* source, View* target);
private:
gfx::Point location_;
DISALLOW_COPY_AND_ASSIGN(LocatedEvent);
};
class MouseEvent : public LocatedEvent {
public:
// Flags specific to mouse events
enum MouseEventFlags {
EF_IS_DOUBLE_CLICK = 1 << 16,
EF_IS_NON_CLIENT = 1 << 17
};
explicit MouseEvent(NativeEvent native_event);
MouseEvent(const MouseEvent& other, View* source, View* target);
// Conveniences to quickly test what button is down:
bool IsOnlyLeftMouseButton() const {
return (flags() & EF_LEFT_BUTTON_DOWN) &&
!(flags() & (EF_MIDDLE_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN));
}
bool IsLeftMouseButton() const {
return (flags() & EF_LEFT_BUTTON_DOWN) != 0;
}
bool IsOnlyMiddleMouseButton() const {
return (flags() & EF_MIDDLE_BUTTON_DOWN) &&
!(flags() & (EF_LEFT_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN));
}
bool IsMiddleMouseButton() const {
return (flags() & EF_MIDDLE_BUTTON_DOWN) != 0;
}
bool IsOnlyRightMouseButton() const {
return (flags() & EF_RIGHT_BUTTON_DOWN) &&
!(flags() & (EF_LEFT_BUTTON_DOWN | EF_MIDDLE_BUTTON_DOWN));
}
bool IsRightMouseButton() const {
return (flags() & EF_RIGHT_BUTTON_DOWN) != 0;
}
private:
DISALLOW_COPY_AND_ASSIGN(MouseEvent);
};
class KeyEvent : public Event {
public:
explicit KeyEvent(NativeEvent native_event);
KeyboardCode key_code() const { return key_code_; }
int repeat_count() const { return repeat_count_; }
private:
KeyboardCode key_code_;
int repeat_count_;
int message_flags_;
DISALLOW_COPY_AND_ASSIGN(KeyEvent);
};
class MouseWheelEvent : public LocatedEvent {
public:
explicit MouseWheelEvent(NativeEvent native_event);
int offset() const { return offset_; }
private:
int offset_;
DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent);
};
/*
class DropTargetEvent : public LocatedEvent {
public:
explicit DropTargetEvent(NativeEvent native_event);
const OSExchangeData& data() const { return data_; }
int source_operations() const { return source_operations_; }
private:
const OSExchangeData& data_;
int source_operations_;
DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
};
*/
} // namespace ui
#endif // UI_VIEWS_EVENTS_EVENT_H_
|