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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/mock_input_method.h"
6
7 #include "base/logging.h"
8 #include "base/string16.h"
9 #include "ui/base/events.h"
10 #include "ui/base/ime/input_method_delegate.h"
11 #include "ui/base/ime/text_input_client.h"
12
13 #if defined(USE_AURA)
14 #include "ui/aura/event.h"
15 #endif
16
17 namespace ui {
18
19 MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
20 : delegate_(NULL),
21 text_input_client_(NULL),
22 consume_next_key_(false) {
23 set_delegate(delegate);
24 }
25
26 MockInputMethod::~MockInputMethod() {
27 }
28
29 void MockInputMethod::set_delegate(internal::InputMethodDelegate* delegate) {
30 delegate_ = delegate;
31 }
32
33 void MockInputMethod::set_text_input_client(TextInputClient* client) {
34 text_input_client_ = client;
35 }
36
37 TextInputClient* MockInputMethod::text_input_client() const {
38 return text_input_client_;
39 }
40
41 void MockInputMethod::Init() {}
42
43 void MockInputMethod::DispatchKeyEvent(gfx::NativeEvent native_key_event) {
44 if (native_key_event->type() == ui::ET_KEY_RELEASED) {
45 // On key release, just dispatch it.
46 delegate_->DispatchKeyEventPostIME(native_key_event);
47 } else {
48 if (consume_next_key_) {
49 // Send the VKEY_PROCESSKEY RawKeyDown event.
50 SendFakeProcessKeyEvent(true, native_key_event->flags());
51 } else {
52 // Send a RawKeyDown event first,
53 delegate_->DispatchKeyEventPostIME(native_key_event);
54 if (text_input_client_) {
55 // then send a Char event via ui::TextInputClient.
56 #if defined(USE_AURA)
57 aura::KeyEvent* key = static_cast<aura::KeyEvent*>(native_key_event);
58 char16 c = key->GetCharacter();
59 KeyboardCode key_code = key->key_code();
60 #else
61 NOTIMPLEMENTED();
62 char16 c = 0;
63 KeyboardCode key_code = VKEY_UNKNOWN;
64 #endif
65 if (c && InputMethod::ShouldSendCharEventForKeyboardCode(key_code))
66 text_input_client_->InsertChar(c, native_key_event->flags());
67 }
68 }
69 }
70 consume_next_key_ = false;
71 }
72
73 void MockInputMethod::OnTextInputTypeChanged(gfx::NativeWindow window) {}
74 void MockInputMethod::OnCaretBoundsChanged(gfx::NativeWindow window) {}
75 void MockInputMethod::CancelComposition(gfx::NativeWindow window) {}
76
77 std::string MockInputMethod::GetInputLocale() {
78 return "";
79 }
80
81 base::i18n::TextDirection MockInputMethod::GetInputTextDirection() {
82 return base::i18n::UNKNOWN_DIRECTION;
83 }
84
85 bool MockInputMethod::IsActive() {
86 return true;
87 }
88
89 ui::TextInputType MockInputMethod::GetTextInputType() const {
90 return ui::TEXT_INPUT_TYPE_NONE;
91 }
92
93 void MockInputMethod::ConsumeNextKey() {
94 consume_next_key_ = true;
95 }
96
97 void MockInputMethod::SendFakeProcessKeyEvent(bool pressed, int flags) const {
98 #if defined(USE_AURA)
99 aura::KeyEvent key(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED,
100 VKEY_PROCESSKEY, flags);
101 delegate_->DispatchKeyEventPostIME(&key);
102 #else
103 NOTIMPLEMENTED();
104 #endif
105 }
106
107 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698