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 "content/public/browser/browser_context.h"
11 #include "grit/ash_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/events/event.h"
14 #include "ui/gfx/screen.h"
15 #include "ui/views/widget/widget.h"
16 #include "ui/web_dialogs/web_dialog_delegate.h"
18 using ui::WebDialogDelegate
;
22 // Keys to invoke Cancel (Escape, Ctrl+Alt+/, or Shift+Ctrl+Alt+/, Help, F14).
23 const ash::KeyboardOverlayView::KeyEventData kCancelKeys
[] = {
24 { ui::VKEY_ESCAPE
, ui::EF_NONE
},
25 { ui::VKEY_OEM_2
, ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
},
26 { ui::VKEY_OEM_2
, ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
},
27 { ui::VKEY_HELP
, ui::EF_NONE
},
28 { ui::VKEY_F14
, ui::EF_NONE
},
35 KeyboardOverlayView::KeyboardOverlayView(
36 content::BrowserContext
* context
,
37 WebDialogDelegate
* delegate
,
38 WebContentsHandler
* handler
)
39 : views::WebDialogView(context
, delegate
, handler
) {
42 KeyboardOverlayView::~KeyboardOverlayView() {
45 void KeyboardOverlayView::Cancel() {
46 Shell::GetInstance()->overlay_filter()->Deactivate(this);
47 views::Widget
* widget
= GetWidget();
52 bool KeyboardOverlayView::IsCancelingKeyEvent(ui::KeyEvent
* event
) {
53 if (event
->type() != ui::ET_KEY_PRESSED
)
55 // Ignore the caps lock state.
56 const int flags
= (event
->flags() & ~ui::EF_CAPS_LOCK_DOWN
);
57 for (size_t i
= 0; i
< arraysize(kCancelKeys
); ++i
) {
58 if ((kCancelKeys
[i
].key_code
== event
->key_code()) &&
59 (kCancelKeys
[i
].flags
== flags
))
65 aura::Window
* KeyboardOverlayView::GetWindow() {
66 return GetWidget()->GetNativeWindow();
70 void KeyboardOverlayView::ShowDialog(
71 content::BrowserContext
* context
,
72 WebContentsHandler
* handler
,
74 if (Shell::GetInstance()->overlay_filter()->IsActive())
77 KeyboardOverlayDelegate
* delegate
= new KeyboardOverlayDelegate(
78 l10n_util::GetStringUTF16(IDS_ASH_KEYBOARD_OVERLAY_TITLE
), url
);
79 KeyboardOverlayView
* view
=
80 new KeyboardOverlayView(context
, delegate
, handler
);
83 Shell::GetInstance()->overlay_filter()->Activate(view
);
86 void KeyboardOverlayView::WindowClosing() {
91 void KeyboardOverlayView::GetCancelingKeysForTesting(
92 std::vector
<KeyboardOverlayView::KeyEventData
>* canceling_keys
) {
93 CHECK(canceling_keys
);
94 canceling_keys
->clear();
95 for (size_t i
= 0; i
< arraysize(kCancelKeys
); ++i
)
96 canceling_keys
->push_back(kCancelKeys
[i
]);