OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/keyboard_overlay/keyboard_overlay_view.h" | 5 #include "ash/keyboard_overlay/keyboard_overlay_view.h" |
6 | 6 |
7 #include "ash/keyboard_overlay/keyboard_overlay_delegate.h" | 7 #include "ash/keyboard_overlay/keyboard_overlay_delegate.h" |
| 8 #include "ash/shell.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
10 #include "grit/ash_strings.h" | 11 #include "grit/ash_strings.h" |
11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
12 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
14 #include "ui/web_dialogs/web_dialog_delegate.h" | 15 #include "ui/web_dialogs/web_dialog_delegate.h" |
15 | 16 |
16 using ui::WebDialogDelegate; | 17 using ui::WebDialogDelegate; |
17 | 18 |
18 namespace { | 19 namespace { |
19 // Store the pointer to the view currently shown. | 20 |
20 KeyboardOverlayView* g_instance = NULL; | 21 // Keys to invoke Cancel (Escape, Ctrl+Alt+/, or Shift+Ctrl+Alt+/). |
| 22 const struct KeyEventData { |
| 23 ui::KeyboardCode key_code; |
| 24 int flags; |
| 25 } kCancelKeys[] = { |
| 26 { ui::VKEY_ESCAPE, 0}, |
| 27 { ui::VKEY_OEM_2, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, |
| 28 { ui::VKEY_OEM_2, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN }, |
| 29 }; |
| 30 |
21 } | 31 } |
22 | 32 |
23 KeyboardOverlayView::KeyboardOverlayView( | 33 KeyboardOverlayView::KeyboardOverlayView( |
24 content::BrowserContext* context, | 34 content::BrowserContext* context, |
25 WebDialogDelegate* delegate, | 35 WebDialogDelegate* delegate, |
26 WebContentsHandler* handler) | 36 WebContentsHandler* handler) |
27 : views::WebDialogView(context, delegate, handler) { | 37 : views::WebDialogView(context, delegate, handler) { |
28 } | 38 } |
29 | 39 |
30 KeyboardOverlayView::~KeyboardOverlayView() { | 40 KeyboardOverlayView::~KeyboardOverlayView() { |
31 } | 41 } |
32 | 42 |
| 43 void KeyboardOverlayView::Cancel() { |
| 44 ash::Shell::GetInstance()->overlay_filter()->Deactivate(); |
| 45 views::Widget* widget = GetWidget(); |
| 46 if (widget) |
| 47 widget->Close(); |
| 48 } |
| 49 |
| 50 bool KeyboardOverlayView::IsCancelingKeyEvent(aura::KeyEvent* event) { |
| 51 if (event->type() != ui::ET_KEY_PRESSED) |
| 52 return false; |
| 53 for (size_t i = 0; i < arraysize(kCancelKeys); ++i) { |
| 54 if ((kCancelKeys[i].key_code == event->key_code()) && |
| 55 (kCancelKeys[i].flags == event->flags())) |
| 56 return true; |
| 57 } |
| 58 return false; |
| 59 } |
| 60 |
| 61 aura::Window* KeyboardOverlayView::GetWindow() { |
| 62 return GetWidget()->GetNativeWindow(); |
| 63 } |
| 64 |
33 void KeyboardOverlayView::ShowDialog( | 65 void KeyboardOverlayView::ShowDialog( |
34 content::BrowserContext* context, | 66 content::BrowserContext* context, |
35 WebContentsHandler* handler, | 67 WebContentsHandler* handler, |
36 const GURL& url) { | 68 const GURL& url) { |
37 // Ignore the call if another view is already shown. | |
38 if (g_instance) | |
39 return; | |
40 | |
41 KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( | 69 KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( |
42 l10n_util::GetStringUTF16(IDS_ASH_KEYBOARD_OVERLAY_TITLE), url); | 70 l10n_util::GetStringUTF16(IDS_ASH_KEYBOARD_OVERLAY_TITLE), url); |
43 KeyboardOverlayView* view = | 71 KeyboardOverlayView* view = |
44 new KeyboardOverlayView(context, delegate, handler); | 72 new KeyboardOverlayView(context, delegate, handler); |
45 delegate->Show(view); | 73 delegate->Show(view); |
46 | 74 |
47 g_instance = view; | 75 ash::Shell::GetInstance()->overlay_filter()->Activate(view); |
48 } | 76 } |
49 | 77 |
50 void KeyboardOverlayView::WindowClosing() { | 78 void KeyboardOverlayView::WindowClosing() { |
51 g_instance = NULL; | 79 Cancel(); |
52 } | 80 } |
OLD | NEW |