diff options
author | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 23:29:02 +0000 |
---|---|---|
committer | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 23:29:02 +0000 |
commit | 23576484b6f85938f72a1c993bfdf754b0c54660 (patch) | |
tree | 9f82476f21cc6f849ec3945bfbac3953d79f7f02 | |
parent | 321792ef1baac764227d55fc944f32cf29e50c6a (diff) | |
download | chromium_src-23576484b6f85938f72a1c993bfdf754b0c54660.zip chromium_src-23576484b6f85938f72a1c993bfdf754b0c54660.tar.gz chromium_src-23576484b6f85938f72a1c993bfdf754b0c54660.tar.bz2 |
Save/restore the focused subview.
http://crbug.com/9420
Review URL: http://codereview.chromium.org/100358
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16013 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 7 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.h | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.mm | 21 |
4 files changed, 27 insertions, 14 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 3dba768..6d87b9d 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -484,12 +484,6 @@ willPositionSheet:(NSWindow *)sheet userGesture:(bool)wasUserGesture { DCHECK(oldContents != newContents); - // We do not store the focus when closing the tab to work-around bug 4633. - // Some reports seem to show that the focus manager and/or focused view can - // be garbage at that point, it is not clear why. - if (oldContents && !oldContents->is_being_destroyed()) - oldContents->view()->StoreFocus(); - // Update various elements that are interested in knowing the current // TabContents. #if 0 @@ -506,10 +500,6 @@ willPositionSheet:(NSWindow *)sheet title:base::SysUTF16ToNSString(newContents->GetTitle()) filename:NO]; - if (BrowserList::GetLastActive() == browser_ && - !browser_->tabstrip_model()->closing_all()) - newContents->view()->RestoreFocus(); - #if 0 // TODO(pinkerton):Update as more things become window-specific // Update all the UI bits. diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 88f1dac..bbc18f0 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -17,6 +17,7 @@ #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" #import "chrome/browser/cocoa/tab_view.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "grit/generated_resources.h" @@ -325,8 +326,14 @@ // size than surrounding tabs if the user has many. [self layoutTabs]; + if (oldContents) + oldContents->view()->StoreFocus(); + // Swap in the contents for the new tab [self swapInTabAtIndex:index]; + + if (newContents) + newContents->view()->RestoreFocus(); } // Called when a notification is received from the model that the given tab diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h index 8259316..2745050 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.h +++ b/chrome/browser/tab_contents/tab_contents_view_mac.h @@ -78,6 +78,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_; + // 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 d0d814d4..7e5e6e8 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -123,13 +123,26 @@ void TabContentsViewMac::SetInitialFocus() { } void TabContentsViewMac::StoreFocus() { - // TODO(port) + 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(); } void TabContentsViewMac::RestoreFocus() { - // TODO(port) - // For now just assume we are viewing the tab for the first time. - SetInitialFocus(); + // TODO(avi): Could we be restoring a view that's no longer in the key view + // chain? + if (latent_focus_view_.get()) { + [[cocoa_view_.get() window] makeFirstResponder:latent_focus_view_.get()]; + latent_focus_view_.reset(); + } } void TabContentsViewMac::UpdateDragCursor(bool is_drop_target) { |