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/chromeos/keyboard_overlay_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | |
9 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 13 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
13 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 14 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 18 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
19 #include "chrome/common/chrome_switches.h" | |
18 #include "chrome/common/jstemplate_builder.h" | 20 #include "chrome/common/jstemplate_builder.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/page_navigator.h" | 24 #include "content/public/browser/page_navigator.h" |
23 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
24 #include "content/public/browser/web_contents_delegate.h" | 26 #include "content/public/browser/web_contents_delegate.h" |
25 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
26 #include "content/public/browser/web_ui_message_handler.h" | 28 #include "content/public/browser/web_ui_message_handler.h" |
27 #include "grit/browser_resources.h" | 29 #include "grit/browser_resources.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
55 {chromeos::input_method::kCapsLockKey, "caps lock"}, | 57 {chromeos::input_method::kCapsLockKey, "caps lock"}, |
56 }; | 58 }; |
57 | 59 |
58 struct I18nContentToMessage { | 60 struct I18nContentToMessage { |
59 const char* i18n_content; | 61 const char* i18n_content; |
60 int message; | 62 int message; |
61 } kI18nContentToMessage[] = { | 63 } kI18nContentToMessage[] = { |
62 { "keyboardOverlayLearnMore", IDS_KEYBOARD_OVERLAY_LEARN_MORE }, | 64 { "keyboardOverlayLearnMore", IDS_KEYBOARD_OVERLAY_LEARN_MORE }, |
63 { "keyboardOverlayTitle", IDS_KEYBOARD_OVERLAY_TITLE }, | 65 { "keyboardOverlayTitle", IDS_KEYBOARD_OVERLAY_TITLE }, |
64 { "keyboardOverlayInstructions", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS }, | 66 { "keyboardOverlayInstructions", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS }, |
67 { "keyboardOverlayInstructionsWithSearch", | |
68 IDS_KEYBOARD_OVERLAY_INSTRUCTIONS_WITH_SEARCH }, | |
65 { "keyboardOverlayInstructionsHide", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS_HIDE }, | 69 { "keyboardOverlayInstructionsHide", IDS_KEYBOARD_OVERLAY_INSTRUCTIONS_HIDE }, |
66 { "keyboardOverlayActivateLastLauncherItem", | 70 { "keyboardOverlayActivateLastLauncherItem", |
67 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_LAUNCHER_ITEM }, | 71 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_LAUNCHER_ITEM }, |
68 { "keyboardOverlayActivateLastTab", IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_TAB }, | 72 { "keyboardOverlayActivateLastTab", IDS_KEYBOARD_OVERLAY_ACTIVATE_LAST_TAB }, |
69 { "keyboardOverlayActivateLauncherItem1", | 73 { "keyboardOverlayActivateLauncherItem1", |
70 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_1 }, | 74 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_1 }, |
71 { "keyboardOverlayActivateLauncherItem2", | 75 { "keyboardOverlayActivateLauncherItem2", |
72 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_2 }, | 76 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_2 }, |
73 { "keyboardOverlayActivateLauncherItem3", | 77 { "keyboardOverlayActivateLauncherItem3", |
74 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_3 }, | 78 IDS_KEYBOARD_OVERLAY_ACTIVATE_LAUNCHER_ITEM_3 }, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 { "keyboardOverlayDecreaseKeyBrightness", | 115 { "keyboardOverlayDecreaseKeyBrightness", |
112 IDS_KEYBOARD_OVERLAY_DECREASE_KEY_BRIGHTNESS }, | 116 IDS_KEYBOARD_OVERLAY_DECREASE_KEY_BRIGHTNESS }, |
113 { "keyboardOverlayDelete", IDS_KEYBOARD_OVERLAY_DELETE }, | 117 { "keyboardOverlayDelete", IDS_KEYBOARD_OVERLAY_DELETE }, |
114 { "keyboardOverlayDeleteWord", IDS_KEYBOARD_OVERLAY_DELETE_WORD }, | 118 { "keyboardOverlayDeleteWord", IDS_KEYBOARD_OVERLAY_DELETE_WORD }, |
115 { "keyboardOverlayDeveloperTools", IDS_KEYBOARD_OVERLAY_DEVELOPER_TOOLS }, | 119 { "keyboardOverlayDeveloperTools", IDS_KEYBOARD_OVERLAY_DEVELOPER_TOOLS }, |
116 { "keyboardOverlayDockWindowLeft", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_LEFT }, | 120 { "keyboardOverlayDockWindowLeft", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_LEFT }, |
117 { "keyboardOverlayDockWindowRight", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_RIGHT }, | 121 { "keyboardOverlayDockWindowRight", IDS_KEYBOARD_OVERLAY_DOCK_WINDOW_RIGHT }, |
118 { "keyboardOverlayDomInspector", IDS_KEYBOARD_OVERLAY_DOM_INSPECTOR }, | 122 { "keyboardOverlayDomInspector", IDS_KEYBOARD_OVERLAY_DOM_INSPECTOR }, |
119 { "keyboardOverlayDownloads", IDS_KEYBOARD_OVERLAY_DOWNLOADS }, | 123 { "keyboardOverlayDownloads", IDS_KEYBOARD_OVERLAY_DOWNLOADS }, |
120 { "keyboardOverlayEnd", IDS_KEYBOARD_OVERLAY_END }, | 124 { "keyboardOverlayEnd", IDS_KEYBOARD_OVERLAY_END }, |
125 { "keyboardOverlayF1", IDS_KEYBOARD_OVERLAY_F1 }, | |
mazda
2012/11/28 05:25:18
Please move these above "keyboardOverlayActivateLa
danakj
2012/11/28 21:11:24
Done.
| |
126 { "keyboardOverlayF2", IDS_KEYBOARD_OVERLAY_F2 }, | |
127 { "keyboardOverlayF3", IDS_KEYBOARD_OVERLAY_F3 }, | |
128 { "keyboardOverlayF4", IDS_KEYBOARD_OVERLAY_F4 }, | |
129 { "keyboardOverlayF5", IDS_KEYBOARD_OVERLAY_F5 }, | |
130 { "keyboardOverlayF6", IDS_KEYBOARD_OVERLAY_F6 }, | |
131 { "keyboardOverlayF7", IDS_KEYBOARD_OVERLAY_F7 }, | |
132 { "keyboardOverlayF8", IDS_KEYBOARD_OVERLAY_F8 }, | |
133 { "keyboardOverlayF9", IDS_KEYBOARD_OVERLAY_F9 }, | |
134 { "keyboardOverlayF10", IDS_KEYBOARD_OVERLAY_F10 }, | |
135 { "keyboardOverlayF11", IDS_KEYBOARD_OVERLAY_F11 }, | |
136 { "keyboardOverlayF12", IDS_KEYBOARD_OVERLAY_F12 }, | |
121 { "keyboardOverlayFindPreviousText", | 137 { "keyboardOverlayFindPreviousText", |
122 IDS_KEYBOARD_OVERLAY_FIND_PREVIOUS_TEXT }, | 138 IDS_KEYBOARD_OVERLAY_FIND_PREVIOUS_TEXT }, |
123 { "keyboardOverlayFindText", IDS_KEYBOARD_OVERLAY_FIND_TEXT }, | 139 { "keyboardOverlayFindText", IDS_KEYBOARD_OVERLAY_FIND_TEXT }, |
124 { "keyboardOverlayFindTextAgain", IDS_KEYBOARD_OVERLAY_FIND_TEXT_AGAIN }, | 140 { "keyboardOverlayFindTextAgain", IDS_KEYBOARD_OVERLAY_FIND_TEXT_AGAIN }, |
125 { "keyboardOverlayFocusAddressBar", IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR }, | 141 { "keyboardOverlayFocusAddressBar", IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR }, |
126 { "keyboardOverlayFocusAddressBarInSearchMode", | 142 { "keyboardOverlayFocusAddressBarInSearchMode", |
127 IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR_IN_SEARCH_MODE }, | 143 IDS_KEYBOARD_OVERLAY_FOCUS_ADDRESS_BAR_IN_SEARCH_MODE }, |
128 { "keyboardOverlayFocusBookmarks", IDS_KEYBOARD_OVERLAY_FOCUS_BOOKMARKS }, | 144 { "keyboardOverlayFocusBookmarks", IDS_KEYBOARD_OVERLAY_FOCUS_BOOKMARKS }, |
129 { "keyboardOverlayFocusLauncher", IDS_KEYBOARD_OVERLAY_FOCUS_LAUNCHER }, | 145 { "keyboardOverlayFocusLauncher", IDS_KEYBOARD_OVERLAY_FOCUS_LAUNCHER }, |
130 { "keyboardOverlayFocusNextPane", IDS_KEYBOARD_OVERLAY_FOCUS_NEXT_PANE }, | 146 { "keyboardOverlayFocusNextPane", IDS_KEYBOARD_OVERLAY_FOCUS_NEXT_PANE }, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 | 231 |
216 std::string ModifierKeyToLabel(ModifierKey modifier) { | 232 std::string ModifierKeyToLabel(ModifierKey modifier) { |
217 for (size_t i = 0; i < arraysize(kModifierToLabels); ++i) { | 233 for (size_t i = 0; i < arraysize(kModifierToLabels); ++i) { |
218 if (modifier == kModifierToLabels[i].modifier) { | 234 if (modifier == kModifierToLabels[i].modifier) { |
219 return kModifierToLabels[i].label; | 235 return kModifierToLabels[i].label; |
220 } | 236 } |
221 } | 237 } |
222 return ""; | 238 return ""; |
223 } | 239 } |
224 | 240 |
225 ChromeWebUIDataSource* CreateKeyboardOverlayUIHTMLSource() { | 241 ChromeWebUIDataSource* CreateKeyboardOverlayUIHTMLSource( |
242 bool search_key_acts_as_function_key) { | |
226 ChromeWebUIDataSource* source = | 243 ChromeWebUIDataSource* source = |
227 new ChromeWebUIDataSource(chrome::kChromeUIKeyboardOverlayHost); | 244 new ChromeWebUIDataSource(chrome::kChromeUIKeyboardOverlayHost); |
228 | 245 |
229 for (size_t i = 0; i < arraysize(kI18nContentToMessage); ++i) { | 246 for (size_t i = 0; i < arraysize(kI18nContentToMessage); ++i) { |
230 source->AddLocalizedString(kI18nContentToMessage[i].i18n_content, | 247 source->AddLocalizedString(kI18nContentToMessage[i].i18n_content, |
231 kI18nContentToMessage[i].message); | 248 kI18nContentToMessage[i].message); |
232 } | 249 } |
233 | 250 |
234 source->AddString("keyboardOverlayLearnMoreURL", UTF8ToUTF16(kLearnMoreURL)); | 251 source->AddString("keyboardOverlayLearnMoreURL", UTF8ToUTF16(kLearnMoreURL)); |
252 source->AddString("keyboardSearchKeyActsAsFunctionKey", | |
253 search_key_acts_as_function_key ? "true" : "false"); | |
235 source->set_json_path("strings.js"); | 254 source->set_json_path("strings.js"); |
236 source->set_use_json_js_format_v2(); | 255 source->set_use_json_js_format_v2(); |
237 source->add_resource_path("keyboard_overlay.js", IDR_KEYBOARD_OVERLAY_JS); | 256 source->add_resource_path("keyboard_overlay.js", IDR_KEYBOARD_OVERLAY_JS); |
238 source->set_default_resource(IDR_KEYBOARD_OVERLAY_HTML); | 257 source->set_default_resource(IDR_KEYBOARD_OVERLAY_HTML); |
239 return source; | 258 return source; |
240 } | 259 } |
241 | 260 |
242 } // namespace | 261 } // namespace |
243 | 262 |
244 // The handler for Javascript messages related to the "keyboardoverlay" view. | 263 // The handler for Javascript messages related to the "keyboardoverlay" view. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 // KeyboardOverlayUI | 359 // KeyboardOverlayUI |
341 // | 360 // |
342 //////////////////////////////////////////////////////////////////////////////// | 361 //////////////////////////////////////////////////////////////////////////////// |
343 | 362 |
344 KeyboardOverlayUI::KeyboardOverlayUI(content::WebUI* web_ui) | 363 KeyboardOverlayUI::KeyboardOverlayUI(content::WebUI* web_ui) |
345 : WebDialogUI(web_ui) { | 364 : WebDialogUI(web_ui) { |
346 Profile* profile = Profile::FromWebUI(web_ui); | 365 Profile* profile = Profile::FromWebUI(web_ui); |
347 KeyboardOverlayHandler* handler = new KeyboardOverlayHandler(profile); | 366 KeyboardOverlayHandler* handler = new KeyboardOverlayHandler(profile); |
348 web_ui->AddMessageHandler(handler); | 367 web_ui->AddMessageHandler(handler); |
349 | 368 |
369 PrefService* pref_service = profile->GetPrefs(); | |
370 bool chromebook_function_key = CommandLine::ForCurrentProcess()->HasSwitch( | |
371 switches::kEnableChromebookFunctionKey); | |
372 | |
373 bool search_key_acts_as_function_key = chromebook_function_key && | |
374 pref_service->GetBoolean(prefs::kLanguageSearchKeyActsAsFunctionKey); | |
375 | |
350 // Set up the chrome://keyboardoverlay/ source. | 376 // Set up the chrome://keyboardoverlay/ source. |
351 ChromeURLDataManager::AddDataSource(profile, | 377 ChromeURLDataManager::AddDataSource(profile, |
352 CreateKeyboardOverlayUIHTMLSource()); | 378 CreateKeyboardOverlayUIHTMLSource(search_key_acts_as_function_key)); |
353 } | 379 } |
OLD | NEW |