summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 02:10:42 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 02:10:42 +0000
commitc868a5251e1251a5b555c181ffb9e6804dc3e84f (patch)
tree75f4e77c78a2a7c156b62326bbf910f93c98300c
parent442d293cc0b415c6f20231ea2a577b316162c5be (diff)
downloadchromium_src-c868a5251e1251a5b555c181ffb9e6804dc3e84f.zip
chromium_src-c868a5251e1251a5b555c181ffb9e6804dc3e84f.tar.gz
chromium_src-c868a5251e1251a5b555c181ffb9e6804dc3e84f.tar.bz2
Wire up Ctrl+Enter for Find on ToolkitViews to match GTK.
BUG=38366 TEST=Find a link, press Ctrl+Enter. Find box should close chrome should navigate the link. Review URL: http://codereview.chromium.org/1562006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43308 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/views/dropdown_bar_host.cc10
-rw-r--r--chrome/browser/views/dropdown_bar_host.h16
-rw-r--r--chrome/browser/views/find_bar_host.cc37
-rw-r--r--chrome/browser/views/find_bar_host.h6
4 files changed, 48 insertions, 21 deletions
diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc
index 539d6cc..963a81e 100644
--- a/chrome/browser/views/dropdown_bar_host.cc
+++ b/chrome/browser/views/dropdown_bar_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -133,11 +133,11 @@ void DropdownBarHost::FocusWillChange(views::View* focused_before,
if (!our_view_before && our_view_now) {
// We are gaining focus from outside the dropdown widget so we must register
// a handler for Escape.
- RegisterEscAccelerator();
+ RegisterAccelerators();
} else if (our_view_before && !our_view_now) {
// We are losing focus to something outside our widget so we restore the
// original handler for Escape.
- UnregisterEscAccelerator();
+ UnregisterAccelerators();
}
}
@@ -302,14 +302,14 @@ void DropdownBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) {
host()->SetShape(region.release());
}
-void DropdownBarHost::RegisterEscAccelerator() {
+void DropdownBarHost::RegisterAccelerators() {
DCHECK(!esc_accel_target_registered_);
views::Accelerator escape(base::VKEY_ESCAPE, false, false, false);
focus_manager_->RegisterAccelerator(escape, this);
esc_accel_target_registered_ = true;
}
-void DropdownBarHost::UnregisterEscAccelerator() {
+void DropdownBarHost::UnregisterAccelerators() {
DCHECK(esc_accel_target_registered_);
views::Accelerator escape(base::VKEY_ESCAPE, false, false, false);
focus_manager_->UnregisterAccelerator(escape, this);
diff --git a/chrome/browser/views/dropdown_bar_host.h b/chrome/browser/views/dropdown_bar_host.h
index 2528e7f..e77ffa5 100644
--- a/chrome/browser/views/dropdown_bar_host.h
+++ b/chrome/browser/views/dropdown_bar_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -88,13 +88,15 @@ class DropdownBarHost : public views::AcceleratorTarget,
// Returns the browser view that the dropdown belongs to.
BrowserView* browser_view() const { return browser_view_; }
- // Registers this class as the handler for when Escape is pressed. We will
- // unregister once we loose focus. See also: SetFocusChangeListener().
- void RegisterEscAccelerator();
+ // Registers this class as the handler for when Escape is pressed. Once we
+ // loose focus we will unregister Escape and (any accelerators the derived
+ // classes registers by using overrides of RegisterAccelerators). See also:
+ // SetFocusChangeListener().
+ virtual void RegisterAccelerators();
- // When we loose focus, we unregister the handler for Escape. See
- // also: SetFocusChangeListener().
- void UnregisterEscAccelerator();
+ // When we loose focus, we unregister all accelerator handlers. See also:
+ // SetFocusChangeListener().
+ virtual void UnregisterAccelerators();
protected:
// Returns the dropdown bar view.
diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc
index 4fb10b2..b957ad2 100644
--- a/chrome/browser/views/find_bar_host.cc
+++ b/chrome/browser/views/find_bar_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -90,13 +90,18 @@ void FindBarHost::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
// FindBarWin, views::AcceleratorTarget implementation:
bool FindBarHost::AcceleratorPressed(const views::Accelerator& accelerator) {
-#if defined(OS_WIN)
- DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key.
-#endif
- // This will end the Find session and hide the window, causing it to loose
- // focus and in the process unregister us as the handler for the Escape
- // accelerator through the FocusWillChange event.
- find_bar_controller_->EndFindSession(FindBarController::kKeepSelection);
+ base::KeyboardCode key = accelerator.GetKeyCode();
+ if (key == base::VKEY_RETURN && accelerator.IsCtrlDown()) {
+ // Ctrl+Enter closes the Find session and navigates any link that is active.
+ find_bar_controller_->EndFindSession(FindBarController::kActivateSelection);
+ } else if (key == base::VKEY_ESCAPE) {
+ // This will end the Find session and hide the window, causing it to loose
+ // focus and in the process unregister us as the handler for the Escape
+ // accelerator through the FocusWillChange event.
+ find_bar_controller_->EndFindSession(FindBarController::kKeepSelection);
+ } else {
+ NOTREACHED() << "Unknown accelerator";
+ }
return true;
}
@@ -189,6 +194,22 @@ void FindBarHost::GetWidgetBounds(gfx::Rect* bounds) {
*bounds = browser_view()->GetFindBarBoundingBox();
}
+void FindBarHost::RegisterAccelerators() {
+ DropdownBarHost::RegisterAccelerators();
+
+ // Register for Ctrl+Return.
+ views::Accelerator escape(base::VKEY_RETURN, false, true, false);
+ focus_manager()->RegisterAccelerator(escape, this);
+}
+
+void FindBarHost::UnregisterAccelerators() {
+ // Unregister Ctrl+Return.
+ views::Accelerator escape(base::VKEY_RETURN, false, true, false);
+ focus_manager()->UnregisterAccelerator(escape, this);
+
+ DropdownBarHost::UnregisterAccelerators();
+}
+
void FindBarHost::RestoreSavedFocus() {
if (focus_tracker() == NULL) {
// TODO(brettw) Focus() should be on TabContentsView.
diff --git a/chrome/browser/views/find_bar_host.h b/chrome/browser/views/find_bar_host.h
index cf15fba..1e2f92a 100644
--- a/chrome/browser/views/find_bar_host.h
+++ b/chrome/browser/views/find_bar_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -109,6 +109,10 @@ class FindBarHost : public DropdownBarHost,
// then |bounds| will be an empty rectangle.
virtual void GetWidgetBounds(gfx::Rect* bounds);
+ // Additional accelerator handling (on top of what DropDownBarHost does).
+ virtual void RegisterAccelerators();
+ virtual void UnregisterAccelerators();
+
private:
// Allows implementation to tweak widget position.
void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect);