15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h>
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/mac/scoped_nsobject.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/ui_base_export.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A class that handles saving and restoring focus.  An instance of
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this class snapshots the currently focused view when it is
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// constructed, and callers can use restoreFocus to return focus to
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that view.  FocusTracker will not restore focus to views that are
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// no longer in the view hierarchy or are not in the correct window.
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)UI_BASE_EXPORT
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface FocusTracker : NSObject {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @private
18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<NSView> focusedView_;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |window| is the window that we are saving focus for.  This
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// method snapshots the currently focused view.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (id)initWithWindow:(NSWindow*)window;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Attempts to restore focus to the snapshotted view.  Returns YES if
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// focus was restored.  Will not restore focus if the view is no
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// longer in the view hierarchy under |window|.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (BOOL)restoreFocusInWindow:(NSWindow*)window;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end
30