| 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_base.h" | 5 #include "ui/base/ime/input_method_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "ui/base/ime/input_method_delegate.h" | 10 #include "ui/base/ime/input_method_delegate.h" |
| 11 #include "ui/base/ime/input_method_observer.h" | 11 #include "ui/base/ime/input_method_observer.h" |
| 12 #include "ui/base/ime/text_input_client.h" | 12 #include "ui/base/ime/text_input_client.h" |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace ui { |
| 16 | 16 |
| 17 InputMethodBase::InputMethodBase() | 17 InputMethodBase::InputMethodBase() |
| 18 : delegate_(NULL), | 18 : delegate_(NULL), |
| 19 text_input_client_(NULL), | 19 text_input_client_(NULL), |
| 20 system_toplevel_window_focused_(false), | 20 system_toplevel_window_focused_(false) { |
| 21 log_collector_(new InputMethodLogCollector()) {} | 21 } |
| 22 | 22 |
| 23 InputMethodBase::~InputMethodBase() { | 23 InputMethodBase::~InputMethodBase() { |
| 24 FOR_EACH_OBSERVER(InputMethodObserver, | 24 FOR_EACH_OBSERVER(InputMethodObserver, |
| 25 observer_list_, | 25 observer_list_, |
| 26 OnInputMethodDestroyed(this)); | 26 OnInputMethodDestroyed(this)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { | 29 void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { |
| 30 delegate_ = delegate; | 30 delegate_ = delegate; |
| 31 } | 31 } |
| 32 | 32 |
| 33 void InputMethodBase::OnFocus() { | 33 void InputMethodBase::OnFocus() { |
| 34 system_toplevel_window_focused_ = true; | 34 system_toplevel_window_focused_ = true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void InputMethodBase::OnBlur() { | 37 void InputMethodBase::OnBlur() { |
| 38 system_toplevel_window_focused_ = false; | 38 system_toplevel_window_focused_ = false; |
| 39 log_collector_->ClearLogs(); | |
| 40 log_collector_->AddString("Input method is blurred."); | |
| 41 } | 39 } |
| 42 | 40 |
| 43 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { | 41 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { |
| 44 SetFocusedTextInputClientInternal(client); | 42 SetFocusedTextInputClientInternal(client); |
| 45 } | 43 } |
| 46 | 44 |
| 47 void InputMethodBase::DetachTextInputClient(TextInputClient* client) { | 45 void InputMethodBase::DetachTextInputClient(TextInputClient* client) { |
| 48 if (text_input_client_ != client) | 46 if (text_input_client_ != client) |
| 49 return; | 47 return; |
| 50 SetFocusedTextInputClientInternal(NULL); | 48 SetFocusedTextInputClientInternal(NULL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 83 } |
| 86 | 84 |
| 87 void InputMethodBase::AddObserver(InputMethodObserver* observer) { | 85 void InputMethodBase::AddObserver(InputMethodObserver* observer) { |
| 88 observer_list_.AddObserver(observer); | 86 observer_list_.AddObserver(observer); |
| 89 } | 87 } |
| 90 | 88 |
| 91 void InputMethodBase::RemoveObserver(InputMethodObserver* observer) { | 89 void InputMethodBase::RemoveObserver(InputMethodObserver* observer) { |
| 92 observer_list_.RemoveObserver(observer); | 90 observer_list_.RemoveObserver(observer); |
| 93 } | 91 } |
| 94 | 92 |
| 95 InputMethodLogCollector* InputMethodBase::GetLogCollector() { | |
| 96 return log_collector_.get(); | |
| 97 } | |
| 98 | |
| 99 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { | 93 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { |
| 100 return client && (client == GetTextInputClient()); | 94 return client && (client == GetTextInputClient()); |
| 101 } | 95 } |
| 102 | 96 |
| 103 bool InputMethodBase::IsTextInputTypeNone() const { | 97 bool InputMethodBase::IsTextInputTypeNone() const { |
| 104 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; | 98 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; |
| 105 } | 99 } |
| 106 | 100 |
| 107 void InputMethodBase::OnInputMethodChanged() const { | 101 void InputMethodBase::OnInputMethodChanged() const { |
| 108 TextInputClient* client = GetTextInputClient(); | 102 TextInputClient* client = GetTextInputClient(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 136 TextInputClient* old = text_input_client_; | 130 TextInputClient* old = text_input_client_; |
| 137 if (old == client) | 131 if (old == client) |
| 138 return; | 132 return; |
| 139 OnWillChangeFocusedClient(old, client); | 133 OnWillChangeFocusedClient(old, client); |
| 140 text_input_client_ = client; // NULL allowed. | 134 text_input_client_ = client; // NULL allowed. |
| 141 OnDidChangeFocusedClient(old, client); | 135 OnDidChangeFocusedClient(old, client); |
| 142 NotifyTextInputStateChanged(text_input_client_); | 136 NotifyTextInputStateChanged(text_input_client_); |
| 143 } | 137 } |
| 144 | 138 |
| 145 } // namespace ui | 139 } // namespace ui |
| OLD | NEW |