Don't focus unfocusable things.
Review URL: http://codereview.chromium.org/20348

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9765 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 7a9124f..c928031f 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -391,12 +391,15 @@
     // If you hit this DCHECK, please report it to Jay (jcampan).
     DCHECK(focus_manager != NULL) << "No focus manager when restoring focus.";
 
-    if (focus_manager && focus_manager->ContainsView(last_focused_view)) {
+    if (last_focused_view->IsFocusable() && focus_manager &&
+        focus_manager->ContainsView(last_focused_view)) {
       last_focused_view->RequestFocus();
     } else {
-      // The focused view may not belong to the same window hierarchy (for
-      // example if the location bar was focused and the tab is dragged out).
-      // In that case we default to the default focus.
+      // The focused view may not belong to the same window hierarchy (e.g.
+      // if the location bar was focused and the tab is dragged out), or it may
+      // no longer be focusable (e.g. if the location bar was focused and then
+      // we switched to fullscreen mode).  In that case we default to the
+      // default focus.
       SetInitialFocus();
     }
     view_storage->RemoveView(last_focused_view_storage_id_);
diff --git a/chrome/views/base_button.cc b/chrome/views/base_button.cc
index bd4987b..bea0c2f 100644
--- a/chrome/views/base_button.cc
+++ b/chrome/views/base_button.cc
@@ -147,8 +147,7 @@
     if (IsTriggerableEvent(e) && HitTest(e.location())) {
       SetState(BS_PUSHED);
     }
-    if (IsFocusable())
-      RequestFocus();
+    RequestFocus();
   }
   return true;
 }
diff --git a/chrome/views/menu_button.cc b/chrome/views/menu_button.cc
index 0b696ff..ff0400a1 100644
--- a/chrome/views/menu_button.cc
+++ b/chrome/views/menu_button.cc
@@ -180,8 +180,7 @@
 }
 
 bool MenuButton::OnMousePressed(const MouseEvent& e) {
-  if (IsFocusable())
-    RequestFocus();
+  RequestFocus();
   if (GetState() != BS_DISABLED) {
     // If we're draggable (GetDragOperations returns a non-zero value), then
     // don't pop on press, instead wait for release.
diff --git a/chrome/views/native_button.cc b/chrome/views/native_button.cc
index 00aea52..d6db326 100644
--- a/chrome/views/native_button.cc
+++ b/chrome/views/native_button.cc
@@ -191,8 +191,7 @@
 void NativeButton::Clicked() {
   DCHECK(enabled_);
   // Give the focus to the button.
-  if (IsFocusable())
-    RequestFocus();
+  RequestFocus();
 
   if (listener_)
     listener_->ButtonPressed(this);
diff --git a/chrome/views/view.cc b/chrome/views/view.cc
index 3a06c3b..59e5b73 100644
--- a/chrome/views/view.cc
+++ b/chrome/views/view.cc
@@ -1372,9 +1372,8 @@
 
 void View::RequestFocus() {
   RootView* rv = GetRootView();
-  if (rv) {
+  if (rv && IsFocusable())
     rv->FocusView(this);
-  }
 }
 
 void View::WillGainFocus() {