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

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

Issue 1146873002: [MacViews] Enable dragging a window by its caption/draggable areas. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/test/windowed_nsnotification_observer.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/windowed_nsnotification_observer.mm
diff --git a/ui/base/test/windowed_nsnotification_observer.mm b/ui/base/test/windowed_nsnotification_observer.mm
new file mode 100644
index 0000000000000000000000000000000000000000..02f45179e9b25e1f75ca215c704a5d93d528a40c
--- /dev/null
+++ b/ui/base/test/windowed_nsnotification_observer.mm
@@ -0,0 +1,67 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/base/test/windowed_nsnotification_observer.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/run_loop.h"
+
+@interface WindowedNSNotificationObserver ()
+- (void)onNotification:(NSNotification*)notification;
+@end
+
+@implementation WindowedNSNotificationObserver
+
+- (id)initForNotification:(NSString*)name {
+ if ((self = [super init])) {
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(onNotification:)
+ name:name
+ object:nil];
+ }
+ return self;
+}
+
+- (id)initForWorkspaceNotification:(NSString*)name
+ bundleId:(NSString*)bundleId {
+ if ((self = [super init])) {
+ bundleId_.reset([bundleId copy]);
+ [[[NSWorkspace sharedWorkspace] notificationCenter]
+ addObserver:self
+ selector:@selector(onNotification:)
+ name:name
+ object:nil];
+ }
+ return self;
+}
+
+- (void)onNotification:(NSNotification*)notification {
+ if (bundleId_) {
+ NSRunningApplication* application =
+ [[notification userInfo] objectForKey:NSWorkspaceApplicationKey];
+ if (![[application bundleIdentifier] isEqualToString:bundleId_])
+ return;
+
+ [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
+ } else {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ }
+
+ notificationReceived_ = YES;
+ if (runLoop_)
+ runLoop_->Quit();
+}
+
+- (void)wait {
+ if (notificationReceived_)
+ return;
+
+ base::RunLoop runLoop;
+ runLoop_ = &runLoop;
+ runLoop.Run();
+ runLoop_ = nullptr;
+}
+
+@end
« no previous file with comments | « ui/base/test/windowed_nsnotification_observer.h ('k') | ui/base/ui_base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698