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

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

Issue 1894383002: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Address review comments. Created 4 years, 7 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ui/base/test/scoped_fake_full_keyboard_access.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/logging.h"
10 #import "base/mac/scoped_objc_class_swizzler.h"
11
12 namespace {
13
14 ui::test::ScopedFakeFullKeyboardAccess* g_instance = nullptr;
15 bool g_full_keyboard_access_mode = true;
tapted 2016/05/03 08:08:25 this can be stored as a data member on ScopedFakeF
karandeepb 2016/05/04 01:56:38 Done.
16
17 } // namespace
18
19 // Donates a testing implementation of [NSApp isFullKeyboardAccessEnabled].
20 @interface FakeNSAppKeyboardAccessDonor : NSObject
21 @end
22
23 @implementation FakeNSAppKeyboardAccessDonor
24
25 - (BOOL)isFullKeyboardAccessEnabled {
26 return g_full_keyboard_access_mode;
27 }
28
29 @end
30
31 namespace ui {
32 namespace test {
33
34 ScopedFakeFullKeyboardAccess::ScopedFakeFullKeyboardAccess()
35 : swizzler_(new base::mac::ScopedObjCClassSwizzler(
36 [NSApplication class],
37 [FakeNSAppKeyboardAccessDonor class],
38 @selector(isFullKeyboardAccessEnabled))) {
39 DCHECK(!g_instance)
40 << "Cannot initialize ScopedFakeFullKeyboardAccess twice\n";
41 g_instance = this;
42 g_full_keyboard_access_mode = true;
43 }
44
45 ScopedFakeFullKeyboardAccess::~ScopedFakeFullKeyboardAccess() {
46 DCHECK_EQ(g_instance, this);
47 g_instance = nullptr;
48 }
49
50 // static
51 ScopedFakeFullKeyboardAccess* ScopedFakeFullKeyboardAccess::GetInstance() {
52 return g_instance;
53 }
54
55 void ScopedFakeFullKeyboardAccess::SetFullKeyboardAccessState(bool new_state) {
56 g_full_keyboard_access_mode = new_state;
57 }
58
59 } // namespace test
60 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698