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

Unified Diff: ui/base/test/scoped_fake_nswindow_focus.mm

Issue 1268293002: [MacViews] Fix AccessiblePaneViewTest.SetPaneFocusAndRestore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove roque delta. Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/test/scoped_fake_nswindow_focus.h ('k') | ui/base/ui_base.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/test/scoped_fake_nswindow_focus.mm
diff --git a/chrome/browser/ui/test/scoped_fake_nswindow_main_status.mm b/ui/base/test/scoped_fake_nswindow_focus.mm
similarity index 21%
rename from chrome/browser/ui/test/scoped_fake_nswindow_main_status.mm
rename to ui/base/test/scoped_fake_nswindow_focus.mm
index 0f2c27d6a5956435fe2055abe29f46849c8e83c5..b78680dba23dec94efc4996da2d114eccf24eafe 100644
--- a/chrome/browser/ui/test/scoped_fake_nswindow_main_status.mm
+++ b/ui/base/test/scoped_fake_nswindow_focus.mm
@@ -2,46 +2,99 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import "chrome/browser/ui/test/scoped_fake_nswindow_main_status.h"
+#import "ui/base/test/scoped_fake_nswindow_focus.h"
#import <Cocoa/Cocoa.h>
#import "base/mac/foundation_util.h"
#import "base/mac/scoped_objc_class_swizzler.h"
+using base::mac::ScopedObjCClassSwizzler;
+
namespace {
-NSWindow* g_fake_main_window = nil;
+NSWindow* g_fake_focused_window = nil;
+
+void SetFocus(NSWindow* window) {
+ g_fake_focused_window = window;
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidBecomeMainNotification
+ object:g_fake_focused_window];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidBecomeKeyNotification
+ object:g_fake_focused_window];
+}
+
+void ClearFocus() {
+ NSWindow* window = g_fake_focused_window;
+ g_fake_focused_window = nil;
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidResignKeyNotification
+ object:window];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:NSWindowDidResignMainNotification
+ object:window];
}
-// Donates a testing implementation of [NSWindow isMainWindow].
-@interface IsMainWindowDonorForWindow : NSObject
+} // namespace
+
+// Donates testing implementations of NSWindow methods.
+@interface FakeNSWindowFocusDonor : NSObject
@end
-@implementation IsMainWindowDonorForWindow
+@implementation FakeNSWindowFocusDonor
+
+- (BOOL)isKeyWindow {
+ NSWindow* selfAsWindow = base::mac::ObjCCastStrict<NSWindow>(self);
+ return selfAsWindow == g_fake_focused_window;
+}
+
- (BOOL)isMainWindow {
NSWindow* selfAsWindow = base::mac::ObjCCastStrict<NSWindow>(self);
- return selfAsWindow == g_fake_main_window;
+ return selfAsWindow == g_fake_focused_window;
}
-@end
-ScopedFakeNSWindowMainStatus::ScopedFakeNSWindowMainStatus(NSWindow* window)
- : swizzler_(new base::mac::ScopedObjCClassSwizzler(
- [NSWindow class],
- [IsMainWindowDonorForWindow class],
- @selector(isMainWindow))) {
- DCHECK(!g_fake_main_window);
- g_fake_main_window = window;
- [[NSNotificationCenter defaultCenter]
- postNotificationName:NSWindowDidBecomeMainNotification
- object:g_fake_main_window];
+- (void)makeKeyWindow {
+ NSWindow* selfAsWindow = base::mac::ObjCCastStrict<NSWindow>(self);
+ if (selfAsWindow == g_fake_focused_window ||
+ ![selfAsWindow canBecomeKeyWindow])
+ return;
+
+ ClearFocus();
+ SetFocus(selfAsWindow);
}
-ScopedFakeNSWindowMainStatus::~ScopedFakeNSWindowMainStatus() {
- NSWindow* window = g_fake_main_window;
- g_fake_main_window = nil;
- [[NSNotificationCenter defaultCenter]
- postNotificationName:NSWindowDidResignMainNotification
- object:window];
+- (void)makeMainWindow {
+ [self makeKeyWindow];
+}
+
+@end
+
+namespace ui {
+namespace test {
+
+ScopedFakeNSWindowFocus::ScopedFakeNSWindowFocus()
+ : is_main_swizzler_(
+ new ScopedObjCClassSwizzler([NSWindow class],
+ [FakeNSWindowFocusDonor class],
+ @selector(isMainWindow))),
+ make_main_swizzler_(
+ new ScopedObjCClassSwizzler([NSWindow class],
+ [FakeNSWindowFocusDonor class],
+ @selector(makeMainWindow))),
+ is_key_swizzler_(
+ new ScopedObjCClassSwizzler([NSWindow class],
+ [FakeNSWindowFocusDonor class],
+ @selector(isKeyWindow))),
+ make_key_swizzler_(
+ new ScopedObjCClassSwizzler([NSWindow class],
+ [FakeNSWindowFocusDonor class],
+ @selector(makeKeyWindow))) {}
+
+ScopedFakeNSWindowFocus::~ScopedFakeNSWindowFocus() {
+ ClearFocus();
}
+
+} // namespace test
+} // namespace ui
« no previous file with comments | « ui/base/test/scoped_fake_nswindow_focus.h ('k') | ui/base/ui_base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698