| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 ResetContext(); | 216 ResetContext(); |
| 217 UpdateContextFocusState(); | 217 UpdateContextFocusState(); |
| 218 if (previous_textinput_type_ != client->GetTextInputType()) | 218 if (previous_textinput_type_ != client->GetTextInputType()) |
| 219 OnInputMethodChanged(); | 219 OnInputMethodChanged(); |
| 220 previous_textinput_type_ = client->GetTextInputType(); | 220 previous_textinput_type_ = client->GetTextInputType(); |
| 221 } | 221 } |
| 222 InputMethodBase::OnTextInputTypeChanged(client); | 222 InputMethodBase::OnTextInputTypeChanged(client); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void InputMethodIBus::OnCaretBoundsChanged(const TextInputClient* client) { | 225 void InputMethodIBus::OnCaretBoundsChanged(const TextInputClient* client) { |
| 226 OnCaretBoundsChangedInternal(client); | 226 if (!context_focused_ || !IsTextInputClientFocused(client)) |
| 227 InputMethodBase::OnCaretBoundsChanged(client); | 227 return; |
| 228 |
| 229 // The current text input type should not be NONE if |context_| is focused. |
| 230 DCHECK(!IsTextInputTypeNone()); |
| 231 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); |
| 232 |
| 233 gfx::Rect composition_head; |
| 234 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, |
| 235 &composition_head)) { |
| 236 composition_head = rect; |
| 237 } |
| 238 |
| 239 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = |
| 240 chromeos::IBusBridge::Get()->GetCandidateWindowHandler(); |
| 241 if (!candidate_window) |
| 242 return; |
| 243 candidate_window->SetCursorBounds(rect, composition_head); |
| 244 |
| 245 gfx::Range text_range; |
| 246 gfx::Range selection_range; |
| 247 string16 surrounding_text; |
| 248 if (!GetTextInputClient()->GetTextRange(&text_range) || |
| 249 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || |
| 250 !GetTextInputClient()->GetSelectionRange(&selection_range)) { |
| 251 previous_surrounding_text_.clear(); |
| 252 previous_selection_range_ = gfx::Range::InvalidRange(); |
| 253 return; |
| 254 } |
| 255 |
| 256 if (previous_selection_range_ == selection_range && |
| 257 previous_surrounding_text_ == surrounding_text) |
| 258 return; |
| 259 |
| 260 previous_selection_range_ = selection_range; |
| 261 previous_surrounding_text_ = surrounding_text; |
| 262 |
| 263 if (!selection_range.IsValid()) { |
| 264 // TODO(nona): Ideally selection_range should not be invalid. |
| 265 // TODO(nona): If javascript changes the focus on page loading, even (0,0) |
| 266 // can not be obtained. Need investigation. |
| 267 return; |
| 268 } |
| 269 |
| 270 // Here SetSurroundingText accepts relative position of |surrounding_text|, so |
| 271 // we have to convert |selection_range| from node coordinates to |
| 272 // |surrounding_text| coordinates. |
| 273 if (!GetEngine()) |
| 274 return; |
| 275 GetEngine()->SetSurroundingText(UTF16ToUTF8(surrounding_text), |
| 276 selection_range.start() - text_range.start(), |
| 277 selection_range.end() - text_range.start()); |
| 228 } | 278 } |
| 229 | 279 |
| 230 void InputMethodIBus::CancelComposition(const TextInputClient* client) { | 280 void InputMethodIBus::CancelComposition(const TextInputClient* client) { |
| 231 if (context_focused_ && IsTextInputClientFocused(client)) | 281 if (context_focused_ && IsTextInputClientFocused(client)) |
| 232 ResetContext(); | 282 ResetContext(); |
| 233 } | 283 } |
| 234 | 284 |
| 235 void InputMethodIBus::OnInputLocaleChanged() { | 285 void InputMethodIBus::OnInputLocaleChanged() { |
| 236 // Not supported. | 286 // Not supported. |
| 237 } | 287 } |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 } | 818 } |
| 769 } | 819 } |
| 770 | 820 |
| 771 // Use a black thin underline by default. | 821 // Use a black thin underline by default. |
| 772 if (out_composition->underlines.empty()) { | 822 if (out_composition->underlines.empty()) { |
| 773 out_composition->underlines.push_back(CompositionUnderline( | 823 out_composition->underlines.push_back(CompositionUnderline( |
| 774 0, length, SK_ColorBLACK, false /* thick */)); | 824 0, length, SK_ColorBLACK, false /* thick */)); |
| 775 } | 825 } |
| 776 } | 826 } |
| 777 | 827 |
| 778 void InputMethodIBus::OnCaretBoundsChangedInternal( | |
| 779 const TextInputClient* client) { | |
| 780 if (!context_focused_ || !IsTextInputClientFocused(client)) | |
| 781 return; | |
| 782 | |
| 783 // The current text input type should not be NONE if |context_| is focused. | |
| 784 DCHECK(!IsTextInputTypeNone()); | |
| 785 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); | |
| 786 | |
| 787 gfx::Rect composition_head; | |
| 788 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, | |
| 789 &composition_head)) { | |
| 790 composition_head = rect; | |
| 791 } | |
| 792 | |
| 793 chromeos::IBusPanelCandidateWindowHandlerInterface* candidate_window = | |
| 794 chromeos::IBusBridge::Get()->GetCandidateWindowHandler(); | |
| 795 if (!candidate_window) | |
| 796 return; | |
| 797 candidate_window->SetCursorBounds(rect, composition_head); | |
| 798 | |
| 799 gfx::Range text_range; | |
| 800 gfx::Range selection_range; | |
| 801 string16 surrounding_text; | |
| 802 if (!GetTextInputClient()->GetTextRange(&text_range) || | |
| 803 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || | |
| 804 !GetTextInputClient()->GetSelectionRange(&selection_range)) { | |
| 805 previous_surrounding_text_.clear(); | |
| 806 previous_selection_range_ = gfx::Range::InvalidRange(); | |
| 807 return; | |
| 808 } | |
| 809 | |
| 810 if (previous_selection_range_ == selection_range && | |
| 811 previous_surrounding_text_ == surrounding_text) | |
| 812 return; | |
| 813 | |
| 814 previous_selection_range_ = selection_range; | |
| 815 previous_surrounding_text_ = surrounding_text; | |
| 816 | |
| 817 if (!selection_range.IsValid()) { | |
| 818 // TODO(nona): Ideally selection_range should not be invalid. | |
| 819 // TODO(nona): If javascript changes the focus on page loading, even (0,0) | |
| 820 // can not be obtained. Need investigation. | |
| 821 return; | |
| 822 } | |
| 823 | |
| 824 // Here SetSurroundingText accepts relative position of |surrounding_text|, so | |
| 825 // we have to convert |selection_range| from node coordinates to | |
| 826 // |surrounding_text| coordinates. | |
| 827 if (!GetEngine()) | |
| 828 return; | |
| 829 GetEngine()->SetSurroundingText( | |
| 830 UTF16ToUTF8(surrounding_text), | |
| 831 selection_range.start() - text_range.start(), | |
| 832 selection_range.end() - text_range.start()); | |
| 833 } | |
| 834 | |
| 835 } // namespace ui | 828 } // namespace ui |
| OLD | NEW |