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/text_input_client.h" | |
9 #include "ui/base/ime/input_method_delegate.h" | |
James Su
2011/11/24 03:57:03
order.
Yusuke Sato
2011/11/28 06:29:40
Done.
| |
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 (!client || client != GetTextInputClient()) | |
66 return; | |
67 // TODO(yusukes): Support TextInputTypeTracker for TOUCH_UI. | |
68 } | |
69 | |
70 TextInputType InputMethodBase::GetTextInputType() const { | |
71 return text_input_client_ ? | |
72 text_input_client_->GetTextInputType() : TEXT_INPUT_TYPE_NONE; | |
73 } | |
74 | |
75 bool InputMethodBase::IsTextInputTypeNone() const { | |
76 return GetTextInputType() == TEXT_INPUT_TYPE_NONE; | |
77 } | |
78 | |
79 void InputMethodBase::OnInputMethodChanged() const { | |
80 if (text_input_client_ && | |
81 text_input_client_->GetTextInputType() != TEXT_INPUT_TYPE_NONE) | |
82 text_input_client_->OnInputMethodChanged(); | |
83 } | |
84 | |
85 void InputMethodBase::DispatchKeyEventPostIME( | |
86 const base::NativeEvent& native_event) const { | |
87 if (delegate_) | |
88 delegate_->DispatchKeyEventPostIME(native_event); | |
89 } | |
90 | |
91 void InputMethodBase::DispatchFabricatedKeyEventPostIME( | |
92 EventType type, KeyboardCode key_code, int flags) const { | |
93 if (delegate_) | |
94 delegate_->DispatchFabricatedKeyEventPostIME(type, key_code, flags); | |
95 } | |
96 | |
97 bool InputMethodBase::system_toplevel_window_focused() const { | |
98 return system_toplevel_window_focused_; | |
99 } | |
100 | |
101 } // namespace ui | |
OLD | NEW |