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

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

Issue 2461323002: Mac: Support Sierra's broken MouseWheel events. (Closed)
Patch Set: events_mac fix Created 4 years, 1 month 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // CGEventGetIntegerValueField(kCGScrollWheelEventPointDeltaAxis{1|2}). 148 // CGEventGetIntegerValueField(kCGScrollWheelEventPointDeltaAxis{1|2}).
149 return gfx::Vector2d([event scrollingDeltaX], [event scrollingDeltaY]); 149 return gfx::Vector2d([event scrollingDeltaX], [event scrollingDeltaY]);
150 } else { 150 } else {
151 // Empirically, a value of 0.1 is typical for one mousewheel click. Positive 151 // Empirically, a value of 0.1 is typical for one mousewheel click. Positive
152 // values when scrolling up or to the left. Scrolling quickly results in a 152 // values when scrolling up or to the left. Scrolling quickly results in a
153 // higher delta per click, up to about 15.0. (Quartz documentation suggests 153 // higher delta per click, up to about 15.0. (Quartz documentation suggests
154 // +/-10). 154 // +/-10).
155 // Use the same multiplier as content::WebMouseWheelEventBuilder. Note this 155 // Use the same multiplier as content::WebMouseWheelEventBuilder. Note this
156 // differs from the value returned by CGEventSourceGetPixelsPerLine(), which 156 // differs from the value returned by CGEventSourceGetPixelsPerLine(), which
157 // is typically 10. 157 // is typically 10.
158 return gfx::Vector2d(kScrollbarPixelsPerCocoaTick * [event deltaX], 158 CGFloat deltaX = [event deltaX] * kScrollbarPixelsPerCocoaTick;
159 kScrollbarPixelsPerCocoaTick * [event deltaY]); 159 CGFloat deltaY = [event deltaY] * kScrollbarPixelsPerCocoaTick;
160 int64_t pointDeltaX = CGEventGetIntegerValueField(
161 [event CGEvent], kCGScrollWheelEventPointDeltaAxis2);
162 int64_t pointDeltaY = CGEventGetIntegerValueField(
163 [event CGEvent], kCGScrollWheelEventPointDeltaAxis1);
164
165 // A rounding bug on Sierra means that single-tick wheel scrolls may be
166 // truncated to zero. Prefer kCGScrollWheelEventPointDeltaAxisXY in those
167 // cases. First assume the CGEventSource has the default value of 10, rather
168 // than querying CGEventSourceGetPixelsPerLine() each time.
169 const float kPixelsPerLine = 10.0;
170 if (deltaX == 0 && pointDeltaX != 0)
171 deltaX = pointDeltaX * kPixelsPerLine;
172 if (deltaY == 0 && pointDeltaY != 0)
173 deltaY = pointDeltaY * kPixelsPerLine;
174
175 return gfx::Vector2d(deltaX, deltaY);
160 } 176 }
161 } 177 }
162 178
163 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { 179 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
164 return [event copy]; 180 return [event copy];
165 } 181 }
166 182
167 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { 183 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) {
168 [event release]; 184 [event release];
169 } 185 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 uint16_t return_value; 316 uint16_t return_value;
301 [text getCharacters:&return_value]; 317 [text getCharacters:&return_value];
302 return return_value; 318 return return_value;
303 } 319 }
304 320
305 bool IsCharFromNative(const base::NativeEvent& native_event) { 321 bool IsCharFromNative(const base::NativeEvent& native_event) {
306 return false; 322 return false;
307 } 323 }
308 324
309 } // namespace ui 325 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698