In dialogs, when the focus moves to a button, that button should become the default button.
When the focus is not a button, then the default button should be the one the delegate specifies.

BUG=4132
TEST=Open the option dialog. OK should be the default and focused button. Move the focus around by pressing tab. When a button is selected, it should be the default button.


Review URL: http://codereview.chromium.org/10230

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5056 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/views/view.cc b/chrome/views/view.cc
index 9fccd77..1dbe9f8 100644
--- a/chrome/views/view.cc
+++ b/chrome/views/view.cc
@@ -988,6 +988,33 @@
   RegisterAccelerators();
 }
 
+void View::RemoveAccelerator(const Accelerator& accelerator) {
+  std::vector<Accelerator>::iterator iter;
+  if (!accelerators_.get() ||
+      ((iter = std::find(accelerators_->begin(), accelerators_->end(),
+          accelerator)) == accelerators_->end())) {
+    NOTREACHED() << "Removing non-existing accelerator";
+    return;
+  }
+
+  accelerators_->erase(iter);
+  RootView* root_view = GetRootView();
+  if (!root_view) {
+    // We are not part of a view hierarchy, so there is nothing to do as we
+    // removed ourselves from accelerators_, we won't be registered when added
+    // to one.
+    return;
+  }
+
+  FocusManager* focus_manager = GetFocusManager();
+  if (focus_manager) {
+    // We may not have a FocusManager if the window containing us is being
+    // closed, in which case the FocusManager is being deleted so there is
+    // nothing to unregister.
+    focus_manager->UnregisterAccelerator(accelerator, this);
+  }
+}
+
 void View::ResetAccelerators() {
   if (accelerators_.get()) {
     UnregisterAccelerators();