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

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

Issue 1680613002: Adding momentum/overscroll to views:: ScrollViews Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Tableview layout. aaaand I think we are done Created 4 years, 4 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
« no previous file with comments | « ui/events/blink/input_scroll_elasticity_controller_unittest.cc ('k') | ui/events/event.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // -scrollingDelta{X|Y} have float return types but they return values that 146 // -scrollingDelta{X|Y} have float return types but they return values that
147 // are already rounded to integers. 147 // are already rounded to integers.
148 // The values are the same as the values returned from calling 148 // The values are the same as the values returned from calling
149 // CGEventGetIntegerValueField(kCGScrollWheelEventPointDeltaAxis{1|2}). 149 // CGEventGetIntegerValueField(kCGScrollWheelEventPointDeltaAxis{1|2}).
150 return gfx::Vector2d([event scrollingDeltaX], [event scrollingDeltaY]); 150 return gfx::Vector2d([event scrollingDeltaX], [event scrollingDeltaY]);
151 } else { 151 } else {
152 // Empirically, a value of 0.1 is typical for one mousewheel click. Positive 152 // Empirically, a value of 0.1 is typical for one mousewheel click. Positive
153 // values when scrolling up or to the left. Scrolling quickly results in a 153 // values when scrolling up or to the left. Scrolling quickly results in a
154 // higher delta per click, up to about 15.0. (Quartz documentation suggests 154 // higher delta per click, up to about 15.0. (Quartz documentation suggests
155 // +/-10). 155 // +/-10).
156 // Multiply by 1000 to vaguely approximate WHEEL_DELTA on Windows (120). 156 // Use the same multiplier as content::WebMouseWheelEventBuilder.
157 const CGFloat kWheelDeltaMultiplier = 1000; 157 const double kScrollbarPixelsPerCocoaTick = 40.0;
158 return gfx::Vector2d(kWheelDeltaMultiplier * [event deltaX], 158 return gfx::Vector2d(kScrollbarPixelsPerCocoaTick * [event deltaX],
159 kWheelDeltaMultiplier * [event deltaY]); 159 kScrollbarPixelsPerCocoaTick * [event deltaY]);
160 } 160 }
161 } 161 }
162 162
163 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { 163 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
164 return [event copy]; 164 return [event copy];
165 } 165 }
166 166
167 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { 167 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) {
168 [event release]; 168 [event release];
169 } 169 }
(...skipping 21 matching lines...) Expand all
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 int* momentum_phase) {
203 return false; 203 gfx::Vector2d offset = GetMouseWheelOffset(native_event);
204 *x_offset_ordinal = offset.x();
205 *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 if ([native_event phase] & kBeginPhaseMask)
218 *momentum_phase |= EM_PHASE_MAY_BEGIN;
219
220 if (([native_event phase] | [native_event momentumPhase]) & kEndPhaseMask)
221 *momentum_phase |= EM_PHASE_END;
222 else if ([native_event momentumPhase] != NSEventPhaseNone)
223 *momentum_phase |= EM_PHASE_INERTIAL_UPDATE;
224
225 // If the event completely lacks phase information, there won't be further
226 // updates, so they must be treated as an end.
227 if (([native_event phase] | [native_event momentumPhase]) == NSEventPhaseNone)
228 *momentum_phase |= EM_PHASE_END;
229
230 return true;
204 } 231 }
205 232
206 bool GetFlingData(const base::NativeEvent& native_event, 233 bool GetFlingData(const base::NativeEvent& native_event,
207 float* vx, 234 float* vx,
208 float* vy, 235 float* vy,
209 float* vx_ordinal, 236 float* vx_ordinal,
210 float* vy_ordinal, 237 float* vy_ordinal,
211 bool* is_cancel) { 238 bool* is_cancel) {
212 NOTIMPLEMENTED(); 239 NOTIMPLEMENTED();
213 return false; 240 return false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 uint16_t return_value; 288 uint16_t return_value;
262 [text getCharacters:&return_value]; 289 [text getCharacters:&return_value];
263 return return_value; 290 return return_value;
264 } 291 }
265 292
266 bool IsCharFromNative(const base::NativeEvent& native_event) { 293 bool IsCharFromNative(const base::NativeEvent& native_event) {
267 return false; 294 return false;
268 } 295 }
269 296
270 } // namespace ui 297 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/input_scroll_elasticity_controller_unittest.cc ('k') | ui/events/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698