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

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

Issue 6480001: Migrate Event API methods to Google Style. (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) 2006-2008 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_EVENT_H_
6 #define VIEWS_EVENT_H_ 6 #define VIEWS_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/keycodes/keyboard_codes.h" 11 #include "ui/base/keycodes/keyboard_codes.h"
12 #include "ui/gfx/point.h" 12 #include "ui/gfx/point.h"
13 #include "views/native_types.h"
13 14
14 #if defined(OS_LINUX) 15 #if defined(OS_LINUX)
15 typedef struct _GdkEventKey GdkEventKey; 16 typedef struct _GdkEventKey GdkEventKey;
16 #endif 17 #endif
17 18
18 #if defined(TOUCH_UI) 19 #if defined(TOUCH_UI)
19 typedef union _XEvent XEvent; 20 typedef union _XEvent XEvent;
20 #endif 21 #endif
21 22
22 namespace ui { 23 namespace ui {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 enum EventFlags { EF_CAPS_LOCK_DOWN = 1 << 0, 70 enum EventFlags { EF_CAPS_LOCK_DOWN = 1 << 0,
70 EF_SHIFT_DOWN = 1 << 1, 71 EF_SHIFT_DOWN = 1 << 1,
71 EF_CONTROL_DOWN = 1 << 2, 72 EF_CONTROL_DOWN = 1 << 2,
72 EF_ALT_DOWN = 1 << 3, 73 EF_ALT_DOWN = 1 << 3,
73 EF_LEFT_BUTTON_DOWN = 1 << 4, 74 EF_LEFT_BUTTON_DOWN = 1 << 4,
74 EF_MIDDLE_BUTTON_DOWN = 1 << 5, 75 EF_MIDDLE_BUTTON_DOWN = 1 << 5,
75 EF_RIGHT_BUTTON_DOWN = 1 << 6, 76 EF_RIGHT_BUTTON_DOWN = 1 << 6,
76 EF_COMMAND_DOWN = 1 << 7, // Only useful on OSX 77 EF_COMMAND_DOWN = 1 << 7, // Only useful on OSX
77 }; 78 };
78 79
79 // Return the event type 80 const NativeEvent& native_event() const { return native_event_; }
80 EventType GetType() const { 81 EventType type() const { return type_; }
81 return type_; 82 const base::Time& time_stamp() const { return time_stamp_; }
82 } 83 int flags() const { return flags_; }
84 void set_flags(int flags) { flags_ = flags; }
83 85
84 // Return the event time stamp. 86 // The following methods return true if the respective keys were pressed at
85 const base::Time& GetTimeStamp() const { 87 // the time the event was created.
86 return time_stamp_; 88 bool IsShiftDown() const { return (flags_ & EF_SHIFT_DOWN) != 0; }
87 } 89 bool IsControlDown() const { return (flags_ & EF_CONTROL_DOWN) != 0; }
88 90 bool IsCapsLockDown() const { return (flags_ & EF_CAPS_LOCK_DOWN) != 0; }
89 // Return the flags 91 bool IsAltDown() const { return (flags_ & EF_ALT_DOWN) != 0; }
90 int GetFlags() const {
91 return flags_;
92 }
93
94 void set_flags(int flags) {
95 flags_ = flags;
96 }
97
98 // Return whether the shift modifier is down
99 bool IsShiftDown() const {
100 return (flags_ & EF_SHIFT_DOWN) != 0;
101 }
102
103 // Return whether the control modifier is down
104 bool IsControlDown() const {
105 return (flags_ & EF_CONTROL_DOWN) != 0;
106 }
107
108 bool IsCapsLockDown() const {
109 return (flags_ & EF_CAPS_LOCK_DOWN) != 0;
110 }
111
112 // Return whether the alt modifier is down
113 bool IsAltDown() const {
114 return (flags_ & EF_ALT_DOWN) != 0;
115 }
116 92
117 bool IsMouseEvent() const { 93 bool IsMouseEvent() const {
118 return type_ == ET_MOUSE_PRESSED || 94 return type_ == ET_MOUSE_PRESSED ||
119 type_ == ET_MOUSE_DRAGGED || 95 type_ == ET_MOUSE_DRAGGED ||
120 type_ == ET_MOUSE_RELEASED || 96 type_ == ET_MOUSE_RELEASED ||
121 type_ == ET_MOUSE_MOVED || 97 type_ == ET_MOUSE_MOVED ||
122 type_ == ET_MOUSE_ENTERED || 98 type_ == ET_MOUSE_ENTERED ||
123 type_ == ET_MOUSE_EXITED || 99 type_ == ET_MOUSE_EXITED ||
124 type_ == ET_MOUSEWHEEL; 100 type_ == ET_MOUSEWHEEL;
125 } 101 }
(...skipping 16 matching lines...) Expand all
142 static int ConvertWindowsFlags(uint32 win_flags); 118 static int ConvertWindowsFlags(uint32 win_flags);
143 #elif defined(OS_LINUX) 119 #elif defined(OS_LINUX)
144 // Convert the state member on a GdkEvent to views::Event flags 120 // Convert the state member on a GdkEvent to views::Event flags
145 static int GetFlagsFromGdkState(int state); 121 static int GetFlagsFromGdkState(int state);
146 #endif 122 #endif
147 123
148 protected: 124 protected:
149 Event(EventType type, int flags); 125 Event(EventType type, int flags);
150 126
151 Event(const Event& model) 127 Event(const Event& model)
152 : type_(model.GetType()), 128 : native_event_(model.native_event()),
153 time_stamp_(model.GetTimeStamp()), 129 type_(model.type()),
154 flags_(model.GetFlags()) { 130 time_stamp_(model.time_stamp()),
131 flags_(model.flags()) {
155 } 132 }
156 133
157 private: 134 private:
158 void operator=(const Event&); 135 void operator=(const Event&);
159 136
137 NativeEvent native_event_;
160 EventType type_; 138 EventType type_;
161 base::Time time_stamp_; 139 base::Time time_stamp_;
162 int flags_; 140 int flags_;
163 }; 141 };
164 142
165 //////////////////////////////////////////////////////////////////////////////// 143 ////////////////////////////////////////////////////////////////////////////////
166 // 144 //
167 // LocatedEvent class 145 // LocatedEvent class
168 // 146 //
169 // A generic event that is used for any events that is located at a specific 147 // A generic event that is used for any events that is located at a specific
170 // position in the screen. 148 // position in the screen.
171 // 149 //
172 //////////////////////////////////////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////////////////
173 class LocatedEvent : public Event { 151 class LocatedEvent : public Event {
174 public: 152 public:
175 LocatedEvent(EventType type, const gfx::Point& location, int flags) 153 LocatedEvent(EventType type, const gfx::Point& location, int flags)
176 : Event(type, flags), 154 : Event(type, flags),
177 location_(location) { 155 location_(location) {
178 } 156 }
179 157
180 // Create a new LocatedEvent which is identical to the provided model. 158 // Create a new LocatedEvent which is identical to the provided model.
181 // If from / to views are provided, the model location will be converted 159 // If from / to views are provided, the model location will be converted
182 // from 'from' coordinate system to 'to' coordinate system 160 // from 'from' coordinate system to 'to' coordinate system
183 LocatedEvent(const LocatedEvent& model, View* from, View* to); 161 LocatedEvent(const LocatedEvent& model, View* from, View* to);
184 162
185 // Returns the X location. 163 int x() const { return location_.x(); }
186 int x() const { 164 int y() const { return location_.y(); }
187 return location_.x(); 165 const gfx::Point& location() const { return location_; }
188 }
189
190 // Returns the Y location.
191 int y() const {
192 return location_.y();
193 }
194
195 // Returns the location.
196 const gfx::Point& location() const {
197 return location_;
198 }
199 166
200 private: 167 private:
201 gfx::Point location_; 168 gfx::Point location_;
202 }; 169 };
203 170
204 //////////////////////////////////////////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////////////////////////
205 // 172 //
206 // MouseEvent class 173 // MouseEvent class
207 // 174 //
208 // A mouse event is used for any input event related to the mouse. 175 // A mouse event is used for any input event related to the mouse.
(...skipping 26 matching lines...) Expand all
235 // from 'from' coordinate system to 'to' coordinate system 202 // from 'from' coordinate system to 'to' coordinate system
236 MouseEvent(const MouseEvent& model, View* from, View* to); 203 MouseEvent(const MouseEvent& model, View* from, View* to);
237 204
238 #if defined(TOUCH_UI) 205 #if defined(TOUCH_UI)
239 // Create a mouse event from an X mouse event. 206 // Create a mouse event from an X mouse event.
240 explicit MouseEvent(XEvent* xevent); 207 explicit MouseEvent(XEvent* xevent);
241 #endif 208 #endif
242 209
243 // Conveniences to quickly test what button is down 210 // Conveniences to quickly test what button is down
244 bool IsOnlyLeftMouseButton() const { 211 bool IsOnlyLeftMouseButton() const {
245 return (GetFlags() & EF_LEFT_BUTTON_DOWN) && 212 return (flags() & EF_LEFT_BUTTON_DOWN) &&
246 !(GetFlags() & (EF_MIDDLE_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN)); 213 !(flags() & (EF_MIDDLE_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN));
247 } 214 }
248 215
249 bool IsLeftMouseButton() const { 216 bool IsLeftMouseButton() const {
250 return (GetFlags() & EF_LEFT_BUTTON_DOWN) != 0; 217 return (flags() & EF_LEFT_BUTTON_DOWN) != 0;
251 } 218 }
252 219
253 bool IsOnlyMiddleMouseButton() const { 220 bool IsOnlyMiddleMouseButton() const {
254 return (GetFlags() & EF_MIDDLE_BUTTON_DOWN) && 221 return (flags() & EF_MIDDLE_BUTTON_DOWN) &&
255 !(GetFlags() & (EF_LEFT_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN)); 222 !(flags() & (EF_LEFT_BUTTON_DOWN | EF_RIGHT_BUTTON_DOWN));
256 } 223 }
257 224
258 bool IsMiddleMouseButton() const { 225 bool IsMiddleMouseButton() const {
259 return (GetFlags() & EF_MIDDLE_BUTTON_DOWN) != 0; 226 return (flags() & EF_MIDDLE_BUTTON_DOWN) != 0;
260 } 227 }
261 228
262 bool IsOnlyRightMouseButton() const { 229 bool IsOnlyRightMouseButton() const {
263 return (GetFlags() & EF_RIGHT_BUTTON_DOWN) && 230 return (flags() & EF_RIGHT_BUTTON_DOWN) &&
264 !(GetFlags() & (EF_LEFT_BUTTON_DOWN | EF_MIDDLE_BUTTON_DOWN)); 231 !(flags() & (EF_LEFT_BUTTON_DOWN | EF_MIDDLE_BUTTON_DOWN));
265 } 232 }
266 233
267 bool IsRightMouseButton() const { 234 bool IsRightMouseButton() const {
268 return (GetFlags() & EF_RIGHT_BUTTON_DOWN) != 0; 235 return (flags() & EF_RIGHT_BUTTON_DOWN) != 0;
269 } 236 }
270 237
271 private: 238 private:
272 DISALLOW_COPY_AND_ASSIGN(MouseEvent); 239 DISALLOW_COPY_AND_ASSIGN(MouseEvent);
273 }; 240 };
274 241
275 #if defined(TOUCH_UI) 242 #if defined(TOUCH_UI)
276 //////////////////////////////////////////////////////////////////////////////// 243 ////////////////////////////////////////////////////////////////////////////////
277 // 244 //
278 // TouchEvent class 245 // TouchEvent class
(...skipping 20 matching lines...) Expand all
299 266
300 // Create a new TouchEvent which is identical to the provided model. 267 // Create a new TouchEvent which is identical to the provided model.
301 // If from / to views are provided, the model location will be converted 268 // If from / to views are provided, the model location will be converted
302 // from 'from' coordinate system to 'to' coordinate system. 269 // from 'from' coordinate system to 'to' coordinate system.
303 TouchEvent(const TouchEvent& model, View* from, View* to); 270 TouchEvent(const TouchEvent& model, View* from, View* to);
304 271
305 #if defined(HAVE_XINPUT2) 272 #if defined(HAVE_XINPUT2)
306 explicit TouchEvent(XEvent* xev); 273 explicit TouchEvent(XEvent* xev);
307 #endif 274 #endif
308 275
309 // Return the touch point for this event. 276 bool identity() const { return touch_id_; }
310 bool identity() const {
311 return touch_id_;
312 }
313 277
314 private: 278 private:
315 // The identity (typically finger) of the touch starting at 0 and incrementing 279 // The identity (typically finger) of the touch starting at 0 and incrementing
316 // for each separable additional touch that the hardware can detect. 280 // for each separable additional touch that the hardware can detect.
317 const int touch_id_; 281 const int touch_id_;
318 282
319 DISALLOW_COPY_AND_ASSIGN(TouchEvent); 283 DISALLOW_COPY_AND_ASSIGN(TouchEvent);
320 }; 284 };
321 #endif 285 #endif
322 286
(...skipping 25 matching lines...) Expand all
348 #if defined(OS_LINUX) 312 #if defined(OS_LINUX)
349 explicit KeyEvent(const GdkEventKey* event); 313 explicit KeyEvent(const GdkEventKey* event);
350 314
351 const GdkEventKey* native_event() const { return native_event_; } 315 const GdkEventKey* native_event() const { return native_event_; }
352 #endif 316 #endif
353 #if defined(TOUCH_UI) 317 #if defined(TOUCH_UI)
354 // Create a key event from an X key event. 318 // Create a key event from an X key event.
355 explicit KeyEvent(XEvent* xevent); 319 explicit KeyEvent(XEvent* xevent);
356 #endif 320 #endif
357 321
358 // This returns a VKEY_ value as defined in app/keyboard_codes.h which is 322 ui::KeyboardCode key_code() const { return key_code_; }
359 // the Windows value.
360 // On GTK, you can use the methods in keyboard_code_conversion_gtk.cc to
361 // convert this value back to a GDK value if needed.
362 ui::KeyboardCode GetKeyCode() const {
363 return key_code_;
364 }
365 323
366 #if defined(OS_WIN) 324 #if defined(OS_WIN)
367 bool IsExtendedKey() const; 325 bool IsExtendedKey() const;
368 326
369 UINT message() const { 327 UINT message() const { return message_; }
370 return message_;
371 }
372 #endif 328 #endif
373 329
374 int GetRepeatCount() const { 330 int repeat_count() const { return repeat_count_; }
375 return repeat_count_;
376 }
377 331
378 #if defined(OS_WIN) 332 #if defined(OS_WIN)
379 static int GetKeyStateFlags(); 333 static int GetKeyStateFlags();
380 #endif 334 #endif
381 335
382 private: 336 private:
383 337
384 ui::KeyboardCode key_code_; 338 ui::KeyboardCode key_code_;
385 int repeat_count_; 339 int repeat_count_;
386 int message_flags_; 340 int message_flags_;
(...skipping 18 matching lines...) Expand all
405 // Create a new key event 359 // Create a new key event
406 MouseWheelEvent(int offset, int x, int y, int flags) 360 MouseWheelEvent(int offset, int x, int y, int flags)
407 : LocatedEvent(ET_MOUSEWHEEL, gfx::Point(x, y), flags), 361 : LocatedEvent(ET_MOUSEWHEEL, gfx::Point(x, y), flags),
408 offset_(offset) { 362 offset_(offset) {
409 } 363 }
410 364
411 #if defined(TOUCH_UI) 365 #if defined(TOUCH_UI)
412 explicit MouseWheelEvent(XEvent* xev); 366 explicit MouseWheelEvent(XEvent* xev);
413 #endif 367 #endif
414 368
415 int GetOffset() const { 369 int offset() const { return offset_; }
416 return offset_;
417 }
418 370
419 private: 371 private:
420 int offset_; 372 int offset_;
421 373
422 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent); 374 DISALLOW_COPY_AND_ASSIGN(MouseWheelEvent);
423 }; 375 };
424 376
425 //////////////////////////////////////////////////////////////////////////////// 377 ////////////////////////////////////////////////////////////////////////////////
426 // 378 //
427 // DropTargetEvent class 379 // DropTargetEvent class
428 // 380 //
429 // A DropTargetEvent is sent to the view the mouse is over during a drag and 381 // A DropTargetEvent is sent to the view the mouse is over during a drag and
430 // drop operation. 382 // drop operation.
431 // 383 //
432 //////////////////////////////////////////////////////////////////////////////// 384 ////////////////////////////////////////////////////////////////////////////////
433 class DropTargetEvent : public LocatedEvent { 385 class DropTargetEvent : public LocatedEvent {
434 public: 386 public:
435 DropTargetEvent(const OSExchangeData& data, 387 DropTargetEvent(const OSExchangeData& data,
436 int x, 388 int x,
437 int y, 389 int y,
438 int source_operations) 390 int source_operations)
439 : LocatedEvent(ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0), 391 : LocatedEvent(ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0),
440 data_(data), 392 data_(data),
441 source_operations_(source_operations) { 393 source_operations_(source_operations) {
442 } 394 }
443 395
396 const OSExchangeData& data() const { return data_; }
397 int source_operations() const { return source_operations_; }
398
399 private:
444 // Data associated with the drag/drop session. 400 // Data associated with the drag/drop session.
445 const OSExchangeData& GetData() const { return data_; } 401 const OSExchangeData& data_;
446 402
447 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. 403 // Bitmask of supported ui::DragDropTypes::DragOperation by the source.
448 int GetSourceOperations() const { return source_operations_; }
449
450 private:
451 const OSExchangeData& data_;
452 int source_operations_; 404 int source_operations_;
453 405
454 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); 406 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
455 }; 407 };
456 408
457 } // namespace views 409 } // namespace views
458 410
459 #endif // VIEWS_EVENT_H_ 411 #endif // VIEWS_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698