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

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

Issue 1777653002: Prepare ui/ module for compilation with OS X 10.7 deployment target. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More compile errors. Created 4 years, 9 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
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl_cocoa.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "ui/base/cocoa/cocoa_base_utils.h"
12 #include "ui/events/event_processor.h" 13 #include "ui/events/event_processor.h"
13 #include "ui/events/event_target.h" 14 #include "ui/events/event_target.h"
14 #include "ui/events/event_target_iterator.h" 15 #include "ui/events/event_target_iterator.h"
15 #include "ui/events/event_targeter.h" 16 #include "ui/events/event_targeter.h"
16 #import "ui/events/test/cocoa_test_event_utils.h" 17 #import "ui/events/test/cocoa_test_event_utils.h"
17 #include "ui/events/test/event_generator.h" 18 #include "ui/events/test/event_generator.h"
18 #include "ui/gfx/mac/coordinate_conversion.h" 19 #include "ui/gfx/mac/coordinate_conversion.h"
19 20
20 namespace { 21 namespace {
21 22
22 // Set (and always cleared) in EmulateSendEvent() to provide an answer for 23 // Set (and always cleared) in EmulateSendEvent() to provide an answer for
23 // [NSApp currentEvent]. 24 // [NSApp currentEvent].
24 NSEvent* g_current_event = nil; 25 NSEvent* g_current_event = nil;
25 26
26 } // namespace 27 } // namespace
27 28
28 @interface NSEventDonor : NSObject 29 @interface NSEventDonor : NSObject
29 @end 30 @end
30 31
31 @interface NSApplicationDonor : NSObject 32 @interface NSApplicationDonor : NSObject
32 @end 33 @end
33 34
34 namespace { 35 namespace {
35 36
36 NSPoint ConvertRootPointToTarget(NSWindow* target, 37 NSPoint ConvertRootPointToTarget(NSWindow* target,
37 const gfx::Point& point_in_root) { 38 const gfx::Point& point_in_root) {
38 // Normally this would do [NSWindow convertScreenToBase:]. However, Cocoa can 39 // Normally this would do ui::ConvertPointFromScreenToWindow. However, Cocoa
39 // reposition the window on screen and make things flaky. Initially, just 40 // can reposition the window on screen and make things flaky. Initially, just
40 // assume that the contentRect of |target| is at the top-left corner of the 41 // assume that the contentRect of |target| is at the top-left corner of the
41 // screen. 42 // screen.
42 NSRect content_rect = [target contentRectForFrameRect:[target frame]]; 43 NSRect content_rect = [target contentRectForFrameRect:[target frame]];
43 return NSMakePoint(point_in_root.x(), 44 return NSMakePoint(point_in_root.x(),
44 NSHeight(content_rect) - point_in_root.y()); 45 NSHeight(content_rect) - point_in_root.y());
45 } 46 }
46 47
47 // Inverse of ui::EventFlagsFromModifiers(). 48 // Inverse of ui::EventFlagsFromModifiers().
48 NSUInteger EventFlagsToModifiers(int flags) { 49 NSUInteger EventFlagsToModifiers(int flags) {
49 NSUInteger modifiers = 0; 50 NSUInteger modifiers = 0;
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 + (NSPoint)mouseLocation { 467 + (NSPoint)mouseLocation {
467 ui::test::EventGenerator* generator = GetActiveGenerator(); 468 ui::test::EventGenerator* generator = GetActiveGenerator();
468 if (!generator) 469 if (!generator)
469 return [NSEventDonor mouseLocation]; // Call original implementation. 470 return [NSEventDonor mouseLocation]; // Call original implementation.
470 471
471 // The location is the point in the root window which, for desktop widgets, is 472 // The location is the point in the root window which, for desktop widgets, is
472 // the widget itself. 473 // the widget itself.
473 gfx::Point point_in_root = generator->current_location(); 474 gfx::Point point_in_root = generator->current_location();
474 NSWindow* window = EventGeneratorDelegateMac::GetInstance()->window(); 475 NSWindow* window = EventGeneratorDelegateMac::GetInstance()->window();
475 NSPoint point_in_window = ConvertRootPointToTarget(window, point_in_root); 476 NSPoint point_in_window = ConvertRootPointToTarget(window, point_in_root);
476 return [window convertBaseToScreen:point_in_window]; 477 return ui::ConvertPointFromWindowToScreen(window, point_in_window);
477 } 478 }
478 479
479 @end 480 @end
480 481
481 @implementation NSApplicationDonor 482 @implementation NSApplicationDonor
482 483
483 - (NSEvent*)currentEvent { 484 - (NSEvent*)currentEvent {
484 if (g_current_event) 485 if (g_current_event)
485 return g_current_event; 486 return g_current_event;
486 487
487 // Find the original implementation and invoke it. 488 // Find the original implementation and invoke it.
488 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod(); 489 IMP original = EventGeneratorDelegateMac::GetInstance()->CurrentEventMethod();
489 return original(self, _cmd); 490 return original(self, _cmd);
490 } 491 }
491 492
492 @end 493 @end
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl_cocoa.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698