Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4887)

Unified Diff: chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc

Issue 10446076: Handle Escape key on constrained window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/print_preview/print_preview.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc
diff --git a/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc b/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc
index c927a4a6742dcc69ba09845230ca891e8a2a8d78..d65cc8a9163dbc72a4113b8b2c24eabaee08d5e9 100644
--- a/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc
+++ b/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc
@@ -8,6 +8,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
+#include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h"
+#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/size.h"
#include "ui/views/controls/webview/webview.h"
@@ -29,8 +31,10 @@ class ConstrainedWebDialogDelegateViews
ConstrainedWebDialogDelegateViews(
Profile* profile,
WebDialogDelegate* delegate,
- WebDialogWebContentsDelegate* tab_delegate)
- : ConstrainedWebDialogDelegateBase(profile, delegate, tab_delegate) {
+ WebDialogWebContentsDelegate* tab_delegate,
+ views::WebView* view)
+ : ConstrainedWebDialogDelegateBase(profile, delegate, tab_delegate),
+ view_(view) {
WebContents* web_contents = tab()->web_contents();
if (tab_delegate) {
set_override_tab_delegate(tab_delegate);
@@ -47,7 +51,19 @@ class ConstrainedWebDialogDelegateViews
window()->CloseConstrainedWindow();
}
+ // contents::WebContentsDelegate
+ virtual void HandleKeyboardEvent(
+ const content::NativeWebKeyboardEvent& event) OVERRIDE {
+ unhandled_keyboard_event_handler_.HandleKeyboardEvent(
+ event, view_->GetFocusManager());
+ }
+
private:
+ // Converts keyboard events on the WebContents to accelerators.
+ UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
+
+ views::WebView* view_;
+
DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews);
};
@@ -113,6 +129,13 @@ class ConstrainedWebDialogDelegateViewViews
}
// views::WebView overrides.
+ virtual bool AcceleratorPressed(
+ const ui::Accelerator& accelerator) OVERRIDE {
+ // Pressing ESC closes the dialog.
+ DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code());
+ window()->CloseConstrainedWindow();
+ return true;
+ }
virtual gfx::Size GetPreferredSize() OVERRIDE {
gfx::Size size;
if (!impl_->closed_via_webui())
@@ -133,8 +156,13 @@ ConstrainedWebDialogDelegateViewViews::ConstrainedWebDialogDelegateViewViews(
: views::WebView(profile),
impl_(new ConstrainedWebDialogDelegateViews(profile,
delegate,
- tab_delegate)) {
+ tab_delegate,
+ this)) {
SetWebContents(tab()->web_contents());
+
+ // Pressing ESC closes the dialog.
+ set_allow_accelerators(true);
+ AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
}
ConstrainedWebDialogDelegateViewViews::~ConstrainedWebDialogDelegateViewViews() {
« no previous file with comments | « chrome/browser/resources/print_preview/print_preview.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698