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 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 NSTimeInterval since_system_startup = [native_event timestamp]; | 80 NSTimeInterval since_system_startup = [native_event timestamp]; |
81 // Truncate to extract seconds before doing floating point arithmetic. | 81 // Truncate to extract seconds before doing floating point arithmetic. |
82 int64_t seconds = since_system_startup; | 82 int64_t seconds = since_system_startup; |
83 since_system_startup -= seconds; | 83 since_system_startup -= seconds; |
84 int64_t microseconds = since_system_startup * 1000000; | 84 int64_t microseconds = since_system_startup * 1000000; |
85 return base::TimeDelta::FromSeconds(seconds) + | 85 return base::TimeDelta::FromSeconds(seconds) + |
86 base::TimeDelta::FromMicroseconds(microseconds); | 86 base::TimeDelta::FromMicroseconds(microseconds); |
87 } | 87 } |
88 | 88 |
89 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 89 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
90 if (![native_event window]) { | 90 NSWindow* window = [native_event window]; |
91 if (!window) { | |
91 NOTIMPLEMENTED(); // Point will be in screen coordinates. | 92 NOTIMPLEMENTED(); // Point will be in screen coordinates. |
92 return gfx::Point(); | 93 return gfx::Point(); |
93 } | 94 } |
94 NSPoint location = [native_event locationInWindow]; | 95 NSPoint location = [native_event locationInWindow]; |
95 return gfx::Point(location.x, | 96 NSRect content_rect = [window contentRectForFrameRect:[window frame]]; |
96 NSHeight([[native_event window] frame]) - location.y); | 97 return gfx::Point(location.x, NSHeight(content_rect) - location.y); |
97 } | 98 } |
tapted
2014/06/05 07:33:35
Note most of my local branches have been using a "
Robert Sesek
2014/06/05 14:08:27
I think I like extracting this information directl
| |
98 | 99 |
99 gfx::Point EventSystemLocationFromNative( | 100 gfx::Point EventSystemLocationFromNative( |
100 const base::NativeEvent& native_event) { | 101 const base::NativeEvent& native_event) { |
101 NOTIMPLEMENTED(); | 102 NOTIMPLEMENTED(); |
102 return gfx::Point(); | 103 return gfx::Point(); |
103 } | 104 } |
104 | 105 |
105 int EventButtonFromNative(const base::NativeEvent& native_event) { | 106 int EventButtonFromNative(const base::NativeEvent& native_event) { |
106 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
107 return 0; | 108 return 0; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 | 219 |
219 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | 220 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { |
220 return KeyboardCodeFromNSEvent(native_event); | 221 return KeyboardCodeFromNSEvent(native_event); |
221 } | 222 } |
222 | 223 |
223 const char* CodeFromNative(const base::NativeEvent& native_event) { | 224 const char* CodeFromNative(const base::NativeEvent& native_event) { |
224 return CodeFromNSEvent(native_event); | 225 return CodeFromNSEvent(native_event); |
225 } | 226 } |
226 | 227 |
227 } // namespace ui | 228 } // namespace ui |
OLD | NEW |