1 // Copyright (c) 2011 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 <Cocoa/Cocoa.h> 6 7 #include "base/memory/scoped_nsobject.h" 8 9 // A class that handles saving and restoring focus. An instance of 10 // this class snapshots the currently focused view when it is 11 // constructed, and callers can use restoreFocus to return focus to 12 // that view. FocusTracker will not restore focus to views that are 13 // no longer in the view hierarchy or are not in the correct window. 14 15 @interface FocusTracker : NSObject { 16 @private 17 scoped_nsobject<NSView> focusedView_; 18 } 19 20 // |window| is the window that we are saving focus for. This 21 // method snapshots the currently focused view. 22 - (id)initWithWindow:(NSWindow*)window; 23 24 // Attempts to restore focus to the snapshotted view. Returns YES if 25 // focus was restored. Will not restore focus if the view is no 26 // longer in the view hierarchy under |window|. 27 - (BOOL)restoreFocusInWindow:(NSWindow*)window; 28 @end 29