| 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 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 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/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
| 16 #import "ui/events/test/cocoa_test_event_utils.h" | 17 #import "ui/events/test/cocoa_test_event_utils.h" |
| 17 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
| 18 #import "ui/gfx/test/ui_cocoa_test_helper.h" | 19 #import "ui/gfx/test/ui_cocoa_test_helper.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 CGEventCreateScrollWheelEvent(NULL, | 103 CGEventCreateScrollWheelEvent(NULL, |
| 103 kCGScrollEventUnitLine, | 104 kCGScrollEventUnitLine, |
| 104 2, | 105 2, |
| 105 delta_y, | 106 delta_y, |
| 106 delta_x)); | 107 delta_x)); |
| 107 // CGEvents are always in global display coordinates. These are like screen | 108 // CGEvents are always in global display coordinates. These are like screen |
| 108 // coordinates, but flipped. But first the point needs to be converted out | 109 // coordinates, but flipped. But first the point needs to be converted out |
| 109 // of window coordinates (which also requires flipping). | 110 // of window coordinates (which also requires flipping). |
| 110 NSPoint window_point = | 111 NSPoint window_point = |
| 111 NSPointFromCGPoint(Flip(window_location).ToCGPoint()); | 112 NSPointFromCGPoint(Flip(window_location).ToCGPoint()); |
| 112 NSPoint screen_point = [test_window() convertBaseToScreen:window_point]; | 113 NSRect window_rect = NSMakeRect(window_point.x, window_point.y, 0, 0); |
| 114 NSPoint screen_point = |
| 115 [test_window() convertRectToScreen:window_rect].origin; |
| 113 CGFloat primary_screen_height = | 116 CGFloat primary_screen_height = |
| 114 NSHeight([[[NSScreen screens] firstObject] frame]); | 117 NSHeight([[[NSScreen screens] firstObject] frame]); |
| 115 screen_point.y = primary_screen_height - screen_point.y; | 118 screen_point.y = primary_screen_height - screen_point.y; |
| 116 CGEventSetLocation(scroll, NSPointToCGPoint(screen_point)); | 119 CGEventSetLocation(scroll, NSPointToCGPoint(screen_point)); |
| 117 return [NSEvent eventWithCGEvent:scroll]; | 120 return [NSEvent eventWithCGEvent:scroll]; |
| 118 } | 121 } |
| 119 | 122 |
| 120 private: | 123 private: |
| 121 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzler_; | 124 scoped_ptr<base::mac::ScopedObjCClassSwizzler> swizzler_; |
| 122 | 125 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0); | 309 event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0); |
| 307 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(event)); | 310 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(event)); |
| 308 | 311 |
| 309 event = cocoa_test_event_utils::EnterEvent(); | 312 event = cocoa_test_event_utils::EnterEvent(); |
| 310 EXPECT_EQ(ui::ET_MOUSE_ENTERED, ui::EventTypeFromNative(event)); | 313 EXPECT_EQ(ui::ET_MOUSE_ENTERED, ui::EventTypeFromNative(event)); |
| 311 event = cocoa_test_event_utils::ExitEvent(); | 314 event = cocoa_test_event_utils::ExitEvent(); |
| 312 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(event)); | 315 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(event)); |
| 313 } | 316 } |
| 314 | 317 |
| 315 } // namespace ui | 318 } // namespace ui |
| OLD | NEW |