Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/base/ime/input_method_base.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ui/base/ime/input_method_delegate.h" | |
| 9 #include "ui/base/ime/text_input_client.h" | |
| 10 | |
| 11 namespace ui { | |
| 12 | |
| 13 InputMethodBase::InputMethodBase() | |
| 14 : delegate_(NULL), | |
| 15 text_input_client_(NULL), | |
| 16 system_toplevel_window_focused_(false) { | |
| 17 } | |
| 18 | |
| 19 InputMethodBase::~InputMethodBase() { | |
| 20 } | |
| 21 | |
| 22 void InputMethodBase::set_delegate( | |
| 23 internal::InputMethodDelegate* delegate) { | |
| 24 DCHECK(delegate); | |
|
sky
2011/12/05 15:15:29
Why does the delegate have to be non-NULL?
Yusuke Sato
2011/12/05 22:55:14
Removed.
| |
| 25 delegate_ = delegate; | |
| 26 } | |
| 27 | |
| 28 void InputMethodBase::Init(bool focused) { | |
| 29 if (focused) | |
| 30 OnFocus(); | |
| 31 } | |
| 32 | |
| 33 void InputMethodBase::OnFocus() { | |
| 34 DCHECK(!system_toplevel_window_focused_); | |
| 35 system_toplevel_window_focused_ = true; | |
| 36 } | |
| 37 | |
| 38 void InputMethodBase::OnBlur() { | |
| 39 DCHECK(system_toplevel_window_focused_); | |
| 40 system_toplevel_window_focused_ = false; | |
| 41 } | |
| 42 | |
| 43 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { | |
| 44 TextInputClient* old = text_input_client_; | |
| 45 OnWillChangeFocusedClient(old, client); | |
| 46 text_input_client_ = client; // NULL allowed. | |
| 47 OnDidChangeFocusedClient(old, client); | |
| 48 } | |
| 49 | |
| 50 TextInputClient* InputMethodBase::GetTextInputClient() const { | |
| 51 return system_toplevel_window_focused_ ? text_input_client_ : NULL; | |
| 52 } | |
| 53 | |
| 54 void InputMethodBase::OnTextInputTypeChanged(const TextInputClient* client) { | |
| 55 if (!IsTextInputClientFocused(client)) | |
| 56 return; | |
| 57 // TODO(yusukes): Support TextInputTypeTracker for TOUCH_UI. | |
| 58 } | |
| 59 | |
| 60 TextInputType InputMethodBase::GetTextInputType() const { | |
| 61 TextInputClient* client = GetTextInputClient(); | |
| 62 return client ? client->GetTextInputType() : TEXT_INPUT_TYPE_NONE; | |
| 63 } | |
| 64 | |
| 65 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { | |
| 66 return client && (client == GetTextInputClient()); | |
| 67 } | |
| 68 | |
| 69 bool InputMethodBase::IsTextInputTypeNone() const { | |
| 70 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; | |
| 71 } | |
| 72 | |
| 73 void InputMethodBase::OnInputMethodChanged() const { | |
| 74 TextInputClient* client = GetTextInputClient(); | |
| 75 if (client && client->GetTextInputType() != TEXT_INPUT_TYPE_NONE) | |
| 76 client->OnInputMethodChanged(); | |
| 77 } | |
| 78 | |
| 79 void InputMethodBase::DispatchKeyEventPostIME( | |
| 80 const base::NativeEvent& native_event) const { | |
| 81 if (delegate_) | |
| 82 delegate_->DispatchKeyEventPostIME(native_event); | |
| 83 } | |
| 84 | |
| 85 void InputMethodBase::DispatchFabricatedKeyEventPostIME( | |
| 86 EventType type, KeyboardCode key_code, int flags) const { | |
| 87 if (delegate_) | |
| 88 delegate_->DispatchFabricatedKeyEventPostIME(type, key_code, flags); | |
| 89 } | |
| 90 | |
| 91 } // namespace ui | |
| OLD | NEW |