| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/ime/mock_input_method.h" | 5 #include "views/ime/mock_input_method.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
| 10 #include "views/events/event.h" | 10 #include "views/events/event.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 active_(true) { | 23 active_(true) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 MockInputMethod::~MockInputMethod() { | 26 MockInputMethod::~MockInputMethod() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 void MockInputMethod::Init(Widget* widget) { | 29 void MockInputMethod::Init(Widget* widget) { |
| 30 InputMethodBase::Init(widget); | 30 InputMethodBase::Init(widget); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void MockInputMethod::DispatchKeyEvent(const KeyEvent& key) { | 33 bool MockInputMethod::OnKeyEvent(const KeyEvent& key) { |
| 34 bool handled = (composition_changed_ || result_text_.length()) && | 34 bool handled = (composition_changed_ || result_text_.length()) && |
| 35 !IsTextInputTypeNone(); | 35 !IsTextInputTypeNone(); |
| 36 | 36 |
| 37 ClearStates(); | 37 ClearStates(); |
| 38 if (handled) { | 38 if (handled) { |
| 39 KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags()); | 39 KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags()); |
| 40 DispatchKeyEventPostIME(mock_key); | 40 DispatchKeyEventPostIME(mock_key); |
| 41 } else { | 41 } else { |
| 42 DispatchKeyEventPostIME(key); | 42 DispatchKeyEventPostIME(key); |
| 43 } | 43 } |
| 44 | 44 |
| 45 if (focus_changed_) | 45 if (focus_changed_) |
| 46 return; | 46 return true; |
| 47 | 47 |
| 48 TextInputClient* client = GetTextInputClient(); | 48 TextInputClient* client = GetTextInputClient(); |
| 49 if (client) { | 49 if (client) { |
| 50 if (handled) { | 50 if (handled) { |
| 51 if (result_text_.length()) | 51 if (result_text_.length()) |
| 52 client->InsertText(result_text_); | 52 client->InsertText(result_text_); |
| 53 if (composition_changed_) { | 53 if (composition_changed_) { |
| 54 if (composition_.text.length()) | 54 if (composition_.text.length()) |
| 55 client->SetCompositionText(composition_); | 55 client->SetCompositionText(composition_); |
| 56 else | 56 else |
| 57 client->ClearCompositionText(); | 57 client->ClearCompositionText(); |
| 58 } | 58 } |
| 59 } else if (key.type() == ui::ET_KEY_PRESSED) { | 59 } else if (key.type() == ui::ET_KEY_PRESSED) { |
| 60 char16 ch = key.GetCharacter(); | 60 char16 ch = key.GetCharacter(); |
| 61 client->InsertChar(ch, key.flags()); | 61 client->InsertChar(ch, key.flags()); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 ClearResult(); | 65 ClearResult(); |
| 66 return true; |
| 66 } | 67 } |
| 67 | 68 |
| 68 void MockInputMethod::OnTextInputTypeChanged(View* view) { | 69 void MockInputMethod::OnTextInputTypeChanged(View* view) { |
| 69 DCHECK(IsViewFocused(view)); | 70 DCHECK(IsViewFocused(view)); |
| 70 text_input_type_changed_ = true; | 71 text_input_type_changed_ = true; |
| 71 } | 72 } |
| 72 | 73 |
| 73 void MockInputMethod::OnCaretBoundsChanged(View* view) { | 74 void MockInputMethod::OnCaretBoundsChanged(View* view) { |
| 74 DCHECK(IsViewFocused(view)); | 75 DCHECK(IsViewFocused(view)); |
| 75 caret_bounds_changed_ = true; | 76 caret_bounds_changed_ = true; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 cancel_composition_called_ = false; | 146 cancel_composition_called_ = false; |
| 146 } | 147 } |
| 147 | 148 |
| 148 void MockInputMethod::ClearResult() { | 149 void MockInputMethod::ClearResult() { |
| 149 composition_.Clear(); | 150 composition_.Clear(); |
| 150 composition_changed_ = false; | 151 composition_changed_ = false; |
| 151 result_text_.clear(); | 152 result_text_.clear(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 } // namespace views | 155 } // namespace views |
| OLD | NEW |