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

Side by Side Diff: ui/base/test/scoped_fake_nswindow_focus.mm

Issue 1894383002: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Rebased. Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/base/test/scoped_fake_nswindow_focus.h" 5 #import "ui/base/test/scoped_fake_nswindow_focus.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #import "base/mac/scoped_objc_class_swizzler.h" 10 #import "base/mac/scoped_objc_class_swizzler.h"
11 11
12 using base::mac::ScopedObjCClassSwizzler; 12 using base::mac::ScopedObjCClassSwizzler;
13 13
14 namespace { 14 namespace {
15 15
16 NSWindow* g_fake_focused_window = nil; 16 NSWindow* g_fake_focused_window = nil;
17 IMP g_order_out_impl_ = nullptr;
17 18
18 void SetFocus(NSWindow* window) { 19 void SetFocus(NSWindow* window) {
19 g_fake_focused_window = window; 20 g_fake_focused_window = window;
20 [[NSNotificationCenter defaultCenter] 21 [[NSNotificationCenter defaultCenter]
21 postNotificationName:NSWindowDidBecomeMainNotification 22 postNotificationName:NSWindowDidBecomeMainNotification
22 object:g_fake_focused_window]; 23 object:g_fake_focused_window];
23 [[NSNotificationCenter defaultCenter] 24 [[NSNotificationCenter defaultCenter]
24 postNotificationName:NSWindowDidBecomeKeyNotification 25 postNotificationName:NSWindowDidBecomeKeyNotification
25 object:g_fake_focused_window]; 26 object:g_fake_focused_window];
26 } 27 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return; 63 return;
63 64
64 ClearFocus(); 65 ClearFocus();
65 SetFocus(selfAsWindow); 66 SetFocus(selfAsWindow);
66 } 67 }
67 68
68 - (void)makeMainWindow { 69 - (void)makeMainWindow {
69 [self makeKeyWindow]; 70 [self makeKeyWindow];
70 } 71 }
71 72
73 - (void)orderOut:(id)sender {
tapted 2016/04/20 06:05:57 What tests ended up needing this? It doesn't seem
karandeepb 2016/05/03 02:54:12 I needed this for NativeWidgetMacFullKeyboardAcces
tapted 2016/05/03 08:08:25 OK sounds good. That's lots of reasons :). For a t
karandeepb 2016/05/04 01:56:38 Hehe yeah :) I realized that after writing this!
74 NSWindow* selfAsWindow = base::mac::ObjCCastStrict<NSWindow>(self);
75 if (selfAsWindow == g_fake_focused_window)
76 g_fake_focused_window = nil;
77 g_order_out_impl_(self, _cmd, sender);
78 }
79
72 @end 80 @end
73 81
74 namespace ui { 82 namespace ui {
75 namespace test { 83 namespace test {
76 84
77 ScopedFakeNSWindowFocus::ScopedFakeNSWindowFocus() 85 ScopedFakeNSWindowFocus::ScopedFakeNSWindowFocus()
78 : is_main_swizzler_( 86 : is_main_swizzler_(
79 new ScopedObjCClassSwizzler([NSWindow class], 87 new ScopedObjCClassSwizzler([NSWindow class],
80 [FakeNSWindowFocusDonor class], 88 [FakeNSWindowFocusDonor class],
81 @selector(isMainWindow))), 89 @selector(isMainWindow))),
82 make_main_swizzler_( 90 make_main_swizzler_(
83 new ScopedObjCClassSwizzler([NSWindow class], 91 new ScopedObjCClassSwizzler([NSWindow class],
84 [FakeNSWindowFocusDonor class], 92 [FakeNSWindowFocusDonor class],
85 @selector(makeMainWindow))), 93 @selector(makeMainWindow))),
86 is_key_swizzler_( 94 is_key_swizzler_(
87 new ScopedObjCClassSwizzler([NSWindow class], 95 new ScopedObjCClassSwizzler([NSWindow class],
88 [FakeNSWindowFocusDonor class], 96 [FakeNSWindowFocusDonor class],
89 @selector(isKeyWindow))), 97 @selector(isKeyWindow))),
90 make_key_swizzler_( 98 make_key_swizzler_(
91 new ScopedObjCClassSwizzler([NSWindow class], 99 new ScopedObjCClassSwizzler([NSWindow class],
92 [FakeNSWindowFocusDonor class], 100 [FakeNSWindowFocusDonor class],
93 @selector(makeKeyWindow))) {} 101 @selector(makeKeyWindow))),
102 order_out_swizzler_(
103 new ScopedObjCClassSwizzler([NSWindow class],
104 [FakeNSWindowFocusDonor class],
105 @selector(orderOut:))) {
106 g_order_out_impl_ = order_out_swizzler_->GetOriginalImplementation();
107 }
94 108
95 ScopedFakeNSWindowFocus::~ScopedFakeNSWindowFocus() { 109 ScopedFakeNSWindowFocus::~ScopedFakeNSWindowFocus() {
96 ClearFocus(); 110 ClearFocus();
97 } 111 }
98 112
99 } // namespace test 113 } // namespace test
100 } // namespace ui 114 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698