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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 keyboard->SetCapsLockEnabled(caps); | 116 keyboard->SetCapsLockEnabled(caps); |
117 } | 117 } |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 // If |context_| is not usable, then we can only dispatch the key event as is. | 121 // If |context_| is not usable, then we can only dispatch the key event as is. |
122 // We only dispatch the key event to input method when the |context_| is an | 122 // We only dispatch the key event to input method when the |context_| is an |
123 // normal input field (not a password field). | 123 // normal input field (not a password field). |
124 // Note: We need to send the key event to ibus even if the |context_| is not | 124 // Note: We need to send the key event to ibus even if the |context_| is not |
125 // enabled, so that ibus can have a chance to enable the |context_|. | 125 // enabled, so that ibus can have a chance to enable the |context_|. |
126 if (!IsInputFieldFocused() || !GetEngine()) { | 126 if (!IsNonPasswordInputFieldFocused() || !GetEngine()) { |
127 if (event.type() == ET_KEY_PRESSED) { | 127 if (event.type() == ET_KEY_PRESSED) { |
128 if (ExecuteCharacterComposer(event)) { | 128 if (ExecuteCharacterComposer(event)) { |
129 // Treating as PostIME event if character composer handles key event and | 129 // Treating as PostIME event if character composer handles key event and |
130 // generates some IME event, | 130 // generates some IME event, |
131 ProcessKeyEventPostIME(event, true); | 131 ProcessKeyEventPostIME(event, true); |
132 return true; | 132 return true; |
133 } | 133 } |
134 ProcessUnfilteredKeyPressEvent(event); | 134 ProcessUnfilteredKeyPressEvent(event); |
135 } else { | 135 } else { |
136 DispatchKeyEventPostIME(event); | 136 DispatchKeyEventPostIME(event); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 engine->FocusIn(context); | 171 engine->FocusIn(context); |
172 } | 172 } |
173 | 173 |
174 InputMethodBase::OnTextInputTypeChanged(client); | 174 InputMethodBase::OnTextInputTypeChanged(client); |
175 } | 175 } |
176 | 176 |
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); |
| 182 |
| 183 if (!IsNonPasswordInputFieldFocused()) |
| 184 return; |
| 185 |
181 // 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. |
182 DCHECK(!IsTextInputTypeNone()); | 187 DCHECK(!IsTextInputTypeNone()); |
183 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); | 188 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); |
184 | 189 |
185 gfx::Rect composition_head; | 190 gfx::Rect composition_head; |
186 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, | 191 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, |
187 &composition_head)) { | 192 &composition_head)) { |
188 composition_head = rect; | 193 composition_head = rect; |
189 } | 194 } |
190 | 195 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // we have to convert |selection_range| from node coordinates to | 228 // we have to convert |selection_range| from node coordinates to |
224 // |surrounding_text| coordinates. | 229 // |surrounding_text| coordinates. |
225 if (!GetEngine()) | 230 if (!GetEngine()) |
226 return; | 231 return; |
227 GetEngine()->SetSurroundingText(base::UTF16ToUTF8(surrounding_text), | 232 GetEngine()->SetSurroundingText(base::UTF16ToUTF8(surrounding_text), |
228 selection_range.start() - text_range.start(), | 233 selection_range.start() - text_range.start(), |
229 selection_range.end() - text_range.start()); | 234 selection_range.end() - text_range.start()); |
230 } | 235 } |
231 | 236 |
232 void InputMethodChromeOS::CancelComposition(const TextInputClient* client) { | 237 void InputMethodChromeOS::CancelComposition(const TextInputClient* client) { |
233 if (IsInputFieldFocused() && IsTextInputClientFocused(client)) | 238 if (IsNonPasswordInputFieldFocused() && IsTextInputClientFocused(client)) |
234 ResetContext(); | 239 ResetContext(); |
235 } | 240 } |
236 | 241 |
237 void InputMethodChromeOS::OnInputLocaleChanged() { | 242 void InputMethodChromeOS::OnInputLocaleChanged() { |
238 // Not supported. | 243 // Not supported. |
239 } | 244 } |
240 | 245 |
241 std::string InputMethodChromeOS::GetInputLocale() { | 246 std::string InputMethodChromeOS::GetInputLocale() { |
242 // Not supported. | 247 // Not supported. |
243 return ""; | 248 return ""; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 283 |
279 void InputMethodChromeOS::ConfirmCompositionText() { | 284 void InputMethodChromeOS::ConfirmCompositionText() { |
280 TextInputClient* client = GetTextInputClient(); | 285 TextInputClient* client = GetTextInputClient(); |
281 if (client && client->HasCompositionText()) | 286 if (client && client->HasCompositionText()) |
282 client->ConfirmCompositionText(); | 287 client->ConfirmCompositionText(); |
283 | 288 |
284 ResetContext(); | 289 ResetContext(); |
285 } | 290 } |
286 | 291 |
287 void InputMethodChromeOS::ResetContext() { | 292 void InputMethodChromeOS::ResetContext() { |
288 if (!IsInputFieldFocused() || !GetTextInputClient()) | 293 if (!IsNonPasswordInputFieldFocused() || !GetTextInputClient()) |
289 return; | 294 return; |
290 | 295 |
291 DCHECK(system_toplevel_window_focused()); | 296 DCHECK(system_toplevel_window_focused()); |
292 | 297 |
293 composition_.Clear(); | 298 composition_.Clear(); |
294 result_text_.clear(); | 299 result_text_.clear(); |
295 composing_text_ = false; | 300 composing_text_ = false; |
296 composition_changed_ = false; | 301 composition_changed_ = false; |
297 | 302 |
298 // We need to abandon all pending key events, but as above comment says, there | 303 // We need to abandon all pending key events, but as above comment says, there |
(...skipping 13 matching lines...) Expand all Loading... |
312 | 317 |
313 void InputMethodChromeOS::UpdateContextFocusState() { | 318 void InputMethodChromeOS::UpdateContextFocusState() { |
314 ResetContext(); | 319 ResetContext(); |
315 OnInputMethodChanged(); | 320 OnInputMethodChanged(); |
316 | 321 |
317 // Propagate the focus event to the candidate window handler which also | 322 // Propagate the focus event to the candidate window handler which also |
318 // manages the input method mode indicator. | 323 // manages the input method mode indicator. |
319 chromeos::IMECandidateWindowHandlerInterface* candidate_window = | 324 chromeos::IMECandidateWindowHandlerInterface* candidate_window = |
320 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); | 325 chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); |
321 if (candidate_window) | 326 if (candidate_window) |
322 candidate_window->FocusStateChanged(IsInputFieldFocused()); | 327 candidate_window->FocusStateChanged(IsNonPasswordInputFieldFocused()); |
323 | 328 |
324 chromeos::IMEBridge::Get()->SetCurrentTextInputType(GetTextInputType()); | 329 chromeos::IMEBridge::Get()->SetCurrentTextInputType(GetTextInputType()); |
325 | 330 |
326 if (!IsTextInputTypeNone()) | 331 if (!IsTextInputTypeNone()) |
327 OnCaretBoundsChanged(GetTextInputClient()); | 332 OnCaretBoundsChanged(GetTextInputClient()); |
328 } | 333 } |
329 | 334 |
330 void InputMethodChromeOS::ProcessKeyEventPostIME( | 335 void InputMethodChromeOS::ProcessKeyEventPostIME( |
331 const ui::KeyEvent& event, | 336 const ui::KeyEvent& event, |
332 bool handled) { | 337 bool handled) { |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 } | 652 } |
648 } | 653 } |
649 | 654 |
650 // Use a black thin underline by default. | 655 // Use a black thin underline by default. |
651 if (out_composition->underlines.empty()) { | 656 if (out_composition->underlines.empty()) { |
652 out_composition->underlines.push_back(CompositionUnderline( | 657 out_composition->underlines.push_back(CompositionUnderline( |
653 0, length, SK_ColorBLACK, false /* thick */, SK_ColorTRANSPARENT)); | 658 0, length, SK_ColorBLACK, false /* thick */, SK_ColorTRANSPARENT)); |
654 } | 659 } |
655 } | 660 } |
656 | 661 |
657 bool InputMethodChromeOS::IsInputFieldFocused() { | 662 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { |
658 TextInputType type = GetTextInputType(); | 663 TextInputType type = GetTextInputType(); |
659 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); | 664 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); |
660 } | 665 } |
661 | 666 |
| 667 bool InputMethodChromeOS::IsInputFieldFocused() { |
| 668 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; |
| 669 } |
| 670 |
662 } // namespace ui | 671 } // namespace ui |
OLD | NEW |