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

Side by Side 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, 6 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/base/test/windowed_nsnotification_observer.h ('k') | ui/base/ui_base.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ui/base/test/windowed_nsnotification_observer.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/run_loop.h"
10
11 @interface WindowedNSNotificationObserver ()
12 - (void)onNotification:(NSNotification*)notification;
13 @end
14
15 @implementation WindowedNSNotificationObserver
16
17 - (id)initForNotification:(NSString*)name {
18 if ((self = [super init])) {
19 [[NSNotificationCenter defaultCenter] addObserver:self
20 selector:@selector(onNotification:)
21 name:name
22 object:nil];
23 }
24 return self;
25 }
26
27 - (id)initForWorkspaceNotification:(NSString*)name
28 bundleId:(NSString*)bundleId {
29 if ((self = [super init])) {
30 bundleId_.reset([bundleId copy]);
31 [[[NSWorkspace sharedWorkspace] notificationCenter]
32 addObserver:self
33 selector:@selector(onNotification:)
34 name:name
35 object:nil];
36 }
37 return self;
38 }
39
40 - (void)onNotification:(NSNotification*)notification {
41 if (bundleId_) {
42 NSRunningApplication* application =
43 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey];
44 if (![[application bundleIdentifier] isEqualToString:bundleId_])
45 return;
46
47 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
48 } else {
49 [[NSNotificationCenter defaultCenter] removeObserver:self];
50 }
51
52 notificationReceived_ = YES;
53 if (runLoop_)
54 runLoop_->Quit();
55 }
56
57 - (void)wait {
58 if (notificationReceived_)
59 return;
60
61 base::RunLoop runLoop;
62 runLoop_ = &runLoop;
63 runLoop.Run();
64 runLoop_ = nullptr;
65 }
66
67 @end
OLDNEW
« 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