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

Side by Side Diff: ui/events/cocoa/events_mac.mm

Issue 2193153002: MacViews: Send Mac scrollWheel NSEvents as ui::ET_SCROLL (ui::ScrollEvent). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20160728-MacViews-ScrollLayers
Patch Set: NSDictionary subscripting Created 4 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ui/events/event_utils.h" 5 #include "ui/events/event_utils.h"
6 6
7 #include <Cocoa/Cocoa.h> 7 #include <Cocoa/Cocoa.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 25 matching lines...) Expand all
36 case NSRightMouseUp: 36 case NSRightMouseUp:
37 case NSOtherMouseUp: 37 case NSOtherMouseUp:
38 return ET_MOUSE_RELEASED; 38 return ET_MOUSE_RELEASED;
39 case NSLeftMouseDragged: 39 case NSLeftMouseDragged:
40 case NSRightMouseDragged: 40 case NSRightMouseDragged:
41 case NSOtherMouseDragged: 41 case NSOtherMouseDragged:
42 return ET_MOUSE_DRAGGED; 42 return ET_MOUSE_DRAGGED;
43 case NSMouseMoved: 43 case NSMouseMoved:
44 return ET_MOUSE_MOVED; 44 return ET_MOUSE_MOVED;
45 case NSScrollWheel: 45 case NSScrollWheel:
46 return ET_MOUSEWHEEL; 46 return ET_SCROLL;
47 case NSMouseEntered: 47 case NSMouseEntered:
48 return ET_MOUSE_ENTERED; 48 return ET_MOUSE_ENTERED;
49 case NSMouseExited: 49 case NSMouseExited:
50 return ET_MOUSE_EXITED; 50 return ET_MOUSE_EXITED;
51 case NSEventTypeSwipe: 51 case NSEventTypeSwipe:
52 return ET_SCROLL_FLING_START; 52 return ET_SCROLL_FLING_START;
53 case NSAppKitDefined: 53 case NSAppKitDefined:
54 case NSSystemDefined: 54 case NSSystemDefined:
55 return ET_UNKNOWN; 55 return ET_UNKNOWN;
56 case NSFlagsChanged: 56 case NSFlagsChanged:
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 /* force */ 0.f, 191 /* force */ 0.f,
192 /* tilt_x */ 0.f, 192 /* tilt_x */ 0.f,
193 /* tilt_y */ 0.f); 193 /* tilt_y */ 0.f);
194 } 194 }
195 195
196 bool GetScrollOffsets(const base::NativeEvent& native_event, 196 bool GetScrollOffsets(const base::NativeEvent& native_event,
197 float* x_offset, 197 float* x_offset,
198 float* y_offset, 198 float* y_offset,
199 float* x_offset_ordinal, 199 float* x_offset_ordinal,
200 float* y_offset_ordinal, 200 float* y_offset_ordinal,
201 int* finger_count) { 201 int* finger_count,
202 NOTIMPLEMENTED(); 202 EventMomentumPhase* momentum_phase) {
203 return false; 203 gfx::Vector2d offset = GetMouseWheelOffset(native_event);
204 *x_offset = *x_offset_ordinal = offset.x();
205 *y_offset = *y_offset_ordinal = offset.y();
206
207 // For non-scrolling events, the finger count can be determined with
208 // [[native_event touchesMatchingPhase:NSTouchPhaseTouching inView:nil] count]
209 // but it's illegal to ask that of scroll events, so say two fingers.
210 *finger_count = 2;
211
212 // If a user just rests two fingers on the touchpad without moving, AppKit
213 // uses NSEventPhaseMayBegin. Treat this the same as NSEventPhaseBegan.
214 const NSUInteger kBeginPhaseMask = NSEventPhaseBegan | NSEventPhaseMayBegin;
215 const NSUInteger kEndPhaseMask = NSEventPhaseCancelled | NSEventPhaseEnded;
216
217 // Note: although the NSEventPhase constants are bit flags, the logic here
218 // assumes AppKit will not combine them, so momentum phase should only be set
219 // once. If one of these DCHECKs fails it could mean some new hardware that
220 // needs tests in events_mac_unittest.mm.
221 DCHECK_EQ(EventMomentumPhase::NONE, *momentum_phase);
222
223 if ([native_event phase] & kBeginPhaseMask)
224 *momentum_phase = EventMomentumPhase::MAY_BEGIN;
225
226 if (([native_event phase] | [native_event momentumPhase]) & kEndPhaseMask) {
227 DCHECK_EQ(EventMomentumPhase::NONE, *momentum_phase);
228 *momentum_phase = EventMomentumPhase::END;
229 } else if ([native_event momentumPhase] != NSEventPhaseNone) {
230 DCHECK_EQ(EventMomentumPhase::NONE, *momentum_phase);
231 *momentum_phase = EventMomentumPhase::INERTIAL_UPDATE;
232 }
233
234 // If the event completely lacks phase information, there won't be further
235 // updates, so they must be treated as an end.
236 if (([native_event phase] | [native_event momentumPhase]) ==
237 NSEventPhaseNone) {
238 DCHECK_EQ(EventMomentumPhase::NONE, *momentum_phase);
239 *momentum_phase = EventMomentumPhase::END;
240 }
241
242 return true;
204 } 243 }
205 244
206 bool GetFlingData(const base::NativeEvent& native_event, 245 bool GetFlingData(const base::NativeEvent& native_event,
207 float* vx, 246 float* vx,
208 float* vy, 247 float* vy,
209 float* vx_ordinal, 248 float* vx_ordinal,
210 float* vy_ordinal, 249 float* vy_ordinal,
211 bool* is_cancel) { 250 bool* is_cancel) {
212 NOTIMPLEMENTED(); 251 NOTIMPLEMENTED();
213 return false; 252 return false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 uint16_t return_value; 300 uint16_t return_value;
262 [text getCharacters:&return_value]; 301 [text getCharacters:&return_value];
263 return return_value; 302 return return_value;
264 } 303 }
265 304
266 bool IsCharFromNative(const base::NativeEvent& native_event) { 305 bool IsCharFromNative(const base::NativeEvent& native_event) {
267 return false; 306 return false;
268 } 307 }
269 308
270 } // namespace ui 309 } // namespace ui
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm ('k') | ui/events/cocoa/events_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698