summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/focus_tracker.h
blob: f8289799d6ccb16981dd637d208dbdff0c847c83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import <Cocoa/Cocoa.h>

#include "base/scoped_nsobject.h"

// A class that handles saving and restoring focus.  An instance of
// this class snapshots the currently focused view when it is
// constructed, and callers can use restoreFocus to return focus to
// that view.  FocusTracker will not restore focus to views that are
// no longer in the view hierarchy or are not in the correct window.

@interface FocusTracker : NSObject {
 @private
  scoped_nsobject<NSView> focusedView_;
}

// |window| is the window that we are saving focus for.  This
// method snapshots the currently focused view.
- (id)initWithWindow:(NSWindow*)window;

// Attempts to restore focus to the snapshotted view.  Returns YES if
// focus was restored.  Will not restore focus if the view is no
// longer in the view hierarchy under |window|.
- (BOOL)restoreFocusInWindow:(NSWindow*)window;
@end