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 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 288 } |
289 | 289 |
290 // ui::IBusClient override. | 290 // ui::IBusClient override. |
291 virtual InputMethodType GetInputMethodType() OVERRIDE { | 291 virtual InputMethodType GetInputMethodType() OVERRIDE { |
292 const std::string current_input_method_id = GetCurrentInputMethodId(); | 292 const std::string current_input_method_id = GetCurrentInputMethodId(); |
293 return InputMethodUtil::IsKeyboardLayout(current_input_method_id) ? | 293 return InputMethodUtil::IsKeyboardLayout(current_input_method_id) ? |
294 INPUT_METHOD_XKB_LAYOUT : INPUT_METHOD_NORMAL; | 294 INPUT_METHOD_XKB_LAYOUT : INPUT_METHOD_NORMAL; |
295 } | 295 } |
296 | 296 |
297 virtual void SetCursorLocation(IBusInputContext* context, | 297 virtual void SetCursorLocation(IBusInputContext* context, |
298 int32 x, | 298 const gfx::Rect& cursor_location, |
299 int32 y, | 299 const gfx::Rect& composition_head) OVERRIDE { |
300 int32 w, | |
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 | |
305 if (!ui_) | 300 if (!ui_) |
306 return; | 301 return; |
307 | |
308 scoped_ptr<InputMethodDescriptors> input_methods( | |
309 InputMethodManager::GetInstance()->GetSupportedInputMethods()); | |
310 for (size_t i = 0; i < arraysize(kMozcJaInputMethodIds); ++i) { | |
311 if (IsActive(kMozcJaInputMethodIds[i], input_methods.get())) { | |
312 // Mozc Japanese IMEs require cursor location information to show the | |
313 // suggestion window in a correct position. | |
314 ui::internal::IBusClientImpl::SetCursorLocation(context, x, y, w, h); | |
315 break; // call IBusUiControllerImpl::SetCursorLocation() as well. | |
316 } | |
317 } | |
318 | |
319 // We don't have to call ibus_input_context_set_cursor_location() on | 302 // We don't have to call ibus_input_context_set_cursor_location() on |
320 // Chrome OS because the candidate window for IBus is integrated with | 303 // Chrome OS because the candidate window for IBus is integrated with |
321 // Chrome. | 304 // Chrome. |
322 ui_->SetCursorLocation(NULL, x, y, w, h); | 305 ui_->SetCursorLocation(NULL, cursor_location, composition_head); |
323 } | 306 } |
324 | 307 |
325 void set_ui(IBusUiControllerImpl* ui) { | 308 void set_ui(IBusUiControllerImpl* ui) { |
326 ui_ = ui; | 309 ui_ = ui; |
327 } | 310 } |
328 | 311 |
329 private: | 312 private: |
330 std::string GetCurrentInputMethodId() { | 313 std::string GetCurrentInputMethodId() { |
331 InputMethodManager* manager = InputMethodManager::GetInstance(); | 314 InputMethodManager* manager = InputMethodManager::GetInstance(); |
332 return manager->GetCurrentInputMethod().id(); | 315 return manager->GetCurrentInputMethod().id(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 static void UpdateAuxiliaryTextThunk(IBusPanelService* sender, | 359 static void UpdateAuxiliaryTextThunk(IBusPanelService* sender, |
377 IBusText* text, gboolean visible, | 360 IBusText* text, gboolean visible, |
378 gpointer userdata) { | 361 gpointer userdata) { |
379 return reinterpret_cast<IBusUiControllerImpl*>(userdata) | 362 return reinterpret_cast<IBusUiControllerImpl*>(userdata) |
380 ->UpdateAuxiliaryText(sender, text, visible); | 363 ->UpdateAuxiliaryText(sender, text, visible); |
381 } | 364 } |
382 static void SetCursorLocationThunk(IBusPanelService* sender, | 365 static void SetCursorLocationThunk(IBusPanelService* sender, |
383 gint x, gint y, gint width, gint height, | 366 gint x, gint y, gint width, gint height, |
384 gpointer userdata) { | 367 gpointer userdata) { |
385 return reinterpret_cast<IBusUiControllerImpl*>(userdata) | 368 return reinterpret_cast<IBusUiControllerImpl*>(userdata) |
386 ->SetCursorLocation(sender, x, y, width, height); | 369 ->SetCursorLocation(sender, gfx::Rect(x, y, width, height), |
| 370 gfx::Rect()); |
387 } | 371 } |
388 static void UpdateLookupTableThunk(IBusPanelService* sender, | 372 static void UpdateLookupTableThunk(IBusPanelService* sender, |
389 IBusLookupTable* table, gboolean visible, | 373 IBusLookupTable* table, gboolean visible, |
390 gpointer userdata) { | 374 gpointer userdata) { |
391 return reinterpret_cast<IBusUiControllerImpl*>(userdata) | 375 return reinterpret_cast<IBusUiControllerImpl*>(userdata) |
392 ->UpdateLookupTable(sender, table, visible); | 376 ->UpdateLookupTable(sender, table, visible); |
393 } | 377 } |
394 static void UpdatePreeditTextThunk(IBusPanelService* sender, | 378 static void UpdatePreeditTextThunk(IBusPanelService* sender, |
395 IBusText* text, | 379 IBusText* text, |
396 guint cursor_pos, | 380 guint cursor_pos, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 g_return_if_fail(text); | 544 g_return_if_fail(text); |
561 g_return_if_fail(text->text); | 545 g_return_if_fail(text->text); |
562 // Convert IBusText to a std::string. IBusText is an attributed text, | 546 // Convert IBusText to a std::string. IBusText is an attributed text, |
563 const std::string simple_text = text->text; | 547 const std::string simple_text = text->text; |
564 FOR_EACH_OBSERVER(Observer, observers_, | 548 FOR_EACH_OBSERVER(Observer, observers_, |
565 OnUpdateAuxiliaryText(simple_text, visible == TRUE)); | 549 OnUpdateAuxiliaryText(simple_text, visible == TRUE)); |
566 } | 550 } |
567 | 551 |
568 // Handles IBusPanelService's |SetCursorLocation| method call. | 552 // Handles IBusPanelService's |SetCursorLocation| method call. |
569 void SetCursorLocation(IBusPanelService *panel, | 553 void SetCursorLocation(IBusPanelService *panel, |
570 gint x, | 554 const gfx::Rect& cursor_location, |
571 gint y, | 555 const gfx::Rect& composition_head) { |
572 gint width, | |
573 gint height) { | |
574 // Note: |panel| might be NULL. See IBusChromeOSClientImpl above. | 556 // Note: |panel| might be NULL. See IBusChromeOSClientImpl above. |
575 FOR_EACH_OBSERVER(Observer, observers_, | 557 FOR_EACH_OBSERVER(Observer, observers_, |
576 OnSetCursorLocation(x, y, width, height)); | 558 OnSetCursorLocation(cursor_location, composition_head)); |
577 } | 559 } |
578 | 560 |
579 // Handles IBusPanelService's |UpdatePreeditText| method call. | 561 // Handles IBusPanelService's |UpdatePreeditText| method call. |
580 void UpdatePreeditText(IBusPanelService *panel, | 562 void UpdatePreeditText(IBusPanelService *panel, |
581 IBusText *text, | 563 IBusText *text, |
582 guint cursor_pos, | 564 guint cursor_pos, |
583 gboolean visible) { | 565 gboolean visible) { |
584 FOR_EACH_OBSERVER(Observer, observers_, | 566 FOR_EACH_OBSERVER(Observer, observers_, |
585 OnUpdatePreeditText(text->text, cursor_pos, visible)); | 567 OnUpdatePreeditText(text->text, cursor_pos, visible)); |
586 } | 568 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 IBusUiController::~IBusUiController() { | 733 IBusUiController::~IBusUiController() { |
752 } | 734 } |
753 | 735 |
754 bool IsActiveForTesting(const std::string& input_method_id, | 736 bool IsActiveForTesting(const std::string& input_method_id, |
755 const InputMethodDescriptors* descriptors) { | 737 const InputMethodDescriptors* descriptors) { |
756 return IsActive(input_method_id, descriptors); | 738 return IsActive(input_method_id, descriptors); |
757 } | 739 } |
758 | 740 |
759 } // namespace input_method | 741 } // namespace input_method |
760 } // namespace chromeos | 742 } // namespace chromeos |
OLD | NEW |