summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/views/frame/browser_view.cc25
-rw-r--r--chrome/browser/views/frame/browser_view.h6
2 files changed, 28 insertions, 3 deletions
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index 937a79a5..53b869b 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -64,6 +64,7 @@
#endif
#include "views/controls/single_split_view.h"
#include "views/fill_layout.h"
+#include "views/focus/external_focus_tracker.h"
#include "views/view.h"
#include "views/widget/root_view.h"
#include "views/window/dialog_delegate.h"
@@ -1624,14 +1625,32 @@ bool BrowserView::MaybeShowInfoBar(TabContents* contents) {
void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) {
TabContents* devtools_contents =
DevToolsWindow::GetDevToolsContents(tab_contents);
+
+ bool should_show = devtools_contents && !devtools_container_->IsVisible();
+ bool should_hide = !devtools_contents && devtools_container_->IsVisible();
+
devtools_container_->ChangeTabContents(devtools_contents);
- if (!devtools_contents && devtools_container_->IsVisible()) {
+
+ if (should_show) {
+ if (!devtools_focus_tracker_.get()) {
+ // Install devtools focus tracker when dev tools window is shown for the
+ // first time.
+ devtools_focus_tracker_.reset(
+ new views::ExternalFocusTracker(devtools_container_,
+ GetFocusManager()));
+ }
+ devtools_container_->SetVisible(true);
+ contents_split_->Layout();
+ } else if (should_hide) {
// Store split offset when hiding devtools window only.
g_browser_process->local_state()->SetInteger(
prefs::kDevToolsSplitLocation, contents_split_->divider_offset());
+ // Restore focus to the last focused view when hiding devtools window.
+ devtools_focus_tracker_->FocusLastFocusedExternalView();
+
+ devtools_container_->SetVisible(false);
+ contents_split_->Layout();
}
- devtools_container_->SetVisible(devtools_contents != NULL);
- contents_split_->Layout();
}
void BrowserView::UpdateUIForContents(TabContents* contents) {
diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h
index 3aaf547..fdb5f86 100644
--- a/chrome/browser/views/frame/browser_view.h
+++ b/chrome/browser/views/frame/browser_view.h
@@ -45,6 +45,7 @@ class ToolbarView;
class ZoomMenuModel;
namespace views {
+class ExternalFocusTracker;
class Menu;
class SingleSplitView;
}
@@ -420,6 +421,11 @@ class BrowserView : public BrowserWindow,
// Split view containing the contents container and devtools container.
views::SingleSplitView* contents_split_;
+ // Tracks and stores the last focused view which is not the
+ // devtools_container_ or any of its children. Used to restore focus once
+ // the devtools_container_ is hidden.
+ scoped_ptr<views::ExternalFocusTracker> devtools_focus_tracker_;
+
// The Status information bubble that appears at the bottom of the window.
scoped_ptr<StatusBubbleViews> status_bubble_;