Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: ui/base/ime/input_method_ibus.cc

Issue 10823141: Support reverse conversion for ChromeOS (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Simplify Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 string16 selection_text;
Yusuke Sato 2012/08/03 05:46:10 nit: move to L.366
Seigo Nonaka 2012/08/03 07:12:44 Done.
360 ui::Range selection_range;
361
362 if (!GetTextInputClient()->GetSelectionRange(&selection_range)) {
363 previous_selected_text_.clear();
364 return;
365 }
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 surrdounding text in
Yusuke Sato 2012/08/03 05:46:10 surrounding
Seigo Nonaka 2012/08/03 07:12:44 Done.
379 // TextInputClient.
380 // TODO(nona): Implement fully surrounding text retrieval.
381 GetInputContextClient()->SetSurroundingText(UTF16ToUTF8(selection_text),
382 0UL,
Yusuke Sato 2012/08/03 05:46:10 is this a caret pos? add /* parameter_name */
Seigo Nonaka 2012/08/03 07:12:44 Done.
383 selection_range.length());
384 LOG(ERROR) << selection_text;
Yusuke Sato 2012/08/03 05:46:10 remove
Seigo Nonaka 2012/08/03 07:12:44 Done.
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
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
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
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
OLDNEW
« ui/base/ime/input_method_ibus.h ('K') | « ui/base/ime/input_method_ibus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698