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

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

Issue 6286013: V2 (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
« no previous file with comments | « ui/views/events/drag_controller.h ('k') | ui/views/events/event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef UI_VIEWS_EVENTS_EVENT_H_
6 #define UI_VIEWS_EVENTS_EVENT_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "gfx/point.h"
11 #include "ui/base/keycodes/keyboard_codes.h"
12 #include "ui/views/native_types.h"
13
14 class OSExchangeData;
15
16 namespace ui {
17
18 class View;
19
20 class Event {
21 public:
22 // Event types.
23 enum EventType { ET_UNKNOWN = 0,
24 ET_MOUSE_PRESSED,
25 ET_MOUSE_DRAGGED,
26 ET_MOUSE_RELEASED,
27 ET_MOUSE_MOVED,
28 ET_MOUSE_ENTERED,
29 ET_MOUSE_EXITED,
30 ET_KEY_PRESSED,
31 ET_KEY_RELEASED,
32 ET_MOUSEWHEEL,
33 ET_DROP_TARGET_EVENT };
34
35 // Event flags currently supported. Although this is a "views"
36 // file, this header is used on non-views platforms (e.g. OSX). For
37 // example, these EventFlags are used by the automation provider for
38 // all platforms.
39 enum EventFlags { EF_CAPS_LOCK_DOWN = 1 << 0,
40 EF_SHIFT_DOWN = 1 << 1,
41 EF_CONTROL_DOWN = 1 << 2,
42 EF_ALT_DOWN = 1 << 3,
43 EF_LEFT_BUTTON_DOWN = 1 << 4,
44 EF_MIDDLE_BUTTON_DOWN = 1 << 5,
45 EF_RIGHT_BUTTON_DOWN = 1 << 6,
46 EF_COMMAND_DOWN = 1 << 7, // Only useful on OSX
47 };
48
49 EventType type() const { return type_; }
50 int flags() const { return flags_; }
51 void set_flags(int flags) { flags_ = flags; }
52
53 // The following methods return true if the respective keys were pressed at
54 // the time the event was created.
55 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; }
56 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; }
57 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; }
58 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; }
59
60 // Returns true if the event is any kind of mouse event.
61 bool IsMouseEvent() const {
62 return type_ == ET_MOUSE_PRESSED ||
63 type_ == ET_MOUSE_RELEASED ||
64 type_ == ET_MOUSE_MOVED ||
65 type_ == ET_MOUSE_EXITED ||
66 type_ == ET_MOUSEWHEEL;
67 }
68
69 protected:
70 Event(EventType type, int flags);
71
72 private:
73 EventType type_;
74 int flags_;
75
76 DISALLOW_COPY_AND_ASSIGN(Event);
77 };
78
79 class LocatedEvent : public Event {
80 public:
81 int x() const { return location_.x(); }
82 int y() const { return location_.y(); }
83 const gfx::Point& location() const { return location_; }
84
85 protected:
86 // Constructors called from subclasses.
87
88 // Simple initialization from cracked metadata.
89 LocatedEvent(EventType type, const gfx::Point& location, int flags);
90
91 // During event processing, event locations are translated from the
92 // coordinates of a source View to a target as the tree is descended. This
93 // translation occurs by constructing a new event from another event object,
94 // specifying a |source| and |target| View to facilitate coordinate
95 // conversion. Events that are processed in this manner will have a similar
96 // constructor that calls into this one.
97 LocatedEvent(const LocatedEvent& other, View* source, View* target);
98
99 private:
100 gfx::Point location_;
101
102 DISALLOW_COPY_AND_ASSIGN(LocatedEvent);
103 };
104
105 class MouseEvent : public LocatedEvent {
106 public:
107 // Flags specific to mouse events
108 enum MouseEventFlags {
109 EF_IS_DOUBLE_CLICK = 1 << 16,
110 EF_IS_NON_CLIENT = 1 << 17
111 };
112
113 explicit MouseEvent(NativeEvent native_event);
114
115 MouseEvent(const MouseEvent& other, View* source, View* target);
116
117 // Conveniences to quickly test what button is down:
118 bool IsOnlyLeftMouseButton() const {
119 return (flags() & EF_LEFT_BUTTON_DOWN) &&
120 !(flags() & (EF_MIDDLE_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN));
121 }
122 bool IsLeftMouseButton() const {
123 return (flags() & EF_LEFT_BUTTON_DOWN) != 0;
124 }
125 bool IsOnlyMiddleMouseButton() const {
126 return (flags() & EF_MIDDLE_BUTTON_DOWN) &&
127 !(flags() & (EF_LEFT_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN));
128 }
129 bool IsMiddleMouseButton() const {
130 return (flags() & EF_MIDDLE_BUTTON_DOWN) != 0;
131 }
132 bool IsOnlyRightMouseButton() const {
133 return (flags() & EF_RIGHT_BUTTON_DOWN) &&
134 !(flags() & (EF_LEFT_BUTTON_DOWN | EF_MIDDLE_BUTTON_DOWN));
135 }
136 bool IsRightMouseButton() const {
137 return (flags() & EF_RIGHT_BUTTON_DOWN) != 0;
138 }
139
140 private:
141 DISALLOW_COPY_AND_ASSIGN(MouseEvent);
142 };
143
144 class KeyEvent : public Event {
145 public:
146 explicit KeyEvent(NativeEvent native_event);
147
148 KeyboardCode key_code() const { return key_code_; }
149
150 int repeat_count() const { return repeat_count_; }
151
152 private:
153 KeyboardCode key_code_;
154 int repeat_count_;
155 int message_flags_;
156
157 DISALLOW_COPY_AND_ASSIGN(KeyEvent);
158 };
159
160 class MouseWheelEvent : public LocatedEvent {
161 public:
162 explicit MouseWheelEvent(NativeEvent native_event);
163
164 int offset() const { return offset_; }
165
166 private:
167 int offset_;
168
169 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent);
170 };
171
172 /*
173 class DropTargetEvent : public LocatedEvent {
174 public:
175 explicit DropTargetEvent(NativeEvent native_event);
176
177 const OSExchangeData& data() const { return data_; }
178 int source_operations() const { return source_operations_; }
179
180 private:
181 const OSExchangeData& data_;
182 int source_operations_;
183
184 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
185 };
186 */
187
188 } // namespace ui
189
190 #endif // UI_VIEWS_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « ui/views/events/drag_controller.h ('k') | ui/views/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698