Chromium Code Reviews| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 | 7 |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #import "base/mac/scoped_objc_class_swizzler.h" | 9 #import "base/mac/scoped_objc_class_swizzler.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 location:point | 210 location:point |
| 211 modifierFlags:modifiers | 211 modifierFlags:modifiers |
| 212 timestamp:0 | 212 timestamp:0 |
| 213 windowNumber:[window windowNumber] | 213 windowNumber:[window windowNumber] |
| 214 context:nil | 214 context:nil |
| 215 eventNumber:0 | 215 eventNumber:0 |
| 216 clickCount:click_count | 216 clickCount:click_count |
| 217 pressure:1.0]; | 217 pressure:1.0]; |
| 218 } | 218 } |
| 219 | 219 |
| 220 NSEvent* CreateMouseWheelEventInWindow(NSWindow* window, | |
| 221 ui::MouseEvent* mouse_event) { | |
| 222 DCHECK(mouse_event->type() == ui::ET_MOUSEWHEEL); | |
|
tapted
2016/10/30 23:54:46
nit: DCHECK_EQ
snake
2016/10/31 11:32:06
Done.
| |
| 223 ui::MouseWheelEvent* mouse_wheel_event = | |
| 224 static_cast<ui::MouseWheelEvent*>(mouse_event); | |
|
tapted
2016/10/30 23:54:46
mouse_event->AsMouseWheelEvent()
snake
2016/10/31 11:32:06
Done.
| |
| 225 return cocoa_test_event_utils::TestScrollEvent( | |
| 226 ConvertRootPointToTarget(window, mouse_wheel_event->location()), window, | |
| 227 mouse_wheel_event->x_offset(), mouse_wheel_event->y_offset(), false, | |
| 228 NSEventPhaseNone, NSEventPhaseNone); | |
| 229 } | |
| 230 | |
| 220 // Implementation of ui::test::EventGeneratorDelegate for Mac. Everything | 231 // Implementation of ui::test::EventGeneratorDelegate for Mac. Everything |
| 221 // defined inline is just a stub. Interesting overrides are defined below the | 232 // defined inline is just a stub. Interesting overrides are defined below the |
| 222 // class. | 233 // class. |
| 223 class EventGeneratorDelegateMac : public ui::EventTarget, | 234 class EventGeneratorDelegateMac : public ui::EventTarget, |
| 224 public ui::EventSource, | 235 public ui::EventSource, |
| 225 public ui::EventHandler, | 236 public ui::EventHandler, |
| 226 public ui::EventProcessor, | 237 public ui::EventProcessor, |
| 227 public ui::EventTargeter, | 238 public ui::EventTargeter, |
| 228 public ui::test::EventGeneratorDelegate { | 239 public ui::test::EventGeneratorDelegate { |
| 229 public: | 240 public: |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 ui::test::EventGenerator::default_delegate = nullptr; | 353 ui::test::EventGenerator::default_delegate = nullptr; |
| 343 } | 354 } |
| 344 | 355 |
| 345 std::unique_ptr<ui::EventTargetIterator> | 356 std::unique_ptr<ui::EventTargetIterator> |
| 346 EventGeneratorDelegateMac::GetChildIterator() const { | 357 EventGeneratorDelegateMac::GetChildIterator() const { |
| 347 // Return nullptr to dispatch all events to the result of GetRootTarget(). | 358 // Return nullptr to dispatch all events to the result of GetRootTarget(). |
| 348 return nullptr; | 359 return nullptr; |
| 349 } | 360 } |
| 350 | 361 |
| 351 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) { | 362 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) { |
| 352 NSEvent* ns_event = CreateMouseEventInWindow(window_, | 363 NSEvent* ns_event = |
| 353 event->type(), | 364 event->type() == ui::ET_MOUSEWHEEL |
| 354 event->location(), | 365 ? CreateMouseWheelEventInWindow(window_, event) |
| 355 event->changed_button_flags()); | 366 : CreateMouseEventInWindow(window_, event->type(), event->location(), |
| 367 event->changed_button_flags()); | |
| 368 | |
| 356 if (owner_->targeting_application()) | 369 if (owner_->targeting_application()) |
| 357 [NSApp sendEvent:ns_event]; | 370 [NSApp sendEvent:ns_event]; |
| 358 else | 371 else |
| 359 EmulateSendEvent(window_, ns_event); | 372 EmulateSendEvent(window_, ns_event); |
| 360 } | 373 } |
| 361 | 374 |
| 362 void EventGeneratorDelegateMac::OnKeyEvent(ui::KeyEvent* event) { | 375 void EventGeneratorDelegateMac::OnKeyEvent(ui::KeyEvent* event) { |
| 363 NSUInteger modifiers = EventFlagsToModifiers(event->flags()); | 376 NSUInteger modifiers = EventFlagsToModifiers(event->flags()); |
| 364 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent( | 377 NSEvent* ns_event = cocoa_test_event_utils::SynthesizeKeyEvent( |
| 365 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(), | 378 window_, event->type() == ui::ET_KEY_PRESSED, event->key_code(), |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 - (NSEvent*)currentEvent { | 504 - (NSEvent*)currentEvent { |
| 492 if (g_current_event) | 505 if (g_current_event) |
| 493 return g_current_event; | 506 return g_current_event; |
| 494 | 507 |
| 495 // Find the original implementation and invoke it. | 508 // Find the original implementation and invoke it. |
| 496 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); | 509 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); |
| 497 return original(self, _cmd); | 510 return original(self, _cmd); |
| 498 } | 511 } |
| 499 | 512 |
| 500 @end | 513 @end |
| OLD | NEW |