Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: ui/views/test/event_generator_delegate_mac.mm

Issue 2794213002: MacViews: Fix some TableView tests, add ui::EventGenerator::set_assume_window_at_origin(bool) (Closed)
Patch Set: Yeah. that's a lot of failures Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 } // namespace 27 } // namespace
28 28
29 @interface NSEventDonor : NSObject 29 @interface NSEventDonor : NSObject
30 @end 30 @end
31 31
32 @interface NSApplicationDonor : NSObject 32 @interface NSApplicationDonor : NSObject
33 @end 33 @end
34 34
35 namespace { 35 namespace {
36 36
37 // Return the current owner of the EventGeneratorDelegate. May be null.
38 ui::test::EventGenerator* GetActiveGenerator();
39
37 NSPoint ConvertRootPointToTarget(NSWindow* target, 40 NSPoint ConvertRootPointToTarget(NSWindow* target,
38 const gfx::Point& point_in_root) { 41 const gfx::Point& point_in_root) {
39 // Normally this would do ui::ConvertPointFromScreenToWindow. However, Cocoa 42 DCHECK(GetActiveGenerator());
40 // can reposition the window on screen and make things flaky. Initially, just 43 gfx::Point point = point_in_root;
41 // assume that the contentRect of |target| is at the top-left corner of the 44
42 // screen. 45 if (GetActiveGenerator()->assume_window_at_origin()) {
43 NSRect content_rect = [target contentRectForFrameRect:[target frame]]; 46 // When assuming the window is at the origin, ignore the titlebar as well.
44 return NSMakePoint(point_in_root.x(), 47 NSRect content_rect = [target contentRectForFrameRect:[target frame]];
45 NSHeight(content_rect) - point_in_root.y()); 48 return NSMakePoint(point.x(), NSHeight(content_rect) - point.y());
49 }
50
51 point -= gfx::ScreenRectFromNSRect([target frame]).OffsetFromOrigin();
52 return NSMakePoint(point.x(), NSHeight([target frame]) - point.y());
46 } 53 }
47 54
48 // Inverse of ui::EventFlagsFromModifiers(). 55 // Inverse of ui::EventFlagsFromModifiers().
49 NSUInteger EventFlagsToModifiers(int flags) { 56 NSUInteger EventFlagsToModifiers(int flags) {
50 NSUInteger modifiers = 0; 57 NSUInteger modifiers = 0;
51 modifiers |= (flags & ui::EF_SHIFT_DOWN) ? NSShiftKeyMask : 0; 58 modifiers |= (flags & ui::EF_SHIFT_DOWN) ? NSShiftKeyMask : 0;
52 modifiers |= (flags & ui::EF_CONTROL_DOWN) ? NSControlKeyMask : 0; 59 modifiers |= (flags & ui::EF_CONTROL_DOWN) ? NSControlKeyMask : 0;
53 modifiers |= (flags & ui::EF_ALT_DOWN) ? NSAlternateKeyMask : 0; 60 modifiers |= (flags & ui::EF_ALT_DOWN) ? NSAlternateKeyMask : 0;
54 modifiers |= (flags & ui::EF_COMMAND_DOWN) ? NSCommandKeyMask : 0; 61 modifiers |= (flags & ui::EF_COMMAND_DOWN) ? NSCommandKeyMask : 0;
55 modifiers |= (flags & ui::EF_CAPS_LOCK_ON) ? NSAlphaShiftKeyMask : 0; 62 modifiers |= (flags & ui::EF_CAPS_LOCK_ON) ? NSAlphaShiftKeyMask : 0;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 EventGeneratorDelegateMac::GetChildIterator() const { 376 EventGeneratorDelegateMac::GetChildIterator() const {
370 // Return nullptr to dispatch all events to the result of GetRootTarget(). 377 // Return nullptr to dispatch all events to the result of GetRootTarget().
371 return nullptr; 378 return nullptr;
372 } 379 }
373 380
374 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) { 381 void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) {
375 NSEvent* ns_event = 382 NSEvent* ns_event =
376 event->type() == ui::ET_MOUSEWHEEL 383 event->type() == ui::ET_MOUSEWHEEL
377 ? CreateMouseWheelEventInWindow(window_, event) 384 ? CreateMouseWheelEventInWindow(window_, event)
378 : CreateMouseEventInWindow(window_, event->type(), event->location(), 385 : CreateMouseEventInWindow(window_, event->type(), event->location(),
379 event->changed_button_flags()); 386 event->flags());
380 387
381 using Target = ui::test::EventGenerator::Target; 388 using Target = ui::test::EventGenerator::Target;
382 switch (owner_->target()) { 389 switch (owner_->target()) {
383 case Target::APPLICATION: 390 case Target::APPLICATION:
384 [NSApp sendEvent:ns_event]; 391 [NSApp sendEvent:ns_event];
385 break; 392 break;
386 case Target::WINDOW: 393 case Target::WINDOW:
387 [window_ sendEvent:ns_event]; 394 [window_ sendEvent:ns_event];
388 break; 395 break;
389 case Target::WIDGET: 396 case Target::WIDGET:
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 561 }
555 562
556 gfx::Point EventGeneratorDelegateMac::CenterOfWindow( 563 gfx::Point EventGeneratorDelegateMac::CenterOfWindow(
557 gfx::NativeWindow window) const { 564 gfx::NativeWindow window) const {
558 DCHECK_EQ(window, window_); 565 DCHECK_EQ(window, window_);
559 // Assume the window is at the top-left of the coordinate system (even if 566 // Assume the window is at the top-left of the coordinate system (even if
560 // AppKit has moved it into the work area) see ConvertRootPointToTarget(). 567 // AppKit has moved it into the work area) see ConvertRootPointToTarget().
561 return gfx::Point(NSWidth([window frame]) / 2, NSHeight([window frame]) / 2); 568 return gfx::Point(NSWidth([window frame]) / 2, NSHeight([window frame]) / 2);
562 } 569 }
563 570
564 // Return the current owner of the EventGeneratorDelegate. May be null.
565 ui::test::EventGenerator* GetActiveGenerator() { 571 ui::test::EventGenerator* GetActiveGenerator() {
566 return EventGeneratorDelegateMac::GetInstance()->owner(); 572 return EventGeneratorDelegateMac::GetInstance()->owner();
567 } 573 }
568 574
569 } // namespace 575 } // namespace
570 576
571 namespace views { 577 namespace views {
572 namespace test { 578 namespace test {
573 579
574 void InitializeMacEventGeneratorDelegate() { 580 void InitializeMacEventGeneratorDelegate() {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 - (NSEvent*)currentEvent { 625 - (NSEvent*)currentEvent {
620 if (g_current_event) 626 if (g_current_event)
621 return g_current_event; 627 return g_current_event;
622 628
623 // Find the original implementation and invoke it. 629 // Find the original implementation and invoke it.
624 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); 630 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod();
625 return original(self, _cmd); 631 return original(self, _cmd);
626 } 632 }
627 633
628 @end 634 @end
OLDNEW
« ui/events/test/event_generator.h ('K') | « ui/views/controls/table/table_view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698