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

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: addressed comments 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 <X11/X.h>
8 #include <X11/Xlib.h>
9 #include <X11/Xutil.h>
10
11 #include "base/logging.h"
12 #include "base/string16.h"
13 #include "ui/base/events.h"
14 #include "ui/base/glib/glib_integers.h"
15 #include "ui/base/ime/input_method_delegate.h"
16 #include "ui/base/ime/text_input_client.h"
17 #include "ui/base/keycodes/keyboard_code_conversion.h"
18 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
19
20 namespace {
21
22 guint32 EventFlagsFromXFlags(unsigned int flags) {
23 return (flags & LockMask ? ui::EF_CAPS_LOCK_DOWN : 0U) |
24 (flags & ControlMask ? ui::EF_CONTROL_DOWN : 0U) |
25 (flags & ShiftMask ? ui::EF_SHIFT_DOWN : 0U) |
26 (flags & Mod1Mask ? ui::EF_ALT_DOWN : 0U);
27 }
28
29 } // namespace
30
31 namespace ui {
32
33 MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
34 : delegate_(NULL),
35 text_input_client_(NULL),
36 consume_next_key_(false) {
37 set_delegate(delegate);
38 }
39
40 MockInputMethod::~MockInputMethod() {
41 }
42
43 void MockInputMethod::set_delegate(internal::InputMethodDelegate* delegate) {
44 delegate_ = delegate;
45 }
46
47 void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) {
48 text_input_client_ = client;
49 }
50
51 TextInputClient* MockInputMethod::GetTextInputClient() const {
52 return text_input_client_;
53 }
54
55 void MockInputMethod::DispatchKeyEvent(const base::NativeEvent& native_event) {
56 if (native_event->type == KeyRelease) {
57 // On key release, just dispatch it.
58 delegate_->DispatchKeyEventPostIME(native_event);
59 } else {
60 const uint32 state =
61 EventFlagsFromXFlags(reinterpret_cast<XKeyEvent*>(native_event)->state);
62 if (consume_next_key_) {
63 // Send the VKEY_PROCESSKEY RawKeyDown event.
64 SendFakeProcessKeyEvent(true, state);
65 } else {
66 // Send a RawKeyDown event first,
67 delegate_->DispatchKeyEventPostIME(native_event);
68 if (text_input_client_) {
69 // then send a Char event via ui::TextInputClient.
70 const KeyboardCode key_code = ui::KeyboardCodeFromNative(native_event);
71 uint16 ch = ui::DefaultSymbolFromXEvent(native_event);
72 if (!ch)
73 ch = ui::GetCharacterFromKeyCode(key_code, state);
74 if (ch)
75 text_input_client_->InsertChar(ch, state);
76 }
77 }
78 }
79 consume_next_key_ = false;
80 }
81
82 void MockInputMethod::Init(const base::NativeWindow& window) {}
83 void MockInputMethod::OnFocus() {}
84 void MockInputMethod::OnBlur() {}
85 void MockInputMethod::OnTextInputTypeChanged(const TextInputClient* client) {}
86 void MockInputMethod::OnCaretBoundsChanged(const TextInputClient* client) {}
87 void MockInputMethod::CancelComposition(const TextInputClient* client) {}
88
89 std::string MockInputMethod::GetInputLocale() {
90 return "";
91 }
92
93 base::i18n::TextDirection MockInputMethod::GetInputTextDirection() {
94 return base::i18n::UNKNOWN_DIRECTION;
95 }
96
97 bool MockInputMethod::IsActive() {
98 return true;
99 }
100
101 ui::TextInputType MockInputMethod::GetTextInputType() const {
102 return ui::TEXT_INPUT_TYPE_NONE;
103 }
104
105 void MockInputMethod::ConsumeNextKey() {
106 consume_next_key_ = true;
107 }
108
109 void MockInputMethod::SendFakeProcessKeyEvent(bool pressed, int flags) const {
110 delegate_->DispatchFabricatedKeyEventPostIME(
111 pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED, VKEY_PROCESSKEY, flags);
112 }
113
114 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698