summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/keyboard_overlay_dialog_view.cc
blob: 2873e5e95d4453564cb90a6817b68685fc441893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/keyboard_overlay_dialog_view.h"

#include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/views/keyboard_overlay_delegate.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
#include "ui/web_dialogs/web_dialog_delegate.h"

#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#endif

using ui::WebDialogDelegate;

namespace {
// Store the pointer to the view currently shown.
KeyboardOverlayDialogView* g_instance = NULL;
}

KeyboardOverlayDialogView::KeyboardOverlayDialogView(
    Profile* profile,
    WebDialogDelegate* delegate)
    : WebDialogView(profile, delegate) {
}

KeyboardOverlayDialogView::~KeyboardOverlayDialogView() {
}

void KeyboardOverlayDialogView::ShowDialog() {
  // Ignore the call if another view is already shown.
  if (g_instance)
    return;

#if defined(OS_CHROMEOS)
  // Temporarily disable all accelerators for IME switching including Shift+Alt
  // since the user might press Shift+Alt to remember an accelerator that starts
  // with Shift+Alt (e.g. Shift+Alt+Tab for moving focus backwards).
  chromeos::input_method::InputMethodManager::GetInstance()->DisableHotkeys();
#endif
  KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate(
      l10n_util::GetStringUTF16(IDS_KEYBOARD_OVERLAY_TITLE));
  KeyboardOverlayDialogView* view = new KeyboardOverlayDialogView(
      ProfileManager::GetDefaultProfileOrOffTheRecord(), delegate);
  delegate->Show(view);

  g_instance = view;
}

void KeyboardOverlayDialogView::WindowClosing() {
#if defined(OS_CHROMEOS)
  // Re-enable the IME accelerators. See the comment in ShowDialog() above.
  chromeos::input_method::InputMethodManager::GetInstance()->EnableHotkeys();
#endif
  g_instance = NULL;
}