Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1486)

Unified Diff: ui/base/ime/mock_input_method.cc

Issue 8576005: IME (input method editor) support for Aura, part 3 of 3: Use ui::InputMethod in ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, review Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/ime/mock_input_method.cc
diff --git a/ui/base/ime/mock_input_method.cc b/ui/base/ime/mock_input_method.cc
new file mode 100644
index 0000000000000000000000000000000000000000..827dcc9e08a942d029ac670c3c271ddebe6df9f0
--- /dev/null
+++ b/ui/base/ime/mock_input_method.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/ime/mock_input_method.h"
+
+#include "base/logging.h"
+#include "base/string16.h"
+#include "ui/base/events.h"
+#include "ui/base/ime/input_method_delegate.h"
+#include "ui/base/ime/text_input_client.h"
+
+#if defined(USE_AURA)
+#include "ui/aura/event.h"
+#endif
+
+namespace ui {
+
+MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
+ : delegate_(NULL),
+ text_input_client_(NULL),
+ consume_next_key_(false) {
+ set_delegate(delegate);
+}
+
+MockInputMethod::~MockInputMethod() {
+}
+
+void MockInputMethod::set_delegate(internal::InputMethodDelegate* delegate) {
+ delegate_ = delegate;
+}
+
+void MockInputMethod::set_text_input_client(TextInputClient* client) {
+ text_input_client_ = client;
+}
+
+TextInputClient* MockInputMethod::text_input_client() const {
+ return text_input_client_;
+}
+
+void MockInputMethod::Init() {}
+
+void MockInputMethod::DispatchKeyEvent(gfx::NativeEvent native_key_event) {
+ if (native_key_event->type() == ui::ET_KEY_RELEASED) {
+ // On key release, just dispatch it.
+ delegate_->DispatchKeyEventPostIME(native_key_event);
+ } else {
+ if (consume_next_key_) {
+ // Send the VKEY_PROCESSKEY RawKeyDown event.
+ SendFakeProcessKeyEvent(true, native_key_event->flags());
+ } else {
+ // Send a RawKeyDown event first,
+ delegate_->DispatchKeyEventPostIME(native_key_event);
+ if (text_input_client_) {
+ // then send a Char event via ui::TextInputClient.
+#if defined(USE_AURA)
+ aura::KeyEvent* key = static_cast<aura::KeyEvent*>(native_key_event);
+ char16 c = key->GetCharacter();
+ KeyboardCode key_code = key->key_code();
+#else
+ NOTIMPLEMENTED();
+ char16 c = 0;
+ KeyboardCode key_code = VKEY_UNKNOWN;
+#endif
+ if (c && InputMethod::ShouldSendCharEventForKeyboardCode(key_code))
+ text_input_client_->InsertChar(c, native_key_event->flags());
+ }
+ }
+ }
+ consume_next_key_ = false;
+}
+
+void MockInputMethod::OnTextInputTypeChanged(gfx::NativeWindow window) {}
+void MockInputMethod::OnCaretBoundsChanged(gfx::NativeWindow window) {}
+void MockInputMethod::CancelComposition(gfx::NativeWindow window) {}
+
+std::string MockInputMethod::GetInputLocale() {
+ return "";
+}
+
+base::i18n::TextDirection MockInputMethod::GetInputTextDirection() {
+ return base::i18n::UNKNOWN_DIRECTION;
+}
+
+bool MockInputMethod::IsActive() {
+ return true;
+}
+
+ui::TextInputType MockInputMethod::GetTextInputType() const {
+ return ui::TEXT_INPUT_TYPE_NONE;
+}
+
+void MockInputMethod::ConsumeNextKey() {
+ consume_next_key_ = true;
+}
+
+void MockInputMethod::SendFakeProcessKeyEvent(bool pressed, int flags) const {
+#if defined(USE_AURA)
+ aura::KeyEvent key(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED,
+ VKEY_PROCESSKEY, flags);
+ delegate_->DispatchKeyEventPostIME(&key);
+#else
+ NOTIMPLEMENTED();
+#endif
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698