OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/chromeos/cros/keyboard_library.h" | 5 #include "chrome/browser/chromeos/cros/keyboard_library.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/cros/cros_library.h" | 7 #include "chrome/browser/chromeos/cros/cros_library.h" |
8 #include "cros/chromeos_keyboard.h" | 8 #include "cros/chromeos_keyboard.h" |
9 | 9 |
10 namespace chromeos { | 10 namespace chromeos { |
11 | 11 |
12 std::string KeyboardLibraryImpl::GetCurrentKeyboardLayoutName() const { | 12 class KeyboardLibraryImpl : public KeyboardLibrary { |
13 if (CrosLibrary::Get()->EnsureLoaded()) { | 13 public: |
14 return chromeos::GetCurrentKeyboardLayoutName(); | 14 KeyboardLibraryImpl() {} |
| 15 virtual ~KeyboardLibraryImpl() {} |
| 16 |
| 17 std::string GetCurrentKeyboardLayoutName() const { |
| 18 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 19 return chromeos::GetCurrentKeyboardLayoutName(); |
| 20 } |
| 21 return ""; |
15 } | 22 } |
16 return ""; | |
17 } | |
18 | 23 |
19 bool KeyboardLibraryImpl::SetCurrentKeyboardLayoutByName( | 24 bool SetCurrentKeyboardLayoutByName(const std::string& layout_name) { |
20 const std::string& layout_name) { | 25 if (CrosLibrary::Get()->EnsureLoaded()) { |
21 if (CrosLibrary::Get()->EnsureLoaded()) { | 26 return chromeos::SetCurrentKeyboardLayoutByName(layout_name); |
22 return chromeos::SetCurrentKeyboardLayoutByName(layout_name); | 27 } |
| 28 return false; |
23 } | 29 } |
24 return false; | |
25 } | |
26 | 30 |
27 bool KeyboardLibraryImpl::RemapModifierKeys(const ModifierMap& modifier_map) { | 31 bool RemapModifierKeys(const ModifierMap& modifier_map) { |
28 if (CrosLibrary::Get()->EnsureLoaded()) { | 32 if (CrosLibrary::Get()->EnsureLoaded()) { |
29 return chromeos::RemapModifierKeys(modifier_map); | 33 return chromeos::RemapModifierKeys(modifier_map); |
| 34 } |
| 35 return false; |
30 } | 36 } |
31 return false; | |
32 } | |
33 | 37 |
34 bool KeyboardLibraryImpl::GetKeyboardLayoutPerWindow( | 38 bool GetKeyboardLayoutPerWindow(bool* is_per_window) const { |
35 bool* is_per_window) const { | 39 if (CrosLibrary::Get()->EnsureLoaded()) { |
36 if (CrosLibrary::Get()->EnsureLoaded()) { | 40 return chromeos::GetKeyboardLayoutPerWindow(is_per_window); |
37 return chromeos::GetKeyboardLayoutPerWindow(is_per_window); | 41 } |
| 42 return false; |
38 } | 43 } |
39 return false; | |
40 } | |
41 | 44 |
42 bool KeyboardLibraryImpl::SetKeyboardLayoutPerWindow(bool is_per_window) { | 45 bool SetKeyboardLayoutPerWindow(bool is_per_window) { |
43 if (CrosLibrary::Get()->EnsureLoaded()) { | 46 if (CrosLibrary::Get()->EnsureLoaded()) { |
44 return chromeos::SetKeyboardLayoutPerWindow(is_per_window); | 47 return chromeos::SetKeyboardLayoutPerWindow(is_per_window); |
| 48 } |
| 49 return false; |
45 } | 50 } |
46 return false; | 51 |
| 52 private: |
| 53 DISALLOW_COPY_AND_ASSIGN(KeyboardLibraryImpl); |
| 54 }; |
| 55 |
| 56 class KeyboardLibraryStubImpl : public KeyboardLibrary { |
| 57 public: |
| 58 KeyboardLibraryStubImpl() {} |
| 59 virtual ~KeyboardLibraryStubImpl() {} |
| 60 |
| 61 std::string GetCurrentKeyboardLayoutName() const { |
| 62 return ""; |
| 63 } |
| 64 |
| 65 bool SetCurrentKeyboardLayoutByName(const std::string& layout_name) { |
| 66 return false; |
| 67 } |
| 68 |
| 69 bool RemapModifierKeys(const ModifierMap& modifier_map) { |
| 70 return false; |
| 71 } |
| 72 |
| 73 bool GetKeyboardLayoutPerWindow(bool* is_per_window) const { |
| 74 return false; |
| 75 } |
| 76 |
| 77 bool SetKeyboardLayoutPerWindow(bool is_per_window) { |
| 78 return false; |
| 79 } |
| 80 |
| 81 private: |
| 82 DISALLOW_COPY_AND_ASSIGN(KeyboardLibraryStubImpl); |
| 83 }; |
| 84 |
| 85 // static |
| 86 KeyboardLibrary* KeyboardLibrary::GetImpl(bool stub) { |
| 87 if (stub) |
| 88 return new KeyboardLibraryStubImpl(); |
| 89 else |
| 90 return new KeyboardLibraryImpl(); |
47 } | 91 } |
48 | 92 |
49 } // namespace chromeos | 93 } // namespace chromeos |
OLD | NEW |