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 } | |
59 | |
60 TextInputClient* InputMethodBase::GetTextInputClient() const { | |
61 return system_toplevel_window_focused_ ? text_input_client_ : NULL; | |
62 } | |
63 | |
64 void InputMethodBase::OnTextInputTypeChanged(const TextInputClient* client) { | |
65 if (!IsTextInputClientFocused(client)) | |
66 return; | |
67 // TODO(yusukes): Support TextInputTypeTracker for TOUCH_UI. | |
68 } | |
69 | |
70 TextInputType InputMethodBase::GetTextInputType() const { | |
71 return text_input_client_ ? | |
James Su
2011/11/29 04:25:53
use GetTextInputClient().
Yusuke Sato
2011/11/29 09:06:36
Done.
| |
72 text_input_client_->GetTextInputType() : TEXT_INPUT_TYPE_NONE; | |
73 } | |
74 | |
75 bool InputMethodBase::IsTextInputClientFocused(const TextInputClient* client) { | |
76 return client && (client == GetTextInputClient()); | |
77 } | |
78 | |
79 bool InputMethodBase::IsTextInputTypeNone() const { | |
80 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; | |
81 } | |
82 | |
83 void InputMethodBase::OnInputMethodChanged() const { | |
84 if (text_input_client_ && | |
James Su
2011/11/29 04:25:53
use GetTextInputClient()
Yusuke Sato
2011/11/29 09:06:36
Done.
| |
85 text_input_client_->GetTextInputType() != TEXT_INPUT_TYPE_NONE) | |
86 text_input_client_->OnInputMethodChanged(); | |
James Su
2011/11/29 04:25:53
multi-line if statement needs {}
Yusuke Sato
2011/11/29 09:06:36
Done.
| |
87 } | |
88 | |
89 void InputMethodBase::DispatchKeyEventPostIME( | |
90 const base::NativeEvent& native_event) const { | |
91 if (delegate_) | |
92 delegate_->DispatchKeyEventPostIME(native_event); | |
93 } | |
94 | |
95 void InputMethodBase::DispatchFabricatedKeyEventPostIME( | |
96 EventType type, KeyboardCode key_code, int flags) const { | |
97 if (delegate_) | |
98 delegate_->DispatchFabricatedKeyEventPostIME(type, key_code, flags); | |
99 } | |
100 | |
101 bool InputMethodBase::system_toplevel_window_focused() const { | |
102 return system_toplevel_window_focused_; | |
103 } | |
104 | |
105 } // namespace ui | |
OLD | NEW |