Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ui / base / ime / input_method_auralinux.cc
blob1bf20174b4ea951c0851d468f7b2fb69b4c279cf
1 // Copyright 2013 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.
5 #include "ui/base/ime/input_method_auralinux.h"
7 #include "base/environment.h"
8 #include "ui/base/ime/linux/linux_input_method_context_factory.h"
9 #include "ui/base/ime/text_input_client.h"
10 #include "ui/events/event.h"
12 namespace ui {
14 InputMethodAuraLinux::InputMethodAuraLinux(
15 internal::InputMethodDelegate* delegate) {
16 SetDelegate(delegate);
19 InputMethodAuraLinux::~InputMethodAuraLinux() {}
21 // Overriden from InputMethod.
23 void InputMethodAuraLinux::Init(bool focused) {
24 CHECK(LinuxInputMethodContextFactory::instance())
25 << "This failure was likely caused because "
26 << "ui::InitializeInputMethod(ForTesting) was not called "
27 << "before instantiating this class.";
28 input_method_context_ =
29 LinuxInputMethodContextFactory::instance()->CreateInputMethodContext(
30 this);
31 CHECK(input_method_context_.get());
33 InputMethodBase::Init(focused);
35 if (focused) {
36 input_method_context_->OnTextInputTypeChanged(
37 GetTextInputClient() ?
38 GetTextInputClient()->GetTextInputType() :
39 TEXT_INPUT_TYPE_TEXT);
43 bool InputMethodAuraLinux::OnUntranslatedIMEMessage(
44 const base::NativeEvent& event,
45 NativeEventResult* result) {
46 return false;
49 bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) {
50 DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED);
51 DCHECK(system_toplevel_window_focused());
53 // If no text input client, do nothing.
54 if (!GetTextInputClient())
55 return DispatchKeyEventPostIME(event);
57 // Let an IME handle the key event first.
58 if (input_method_context_->DispatchKeyEvent(event)) {
59 if (event.type() == ET_KEY_PRESSED &&
60 (event.flags() & ui::EF_IME_FABRICATED_KEY) == 0) {
61 const ui::KeyEvent fabricated_event(ET_KEY_PRESSED,
62 VKEY_PROCESSKEY,
63 event.flags(),
64 false); // is_char
65 DispatchKeyEventPostIME(fabricated_event);
67 return true;
70 // Otherwise, insert the character.
71 const bool handled = DispatchKeyEventPostIME(event);
72 if (event.type() == ET_KEY_PRESSED && GetTextInputClient()) {
73 const uint16 ch = event.GetCharacter();
74 if (ch) {
75 GetTextInputClient()->InsertChar(ch, event.flags());
76 return true;
79 return handled;
82 void InputMethodAuraLinux::OnTextInputTypeChanged(
83 const TextInputClient* client) {
84 if (!IsTextInputClientFocused(client))
85 return;
86 input_method_context_->Reset();
87 // TODO(yoichio): Support inputmode HTML attribute.
88 input_method_context_->OnTextInputTypeChanged(client->GetTextInputType());
91 void InputMethodAuraLinux::OnCaretBoundsChanged(const TextInputClient* client) {
92 if (!IsTextInputClientFocused(client))
93 return;
94 input_method_context_->OnCaretBoundsChanged(
95 GetTextInputClient()->GetCaretBounds());
98 void InputMethodAuraLinux::CancelComposition(const TextInputClient* client) {
99 if (!IsTextInputClientFocused(client))
100 return;
101 input_method_context_->Reset();
102 input_method_context_->OnTextInputTypeChanged(client->GetTextInputType());
105 void InputMethodAuraLinux::OnInputLocaleChanged() {
108 std::string InputMethodAuraLinux::GetInputLocale() {
109 return "";
112 bool InputMethodAuraLinux::IsActive() {
113 // InputMethodAuraLinux is always ready and up.
114 return true;
117 bool InputMethodAuraLinux::IsCandidatePopupOpen() const {
118 // There seems no way to detect candidate windows or any popups.
119 return false;
122 // Overriden from ui::LinuxInputMethodContextDelegate
124 void InputMethodAuraLinux::OnCommit(const base::string16& text) {
125 if (!IsTextInputTypeNone())
126 GetTextInputClient()->InsertText(text);
129 void InputMethodAuraLinux::OnPreeditChanged(
130 const CompositionText& composition_text) {
131 TextInputClient* text_input_client = GetTextInputClient();
132 if (text_input_client)
133 text_input_client->SetCompositionText(composition_text);
136 void InputMethodAuraLinux::OnPreeditEnd() {
137 TextInputClient* text_input_client = GetTextInputClient();
138 if (text_input_client && text_input_client->HasCompositionText())
139 text_input_client->ClearCompositionText();
142 void InputMethodAuraLinux::OnPreeditStart() {}
144 // Overridden from InputMethodBase.
146 void InputMethodAuraLinux::OnDidChangeFocusedClient(
147 TextInputClient* focused_before,
148 TextInputClient* focused) {
149 input_method_context_->Reset();
150 input_method_context_->OnTextInputTypeChanged(
151 focused ? focused->GetTextInputType() : TEXT_INPUT_TYPE_NONE);
153 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
156 } // namespace ui