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 #if defined(USE_X11) |
| 12 #include <X11/Xlib.h> |
| 13 #include "base/message_pump_x.h" |
| 14 #endif |
| 15 |
| 16 namespace ui { |
| 17 |
| 18 InputMethodBase::InputMethodBase() |
| 19 : delegate_(NULL), |
| 20 text_input_client_(NULL), |
| 21 system_toplevel_window_focused_(false) { |
| 22 } |
| 23 |
| 24 InputMethodBase::~InputMethodBase() { |
| 25 } |
| 26 |
| 27 void InputMethodBase::set_delegate( |
| 28 internal::InputMethodDelegate* delegate) { |
| 29 DCHECK(delegate); |
| 30 delegate_ = delegate; |
| 31 } |
| 32 |
| 33 void InputMethodBase::Init(const base::NativeWindow& system_toplevel_window) { |
| 34 #if defined(USE_X11) |
| 35 Window focus = None; |
| 36 int revert_to = 0; |
| 37 XGetInputFocus(base::MessagePumpX::GetDefaultXDisplay(), &focus, &revert_to); |
| 38 if (focus == system_toplevel_window) |
| 39 OnFocus(); |
| 40 #else |
| 41 // TODO(yusukes): Add OS_WIN implementation here. |
| 42 NOTIMPLEMENTED(); |
| 43 #endif |
| 44 } |
| 45 |
| 46 void InputMethodBase::OnFocus() { |
| 47 DCHECK(!system_toplevel_window_focused_); |
| 48 system_toplevel_window_focused_ = true; |
| 49 } |
| 50 |
| 51 void InputMethodBase::OnBlur() { |
| 52 DCHECK(system_toplevel_window_focused_); |
| 53 system_toplevel_window_focused_ = false; |
| 54 } |
| 55 |
| 56 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { |
| 57 TextInputClient* old = text_input_client_; |
| 58 OnWillChangeFocusedClient(old, client); |
| 59 text_input_client_ = client; // NULL allowed. |
| 60 OnDidChangeFocusedClient(old, client); |
| 61 } |
| 62 |
| 63 TextInputClient* InputMethodBase::GetTextInputClient() const { |
| 64 return system_toplevel_window_focused_ ? text_input_client_ : NULL; |
| 65 } |
| 66 |
| 67 void InputMethodBase::OnTextInputTypeChanged(const TextInputClient* client) { |
| 68 if (!IsTextInputClientFocused(client)) |
| 69 return; |
| 70 // TODO(yusukes): Support TextInputTypeTracker for TOUCH_UI. |
| 71 } |
| 72 |
| 73 TextInputType InputMethodBase::GetTextInputType() const { |
| 74 TextInputClient* client = GetTextInputClient(); |
| 75 return client ? client->GetTextInputType() : TEXT_INPUT_TYPE_NONE; |
| 76 } |
| 77 |
| 78 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { |
| 79 return client && (client == GetTextInputClient()); |
| 80 } |
| 81 |
| 82 bool InputMethodBase::IsTextInputTypeNone() const { |
| 83 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; |
| 84 } |
| 85 |
| 86 void InputMethodBase::OnInputMethodChanged() const { |
| 87 TextInputClient* client = GetTextInputClient(); |
| 88 if (client && client->GetTextInputType() != TEXT_INPUT_TYPE_NONE) |
| 89 client->OnInputMethodChanged(); |
| 90 } |
| 91 |
| 92 void InputMethodBase::DispatchKeyEventPostIME( |
| 93 const base::NativeEvent& native_event) const { |
| 94 if (delegate_) |
| 95 delegate_->DispatchKeyEventPostIME(native_event); |
| 96 } |
| 97 |
| 98 void InputMethodBase::DispatchFabricatedKeyEventPostIME( |
| 99 EventType type, KeyboardCode key_code, int flags) const { |
| 100 if (delegate_) |
| 101 delegate_->DispatchFabricatedKeyEventPostIME(type, key_code, flags); |
| 102 } |
| 103 |
| 104 } // namespace ui |
OLD | NEW |