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/chromeos/input_method/ibus_ui_controller.h" | 5 #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h" |
6 | 6 |
7 #if defined(HAVE_IBUS) | 7 #if defined(HAVE_IBUS) |
8 #include <ibus.h> | 8 #include <ibus.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <sstream> | 11 #include <sstream> |
12 | 12 |
| 13 #include "ash/shell.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/string_util.h" | 16 #include "base/string_util.h" |
15 #include "third_party/mozc/session/candidates_lite.pb.h" | 17 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h" |
16 | |
17 #if defined(HAVE_IBUS) | |
18 #include "ash/shell.h" | |
19 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 18 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
20 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 19 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 20 #include "third_party/mozc/session/candidates_lite.pb.h" |
21 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
22 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
23 #include "ui/base/ime/ibus_client_impl.h" | 23 #include "ui/base/ime/ibus_client_impl.h" |
24 #include "ui/base/ime/input_method_ibus.h" | 24 #include "ui/base/ime/input_method_ibus.h" |
25 | 25 |
| 26 namespace chromeos { |
| 27 namespace input_method { |
26 namespace { | 28 namespace { |
27 | 29 |
28 // The list of input method IDs for Mozc Japanese IMEs. | 30 bool IsActive(const std::string& input_method_id, |
29 const char* kMozcJaInputMethodIds[] = { "mozc", "mozc-jp", "mozc-dv" }; | 31 const InputMethodDescriptors* descriptors) { |
| 32 for (size_t i = 0; i < descriptors->size(); ++i) { |
| 33 if (descriptors->at(i).id() == input_method_id) { |
| 34 return true; |
| 35 } |
| 36 } |
| 37 return false; |
| 38 } |
30 | 39 |
31 } // namespace | 40 } // namespace |
32 #endif | |
33 | |
34 namespace chromeos { | |
35 namespace input_method { | |
36 | 41 |
37 InputMethodLookupTable::InputMethodLookupTable() | 42 InputMethodLookupTable::InputMethodLookupTable() |
38 : visible(false), | 43 : visible(false), |
39 cursor_absolute_index(0), | 44 cursor_absolute_index(0), |
40 page_size(0), | 45 page_size(0), |
41 orientation(kHorizontal) { | 46 orientation(kHorizontal) { |
42 } | 47 } |
43 | 48 |
44 InputMethodLookupTable::~InputMethodLookupTable() { | 49 InputMethodLookupTable::~InputMethodLookupTable() { |
45 } | 50 } |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 const std::string current_input_method_id = GetCurrentInputMethodId(); | 292 const std::string current_input_method_id = GetCurrentInputMethodId(); |
288 return InputMethodUtil::IsKeyboardLayout(current_input_method_id) ? | 293 return InputMethodUtil::IsKeyboardLayout(current_input_method_id) ? |
289 INPUT_METHOD_XKB_LAYOUT : INPUT_METHOD_NORMAL; | 294 INPUT_METHOD_XKB_LAYOUT : INPUT_METHOD_NORMAL; |
290 } | 295 } |
291 | 296 |
292 virtual void SetCursorLocation(IBusInputContext* context, | 297 virtual void SetCursorLocation(IBusInputContext* context, |
293 int32 x, | 298 int32 x, |
294 int32 y, | 299 int32 y, |
295 int32 w, | 300 int32 w, |
296 int32 h) OVERRIDE { | 301 int32 h) OVERRIDE { |
| 302 // The list of input method IDs for Mozc Japanese IMEs. |
| 303 const char* kMozcJaInputMethodIds[] = { "mozc", "mozc-jp", "mozc-dv" }; |
| 304 |
297 if (!ui_) | 305 if (!ui_) |
298 return; | 306 return; |
299 | 307 |
300 const std::string current_input_method_id = GetCurrentInputMethodId(); | 308 scoped_ptr<InputMethodDescriptors> input_methods( |
| 309 InputMethodManager::GetInstance()->GetSupportedInputMethods()); |
301 for (size_t i = 0; i < arraysize(kMozcJaInputMethodIds); ++i) { | 310 for (size_t i = 0; i < arraysize(kMozcJaInputMethodIds); ++i) { |
302 if (kMozcJaInputMethodIds[i] == current_input_method_id) { | 311 if (IsActive(kMozcJaInputMethodIds[i], input_methods.get())) { |
303 // Mozc Japanese IMEs require cursor location information to show the | 312 // Mozc Japanese IMEs require cursor location information to show the |
304 // suggestion window in a correct position. | 313 // suggestion window in a correct position. |
305 ui::internal::IBusClientImpl::SetCursorLocation(context, x, y, w, h); | 314 ui::internal::IBusClientImpl::SetCursorLocation(context, x, y, w, h); |
306 break; // call IBusUiControllerImpl::SetCursorLocation() as well. | 315 break; // call IBusUiControllerImpl::SetCursorLocation() as well. |
307 } | 316 } |
308 } | 317 } |
309 | 318 |
310 // We don't have to call ibus_input_context_set_cursor_location() on | 319 // We don't have to call ibus_input_context_set_cursor_location() on |
311 // Chrome OS because the candidate window for IBus is integrated with | 320 // Chrome OS because the candidate window for IBus is integrated with |
312 // Chrome. | 321 // Chrome. |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 #if defined(HAVE_IBUS) | 740 #if defined(HAVE_IBUS) |
732 return new IBusUiControllerImpl; | 741 return new IBusUiControllerImpl; |
733 #else | 742 #else |
734 return new IBusUiControllerStubImpl; | 743 return new IBusUiControllerStubImpl; |
735 #endif | 744 #endif |
736 } | 745 } |
737 | 746 |
738 IBusUiController::~IBusUiController() { | 747 IBusUiController::~IBusUiController() { |
739 } | 748 } |
740 | 749 |
| 750 bool IsActiveForTesting(const std::string& input_method_id, |
| 751 const InputMethodDescriptors* descriptors) { |
| 752 return IsActive(input_method_id, descriptors); |
| 753 } |
| 754 |
741 } // namespace input_method | 755 } // namespace input_method |
742 } // namespace chromeos | 756 } // namespace chromeos |
OLD | NEW |