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_deletion_observer_cocoa.h" |
| 6 |
| 7 #import <AppKit/AppKit.h> |
| 8 |
| 9 @interface BridgedNativeWindowDeletionObserver : NSObject { |
| 10 @private |
| 11 NSWindow* window_; |
| 12 } |
| 13 |
| 14 - (id)initWithNSWindow:(NSWindow*)window; |
| 15 - (bool)isNSWindowAlive; |
| 16 - (void)onWindowWillClose:(NSNotification*)notification; |
| 17 |
| 18 @end |
| 19 |
| 20 @implementation BridgedNativeWindowDeletionObserver |
| 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)isNSWindowAlive { |
| 38 return window_; |
| 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 NativeWindowDeletionObserverCocoa::NativeWindowDeletionObserverCocoa( |
| 52 gfx::NativeWindow window) { |
| 53 bridge_.reset([[BridgedNativeWindowDeletionObserver alloc] |
| 54 initWithNSWindow:window]); |
| 55 } |
| 56 |
| 57 NativeWindowDeletionObserverCocoa::~NativeWindowDeletionObserverCocoa() { |
| 58 } |
| 59 |
| 60 bool NativeWindowDeletionObserverCocoa::IsNativeWindowAlive() const { |
| 61 return [bridge_ isNSWindowAlive]; |
| 62 } |
| 63 |
| 64 // static |
| 65 scoped_ptr<NativeWindowDeletionObserver> NativeWindowDeletionObserver::Create( |
| 66 gfx::NativeWindow window) { |
| 67 return scoped_ptr<NativeWindowDeletionObserver>( |
| 68 new NativeWindowDeletionObserverCocoa(window)); |
| 69 } |
OLD | NEW |