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/webui/options/chromeos/keyboard_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/keyboard_handler.h" |
6 | 6 |
7 #include "ash/new_window_delegate.h" | 7 #include "ash/new_window_delegate.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
15 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
16 #include "ui/base/ime/chromeos/ime_keyboard.h" | 16 #include "ui/base/ime/chromeos/ime_keyboard.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/events/devices/device_data_manager.h" | |
19 #include "ui/events/devices/keyboard_device.h" | |
18 | 20 |
19 namespace { | 21 namespace { |
20 const struct ModifierKeysSelectItem { | 22 const struct ModifierKeysSelectItem { |
21 int message_id; | 23 int message_id; |
22 chromeos::input_method::ModifierKey value; | 24 chromeos::input_method::ModifierKey value; |
23 } kModifierKeysSelectItems[] = { | 25 } kModifierKeysSelectItems[] = { |
24 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_SEARCH, | 26 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_SEARCH, |
25 chromeos::input_method::kSearchKey }, | 27 chromeos::input_method::kSearchKey }, |
26 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_CTRL, | 28 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_CTRL, |
27 chromeos::input_method::kControlKey }, | 29 chromeos::input_method::kControlKey }, |
28 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_ALT, | 30 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_LEFT_ALT, |
29 chromeos::input_method::kAltKey }, | 31 chromeos::input_method::kAltKey }, |
30 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_VOID, | 32 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_VOID, |
31 chromeos::input_method::kVoidKey }, | 33 chromeos::input_method::kVoidKey }, |
32 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_CAPS_LOCK, | 34 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_CAPS_LOCK, |
33 chromeos::input_method::kCapsLockKey }, | 35 chromeos::input_method::kCapsLockKey }, |
34 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_ESCAPE, | 36 { IDS_OPTIONS_SETTINGS_LANGUAGES_KEY_ESCAPE, |
35 chromeos::input_method::kEscapeKey }, | 37 chromeos::input_method::kEscapeKey }, |
36 }; | 38 }; |
37 | 39 |
38 const char* kDataValuesNames[] = { | 40 const char* kDataValuesNames[] = { |
39 "remapSearchKeyToValue", | 41 "remapSearchKeyToValue", |
40 "remapControlKeyToValue", | 42 "remapControlKeyToValue", |
41 "remapAltKeyToValue", | 43 "remapAltKeyToValue", |
42 "remapCapsLockKeyToValue", | 44 "remapCapsLockKeyToValue", |
43 "remapDiamondKeyToValue", | 45 "remapDiamondKeyToValue", |
44 }; | 46 }; |
47 | |
48 bool HasExternalKeyboard() { | |
49 for (const ui::KeyboardDevice& keyboard : | |
50 ui::DeviceDataManager::GetInstance()->keyboard_devices()) { | |
51 if (keyboard.type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL) | |
52 return true; | |
53 } | |
54 | |
55 return false; | |
56 } | |
45 } // namespace | 57 } // namespace |
46 | 58 |
47 namespace chromeos { | 59 namespace chromeos { |
48 namespace options { | 60 namespace options { |
49 | 61 |
50 KeyboardHandler::KeyboardHandler() { | 62 KeyboardHandler::KeyboardHandler() { |
63 ui::DeviceDataManager::GetInstance()->AddObserver(this); | |
51 } | 64 } |
52 | 65 |
53 KeyboardHandler::~KeyboardHandler() { | 66 KeyboardHandler::~KeyboardHandler() { |
67 ui::DeviceDataManager::GetInstance()->RemoveObserver(this); | |
54 } | 68 } |
55 | 69 |
56 void KeyboardHandler::GetLocalizedValues( | 70 void KeyboardHandler::GetLocalizedValues( |
57 base::DictionaryValue* localized_strings) { | 71 base::DictionaryValue* localized_strings) { |
58 DCHECK(localized_strings); | 72 DCHECK(localized_strings); |
59 RegisterTitle(localized_strings, "keyboardOverlay", | 73 RegisterTitle(localized_strings, "keyboardOverlay", |
60 IDS_OPTIONS_KEYBOARD_OVERLAY_TITLE); | 74 IDS_OPTIONS_KEYBOARD_OVERLAY_TITLE); |
61 | 75 |
62 localized_strings->SetString("remapSearchKeyToContent", | 76 localized_strings->SetString("remapSearchKeyToContent", |
63 l10n_util::GetStringUTF16( | 77 l10n_util::GetStringUTF16( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 option->Append(new base::FundamentalValue(value)); | 138 option->Append(new base::FundamentalValue(value)); |
125 option->Append(new base::StringValue(l10n_util::GetStringUTF16( | 139 option->Append(new base::StringValue(l10n_util::GetStringUTF16( |
126 message_id))); | 140 message_id))); |
127 list_value->Append(option); | 141 list_value->Append(option); |
128 } | 142 } |
129 localized_strings->Set(kDataValuesNames[i], list_value); | 143 localized_strings->Set(kDataValuesNames[i], list_value); |
130 } | 144 } |
131 } | 145 } |
132 | 146 |
133 void KeyboardHandler::InitializePage() { | 147 void KeyboardHandler::InitializePage() { |
134 bool chromeos_keyboard = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
135 chromeos::switches::kHasChromeOSKeyboard); | |
Jun Mukai
2015/06/15 23:57:25
Do we need to keep this flag?
It looks like:
- def
afakhry
2015/06/16 00:52:47
Yes I noticed that this flag is no longer used, bu
| |
136 const base::FundamentalValue show_caps_lock_options(!chromeos_keyboard); | |
137 | |
138 bool has_diamond_key = base::CommandLine::ForCurrentProcess()->HasSwitch( | 148 bool has_diamond_key = base::CommandLine::ForCurrentProcess()->HasSwitch( |
139 chromeos::switches::kHasChromeOSDiamondKey); | 149 chromeos::switches::kHasChromeOSDiamondKey); |
140 const base::FundamentalValue show_diamond_key_options(has_diamond_key); | 150 const base::FundamentalValue show_diamond_key_options(has_diamond_key); |
141 | 151 |
142 web_ui()->CallJavascriptFunction( | 152 web_ui()->CallJavascriptFunction( |
143 "options.KeyboardOverlay.showCapsLockOptions", | |
144 show_caps_lock_options); | |
145 web_ui()->CallJavascriptFunction( | |
146 "options.KeyboardOverlay.showDiamondKeyOptions", | 153 "options.KeyboardOverlay.showDiamondKeyOptions", |
147 show_diamond_key_options); | 154 show_diamond_key_options); |
155 | |
156 UpdateCapsLockOptions(); | |
148 } | 157 } |
149 | 158 |
150 void KeyboardHandler::RegisterMessages() { | 159 void KeyboardHandler::RegisterMessages() { |
151 // Callback to show keyboard overlay. | 160 // Callback to show keyboard overlay. |
152 web_ui()->RegisterMessageCallback( | 161 web_ui()->RegisterMessageCallback( |
153 "showKeyboardShortcuts", | 162 "showKeyboardShortcuts", |
154 base::Bind(&KeyboardHandler::HandleShowKeyboardShortcuts, | 163 base::Bind(&KeyboardHandler::HandleShowKeyboardShortcuts, |
155 base::Unretained(this))); | 164 base::Unretained(this))); |
156 } | 165 } |
157 | 166 |
167 void KeyboardHandler::OnKeyboardDeviceConfigurationChanged() { | |
168 UpdateCapsLockOptions(); | |
169 } | |
170 | |
158 void KeyboardHandler::HandleShowKeyboardShortcuts(const base::ListValue* args) { | 171 void KeyboardHandler::HandleShowKeyboardShortcuts(const base::ListValue* args) { |
159 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay(); | 172 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay(); |
160 } | 173 } |
161 | 174 |
175 void KeyboardHandler::UpdateCapsLockOptions() const { | |
176 const base::FundamentalValue show_caps_lock_options(HasExternalKeyboard()); | |
177 web_ui()->CallJavascriptFunction( | |
178 "options.KeyboardOverlay.showCapsLockOptions", | |
179 show_caps_lock_options); | |
180 } | |
181 | |
162 } // namespace options | 182 } // namespace options |
163 } // namespace chromeos | 183 } // namespace chromeos |
OLD | NEW |