summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 15:10:58 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 15:10:58 +0000
commit46b44f5d2b5720480d27b9cae607b7b0a078430e (patch)
tree1ff28321cf88b56db6ba61c64cf7fd5a5bc7fc0a /chrome/browser/tab_contents
parentfb05865fb200994c4f861f94ca198eed522b4976 (diff)
downloadchromium_src-46b44f5d2b5720480d27b9cae607b7b0a078430e.zip
chromium_src-46b44f5d2b5720480d27b9cae607b7b0a078430e.tar.gz
chromium_src-46b44f5d2b5720480d27b9cae607b7b0a078430e.tar.bz2
[Mac] Save/restore focus in TabContentsViewMac.
BUG=http://crbug.com/12556 TEST=Open two tabs. Focus the omnibox in one, switch tabs and then back again. Omnibox should still have focus. Repeat with the findbar instead of the omnibox. Review URL: http://codereview.chromium.org/206015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26682 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_mac.h6
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_mac.mm25
2 files changed, 14 insertions, 17 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h
index d140c6c..c9151378 100644
--- a/chrome/browser/tab_contents/tab_contents_view_mac.h
+++ b/chrome/browser/tab_contents/tab_contents_view_mac.h
@@ -18,6 +18,7 @@
class FilePath;
class FindBarMac;
+@class FocusTracker;
@class SadTabView;
class TabContentsViewMac;
@class WebDragSource;
@@ -86,8 +87,9 @@ class TabContentsViewMac : public TabContentsView,
// The Cocoa NSView that lives in the view hierarchy.
scoped_nsobject<TabContentsViewCocoa> cocoa_view_;
- // The Cocoa NSView to restore the focus to when focus returns.
- scoped_nsobject<NSView> latent_focus_view_;
+ // Keeps track of which NSView has focus so we can restore the focus when
+ // focus returns.
+ scoped_nsobject<FocusTracker> focus_tracker_;
// Used to get notifications about renderers coming and going.
NotificationRegistrar registrar_;
diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm
index 7c85dfd..1dad0a5 100644
--- a/chrome/browser/tab_contents/tab_contents_view_mac.mm
+++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm
@@ -7,6 +7,7 @@
#include <string>
#include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
+#import "chrome/browser/cocoa/focus_tracker.h"
#include "chrome/browser/cocoa/sad_tab_view.h"
#import "chrome/browser/cocoa/web_drag_source.h"
#import "chrome/browser/cocoa/web_drop_target.h"
@@ -158,32 +159,26 @@ void TabContentsViewMac::SetInitialFocus() {
}
void TabContentsViewMac::StoreFocus() {
- NSResponder* current_focus = [[cocoa_view_.get() window] firstResponder];
- if ([current_focus isKindOfClass:[NSView class]]) {
- NSView* current_focus_view = (NSView*)current_focus;
-
- if ([current_focus_view isDescendantOf:cocoa_view_.get()]) {
- latent_focus_view_.reset([current_focus_view retain]);
- return;
- }
- }
-
- latent_focus_view_.reset();
+ // We're explicitly being asked to store focus, so don't worry if there's
+ // already a view saved.
+ focus_tracker_.reset(
+ [[FocusTracker alloc] initWithWindow:[cocoa_view_ window]]);
}
void TabContentsViewMac::RestoreFocus() {
// TODO(avi): Could we be restoring a view that's no longer in the key view
// chain?
- if (latent_focus_view_.get()) {
- [[cocoa_view_ window] makeFirstResponder:latent_focus_view_.get()];
- latent_focus_view_.reset();
- } else {
+ if (!(focus_tracker_.get() &&
+ [focus_tracker_ restoreFocusInWindow:[cocoa_view_ window]])) {
+ // Fall back to the default focus behavior if we could not restore focus.
// TODO(shess): If location-bar gets focus by default, this will
// select-all in the field. If there was a specific selection in
// the field when we navigated away from it, we should restore
// that selection.
SetInitialFocus();
}
+
+ focus_tracker_.reset(nil);
}
void TabContentsViewMac::UpdateDragCursor(WebDragOperation operation) {