diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-18 17:36:33 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-18 17:36:33 +0000 |
commit | 31f2db3de431af43175c912298addbb4f7465c50 (patch) | |
tree | 1087b7a1cadfe287674f7e790c79c7d8347eafb2 /chrome | |
parent | 9f07e60d403013e3f17b5dd55e5031318c34d4cd (diff) | |
download | chromium_src-31f2db3de431af43175c912298addbb4f7465c50.zip chromium_src-31f2db3de431af43175c912298addbb4f7465c50.tar.gz chromium_src-31f2db3de431af43175c912298addbb4f7465c50.tar.bz2 |
Fixes several focus issue with popup in the extensions' browser actions:
- when opening a browser action popup, it gets the focus.
- tab traversal now works in the popup
- pressing esc closes the popup (if the keyboard event is not processed by the page)
BUG=22654, 28087, 28086
TEST=Create an extension with a browser extension that shows a popup. Make the popup
so that it has a textfield (that gets focused when the popup show) and a button.
Install the extension. Open the popup, the textfield should have focus. Press
tab, the focus should go to the button. Press Esc, the popup should be closed.
Review URL: http://codereview.chromium.org/402036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32335 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension_host.cc | 17 | ||||
-rw-r--r-- | chrome/browser/views/browser_actions_container.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/browser_bubble_win.cc | 8 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/views/extensions/extension_view.h | 1 |
5 files changed, 41 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index b0771ad..7bf6c7b 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "base/keyboard_codes.h" #include "base/message_loop.h" #include "base/singleton.h" #include "base/string_util.h" @@ -483,6 +484,14 @@ void ExtensionHost::UpdateDragCursor(WebDragOperation operation) { } void ExtensionHost::GotFocus() { +#if defined(TOOLKIT_VIEWS) + // Request focus so that the FocusManager has a focused view and can perform + // normally its key event processing (so that it lets tab key events go to the + // renderer). + view()->RequestFocus(); +#else + // TODO(port) +#endif } void ExtensionHost::TakeFocus(bool reverse) { @@ -493,6 +502,14 @@ bool ExtensionHost::IsReservedAccelerator(const NativeWebKeyboardEvent& event) { } bool ExtensionHost::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { + if (extension_host_type_ == ViewType::EXTENSION_POPUP && + event.windowsKeyCode == base::VKEY_ESCAPE) { + NotificationService::current()->Notify( + NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, + Source<Profile>(profile_), + Details<ExtensionHost>(this)); + return true; + } return false; } diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index f3395a7..b405906 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -11,6 +11,7 @@ #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/profile.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/extensions/extension_popup.h" @@ -451,6 +452,11 @@ void BrowserActionsContainer::BubbleBrowserWindowClosing( } void BrowserActionsContainer::BubbleGotFocus(BrowserBubble* bubble) { + if (!popup_) + return; + + // Forward the focus to the renderer. + popup_->host()->render_view_host()->view()->Focus(); } void BrowserActionsContainer::BubbleLostFocus(BrowserBubble* bubble) { diff --git a/chrome/browser/views/browser_bubble_win.cc b/chrome/browser/views/browser_bubble_win.cc index 3b0b9b8..33a57e1 100644 --- a/chrome/browser/views/browser_bubble_win.cc +++ b/chrome/browser/views/browser_bubble_win.cc @@ -58,11 +58,15 @@ class BubbleWidget : public views::WidgetWin { if (action == WA_INACTIVE && !closed_) { delegate->BubbleLostFocus(bubble_); - } else if (action == WA_ACTIVE) { - delegate->BubbleGotFocus(bubble_); } } + virtual void OnSetFocus(HWND focused_window) { + BrowserBubble::Delegate* delegate = bubble_->delegate(); + if (delegate) + delegate->BubbleGotFocus(bubble_); + } + private: bool closed_; BrowserBubble* bubble_; diff --git a/chrome/browser/views/extensions/extension_view.cc b/chrome/browser/views/extensions/extension_view.cc index c0118ba..7945307 100644 --- a/chrome/browser/views/extensions/extension_view.cc +++ b/chrome/browser/views/extensions/extension_view.cc @@ -22,6 +22,11 @@ ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) container_(NULL), is_clipped_(false) { host_->set_view(this); + + // This view needs to be focusable so it can act as the focused view for the + // focus manager. This is required to have SkipDefaultKeyEventProcessing + // called so the tab key events are forwarded to the renderer. + SetFocusable(true); } ExtensionView::~ExtensionView() { @@ -170,6 +175,12 @@ void ExtensionView::PreferredSizeChanged() { } } +bool ExtensionView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { + // Let the tab key event be processed by the renderer (instead of moving the + // focus to the next focusable view). + return (e.GetKeyCode() == base::VKEY_TAB); +} + void ExtensionView::HandleMouseEvent() { if (container_) container_->OnExtensionMouseEvent(this); diff --git a/chrome/browser/views/extensions/extension_view.h b/chrome/browser/views/extensions/extension_view.h index bd63d73..3b379b1 100644 --- a/chrome/browser/views/extensions/extension_view.h +++ b/chrome/browser/views/extensions/extension_view.h @@ -66,6 +66,7 @@ class ExtensionView : public views::NativeViewHost { protected: // Overridden from views::View. virtual void PreferredSizeChanged(); + virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e); private: friend class ExtensionHost; |