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

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: Fix Windows support Created 9 years 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/ime/mock_input_method.h" 5 #include "ui/base/ime/mock_input_method.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "ui/base/events.h" 9 #include "ui/base/events.h"
10 #include "ui/base/glib/glib_integers.h" 10 #include "ui/base/glib/glib_integers.h"
(...skipping 18 matching lines...) Expand all
29 (flags & Mod1Mask ? ui::EF_ALT_DOWN : 0U); 29 (flags & Mod1Mask ? ui::EF_ALT_DOWN : 0U);
30 } 30 }
31 #endif 31 #endif
32 32
33 } // namespace 33 } // namespace
34 34
35 namespace ui { 35 namespace ui {
36 36
37 MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate) 37 MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
38 : delegate_(NULL), 38 : delegate_(NULL),
39 text_input_client_(NULL), 39 text_input_client_(NULL) {
40 consume_next_key_(false) {
41 SetDelegate(delegate); 40 SetDelegate(delegate);
42 } 41 }
43 42
44 MockInputMethod::~MockInputMethod() { 43 MockInputMethod::~MockInputMethod() {
45 } 44 }
46 45
47 void MockInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) { 46 void MockInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) {
48 delegate_ = delegate; 47 delegate_ = delegate;
49 } 48 }
50 49
51 void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) { 50 void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) {
52 text_input_client_ = client; 51 text_input_client_ = client;
53 } 52 }
54 53
55 TextInputClient* MockInputMethod::GetTextInputClient() const { 54 TextInputClient* MockInputMethod::GetTextInputClient() const {
56 return text_input_client_; 55 return text_input_client_;
57 } 56 }
58 57
59 void MockInputMethod::DispatchKeyEvent(const base::NativeEvent& native_event) { 58 void MockInputMethod::DispatchKeyEvent(const base::NativeEvent& native_event) {
60 #if defined(USE_X11) 59 #if defined(OS_WIN)
60 if (native_event.message == WM_CHAR) {
Yusuke Sato 2011/12/21 16:57:27 Added code for Windows. Since NWA completely migra
61 if (text_input_client_) {
62 text_input_client_->InsertChar(ui::KeyboardCodeFromNative(native_event),
63 ui::EventFlagsFromNative(native_event));
64 }
65 } else {
66 delegate_->DispatchKeyEventPostIME(native_event);
67 }
68 #elif defined(USE_X11)
61 DCHECK(native_event); 69 DCHECK(native_event);
62 if (native_event->type == KeyRelease) { 70 if (native_event->type == KeyRelease) {
63 // On key release, just dispatch it. 71 // On key release, just dispatch it.
64 delegate_->DispatchKeyEventPostIME(native_event); 72 delegate_->DispatchKeyEventPostIME(native_event);
65 } else { 73 } else {
66 const uint32 state = EventFlagsFromXFlags(native_event->xkey.state); 74 const uint32 state = EventFlagsFromXFlags(native_event->xkey.state);
67 if (consume_next_key_) { 75 // Send a RawKeyDown event first,
68 // Send the VKEY_PROCESSKEY RawKeyDown event. 76 delegate_->DispatchKeyEventPostIME(native_event);
69 SendFakeProcessKeyEvent(true, state); 77 if (text_input_client_) {
70 } else { 78 // then send a Char event via ui::TextInputClient.
71 // Send a RawKeyDown event first, 79 const KeyboardCode key_code = ui::KeyboardCodeFromNative(native_event);
72 delegate_->DispatchKeyEventPostIME(native_event); 80 uint16 ch = 0;
73 if (text_input_client_) { 81 if (!(state & ui::EF_CONTROL_DOWN))
74 // then send a Char event via ui::TextInputClient. 82 ch = ui::GetCharacterFromXEvent(native_event);
75 const KeyboardCode key_code = ui::KeyboardCodeFromNative(native_event); 83 if (!ch)
76 uint16 ch = 0; 84 ch = ui::GetCharacterFromKeyCode(key_code, state);
77 if (!(state & ui::EF_CONTROL_DOWN)) 85 if (ch)
78 ch = ui::GetCharacterFromXEvent(native_event); 86 text_input_client_->InsertChar(ch, state);
79 if (!ch)
80 ch = ui::GetCharacterFromKeyCode(key_code, state);
81 if (ch)
82 text_input_client_->InsertChar(ch, state);
83 }
84 } 87 }
85 } 88 }
86 consume_next_key_ = false;
87 #else 89 #else
88 // TODO(yusukes): Support Windows. 90 // TODO(yusukes): Support other platforms. Call InsertChar() when necessary.
89 delegate_->DispatchKeyEventPostIME(native_event); 91 delegate_->DispatchKeyEventPostIME(native_event);
90 #endif 92 #endif
91 } 93 }
92 94
93 void MockInputMethod::Init(bool focused) {} 95 void MockInputMethod::Init(bool focused) {}
94 void MockInputMethod::OnFocus() {} 96 void MockInputMethod::OnFocus() {}
95 void MockInputMethod::OnBlur() {} 97 void MockInputMethod::OnBlur() {}
96 void MockInputMethod::OnTextInputTypeChanged(const TextInputClient* client) {} 98 void MockInputMethod::OnTextInputTypeChanged(const TextInputClient* client) {}
97 void MockInputMethod::OnCaretBoundsChanged(const TextInputClient* client) {} 99 void MockInputMethod::OnCaretBoundsChanged(const TextInputClient* client) {}
98 void MockInputMethod::CancelComposition(const TextInputClient* client) {} 100 void MockInputMethod::CancelComposition(const TextInputClient* client) {}
99 101
100 std::string MockInputMethod::GetInputLocale() { 102 std::string MockInputMethod::GetInputLocale() {
101 return ""; 103 return "";
102 } 104 }
103 105
104 base::i18n::TextDirection MockInputMethod::GetInputTextDirection() { 106 base::i18n::TextDirection MockInputMethod::GetInputTextDirection() {
105 return base::i18n::UNKNOWN_DIRECTION; 107 return base::i18n::UNKNOWN_DIRECTION;
106 } 108 }
107 109
108 bool MockInputMethod::IsActive() { 110 bool MockInputMethod::IsActive() {
109 return true; 111 return true;
110 } 112 }
111 113
112 ui::TextInputType MockInputMethod::GetTextInputType() const { 114 ui::TextInputType MockInputMethod::GetTextInputType() const {
113 return ui::TEXT_INPUT_TYPE_NONE; 115 return ui::TEXT_INPUT_TYPE_NONE;
114 } 116 }
115 117
116 void MockInputMethod::ConsumeNextKey() {
117 consume_next_key_ = true;
118 }
119
120 void MockInputMethod::SendFakeProcessKeyEvent(bool pressed, int flags) const {
121 delegate_->DispatchFabricatedKeyEventPostIME(
122 pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED, VKEY_PROCESSKEY, flags);
123 }
124
125 } // namespace ui 118 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698