Chromium Code Reviews| Index: ash/keyboard_overlay/keyboard_overlay_view.cc |
| diff --git a/ash/keyboard_overlay/keyboard_overlay_view.cc b/ash/keyboard_overlay/keyboard_overlay_view.cc |
| index d9a7b6cf615a9b9b1118fe2fbe073b2bdb9e452d..071c26f5f4aae0ec476899f149d0211175cb1b21 100644 |
| --- a/ash/keyboard_overlay/keyboard_overlay_view.cc |
| +++ b/ash/keyboard_overlay/keyboard_overlay_view.cc |
| @@ -5,6 +5,7 @@ |
| #include "ash/keyboard_overlay/keyboard_overlay_view.h" |
| #include "ash/keyboard_overlay/keyboard_overlay_delegate.h" |
| +#include "ash/shell.h" |
| #include "base/utf_string_conversions.h" |
| #include "content/public/browser/browser_context.h" |
| #include "grit/ash_strings.h" |
| @@ -16,8 +17,17 @@ |
| using ui::WebDialogDelegate; |
| namespace { |
| -// Store the pointer to the view currently shown. |
| -KeyboardOverlayView* g_instance = NULL; |
| + |
| +// Keys to invoke Cancel (Escape, Ctrl+Alt+/, or Shift+Ctrl+Alt+/). |
| +const struct KeyEventData { |
| + ui::KeyboardCode key_code; |
| + int flags; |
| +} kCancelKeys[] = { |
| + { ui::VKEY_ESCAPE, 0}, |
| + { ui::VKEY_OEM_2, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, |
| + { ui::VKEY_OEM_2, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, |
| +}; |
| + |
| } |
| KeyboardOverlayView::KeyboardOverlayView( |
| @@ -30,23 +40,40 @@ KeyboardOverlayView::KeyboardOverlayView( |
| KeyboardOverlayView::~KeyboardOverlayView() { |
| } |
| +void KeyboardOverlayView::Cancel() { |
| + ash::Shell::GetInstance()->overlay_filter()->Deactivate(); |
| + views::Widget* widget = GetWidget(); |
| + if (widget) |
| + widget->Close(); |
| +} |
| + |
| +bool KeyboardOverlayView::IsCancelKeyEvent(aura::KeyEvent* event) { |
|
Daniel Erat
2012/07/26 00:44:54
nit: KeyEventShouldCancel()? KeyEventCancels()?
mazda
2012/07/26 01:17:06
Changed it to IsCancelingKeyEvent.
|
| + for (size_t i = 0; i < arraysize(kCancelKeys); ++i) { |
| + if ((event->type() == ui::ET_KEY_PRESSED) && |
|
Daniel Erat
2012/07/26 00:44:54
just check this before the loop?
mazda
2012/07/26 01:17:06
Done.
|
| + (kCancelKeys[i].key_code == event->key_code()) && |
| + (kCancelKeys[i].flags == event->flags())) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +aura::Window* KeyboardOverlayView::GetWindow() { |
| + return GetWidget()->GetNativeWindow(); |
| +} |
| + |
| void KeyboardOverlayView::ShowDialog( |
| content::BrowserContext* context, |
| WebContentsHandler* handler, |
| const GURL& url) { |
| - // Ignore the call if another view is already shown. |
| - if (g_instance) |
| - return; |
| - |
| KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( |
| l10n_util::GetStringUTF16(IDS_ASH_KEYBOARD_OVERLAY_TITLE), url); |
| KeyboardOverlayView* view = |
| new KeyboardOverlayView(context, delegate, handler); |
| delegate->Show(view); |
| - g_instance = view; |
| + ash::Shell::GetInstance()->overlay_filter()->Activate(view); |
| } |
| void KeyboardOverlayView::WindowClosing() { |
| - g_instance = NULL; |
| + Cancel(); |
| } |