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

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

Issue 6591120: Update MouseEvent (initial pass). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update MouseEvent (initial pass). Created 9 years, 9 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 | « no previous file | views/events/event.cc » ('j') | views/widget/widget_win.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 VIEWS_EVENTS_EVENT_H_ 5 #ifndef VIEWS_EVENTS_EVENT_H_
6 #define VIEWS_EVENTS_EVENT_H_ 6 #define VIEWS_EVENTS_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"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 type_ == ui::ET_TOUCH_PRESSED || 76 type_ == ui::ET_TOUCH_PRESSED ||
77 type_ == ui::ET_TOUCH_MOVED || 77 type_ == ui::ET_TOUCH_MOVED ||
78 type_ == ui::ET_TOUCH_STATIONARY || 78 type_ == ui::ET_TOUCH_STATIONARY ||
79 type_ == ui::ET_TOUCH_CANCELLED; 79 type_ == ui::ET_TOUCH_CANCELLED;
80 } 80 }
81 #endif 81 #endif
82 82
83 #if defined(OS_WIN) 83 #if defined(OS_WIN)
84 // Returns the EventFlags in terms of windows flags. 84 // Returns the EventFlags in terms of windows flags.
85 int GetWindowsFlags() const; 85 int GetWindowsFlags() const;
86
87 // Convert windows flags to views::Event flags
88 static int ConvertWindowsFlags(uint32 win_flags);
89 #elif defined(OS_LINUX) 86 #elif defined(OS_LINUX)
90 // Convert the state member on a GdkEvent to views::Event flags 87 // Convert the state member on a GdkEvent to views::Event flags
91 static int GetFlagsFromGdkState(unsigned int state); 88 static int GetFlagsFromGdkState(unsigned int state);
92 #endif 89 #endif
93 90
94 protected: 91 protected:
95 Event(ui::EventType type, int flags); 92 Event(ui::EventType type, int flags);
96 Event(NativeEvent native_event, ui::EventType type, int flags); 93 Event(NativeEvent native_event, ui::EventType type, int flags);
97 // Because the world is complicated, sometimes we have two different kinds of 94 // Because the world is complicated, sometimes we have two different kinds of
98 // NativeEvent in play in the same executable. See native_types.h for the tale 95 // NativeEvent in play in the same executable. See native_types.h for the tale
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // position in the screen. 127 // position in the screen.
131 // 128 //
132 //////////////////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////////////////
133 class LocatedEvent : public Event { 130 class LocatedEvent : public Event {
134 public: 131 public:
135 int x() const { return location_.x(); } 132 int x() const { return location_.x(); }
136 int y() const { return location_.y(); } 133 int y() const { return location_.y(); }
137 const gfx::Point& location() const { return location_; } 134 const gfx::Point& location() const { return location_; }
138 135
139 protected: 136 protected:
140 // This constructor is to allow converting the location of an event from the
141 // widget's coordinate system to the RootView's coordinate system.
142 LocatedEvent(const LocatedEvent& model, RootView* root);
143
144 explicit LocatedEvent(NativeEvent native_event); 137 explicit LocatedEvent(NativeEvent native_event);
145 LocatedEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); 138 LocatedEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
146 139
147 // TODO(msw): Kill this legacy constructor when we update MouseEvent??? 140 // TODO(msw): Kill this legacy constructor when we update uses.
148 // Simple initialization from cracked metadata. 141 // Simple initialization from cracked metadata.
149 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags); 142 LocatedEvent(ui::EventType type, const gfx::Point& location, int flags);
150 143
151 // Create a new LocatedEvent which is identical to the provided model. 144 // Create a new LocatedEvent which is identical to the provided model.
152 // If source / target views are provided, the model location will be converted 145 // If source / target views are provided, the model location will be converted
153 // from 'source' coordinate system to 'target' coordinate system 146 // from |source| coordinate system to |target| coordinate system.
154 LocatedEvent(const LocatedEvent& model, View* source, View* target); 147 LocatedEvent(const LocatedEvent& model, View* source, View* target);
155 148
149 // This constructor is to allow converting the location of an event from the
150 // widget's coordinate system to the RootView's coordinate system.
151 LocatedEvent(const LocatedEvent& model, RootView* root);
152
156 private: 153 private:
157 gfx::Point location_; 154 gfx::Point location_;
158 }; 155 };
159 156
160 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
161 // 158 //
162 // MouseEvent class 159 // MouseEvent class
163 // 160 //
164 // A mouse event is used for any input event related to the mouse. 161 // A mouse event is used for any input event related to the mouse.
165 // 162 //
166 //////////////////////////////////////////////////////////////////////////////// 163 ////////////////////////////////////////////////////////////////////////////////
167 class MouseEvent : public LocatedEvent { 164 class MouseEvent : public LocatedEvent {
168 public: 165 public:
166 explicit MouseEvent(NativeEvent native_event);
167 MouseEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
168
169 // Create a new MouseEvent which is identical to the provided model.
170 // If source / target views are provided, the model location will be converted
171 // from |source| coordinate system to |target| coordinate system.
172 MouseEvent(const MouseEvent& model, View* source, View* target);
173
174 // TODO(msw): Kill this legacy constructor when we update uses.
169 // Create a new mouse event 175 // Create a new mouse event
170 MouseEvent(ui::EventType type, int x, int y, int flags) 176 MouseEvent(ui::EventType type, int x, int y, int flags)
171 : LocatedEvent(type, gfx::Point(x, y), flags) { 177 : LocatedEvent(type, gfx::Point(x, y), flags) {
172 } 178 }
173 179
174 // Create a new mouse event from a type and a point. If from / to views 180 // TODO(msw): Kill this legacy constructor when we update uses.
175 // are provided, the point will be converted from 'from' coordinate system to 181 // Create a new mouse event from a type and a point. If source / target views
176 // 'to' coordinate system. 182 // are provided, the point will be converted from |source| coordinate system
183 // to |target| coordinate system.
177 MouseEvent(ui::EventType type, 184 MouseEvent(ui::EventType type,
178 View* from, 185 View* source,
179 View* to, 186 View* target,
180 const gfx::Point &l, 187 const gfx::Point &l,
181 int flags); 188 int flags);
182 189
183 // Create a new MouseEvent which is identical to the provided model.
184 // If from / to views are provided, the model location will be converted
185 // from 'from' coordinate system to 'to' coordinate system
186 MouseEvent(const MouseEvent& model, View* from, View* to);
187
188 #if defined(TOUCH_UI)
189 // Create a mouse event from an X mouse event.
190 explicit MouseEvent(XEvent* xevent);
191 #endif
192
193 // Conveniences to quickly test what button is down 190 // Conveniences to quickly test what button is down
194 bool IsOnlyLeftMouseButton() const { 191 bool IsOnlyLeftMouseButton() const {
195 return (flags() & ui::EF_LEFT_BUTTON_DOWN) && 192 return (flags() & ui::EF_LEFT_BUTTON_DOWN) &&
196 !(flags() & (ui::EF_MIDDLE_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN)); 193 !(flags() & (ui::EF_MIDDLE_BUTTON_DOWN | ui::EF_RIGHT_BUTTON_DOWN));
197 } 194 }
198 195
199 bool IsLeftMouseButton() const { 196 bool IsLeftMouseButton() const {
200 return (flags() & ui::EF_LEFT_BUTTON_DOWN) != 0; 197 return (flags() & ui::EF_LEFT_BUTTON_DOWN) != 0;
201 } 198 }
202 199
(...skipping 30 matching lines...) Expand all
233 // 230 //
234 // TouchEvent class 231 // TouchEvent class
235 // 232 //
236 // A touch event is generated by touch screen and advanced track 233 // A touch event is generated by touch screen and advanced track
237 // pad devices. There is a deliberate direct correspondence between 234 // pad devices. There is a deliberate direct correspondence between
238 // TouchEvent and PlatformTouchPoint. 235 // TouchEvent and PlatformTouchPoint.
239 // 236 //
240 //////////////////////////////////////////////////////////////////////////////// 237 ////////////////////////////////////////////////////////////////////////////////
241 class TouchEvent : public LocatedEvent { 238 class TouchEvent : public LocatedEvent {
242 public: 239 public:
240 explicit TouchEvent(NativeEvent native_event);
241 TouchEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
242
243 // Create a new touch event. 243 // Create a new touch event.
244 TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id); 244 TouchEvent(ui::EventType type, int x, int y, int flags, int touch_id);
245 245
246 // Create a new touch event from a type and a point. If from / to views 246 // Create a new touch event from a type and a point. If from / to views
247 // are provided, the point will be converted from 'from' coordinate system to 247 // are provided, the point will be converted from 'source' coordinate system
248 // 'to' coordinate system. 248 // to 'target' coordinate system.
249 TouchEvent(ui::EventType type, 249 TouchEvent(ui::EventType type,
250 View* from, 250 View* source,
251 View* to, 251 View* target,
252 const gfx::Point& l, 252 const gfx::Point& l,
253 int flags, 253 int flags,
254 int touch_id); 254 int touch_id);
255 255
256 // Create a new TouchEvent which is identical to the provided model. 256 // Create a new MouseEvent which is identical to the provided model.
257 // If from / to views are provided, the model location will be converted 257 // If source / target views are provided, the model location will be converted
258 // from 'from' coordinate system to 'to' coordinate system. 258 // from |source| coordinate system to |target| coordinate system.
259 TouchEvent(const TouchEvent& model, View* from, View* to); 259 TouchEvent(const TouchEvent& model, View* source, View* target);
260
261 #if defined(HAVE_XINPUT2)
262 explicit TouchEvent(XEvent* xev);
263 #endif
264 260
265 bool identity() const { return touch_id_; } 261 bool identity() const { return touch_id_; }
266 262
267 private: 263 private:
268 friend class RootView; 264 friend class RootView;
269 265
270 TouchEvent(const TouchEvent& model, RootView* root) 266 TouchEvent(const TouchEvent& model, RootView* root)
271 : LocatedEvent(model, root), 267 : LocatedEvent(model, root),
272 touch_id_(model.touch_id_) { 268 touch_id_(model.touch_id_) {
273 } 269 }
274 270
275 // The identity (typically finger) of the touch starting at 0 and incrementing 271 // The identity (typically finger) of the touch starting at 0 and incrementing
276 // for each separable additional touch that the hardware can detect. 272 // for each separable additional touch that the hardware can detect.
277 const int touch_id_; 273 const int touch_id_;
278 274
279 DISALLOW_COPY_AND_ASSIGN(TouchEvent); 275 DISALLOW_COPY_AND_ASSIGN(TouchEvent);
280 }; 276 };
281 #endif 277 #endif
282 278
283 //////////////////////////////////////////////////////////////////////////////// 279 ////////////////////////////////////////////////////////////////////////////////
284 // KeyEvent class 280 // KeyEvent class
285 // 281 //
286 // KeyEvent encapsulates keyboard input events - key press and release. 282 // KeyEvent encapsulates keyboard input events - key press and release.
287 // 283 //
284 ////////////////////////////////////////////////////////////////////////////////
288 class KeyEvent : public Event { 285 class KeyEvent : public Event {
289 public: 286 public:
290 explicit KeyEvent(NativeEvent native_event); 287 explicit KeyEvent(NativeEvent native_event);
291 KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native); 288 KeyEvent(NativeEvent2 native_event_2, FromNativeEvent2 from_native);
292 289
293 // Creates a new KeyEvent synthetically (i.e. not in response to an input 290 // Creates a new KeyEvent synthetically (i.e. not in response to an input
294 // event from the host environment). This is typically only used in testing as 291 // event from the host environment). This is typically only used in testing as
295 // some metadata obtainable from the underlying native event is not present. 292 // some metadata obtainable from the underlying native event is not present.
296 // TODO(beng): see if we can kill this. 293 // TODO(beng): see if we can kill this.
297 KeyEvent(ui::EventType type, 294 KeyEvent(ui::EventType type,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 //////////////////////////////////////////////////////////////////////////////// 334 ////////////////////////////////////////////////////////////////////////////////
338 // 335 //
339 // DropTargetEvent class 336 // DropTargetEvent class
340 // 337 //
341 // A DropTargetEvent is sent to the view the mouse is over during a drag and 338 // A DropTargetEvent is sent to the view the mouse is over during a drag and
342 // drop operation. 339 // drop operation.
343 // 340 //
344 //////////////////////////////////////////////////////////////////////////////// 341 ////////////////////////////////////////////////////////////////////////////////
345 class DropTargetEvent : public LocatedEvent { 342 class DropTargetEvent : public LocatedEvent {
346 public: 343 public:
344 // Are DropTargetEvents actually backed by any native event? MouseEvent???
345 //explicit DropTargetEvent(NativeEvent native_event);
Ben Goodger (Google) 2011/03/03 00:13:41 poke
346
347 DropTargetEvent(const OSExchangeData& data, 347 DropTargetEvent(const OSExchangeData& data,
348 int x, 348 int x,
349 int y, 349 int y,
350 int source_operations) 350 int source_operations)
351 : LocatedEvent(ui::ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0), 351 : LocatedEvent(ui::ET_DROP_TARGET_EVENT, gfx::Point(x, y), 0),
352 data_(data), 352 data_(data),
353 source_operations_(source_operations) { 353 source_operations_(source_operations) {
354 } 354 }
355 355
356 const OSExchangeData& data() const { return data_; } 356 const OSExchangeData& data() const { return data_; }
357 int source_operations() const { return source_operations_; } 357 int source_operations() const { return source_operations_; }
358 358
359 private: 359 private:
360 // Data associated with the drag/drop session. 360 // Data associated with the drag/drop session.
361 const OSExchangeData& data_; 361 const OSExchangeData& data_;
362 362
363 // Bitmask of supported ui::DragDropTypes::DragOperation by the source. 363 // Bitmask of supported ui::DragDropTypes::DragOperation by the source.
364 int source_operations_; 364 int source_operations_;
365 365
366 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); 366 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
367 }; 367 };
368 368
369 } // namespace views 369 } // namespace views
370 370
371 #endif // VIEWS_EVENTS_EVENT_H_ 371 #endif // VIEWS_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | views/events/event.cc » ('j') | views/widget/widget_win.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698