summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-05 00:51:05 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-05 00:51:05 +0000
commitc214f4cd90d4bc6db13b861b66d0f72901396c87 (patch)
treeacb6df0d3442d77118518de2a6e74e81a040e339
parentf1491e2bce585acadf7921756ded7ebd1a5396ee (diff)
downloadchromium_src-c214f4cd90d4bc6db13b861b66d0f72901396c87.zip
chromium_src-c214f4cd90d4bc6db13b861b66d0f72901396c87.tar.gz
chromium_src-c214f4cd90d4bc6db13b861b66d0f72901396c87.tar.bz2
Add a PreTarget handler to dispatch Ctrl-Enter during Find in Page
Allows the FocusManager to dispatch the Ctrl-Enter as an accelerator rather than having the Textfield handle a regular return. R=sky@chromium.org BUG=295753 Review URL: https://codereview.chromium.org/23533077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227154 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/find_bar_host_interactive_uitest.cc30
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc20
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.h3
-rw-r--r--ui/views/focus/focus_manager.cc26
-rw-r--r--ui/views/focus/focus_manager.h6
-rw-r--r--ui/views/widget/desktop_aura/desktop_native_widget_aura.cc6
6 files changed, 82 insertions, 9 deletions
diff --git a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc
index 35735ea..4b0963c 100644
--- a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc
+++ b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc
@@ -391,3 +391,33 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_PasteWithoutTextChange) {
ASSERT_TRUE(observer.GetDetailsFor(notification_source.map_key(), &details));
EXPECT_TRUE(details.number_of_matches() > 0);
}
+
+#if defined(OS_WIN)
+IN_PROC_BROWSER_TEST_F(FindInPageTest, CtrlEnter) {
+ ui_test_utils::NavigateToURL(browser(),
+ GURL("data:text/html,This is some text with a "
+ "<a href=\"about:blank\">link</a>."));
+
+ browser()->GetFindBarController()->Show();
+
+ // Search for "link".
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ browser(), ui::VKEY_L, false, false, false, false));
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ browser(), ui::VKEY_I, false, false, false, false));
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ browser(), ui::VKEY_N, false, false, false, false));
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ browser(), ui::VKEY_K, false, false, false, false));
+ EXPECT_EQ(ASCIIToUTF16("link"), GetFindBarText());
+
+ ui_test_utils::UrlLoadObserver observer(
+ GURL("about:blank"), content::NotificationService::AllSources());
+
+ // Send Ctrl-Enter, should cause navigation to about:blank.
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ browser(), ui::VKEY_RETURN, true, false, false, false));
+
+ observer.Wait();
+}
+#endif
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index eb34f07..8753ad4 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -303,12 +303,7 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
break;
}
- bool handled = views::Textfield::OnKeyPressed(event);
-#if !defined(OS_WIN) || defined(USE_AURA)
- // TODO(msw): Avoid this complexity, consolidate cross-platform behavior.
- handled |= SkipDefaultKeyEventProcessing(event);
-#endif
- return handled;
+ return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event);
}
bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) {
@@ -320,8 +315,17 @@ bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) {
bool OmniboxViewViews::SkipDefaultKeyEventProcessing(
const ui::KeyEvent& event) {
- // Handle keyword hint tab-to-search and tabbing through dropdown results.
+ if (views::FocusManager::IsTabTraversalKeyEvent(event) &&
+ ((model()->is_keyword_hint() && !event.IsShiftDown()) ||
+ model()->popup_model()->IsOpen())) {
+ return true;
+ }
+ return Textfield::SkipDefaultKeyEventProcessing(event);
+}
+
+bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {
// This must run before acclerator handling invokes a focus change on tab.
+ // Note the parallel with SkipDefaultKeyEventProcessing above.
if (views::FocusManager::IsTabTraversalKeyEvent(event)) {
if (model()->is_keyword_hint() && !event.IsShiftDown()) {
model()->AcceptKeyword(ENTERED_KEYWORD_MODE_VIA_TAB);
@@ -339,7 +343,7 @@ bool OmniboxViewViews::SkipDefaultKeyEventProcessing(
}
}
- return Textfield::SkipDefaultKeyEventProcessing(event);
+ return false;
}
void OmniboxViewViews::OnFocus() {
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.h b/chrome/browser/ui/views/omnibox/omnibox_view_views.h
index af991f0..635be17 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.h
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.h
@@ -163,6 +163,9 @@ class OmniboxViewViews
// that after invoking this OnAfterPossibleChange() is invoked.
void OnPaste();
+ // Handle keyword hint tab-to-search and tabbing through dropdown results.
+ bool HandleEarlyTabActions(const ui::KeyEvent& event);
+
// When true, the location bar view is read only and also is has a slightly
// different presentation (smaller font size). This is used for popups.
bool popup_window_mode_;
diff --git a/ui/views/focus/focus_manager.cc b/ui/views/focus/focus_manager.cc
index 429b9ad..9000a0d 100644
--- a/ui/views/focus/focus_manager.cc
+++ b/ui/views/focus/focus_manager.cc
@@ -24,6 +24,24 @@
namespace views {
+namespace {
+
+class FocusManagerEventHandler : public ui::EventHandler {
+ public:
+ FocusManagerEventHandler(FocusManager* parent) : focus_manager_(parent) {}
+
+ // Implementation of ui::EventHandler:
+ virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
+ if (!focus_manager_->OnKeyEvent(*event))
+ event->SetHandled();
+ }
+
+ private:
+ FocusManager* focus_manager_;
+};
+
+} // namespace
+
bool FocusManager::shortcut_handling_suspended_ = false;
bool FocusManager::arrow_key_traversal_enabled_ = false;
@@ -62,7 +80,7 @@ bool FocusManager::OnKeyEvent(const ui::KeyEvent& event) {
accelerator.set_type(event.type());
if (event.type() == ui::ET_KEY_PRESSED) {
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(OS_WIN)
// If the focused view wants to process the key event as is, let it be.
// This is not used for linux/aura.
if (focused_view_ && focused_view_->SkipDefaultKeyEventProcessing(event) &&
@@ -512,6 +530,12 @@ bool FocusManager::IsTabTraversalKeyEvent(const ui::KeyEvent& key_event) {
return key_event.key_code() == ui::VKEY_TAB && !key_event.IsControlDown();
}
+ui::EventHandler* FocusManager::GetEventHandler() {
+ if (!event_handler_)
+ event_handler_.reset(new FocusManagerEventHandler(this));
+ return event_handler_.get();
+}
+
void FocusManager::ViewRemoved(View* removed) {
// If the view being removed contains (or is) the focused view,
// clear the focus. However, it's not safe to call ClearFocus()
diff --git a/ui/views/focus/focus_manager.h b/ui/views/focus/focus_manager.h
index be25413..ae3e088 100644
--- a/ui/views/focus/focus_manager.h
+++ b/ui/views/focus/focus_manager.h
@@ -74,6 +74,7 @@
namespace ui {
class AcceleratorTarget;
class AcceleratorManager;
+class EventHandler;
class KeyEvent;
}
@@ -307,6 +308,9 @@ class VIEWS_EXPORT FocusManager {
return arrow_key_traversal_enabled_;
}
+ // Gets an event handler suitable for registering as an observer.
+ ui::EventHandler* GetEventHandler();
+
private:
// Returns the next focusable view. Traversal starts at |starting_view|. If
// |starting_view| is NULL |starting_widget| is consuled to determine which
@@ -363,6 +367,8 @@ class VIEWS_EXPORT FocusManager {
// See description above getter.
bool is_changing_focus_;
+ scoped_ptr<ui::EventHandler> event_handler_;
+
DISALLOW_COPY_AND_ASSIGN(FocusManager);
};
diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
index 48be6df..219f9d9 100644
--- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
+++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
@@ -369,6 +369,12 @@ void DesktopNativeWidgetAura::InitNativeWidget(
content_window_container_);
}
+ if (params.type == Widget::InitParams::TYPE_WINDOW) {
+ FocusManager* focus_manager =
+ native_widget_delegate_->AsWidget()->GetFocusManager();
+ root_window_->AddPreTargetHandler(focus_manager->GetEventHandler());
+ }
+
window_->Show();
desktop_root_window_host_->InitFocus(window_);