| 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/mock_input_method.h" | 5 #include "ui/base/ime/mock_input_method.h" |
| 6 | 6 |
| 7 #include "ui/base/ime/input_method_delegate.h" | 7 #include "ui/base/ime/input_method_delegate.h" |
| 8 #include "ui/base/ime/text_input_focus_manager.h" | |
| 9 #include "ui/base/ui_base_switches_util.h" | 8 #include "ui/base/ui_base_switches_util.h" |
| 10 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 11 | 10 |
| 12 namespace ui { | 11 namespace ui { |
| 13 | 12 |
| 14 MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate) | 13 MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate) |
| 15 : text_input_client_(NULL), delegate_(delegate) { | 14 : text_input_client_(NULL), delegate_(delegate) { |
| 16 } | 15 } |
| 17 | 16 |
| 18 MockInputMethod::~MockInputMethod() { | 17 MockInputMethod::~MockInputMethod() { |
| 19 FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, | 18 FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, |
| 20 OnInputMethodDestroyed(this)); | 19 OnInputMethodDestroyed(this)); |
| 21 } | 20 } |
| 22 | 21 |
| 23 void MockInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) { | 22 void MockInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) { |
| 24 delegate_ = delegate; | 23 delegate_ = delegate; |
| 25 } | 24 } |
| 26 | 25 |
| 27 void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) { | 26 void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) { |
| 28 if (switches::IsTextInputFocusManagerEnabled()) | |
| 29 return; | |
| 30 | |
| 31 if (text_input_client_ == client) | 27 if (text_input_client_ == client) |
| 32 return; | 28 return; |
| 33 text_input_client_ = client; | 29 text_input_client_ = client; |
| 34 if (client) | 30 if (client) |
| 35 OnTextInputTypeChanged(client); | 31 OnTextInputTypeChanged(client); |
| 36 } | 32 } |
| 37 | 33 |
| 38 void MockInputMethod::DetachTextInputClient(TextInputClient* client) { | 34 void MockInputMethod::DetachTextInputClient(TextInputClient* client) { |
| 39 if (text_input_client_ == client) { | 35 if (text_input_client_ == client) { |
| 40 text_input_client_ = NULL; | 36 text_input_client_ = NULL; |
| 41 } | 37 } |
| 42 } | 38 } |
| 43 | 39 |
| 44 TextInputClient* MockInputMethod::GetTextInputClient() const { | 40 TextInputClient* MockInputMethod::GetTextInputClient() const { |
| 45 if (switches::IsTextInputFocusManagerEnabled()) | |
| 46 return TextInputFocusManager::GetInstance()->GetFocusedTextInputClient(); | |
| 47 | |
| 48 return text_input_client_; | 41 return text_input_client_; |
| 49 } | 42 } |
| 50 | 43 |
| 51 bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) { | 44 bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) { |
| 52 return delegate_->DispatchKeyEventPostIME(event); | 45 return delegate_->DispatchKeyEventPostIME(event); |
| 53 } | 46 } |
| 54 | 47 |
| 55 void MockInputMethod::OnFocus() { | 48 void MockInputMethod::OnFocus() { |
| 56 FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnFocus()); | 49 FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnFocus()); |
| 57 } | 50 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 115 |
| 123 void MockInputMethod::AddObserver(InputMethodObserver* observer) { | 116 void MockInputMethod::AddObserver(InputMethodObserver* observer) { |
| 124 observer_list_.AddObserver(observer); | 117 observer_list_.AddObserver(observer); |
| 125 } | 118 } |
| 126 | 119 |
| 127 void MockInputMethod::RemoveObserver(InputMethodObserver* observer) { | 120 void MockInputMethod::RemoveObserver(InputMethodObserver* observer) { |
| 128 observer_list_.RemoveObserver(observer); | 121 observer_list_.RemoveObserver(observer); |
| 129 } | 122 } |
| 130 | 123 |
| 131 } // namespace ui | 124 } // namespace ui |
| OLD | NEW |