| 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 } | 21 log_collector_(new InputMethodLogCollector()) {} |
| 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."); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { | 43 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { |
| 42 SetFocusedTextInputClientInternal(client); | 44 SetFocusedTextInputClientInternal(client); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void InputMethodBase::DetachTextInputClient(TextInputClient* client) { | 47 void InputMethodBase::DetachTextInputClient(TextInputClient* client) { |
| 46 if (text_input_client_ != client) | 48 if (text_input_client_ != client) |
| 47 return; | 49 return; |
| 48 SetFocusedTextInputClientInternal(NULL); | 50 SetFocusedTextInputClientInternal(NULL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 85 } |
| 84 | 86 |
| 85 void InputMethodBase::AddObserver(InputMethodObserver* observer) { | 87 void InputMethodBase::AddObserver(InputMethodObserver* observer) { |
| 86 observer_list_.AddObserver(observer); | 88 observer_list_.AddObserver(observer); |
| 87 } | 89 } |
| 88 | 90 |
| 89 void InputMethodBase::RemoveObserver(InputMethodObserver* observer) { | 91 void InputMethodBase::RemoveObserver(InputMethodObserver* observer) { |
| 90 observer_list_.RemoveObserver(observer); | 92 observer_list_.RemoveObserver(observer); |
| 91 } | 93 } |
| 92 | 94 |
| 95 InputMethodLogCollector* InputMethodBase::GetLogCollector() { |
| 96 return log_collector_.get(); |
| 97 } |
| 98 |
| 93 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { | 99 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { |
| 94 return client && (client == GetTextInputClient()); | 100 return client && (client == GetTextInputClient()); |
| 95 } | 101 } |
| 96 | 102 |
| 97 bool InputMethodBase::IsTextInputTypeNone() const { | 103 bool InputMethodBase::IsTextInputTypeNone() const { |
| 98 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; | 104 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; |
| 99 } | 105 } |
| 100 | 106 |
| 101 void InputMethodBase::OnInputMethodChanged() const { | 107 void InputMethodBase::OnInputMethodChanged() const { |
| 102 TextInputClient* client = GetTextInputClient(); | 108 TextInputClient* client = GetTextInputClient(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 130 TextInputClient* old = text_input_client_; | 136 TextInputClient* old = text_input_client_; |
| 131 if (old == client) | 137 if (old == client) |
| 132 return; | 138 return; |
| 133 OnWillChangeFocusedClient(old, client); | 139 OnWillChangeFocusedClient(old, client); |
| 134 text_input_client_ = client; // NULL allowed. | 140 text_input_client_ = client; // NULL allowed. |
| 135 OnDidChangeFocusedClient(old, client); | 141 OnDidChangeFocusedClient(old, client); |
| 136 NotifyTextInputStateChanged(text_input_client_); | 142 NotifyTextInputStateChanged(text_input_client_); |
| 137 } | 143 } |
| 138 | 144 |
| 139 } // namespace ui | 145 } // namespace ui |
| OLD | NEW |