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
3 // found in the LICENSE file.
5 #include "ash/keyboard_overlay/keyboard_overlay_view.h"
7 #include "ash/keyboard_overlay/keyboard_overlay_delegate.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "grit/ash_strings.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/events/event.h"
13 #include "ui/gfx/screen.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/web_dialogs/web_dialog_delegate.h"
17 using ui::WebDialogDelegate
;
21 // Keys to invoke Cancel (Escape, Ctrl+Alt+/, or Shift+Ctrl+Alt+/, Help, F14).
22 const ash::KeyboardOverlayView::KeyEventData kCancelKeys
[] = {
23 { ui::VKEY_ESCAPE
, ui::EF_NONE
},
24 { ui::VKEY_OEM_2
, ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
},
25 { ui::VKEY_OEM_2
, ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
},
26 { ui::VKEY_HELP
, ui::EF_NONE
},
27 { ui::VKEY_F14
, ui::EF_NONE
},
34 KeyboardOverlayView::KeyboardOverlayView(
35 content::BrowserContext
* context
,
36 WebDialogDelegate
* delegate
,
37 WebContentsHandler
* handler
)
38 : views::WebDialogView(context
, delegate
, handler
) {
41 KeyboardOverlayView::~KeyboardOverlayView() {
44 void KeyboardOverlayView::Cancel() {
45 Shell::GetInstance()->overlay_filter()->Deactivate(this);
46 views::Widget
* widget
= GetWidget();
51 bool KeyboardOverlayView::IsCancelingKeyEvent(ui::KeyEvent
* event
) {
52 if (event
->type() != ui::ET_KEY_PRESSED
)
54 // Ignore the caps lock state.
55 const int flags
= (event
->flags() & ~ui::EF_CAPS_LOCK_DOWN
);
56 for (size_t i
= 0; i
< arraysize(kCancelKeys
); ++i
) {
57 if ((kCancelKeys
[i
].key_code
== event
->key_code()) &&
58 (kCancelKeys
[i
].flags
== flags
))
64 aura::Window
* KeyboardOverlayView::GetWindow() {
65 return GetWidget()->GetNativeWindow();
69 void KeyboardOverlayView::ShowDialog(
70 content::BrowserContext
* context
,
71 WebContentsHandler
* handler
,
73 if (Shell::GetInstance()->overlay_filter()->IsActive())
76 KeyboardOverlayDelegate
* delegate
= new KeyboardOverlayDelegate(
77 l10n_util::GetStringUTF16(IDS_ASH_KEYBOARD_OVERLAY_TITLE
), url
);
78 KeyboardOverlayView
* view
=
79 new KeyboardOverlayView(context
, delegate
, handler
);
82 Shell::GetInstance()->overlay_filter()->Activate(view
);
85 void KeyboardOverlayView::WindowClosing() {
90 void KeyboardOverlayView::GetCancelingKeysForTesting(
91 std::vector
<KeyboardOverlayView::KeyEventData
>* canceling_keys
) {
92 CHECK(canceling_keys
);
93 canceling_keys
->clear();
94 for (size_t i
= 0; i
< arraysize(kCancelKeys
); ++i
)
95 canceling_keys
->push_back(kCancelKeys
[i
]);