OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/fake_input_method.h" | 5 #include "ui/base/ime/fake_input_method.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "ui/base/glib/glib_integers.h" | 9 #include "ui/base/glib/glib_integers.h" |
10 #include "ui/base/ime/input_method_delegate.h" | 10 #include "ui/base/ime/input_method_delegate.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 text_input_client_ = NULL; | 60 text_input_client_ = NULL; |
61 FOR_EACH_OBSERVER(InputMethodObserver, observers_, | 61 FOR_EACH_OBSERVER(InputMethodObserver, observers_, |
62 OnTextInputStateChanged(client)); | 62 OnTextInputStateChanged(client)); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 TextInputClient* FakeInputMethod::GetTextInputClient() const { | 66 TextInputClient* FakeInputMethod::GetTextInputClient() const { |
67 return text_input_client_; | 67 return text_input_client_; |
68 } | 68 } |
69 | 69 |
70 bool FakeInputMethod::DispatchKeyEvent(const base::NativeEvent& native_event) { | 70 bool FakeInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) { |
| 71 if (!event.HasNativeEvent()) |
| 72 return DispatchFabricatedKeyEvent(event); |
| 73 |
| 74 const base::NativeEvent& native_event = event.native_event(); |
71 bool handled = false; | 75 bool handled = false; |
72 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
73 if (native_event.message == WM_CHAR) { | 77 if (native_event.message == WM_CHAR) { |
74 if (text_input_client_) { | 78 if (text_input_client_) { |
75 text_input_client_->InsertChar(ui::KeyboardCodeFromNative(native_event), | 79 text_input_client_->InsertChar(ui::KeyboardCodeFromNative(native_event), |
76 ui::EventFlagsFromNative(native_event)); | 80 ui::EventFlagsFromNative(native_event)); |
77 handled = true; | 81 handled = true; |
78 } | 82 } |
79 } else { | 83 } else { |
80 handled = delegate_->DispatchKeyEventPostIME(native_event); | 84 handled = delegate_->DispatchKeyEventPostIME(native_event); |
81 } | 85 } |
82 #elif defined(USE_X11) | 86 #elif defined(USE_X11) |
83 DCHECK(native_event); | 87 DCHECK(native_event); |
84 if (native_event->type == KeyRelease) { | 88 if (native_event->type == KeyRelease) { |
85 // On key release, just dispatch it. | 89 // On key release, just dispatch it. |
86 handled = delegate_->DispatchKeyEventPostIME(native_event); | 90 handled = delegate_->DispatchKeyEventPostIME(event); |
87 } else { | 91 } else { |
88 const uint32 state = EventFlagsFromXFlags(native_event->xkey.state); | 92 const uint32 state = EventFlagsFromXFlags(native_event->xkey.state); |
89 // Send a RawKeyDown event first, | 93 // Send a RawKeyDown event first, |
90 handled = delegate_->DispatchKeyEventPostIME(native_event); | 94 handled = delegate_->DispatchKeyEventPostIME(event); |
91 if (text_input_client_) { | 95 if (text_input_client_) { |
92 // then send a Char event via ui::TextInputClient. | 96 // then send a Char event via ui::TextInputClient. |
93 const KeyboardCode key_code = ui::KeyboardCodeFromNative(native_event); | 97 const KeyboardCode key_code = ui::KeyboardCodeFromNative(native_event); |
94 uint16 ch = 0; | 98 uint16 ch = 0; |
95 if (!(state & ui::EF_CONTROL_DOWN)) | 99 if (!(state & ui::EF_CONTROL_DOWN)) |
96 ch = ui::GetCharacterFromXEvent(native_event); | 100 ch = ui::GetCharacterFromXEvent(native_event); |
97 if (!ch) | 101 if (!ch) |
98 ch = ui::GetCharacterFromKeyCode(key_code, state); | 102 ch = ui::GetCharacterFromKeyCode(key_code, state); |
99 if (ch) | 103 if (ch) |
100 text_input_client_->InsertChar(ch, state); | 104 text_input_client_->InsertChar(ch, state); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 188 |
185 void FakeInputMethod::AddObserver(InputMethodObserver* observer) { | 189 void FakeInputMethod::AddObserver(InputMethodObserver* observer) { |
186 observers_.AddObserver(observer); | 190 observers_.AddObserver(observer); |
187 } | 191 } |
188 | 192 |
189 void FakeInputMethod::RemoveObserver(InputMethodObserver* observer) { | 193 void FakeInputMethod::RemoveObserver(InputMethodObserver* observer) { |
190 observers_.RemoveObserver(observer); | 194 observers_.RemoveObserver(observer); |
191 } | 195 } |
192 | 196 |
193 } // namespace ui | 197 } // namespace ui |
OLD | NEW |