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 text_input_client_ = client; // NULL allowed. | |
58 if (!client) | |
James Su
2011/11/30 02:32:18
I think we still need to reset the input method wh
Yusuke Sato
2011/11/30 04:23:08
Added such functions. Please take another look at
| |
59 return; | |
60 // Force to update the input type since client's TextInputStateChanged() | |
61 // function might not be called if text input types before the client loses | |
62 // focus and after it acquires focus again are the same. | |
63 OnTextInputTypeChanged(client); | |
64 // Force to update caret bounds, in case the client thinks that the caret | |
65 // bounds has not changed. | |
66 OnCaretBoundsChanged(client); | |
67 } | |
68 | |
69 TextInputClient* InputMethodBase::GetTextInputClient() const { | |
70 return system_toplevel_window_focused_ ? text_input_client_ : NULL; | |
71 } | |
72 | |
73 void InputMethodBase::OnTextInputTypeChanged(const TextInputClient* client) { | |
74 if (!IsTextInputClientFocused(client)) | |
75 return; | |
76 // TODO(yusukes): Support TextInputTypeTracker for TOUCH_UI. | |
77 } | |
78 | |
79 TextInputType InputMethodBase::GetTextInputType() const { | |
80 TextInputClient* client = GetTextInputClient(); | |
81 return client ? client->GetTextInputType() : TEXT_INPUT_TYPE_NONE; | |
82 } | |
83 | |
84 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { | |
85 return client && (client == GetTextInputClient()); | |
86 } | |
87 | |
88 bool InputMethodBase::IsTextInputTypeNone() const { | |
89 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; | |
90 } | |
91 | |
92 void InputMethodBase::OnInputMethodChanged() const { | |
93 TextInputClient* client = GetTextInputClient(); | |
94 if (client && client->GetTextInputType() != TEXT_INPUT_TYPE_NONE) | |
95 client->OnInputMethodChanged(); | |
96 } | |
97 | |
98 void InputMethodBase::DispatchKeyEventPostIME( | |
99 const base::NativeEvent& native_event) const { | |
100 if (delegate_) | |
101 delegate_->DispatchKeyEventPostIME(native_event); | |
102 } | |
103 | |
104 void InputMethodBase::DispatchFabricatedKeyEventPostIME( | |
105 EventType type, KeyboardCode key_code, int flags) const { | |
106 if (delegate_) | |
107 delegate_->DispatchFabricatedKeyEventPostIME(type, key_code, flags); | |
108 } | |
109 | |
110 } // namespace ui | |
OLD | NEW |