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" | |
6 | |
7 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
8 #include <stdint.h> | 6 #include <stdint.h> |
9 | 7 |
| 8 #include <memory> |
| 9 |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
11 #import "base/mac/scoped_objc_class_swizzler.h" | 11 #import "base/mac/scoped_objc_class_swizzler.h" |
12 #include "base/mac/sdk_forward_declarations.h" | 12 #include "base/mac/sdk_forward_declarations.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 16 #include "ui/events/event_utils.h" |
17 #import "ui/events/test/cocoa_test_event_utils.h" | 17 #import "ui/events/test/cocoa_test_event_utils.h" |
18 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
19 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 19 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 NSWindow* g_test_window = nil; | 23 NSWindow* g_test_window = nil; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 NSPoint screen_point = | 114 NSPoint screen_point = |
115 [test_window() convertRectToScreen:window_rect].origin; | 115 [test_window() convertRectToScreen:window_rect].origin; |
116 CGFloat primary_screen_height = | 116 CGFloat primary_screen_height = |
117 NSHeight([[[NSScreen screens] firstObject] frame]); | 117 NSHeight([[[NSScreen screens] firstObject] frame]); |
118 screen_point.y = primary_screen_height - screen_point.y; | 118 screen_point.y = primary_screen_height - screen_point.y; |
119 CGEventSetLocation(scroll, NSPointToCGPoint(screen_point)); | 119 CGEventSetLocation(scroll, NSPointToCGPoint(screen_point)); |
120 return [NSEvent eventWithCGEvent:scroll]; | 120 return [NSEvent eventWithCGEvent:scroll]; |
121 } | 121 } |
122 | 122 |
123 private: | 123 private: |
124 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzler_; | 124 std::unique_ptr<base::mac::ScopedObjCClassSwizzler> swizzler_; |
125 | 125 |
126 DISALLOW_COPY_AND_ASSIGN(EventsMacTest); | 126 DISALLOW_COPY_AND_ASSIGN(EventsMacTest); |
127 }; | 127 }; |
128 | 128 |
129 } // namespace | 129 } // namespace |
130 | 130 |
131 TEST_F(EventsMacTest, EventFlagsFromNative) { | 131 TEST_F(EventsMacTest, EventFlagsFromNative) { |
132 // Left click. | 132 // Left click. |
133 NSEvent* left = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0); | 133 NSEvent* left = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0); |
134 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, EventFlagsFromNative(left)); | 134 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, EventFlagsFromNative(left)); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0); | 309 event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0); |
310 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(event)); | 310 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(event)); |
311 | 311 |
312 event = cocoa_test_event_utils::EnterEvent(); | 312 event = cocoa_test_event_utils::EnterEvent(); |
313 EXPECT_EQ(ui::ET_MOUSE_ENTERED, ui::EventTypeFromNative(event)); | 313 EXPECT_EQ(ui::ET_MOUSE_ENTERED, ui::EventTypeFromNative(event)); |
314 event = cocoa_test_event_utils::ExitEvent(); | 314 event = cocoa_test_event_utils::ExitEvent(); |
315 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(event)); | 315 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(event)); |
316 } | 316 } |
317 | 317 |
318 } // namespace ui | 318 } // namespace ui |
OLD | NEW |