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