OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "ui/base/ime/input_method_chromeos.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 void InputMethodChromeOS::OnCaretBoundsChanged(const TextInputClient* client) { | 177 void InputMethodChromeOS::OnCaretBoundsChanged(const TextInputClient* client) { |
178 if (!IsInputFieldFocused() || !IsTextInputClientFocused(client)) | 178 if (!IsInputFieldFocused() || !IsTextInputClientFocused(client)) |
179 return; | 179 return; |
180 | 180 |
181 NotifyTextInputCaretBoundsChanged(client); | 181 NotifyTextInputCaretBoundsChanged(client); |
182 | 182 |
183 if (!IsNonPasswordInputFieldFocused()) | 183 if (!IsNonPasswordInputFieldFocused()) |
184 return; | 184 return; |
185 | 185 |
186 // The current text input type should not be NONE if |context_| is focused. | 186 // The current text input type should not be NONE if |context_| is focused. |
| 187 DCHECK(client == GetTextInputClient()); |
187 DCHECK(!IsTextInputTypeNone()); | 188 DCHECK(!IsTextInputTypeNone()); |
188 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); | 189 const gfx::Rect rect = client->GetCaretBounds(); |
189 | 190 |
190 gfx::Rect composition_head; | 191 gfx::Rect composition_head; |
191 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, | 192 if (client->GetCompositionCharacterBounds(0, &composition_head)) { |
192 &composition_head)) { | 193 if (GetEngine()) |
| 194 GetEngine()->SetCompositionBounds(composition_head); |
| 195 } else { |
193 composition_head = rect; | 196 composition_head = rect; |
194 } | 197 } |
195 | 198 |
196 chromeos::IMECandidateWindowHandlerInterface* candidate_window = | 199 chromeos::IMECandidateWindowHandlerInterface* candidate_window = |
197 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); | 200 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); |
198 if (!candidate_window) | 201 if (!candidate_window) |
199 return; | 202 return; |
200 candidate_window->SetCursorBounds(rect, composition_head); | 203 candidate_window->SetCursorBounds(rect, composition_head); |
201 | 204 |
202 gfx::Range text_range; | 205 gfx::Range text_range; |
203 gfx::Range selection_range; | 206 gfx::Range selection_range; |
204 base::string16 surrounding_text; | 207 base::string16 surrounding_text; |
205 if (!GetTextInputClient()->GetTextRange(&text_range) || | 208 if (!client->GetTextRange(&text_range) || |
206 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || | 209 !client->GetTextFromRange(text_range, &surrounding_text) || |
207 !GetTextInputClient()->GetSelectionRange(&selection_range)) { | 210 !client->GetSelectionRange(&selection_range)) { |
208 previous_surrounding_text_.clear(); | 211 previous_surrounding_text_.clear(); |
209 previous_selection_range_ = gfx::Range::InvalidRange(); | 212 previous_selection_range_ = gfx::Range::InvalidRange(); |
210 return; | 213 return; |
211 } | 214 } |
212 | 215 |
213 if (previous_selection_range_ == selection_range && | 216 if (previous_selection_range_ == selection_range && |
214 previous_surrounding_text_ == surrounding_text) | 217 previous_surrounding_text_ == surrounding_text) |
215 return; | 218 return; |
216 | 219 |
217 previous_selection_range_ = selection_range; | 220 previous_selection_range_ = selection_range; |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { | 665 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { |
663 TextInputType type = GetTextInputType(); | 666 TextInputType type = GetTextInputType(); |
664 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); | 667 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); |
665 } | 668 } |
666 | 669 |
667 bool InputMethodChromeOS::IsInputFieldFocused() { | 670 bool InputMethodChromeOS::IsInputFieldFocused() { |
668 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; | 671 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; |
669 } | 672 } |
670 | 673 |
671 } // namespace ui | 674 } // namespace ui |
OLD | NEW |