OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 #include "chrome/browser/ui/cocoa/native_window_tracker_cocoa.h" |
| 6 |
| 7 #import <AppKit/AppKit.h> |
| 8 |
| 9 @interface BridgedNativeWindowTracker : NSObject { |
| 10 @private |
| 11 NSWindow* window_; |
| 12 } |
| 13 |
| 14 - (id)initWithNSWindow:(NSWindow*)window; |
| 15 - (bool)wasNSWindowClosed; |
| 16 - (void)onWindowWillClose:(NSNotification*)notification; |
| 17 |
| 18 @end |
| 19 |
| 20 @implementation BridgedNativeWindowTracker |
| 21 |
| 22 - (id)initWithNSWindow:(NSWindow*)window { |
| 23 window_ = window; |
| 24 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 25 [center addObserver:self |
| 26 selector:@selector(onWindowWillClose:) |
| 27 name:NSWindowWillCloseNotification |
| 28 object:window_]; |
| 29 return self; |
| 30 } |
| 31 |
| 32 - (void)dealloc { |
| 33 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 34 [super dealloc]; |
| 35 } |
| 36 |
| 37 - (bool)wasNSWindowClosed { |
| 38 return window_ == nil; |
| 39 } |
| 40 |
| 41 - (void)onWindowWillClose:(NSNotification*)notification { |
| 42 [[NSNotificationCenter defaultCenter] |
| 43 removeObserver:self |
| 44 name:NSWindowWillCloseNotification |
| 45 object:window_]; |
| 46 window_ = nil; |
| 47 } |
| 48 |
| 49 @end |
| 50 |
| 51 NativeWindowTrackerCocoa::NativeWindowTrackerCocoa(gfx::NativeWindow window) { |
| 52 bridge_.reset([[BridgedNativeWindowTracker alloc] initWithNSWindow:window]); |
| 53 } |
| 54 |
| 55 NativeWindowTrackerCocoa::~NativeWindowTrackerCocoa() { |
| 56 } |
| 57 |
| 58 bool NativeWindowTrackerCocoa::WasNativeWindowClosed() const { |
| 59 return [bridge_ wasNSWindowClosed]; |
| 60 } |
| 61 |
| 62 // static |
| 63 scoped_ptr<NativeWindowTracker> NativeWindowTracker::Create( |
| 64 gfx::NativeWindow window) { |
| 65 return scoped_ptr<NativeWindowTracker>(new NativeWindowTrackerCocoa(window)); |
| 66 } |
OLD | NEW |