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 "chrome/browser/ui/views/keyboard_overlay_dialog_view.h" | 5 #include "chrome/browser/ui/views/keyboard_overlay_dialog_view.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/browser_dialogs.h" | 10 #include "chrome/browser/ui/browser_dialogs.h" |
11 #include "chrome/browser/ui/views/keyboard_overlay_delegate.h" | 11 #include "chrome/browser/ui/views/keyboard_overlay_delegate.h" |
12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
16 #include "ui/web_dialogs/web_dialog_delegate.h" | 16 #include "ui/web_dialogs/web_dialog_delegate.h" |
17 | 17 |
| 18 #if defined(OS_CHROMEOS) |
| 19 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 20 #endif |
| 21 |
18 using ui::WebDialogDelegate; | 22 using ui::WebDialogDelegate; |
19 | 23 |
20 namespace { | 24 namespace { |
21 // Store the pointer to the view currently shown. | 25 // Store the pointer to the view currently shown. |
22 KeyboardOverlayDialogView* g_instance = NULL; | 26 KeyboardOverlayDialogView* g_instance = NULL; |
23 } | 27 } |
24 | 28 |
25 KeyboardOverlayDialogView::KeyboardOverlayDialogView( | 29 KeyboardOverlayDialogView::KeyboardOverlayDialogView( |
26 Profile* profile, | 30 Profile* profile, |
27 WebDialogDelegate* delegate) | 31 WebDialogDelegate* delegate) |
28 : WebDialogView(profile, NULL, delegate) { | 32 : WebDialogView(profile, NULL, delegate) { |
29 } | 33 } |
30 | 34 |
31 KeyboardOverlayDialogView::~KeyboardOverlayDialogView() { | 35 KeyboardOverlayDialogView::~KeyboardOverlayDialogView() { |
32 } | 36 } |
33 | 37 |
34 void KeyboardOverlayDialogView::ShowDialog() { | 38 void KeyboardOverlayDialogView::ShowDialog() { |
35 // Ignore the call if another view is already shown. | 39 // Ignore the call if another view is already shown. |
36 if (g_instance) | 40 if (g_instance) |
37 return; | 41 return; |
38 | 42 |
| 43 #if defined(OS_CHROMEOS) |
| 44 // Temporarily disable all accelerators for IME switching including Shift+Alt |
| 45 // since the user might press Shift+Alt to remember an accelerator that starts |
| 46 // with Shift+Alt (e.g. Shift+Alt+Tab for moving focus backwards). |
| 47 chromeos::input_method::InputMethodManager::GetInstance()->DisableHotkeys(); |
| 48 #endif |
39 KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( | 49 KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( |
40 l10n_util::GetStringUTF16(IDS_KEYBOARD_OVERLAY_TITLE)); | 50 l10n_util::GetStringUTF16(IDS_KEYBOARD_OVERLAY_TITLE)); |
41 KeyboardOverlayDialogView* view = new KeyboardOverlayDialogView( | 51 KeyboardOverlayDialogView* view = new KeyboardOverlayDialogView( |
42 ProfileManager::GetDefaultProfileOrOffTheRecord(), delegate); | 52 ProfileManager::GetDefaultProfileOrOffTheRecord(), delegate); |
43 delegate->set_view(view); | 53 delegate->set_view(view); |
44 | 54 |
45 views::Widget* widget = new views::Widget; | 55 views::Widget* widget = new views::Widget; |
46 views::Widget::InitParams params( | 56 views::Widget::InitParams params( |
47 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 57 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
48 params.delegate = view; | 58 params.delegate = view; |
49 widget->Init(params); | 59 widget->Init(params); |
50 | 60 |
51 // Show the widget at the bottom of the work area. | 61 // Show the widget at the bottom of the work area. |
52 gfx::Size size; | 62 gfx::Size size; |
53 delegate->GetDialogSize(&size); | 63 delegate->GetDialogSize(&size); |
54 gfx::Rect rect = gfx::Screen::GetMonitorNearestWindow( | 64 gfx::Rect rect = gfx::Screen::GetMonitorNearestWindow( |
55 view->GetWidget()->GetNativeView()).work_area(); | 65 view->GetWidget()->GetNativeView()).work_area(); |
56 gfx::Rect bounds((rect.width() - size.width()) / 2, | 66 gfx::Rect bounds((rect.width() - size.width()) / 2, |
57 rect.height() - size.height(), | 67 rect.height() - size.height(), |
58 size.width(), | 68 size.width(), |
59 size.height()); | 69 size.height()); |
60 view->GetWidget()->SetBounds(bounds); | 70 view->GetWidget()->SetBounds(bounds); |
61 view->GetWidget()->Show(); | 71 view->GetWidget()->Show(); |
62 | 72 |
63 g_instance = view; | 73 g_instance = view; |
64 } | 74 } |
65 | 75 |
66 void KeyboardOverlayDialogView::WindowClosing() { | 76 void KeyboardOverlayDialogView::WindowClosing() { |
| 77 #if defined(OS_CHROMEOS) |
| 78 // Re-enable the IME accelerators. See the comment in ShowDialog() above. |
| 79 chromeos::input_method::InputMethodManager::GetInstance()->EnableHotkeys(); |
| 80 #endif |
67 g_instance = NULL; | 81 g_instance = NULL; |
68 } | 82 } |
OLD | NEW |