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/ash/ime_controller_chromeos.h" | 5 #include "chrome/browser/ui/views/ash/ime_controller_chromeos.h" |
6 | 6 |
7 #include "base/string_util.h" | |
7 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 8 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
8 | 9 |
mazda
2012/05/29 17:08:06
nit: unnecessary empty line
| |
10 #include "chrome/browser/browser_process.h" | |
11 #include "chrome/browser/prefs/pref_service.h" | |
12 #include "chrome/browser/chromeos/language_preferences.h" | |
mazda
2012/05/29 17:08:06
nit: alphabetical order
| |
13 #include "ui/base/accelerators/accelerator.h" | |
14 | |
9 bool ImeController::HandleNextIme() { | 15 bool ImeController::HandleNextIme() { |
10 chromeos::input_method::InputMethodManager* manager = | 16 chromeos::input_method::InputMethodManager* manager = |
11 chromeos::input_method::InputMethodManager::GetInstance(); | 17 chromeos::input_method::InputMethodManager::GetInstance(); |
12 return manager->SwitchToNextInputMethod(); | 18 return manager->SwitchToNextInputMethod(); |
13 } | 19 } |
14 | 20 |
15 bool ImeController::HandlePreviousIme() { | 21 bool ImeController::HandlePreviousIme() { |
16 chromeos::input_method::InputMethodManager* manager = | 22 chromeos::input_method::InputMethodManager* manager = |
17 chromeos::input_method::InputMethodManager::GetInstance(); | 23 chromeos::input_method::InputMethodManager::GetInstance(); |
18 return manager->SwitchToPreviousInputMethod(); | 24 return manager->SwitchToPreviousInputMethod(); |
19 } | 25 } |
20 | 26 |
21 bool ImeController::HandleSwitchIme(const ui::Accelerator& accelerator) { | 27 bool ImeController::HandleSwitchIme(const ui::Accelerator& accelerator) { |
22 chromeos::input_method::InputMethodManager* manager = | 28 chromeos::input_method::InputMethodManager* manager = |
23 chromeos::input_method::InputMethodManager::GetInstance(); | 29 chromeos::input_method::InputMethodManager::GetInstance(); |
24 return manager->SwitchInputMethod(accelerator); | 30 return manager->SwitchInputMethod(accelerator); |
25 } | 31 } |
32 | |
33 bool ImeController::IsFrenchKeyboard() { | |
34 // First check the settings. | |
35 std::string layout = g_browser_process->local_state()->GetString( | |
36 chromeos::language_prefs::kPreferredKeyboardLayout); | |
37 if (layout == "") { | |
mazda
2012/05/29 17:08:06
nit: layout.empty()
| |
38 // If it is unset we check the hardware. | |
39 chromeos::input_method::InputMethodManager* manager = | |
40 chromeos::input_method::InputMethodManager::GetInstance(); | |
41 const chromeos::input_method::InputMethodDescriptor& descriptor = | |
42 manager->GetCurrentInputMethod(); | |
43 layout = descriptor.id(); | |
44 } | |
45 return (layout == "xkb:fr::fra" || layout == "xkb:be::fra"); | |
46 } | |
47 | |
48 ui::Accelerator ImeController::RemapAccelerator( | |
49 const ui::Accelerator& accelerator) { | |
50 ui::KeyboardCode key = accelerator.key_code(); | |
51 int modifiers = accelerator.modifiers(); | |
52 // On French keyboards the user needs to press a number key in conjunction | |
53 // with the shift key. To get the right accelerator from our static table | |
54 // we modify the received accelerator to match this. | |
55 if (key >= ui::VKEY_0 && key <= ui::VKEY_9) { | |
56 // A keyboard layout can get changed by the user, so we need to dynamically | |
57 // check if a modification is required. | |
58 if (IsFrenchKeyboard()) | |
59 // We toggle the shift key to get the correct accelerator from our table. | |
60 modifiers ^= ui::EF_SHIFT_DOWN; | |
mazda
2012/05/29 17:08:06
Do we need to toggle the shift key when the shift
| |
61 } | |
62 return ui::Accelerator(key, modifiers); | |
63 } | |
OLD | NEW |