| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 if (IsTextInputClientFocused(client)) { | 227 if (IsTextInputClientFocused(client)) { |
| 228 ResetContext(); | 228 ResetContext(); |
| 229 UpdateContextFocusState(); | 229 UpdateContextFocusState(); |
| 230 if (previous_textinput_type_ != client->GetTextInputType()) | 230 if (previous_textinput_type_ != client->GetTextInputType()) |
| 231 OnInputMethodChanged(); | 231 OnInputMethodChanged(); |
| 232 } | 232 } |
| 233 InputMethodBase::OnTextInputTypeChanged(client); | 233 InputMethodBase::OnTextInputTypeChanged(client); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void InputMethodIBus::OnCaretBoundsChanged(const TextInputClient* client) { | 236 void InputMethodIBus::OnCaretBoundsChanged(const TextInputClient* client) { |
| 237 if (!context_focused_ || !IsTextInputClientFocused(client)) | 237 OnCaretBoundsChangedInternal(client); |
| 238 return; | 238 InputMethodBase::OnCaretBoundsChanged(client); |
| 239 | |
| 240 // The current text input type should not be NONE if |context_| is focused. | |
| 241 DCHECK(!IsTextInputTypeNone()); | |
| 242 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); | |
| 243 | |
| 244 gfx::Rect composition_head; | |
| 245 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, | |
| 246 &composition_head)) { | |
| 247 composition_head = rect; | |
| 248 } | |
| 249 | |
| 250 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = | |
| 251 chromeos::IBusBridge::Get()->GetCandidateWindowHandler(); | |
| 252 if (!candidate_window) | |
| 253 return; | |
| 254 candidate_window->SetCursorLocation( | |
| 255 GfxRectToIBusRect(rect), | |
| 256 GfxRectToIBusRect(composition_head)); | |
| 257 | |
| 258 gfx::Range text_range; | |
| 259 gfx::Range selection_range; | |
| 260 string16 surrounding_text; | |
| 261 if (!GetTextInputClient()->GetTextRange(&text_range) || | |
| 262 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || | |
| 263 !GetTextInputClient()->GetSelectionRange(&selection_range)) { | |
| 264 previous_surrounding_text_.clear(); | |
| 265 previous_selection_range_ = gfx::Range::InvalidRange(); | |
| 266 return; | |
| 267 } | |
| 268 | |
| 269 if (previous_selection_range_ == selection_range && | |
| 270 previous_surrounding_text_ == surrounding_text) | |
| 271 return; | |
| 272 | |
| 273 previous_selection_range_ = selection_range; | |
| 274 previous_surrounding_text_ = surrounding_text; | |
| 275 | |
| 276 if (!selection_range.IsValid()) { | |
| 277 // TODO(nona): Ideally selection_range should not be invalid. | |
| 278 // TODO(nona): If javascript changes the focus on page loading, even (0,0) | |
| 279 // can not be obtained. Need investigation. | |
| 280 return; | |
| 281 } | |
| 282 | |
| 283 // Here SetSurroundingText accepts relative position of |surrounding_text|, so | |
| 284 // we have to convert |selection_range| from node coordinates to | |
| 285 // |surrounding_text| coordinates. | |
| 286 if (!GetEngine()) | |
| 287 return; | |
| 288 GetEngine()->SetSurroundingText( | |
| 289 UTF16ToUTF8(surrounding_text), | |
| 290 selection_range.start() - text_range.start(), | |
| 291 selection_range.end() - text_range.start()); | |
| 292 } | 239 } |
| 293 | 240 |
| 294 void InputMethodIBus::CancelComposition(const TextInputClient* client) { | 241 void InputMethodIBus::CancelComposition(const TextInputClient* client) { |
| 295 if (context_focused_ && IsTextInputClientFocused(client)) | 242 if (context_focused_ && IsTextInputClientFocused(client)) |
| 296 ResetContext(); | 243 ResetContext(); |
| 297 } | 244 } |
| 298 | 245 |
| 299 void InputMethodIBus::OnInputLocaleChanged() { | |
| 300 // Not supported. | |
| 301 } | |
| 302 | |
| 303 std::string InputMethodIBus::GetInputLocale() { | 246 std::string InputMethodIBus::GetInputLocale() { |
| 304 // Not supported. | 247 // Not supported. |
| 305 return ""; | 248 return ""; |
| 306 } | 249 } |
| 307 | 250 |
| 308 base::i18n::TextDirection InputMethodIBus::GetInputTextDirection() { | 251 base::i18n::TextDirection InputMethodIBus::GetInputTextDirection() { |
| 309 // Not supported. | 252 // Not supported. |
| 310 return base::i18n::UNKNOWN_DIRECTION; | 253 return base::i18n::UNKNOWN_DIRECTION; |
| 311 } | 254 } |
| 312 | 255 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 } | 742 } |
| 800 } | 743 } |
| 801 | 744 |
| 802 // Use a black thin underline by default. | 745 // Use a black thin underline by default. |
| 803 if (out_composition->underlines.empty()) { | 746 if (out_composition->underlines.empty()) { |
| 804 out_composition->underlines.push_back(CompositionUnderline( | 747 out_composition->underlines.push_back(CompositionUnderline( |
| 805 0, length, SK_ColorBLACK, false /* thick */)); | 748 0, length, SK_ColorBLACK, false /* thick */)); |
| 806 } | 749 } |
| 807 } | 750 } |
| 808 | 751 |
| 752 void InputMethodIBus::OnCaretBoundsChangedInternal( |
| 753 const TextInputClient* client) { |
| 754 if (!context_focused_ || !IsTextInputClientFocused(client)) |
| 755 return; |
| 756 |
| 757 // The current text input type should not be NONE if |context_| is focused. |
| 758 DCHECK(!IsTextInputTypeNone()); |
| 759 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); |
| 760 |
| 761 gfx::Rect composition_head; |
| 762 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, |
| 763 &composition_head)) { |
| 764 composition_head = rect; |
| 765 } |
| 766 |
| 767 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = |
| 768 chromeos::IBusBridge::Get()->GetCandidateWindowHandler(); |
| 769 if (!candidate_window) |
| 770 return; |
| 771 candidate_window->SetCursorLocation( |
| 772 GfxRectToIBusRect(rect), |
| 773 GfxRectToIBusRect(composition_head)); |
| 774 |
| 775 gfx::Range text_range; |
| 776 gfx::Range selection_range; |
| 777 string16 surrounding_text; |
| 778 if (!GetTextInputClient()->GetTextRange(&text_range) || |
| 779 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || |
| 780 !GetTextInputClient()->GetSelectionRange(&selection_range)) { |
| 781 previous_surrounding_text_.clear(); |
| 782 previous_selection_range_ = gfx::Range::InvalidRange(); |
| 783 return; |
| 784 } |
| 785 |
| 786 if (previous_selection_range_ == selection_range && |
| 787 previous_surrounding_text_ == surrounding_text) |
| 788 return; |
| 789 |
| 790 previous_selection_range_ = selection_range; |
| 791 previous_surrounding_text_ = surrounding_text; |
| 792 |
| 793 if (!selection_range.IsValid()) { |
| 794 // TODO(nona): Ideally selection_range should not be invalid. |
| 795 // TODO(nona): If javascript changes the focus on page loading, even (0,0) |
| 796 // can not be obtained. Need investigation. |
| 797 return; |
| 798 } |
| 799 |
| 800 // Here SetSurroundingText accepts relative position of |surrounding_text|, so |
| 801 // we have to convert |selection_range| from node coordinates to |
| 802 // |surrounding_text| coordinates. |
| 803 if (!GetEngine()) |
| 804 return; |
| 805 GetEngine()->SetSurroundingText( |
| 806 UTF16ToUTF8(surrounding_text), |
| 807 selection_range.start() - text_range.start(), |
| 808 selection_range.end() - text_range.start()); |
| 809 } |
| 810 |
| 809 } // namespace ui | 811 } // namespace ui |
| OLD | NEW |