| 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 "ui/base/ime/input_method_ibus.h" | 5 #include "ui/base/ime/input_method_ibus.h" |
| 6 | 6 |
| 7 #include <X11/X.h> | 7 #include <X11/X.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/Xutil.h> | 9 #include <X11/Xutil.h> |
| 10 #undef FocusIn | 10 #undef FocusIn |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const int kIBusReleaseMask = 1 << 30; | 39 const int kIBusReleaseMask = 1 << 30; |
| 40 const char kClientName[] = "chrome"; | 40 const char kClientName[] = "chrome"; |
| 41 | 41 |
| 42 // Following capability mask is introduced from | 42 // Following capability mask is introduced from |
| 43 // http://ibus.googlecode.com/svn/docs/ibus-1.4/ibus-ibustypes.html#IBusCapabili
te | 43 // http://ibus.googlecode.com/svn/docs/ibus-1.4/ibus-ibustypes.html#IBusCapabili
te |
| 44 const uint32 kIBusCapabilityPreeditText = 1U; | 44 const uint32 kIBusCapabilityPreeditText = 1U; |
| 45 const uint32 kIBusCapabilityFocus = 8U; | 45 const uint32 kIBusCapabilityFocus = 8U; |
| 46 const uint32 kIBusCapabilitySurroundingText = 32U; |
| 46 | 47 |
| 47 XKeyEvent* GetKeyEvent(XEvent* event) { | 48 XKeyEvent* GetKeyEvent(XEvent* event) { |
| 48 DCHECK(event && (event->type == KeyPress || event->type == KeyRelease)); | 49 DCHECK(event && (event->type == KeyPress || event->type == KeyRelease)); |
| 49 return &event->xkey; | 50 return &event->xkey; |
| 50 } | 51 } |
| 51 | 52 |
| 52 // Converts X (and ibus) flags to event flags. | 53 // Converts X (and ibus) flags to event flags. |
| 53 int EventFlagsFromXFlags(unsigned int flags) { | 54 int EventFlagsFromXFlags(unsigned int flags) { |
| 54 return (flags & LockMask ? ui::EF_CAPS_LOCK_DOWN : 0) | | 55 return (flags & LockMask ? ui::EF_CAPS_LOCK_DOWN : 0) | |
| 55 (flags & ControlMask ? ui::EF_CONTROL_DOWN : 0) | | 56 (flags & ControlMask ? ui::EF_CONTROL_DOWN : 0) | |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); | 348 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); |
| 348 | 349 |
| 349 gfx::Rect composition_head; | 350 gfx::Rect composition_head; |
| 350 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, | 351 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, |
| 351 &composition_head)) { | 352 &composition_head)) { |
| 352 composition_head = rect; | 353 composition_head = rect; |
| 353 } | 354 } |
| 354 | 355 |
| 355 // This function runs asynchronously. | 356 // This function runs asynchronously. |
| 356 ibus_client_->SetCursorLocation(rect, composition_head); | 357 ibus_client_->SetCursorLocation(rect, composition_head); |
| 358 |
| 359 ui::Range selection_range; |
| 360 if (!GetTextInputClient()->GetSelectionRange(&selection_range)) { |
| 361 previous_selected_text_.clear(); |
| 362 return; |
| 363 } |
| 364 |
| 365 string16 selection_text; |
| 366 if (!GetTextInputClient()->GetTextFromRange(selection_range, |
| 367 &selection_text)) { |
| 368 previous_selected_text_.clear(); |
| 369 return; |
| 370 } |
| 371 |
| 372 if (previous_selected_text_ == selection_text) |
| 373 return; |
| 374 |
| 375 previous_selected_text_ = selection_text; |
| 376 |
| 377 // In the original meaning of SetSurroundingText is not just selection text, |
| 378 // but currently there are no way to retrieve surrounding text in |
| 379 // TextInputClient. |
| 380 // TODO(nona): Implement fully surrounding text retrieval. |
| 381 GetInputContextClient()->SetSurroundingText( |
| 382 UTF16ToUTF8(selection_text), |
| 383 0UL, /* cursor position. */ |
| 384 selection_range.length()); /* selection anchor position. */ |
| 357 } | 385 } |
| 358 | 386 |
| 359 void InputMethodIBus::CancelComposition(const TextInputClient* client) { | 387 void InputMethodIBus::CancelComposition(const TextInputClient* client) { |
| 360 if (context_focused_ && IsTextInputClientFocused(client)) | 388 if (context_focused_ && IsTextInputClientFocused(client)) |
| 361 ResetContext(); | 389 ResetContext(); |
| 362 } | 390 } |
| 363 | 391 |
| 364 std::string InputMethodIBus::GetInputLocale() { | 392 std::string InputMethodIBus::GetInputLocale() { |
| 365 // Not supported. | 393 // Not supported. |
| 366 return ""; | 394 return ""; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 459 |
| 432 input_context_client->SetShowPreeditTextHandler( | 460 input_context_client->SetShowPreeditTextHandler( |
| 433 base::Bind(&InputMethodIBus::OnShowPreeditText, | 461 base::Bind(&InputMethodIBus::OnShowPreeditText, |
| 434 weak_ptr_factory_.GetWeakPtr())); | 462 weak_ptr_factory_.GetWeakPtr())); |
| 435 | 463 |
| 436 input_context_client->SetHidePreeditTextHandler( | 464 input_context_client->SetHidePreeditTextHandler( |
| 437 base::Bind(&InputMethodIBus::OnHidePreeditText, | 465 base::Bind(&InputMethodIBus::OnHidePreeditText, |
| 438 weak_ptr_factory_.GetWeakPtr())); | 466 weak_ptr_factory_.GetWeakPtr())); |
| 439 | 467 |
| 440 GetInputContextClient()->SetCapabilities( | 468 GetInputContextClient()->SetCapabilities( |
| 441 kIBusCapabilityPreeditText | kIBusCapabilityFocus); | 469 kIBusCapabilityPreeditText | kIBusCapabilityFocus | |
| 470 kIBusCapabilitySurroundingText); |
| 442 | 471 |
| 443 UpdateContextFocusState(); | 472 UpdateContextFocusState(); |
| 444 // Since ibus-daemon is launched in an on-demand basis on Chrome OS, RWHVA (or | 473 // Since ibus-daemon is launched in an on-demand basis on Chrome OS, RWHVA (or |
| 445 // equivalents) might call OnCaretBoundsChanged() before the daemon starts. To | 474 // equivalents) might call OnCaretBoundsChanged() before the daemon starts. To |
| 446 // save the case, call OnCaretBoundsChanged() here. | 475 // save the case, call OnCaretBoundsChanged() here. |
| 447 OnCaretBoundsChanged(GetTextInputClient()); | 476 OnCaretBoundsChanged(GetTextInputClient()); |
| 448 OnInputMethodChanged(); | 477 OnInputMethodChanged(); |
| 449 } | 478 } |
| 450 | 479 |
| 451 void InputMethodIBus::DestroyContext() { | 480 void InputMethodIBus::DestroyContext() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 557 } |
| 529 | 558 |
| 530 // We only focus in |context_| when the focus is in a normal textfield. | 559 // We only focus in |context_| when the focus is in a normal textfield. |
| 531 // ibus_input_context_focus_{in|out}() run asynchronously. | 560 // ibus_input_context_focus_{in|out}() run asynchronously. |
| 532 if (old_context_focused && !context_focused_) | 561 if (old_context_focused && !context_focused_) |
| 533 GetInputContextClient()->FocusOut(); | 562 GetInputContextClient()->FocusOut(); |
| 534 else if (!old_context_focused && context_focused_) | 563 else if (!old_context_focused && context_focused_) |
| 535 GetInputContextClient()->FocusIn(); | 564 GetInputContextClient()->FocusIn(); |
| 536 | 565 |
| 537 if (context_focused_) { | 566 if (context_focused_) { |
| 538 uint32 capability = kIBusCapabilityFocus; | 567 uint32 capability = kIBusCapabilityFocus | kIBusCapabilitySurroundingText; |
| 539 if (CanComposeInline()) | 568 if (CanComposeInline()) |
| 540 capability |= kIBusCapabilityPreeditText; | 569 capability |= kIBusCapabilityPreeditText; |
| 541 GetInputContextClient()->SetCapabilities(capability); | 570 GetInputContextClient()->SetCapabilities(capability); |
| 542 } | 571 } |
| 543 } | 572 } |
| 544 | 573 |
| 545 void InputMethodIBus::ProcessKeyEventPostIME( | 574 void InputMethodIBus::ProcessKeyEventPostIME( |
| 546 const base::NativeEvent& native_event, | 575 const base::NativeEvent& native_event, |
| 547 uint32 ibus_keyval, | 576 uint32 ibus_keyval, |
| 548 bool handled) { | 577 bool handled) { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 } | 1026 } |
| 998 | 1027 |
| 999 // Use a black thin underline by default. | 1028 // Use a black thin underline by default. |
| 1000 if (out_composition->underlines.empty()) { | 1029 if (out_composition->underlines.empty()) { |
| 1001 out_composition->underlines.push_back(CompositionUnderline( | 1030 out_composition->underlines.push_back(CompositionUnderline( |
| 1002 0, length, SK_ColorBLACK, false /* thick */)); | 1031 0, length, SK_ColorBLACK, false /* thick */)); |
| 1003 } | 1032 } |
| 1004 } | 1033 } |
| 1005 | 1034 |
| 1006 } // namespace ui | 1035 } // namespace ui |
| OLD | NEW |