| OLD | NEW |
| 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 Loading... |
| 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 |
| 161 // A rounding bug on Sierra means that single-tick wheel scrolls may be |
| 162 // truncated to zero. Prefer kCGScrollWheelEventPointDeltaAxisXY in those |
| 163 // cases. However, kCGScrollWheelEventPointDeltaAxisXY has a "nasty bug" |
| 164 // when holding Shift (see "Of Mice and Men", above). So only check vertical |
| 165 // scrolls. Also, to be consistent with the values when truncation does NOT |
| 166 // scroll, it needs to be multiplied by some factor. The documentation for |
| 167 // CGEventSourceGetPixelsPerLine() says "By default, the scale is about ten |
| 168 // pixels per line." However, the actual relationship is fuzzy because of |
| 169 // acceleration. Using a constant of 10 for small values seems to "feel |
| 170 // right" when this bug is encountered. See http://crbug.com/660773. |
| 171 const float kPixelsPerLine = 10.0; |
| 172 int64_t pointDeltaY = CGEventGetIntegerValueField( |
| 173 [event CGEvent], kCGScrollWheelEventPointDeltaAxis1); |
| 174 if (deltaY == 0 && pointDeltaY != 0) |
| 175 deltaY = pointDeltaY * kPixelsPerLine; |
| 176 |
| 177 return gfx::Vector2d(deltaX, deltaY); |
| 160 } | 178 } |
| 161 } | 179 } |
| 162 | 180 |
| 163 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { | 181 base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) { |
| 164 return [event copy]; | 182 return [event copy]; |
| 165 } | 183 } |
| 166 | 184 |
| 167 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { | 185 void ReleaseCopiedNativeEvent(const base::NativeEvent& event) { |
| 168 [event release]; | 186 [event release]; |
| 169 } | 187 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 uint16_t return_value; | 318 uint16_t return_value; |
| 301 [text getCharacters:&return_value]; | 319 [text getCharacters:&return_value]; |
| 302 return return_value; | 320 return return_value; |
| 303 } | 321 } |
| 304 | 322 |
| 305 bool IsCharFromNative(const base::NativeEvent& native_event) { | 323 bool IsCharFromNative(const base::NativeEvent& native_event) { |
| 306 return false; | 324 return false; |
| 307 } | 325 } |
| 308 | 326 |
| 309 } // namespace ui | 327 } // namespace ui |
| OLD | NEW |