Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / keyboard_handler.cc
blobf6455dd1b03f71f8399bff576948281b8fe85fe6
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 "chrome/browser/ui/webui/options/chromeos/keyboard_handler.h"
7 #include "ash/new_window_delegate.h"
8 #include "ash/shell.h"
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/command_line.h"
12 #include "base/values.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "chromeos/chromeos_switches.h"
15 #include "content/public/browser/web_ui.h"
16 #include "ui/base/ime/chromeos/ime_keyboard.h"
17 #include "ui/base/l10n/l10n_util.h"
19 namespace {
20 const struct ModifierKeysSelectItem {
21 int message_id;
22 chromeos::input_method::ModifierKey value;
23 } kModifierKeysSelectItems[] = {
24 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_SEARCH,
25 chromeos::input_method::kSearchKey },
26 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_CTRL,
27 chromeos::input_method::kControlKey },
28 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_ALT,
29 chromeos::input_method::kAltKey },
30 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_VOID,
31 chromeos::input_method::kVoidKey },
32 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_CAPS_LOCK,
33 chromeos::input_method::kCapsLockKey },
34 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_ESCAPE,
35 chromeos::input_method::kEscapeKey },
38 const char* kDataValuesNames[] = {
39 "remapSearchKeyToValue",
40 "remapControlKeyToValue",
41 "remapAltKeyToValue",
42 "remapCapsLockKeyToValue",
43 "remapDiamondKeyToValue",
45 } // namespace
47 namespace chromeos {
48 namespace options {
50 KeyboardHandler::KeyboardHandler() {
53 KeyboardHandler::~KeyboardHandler() {
56 void KeyboardHandler::GetLocalizedValues(
57 base::DictionaryValue* localized_strings) {
58 DCHECK(localized_strings);
59 RegisterTitle(localized_strings, "keyboardOverlay",
60 IDS_OPTIONS_KEYBOARD_OVERLAY_TITLE);
62 localized_strings->SetString("remapSearchKeyToContent",
63 l10n_util::GetStringUTF16(
64 IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_SEARCH_LABEL));
65 localized_strings->SetString("remapControlKeyToContent",
66 l10n_util::GetStringUTF16(
67 IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_CTRL_LABEL));
68 localized_strings->SetString("remapAltKeyToContent",
69 l10n_util::GetStringUTF16(
70 IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_ALT_LABEL));
71 localized_strings->SetString("remapCapsLockKeyToContent",
72 l10n_util::GetStringUTF16(
73 IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_CAPS_LOCK_LABEL));
74 localized_strings->SetString("remapDiamondKeyToContent",
75 l10n_util::GetStringUTF16(
76 IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_DIAMOND_KEY_LABEL));
77 localized_strings->SetString("sendFunctionKeys",
78 l10n_util::GetStringUTF16(
79 IDS_OPTIONS_SETTINGS_LANGUAGES_SEND_FUNCTION_KEYS));
80 localized_strings->SetString("sendFunctionKeysDescription",
81 l10n_util::GetStringUTF16(
82 IDS_OPTIONS_SETTINGS_LANGUAGES_SEND_FUNCTION_KEYS_DESCRIPTION));
83 localized_strings->SetString("enableAutoRepeat",
84 l10n_util::GetStringUTF16(
85 IDS_OPTIONS_SETTINGS_LANGUAGES_AUTO_REPEAT_ENABLE));
86 localized_strings->SetString("autoRepeatDelay",
87 l10n_util::GetStringUTF16(
88 IDS_OPTIONS_SETTINGS_LANGUAGES_AUTO_REPEAT_DELAY));
89 localized_strings->SetString("autoRepeatDelayLong",
90 l10n_util::GetStringUTF16(
91 IDS_OPTIONS_SETTINGS_LANGUAGES_AUTO_REPEAT_DELAY_LONG));
92 localized_strings->SetString("autoRepeatDelayShort",
93 l10n_util::GetStringUTF16(
94 IDS_OPTIONS_SETTINGS_LANGUAGES_AUTO_REPEAT_DELAY_SHORT));
95 localized_strings->SetString("autoRepeatRate",
96 l10n_util::GetStringUTF16(
97 IDS_OPTIONS_SETTINGS_LANGUAGES_AUTO_REPEAT_RATE));
98 localized_strings->SetString("autoRepeatRateSlow",
99 l10n_util::GetStringUTF16(
100 IDS_OPTIONS_SETTINGS_LANGUAGES_AUTO_REPEAT_RATE_SLOW));
101 localized_strings->SetString("autoRepeatRateFast",
102 l10n_util::GetStringUTF16(
103 IDS_OPTIONS_SETTINGS_LANGUAGES_AUTO_REPEAT_RATE_FAST));
104 localized_strings->SetString("changeLanguageAndInputSettings",
105 l10n_util::GetStringUTF16(
106 IDS_OPTIONS_SETTINGS_CHANGE_LANGUAGE_AND_INPUT_SETTINGS));
107 localized_strings->SetString("showKeyboardShortcuts",
108 l10n_util::GetStringUTF16(
109 IDS_OPTIONS_SETTINGS_SHOW_KEYBOARD_SHORTCUTS));
111 for (size_t i = 0; i < arraysize(kDataValuesNames); ++i) {
112 base::ListValue* list_value = new base::ListValue();
113 for (size_t j = 0; j < arraysize(kModifierKeysSelectItems); ++j) {
114 const input_method::ModifierKey value =
115 kModifierKeysSelectItems[j].value;
116 const int message_id = kModifierKeysSelectItems[j].message_id;
117 // Only the seach key can be remapped to the caps lock key.
118 if (kDataValuesNames[i] != std::string("remapSearchKeyToValue") &&
119 kDataValuesNames[i] != std::string("remapCapsLockKeyToValue") &&
120 value == input_method::kCapsLockKey) {
121 continue;
123 base::ListValue* option = new base::ListValue();
124 option->Append(new base::FundamentalValue(value));
125 option->Append(new base::StringValue(l10n_util::GetStringUTF16(
126 message_id)));
127 list_value->Append(option);
129 localized_strings->Set(kDataValuesNames[i], list_value);
133 void KeyboardHandler::InitializePage() {
134 bool chromeos_keyboard = base::CommandLine::ForCurrentProcess()->HasSwitch(
135 chromeos::switches::kHasChromeOSKeyboard);
136 const base::FundamentalValue show_caps_lock_options(!chromeos_keyboard);
138 bool has_diamond_key = base::CommandLine::ForCurrentProcess()->HasSwitch(
139 chromeos::switches::kHasChromeOSDiamondKey);
140 const base::FundamentalValue show_diamond_key_options(has_diamond_key);
142 web_ui()->CallJavascriptFunction(
143 "options.KeyboardOverlay.showCapsLockOptions",
144 show_caps_lock_options);
145 web_ui()->CallJavascriptFunction(
146 "options.KeyboardOverlay.showDiamondKeyOptions",
147 show_diamond_key_options);
150 void KeyboardHandler::RegisterMessages() {
151 // Callback to show keyboard overlay.
152 web_ui()->RegisterMessageCallback(
153 "showKeyboardShortcuts",
154 base::Bind(&KeyboardHandler::HandleShowKeyboardShortcuts,
155 base::Unretained(this)));
158 void KeyboardHandler::HandleShowKeyboardShortcuts(const base::ListValue* args) {
159 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
162 } // namespace options
163 } // namespace chromeos