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

Side by Side Diff: mandoline/ui/aura/input_method_mandoline.cc

Issue 1286383003: Mandoline: Enable Android software keyboard for the Omnibox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 5 years, 4 months 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "mandoline/ui/aura/input_method_mandoline.h" 5 #include "mandoline/ui/aura/input_method_mandoline.h"
6 6
7 #include "base/logging.h"
8 #include "components/view_manager/public/cpp/view.h"
9 #include "mojo/converters/ime/ime_type_converters.h"
7 #include "ui/base/ime/text_input_client.h" 10 #include "ui/base/ime/text_input_client.h"
8 #include "ui/events/event.h" 11 #include "ui/events/event.h"
12 #include "ui/mojo/ime/text_input_state.mojom.h"
9 13
10 namespace mandoline { 14 namespace mandoline {
11 15
12 //////////////////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////////////////
13 // InputMethodMandoline, public: 17 // InputMethodMandoline, public:
14 18
15 InputMethodMandoline::InputMethodMandoline( 19 InputMethodMandoline::InputMethodMandoline(
16 ui::internal::InputMethodDelegate* delegate) { 20 ui::internal::InputMethodDelegate* delegate,
21 mojo::View* view)
22 : view_(view) {
17 SetDelegate(delegate); 23 SetDelegate(delegate);
18 } 24 }
19 25
20 InputMethodMandoline::~InputMethodMandoline() {} 26 InputMethodMandoline::~InputMethodMandoline() {}
21 27
22 //////////////////////////////////////////////////////////////////////////////// 28 ////////////////////////////////////////////////////////////////////////////////
23 // InputMethodMandoline, ui::InputMethod implementation: 29 // InputMethodMandoline, ui::InputMethod implementation:
24 30
31 void InputMethodMandoline::OnFocus() {
32 InputMethodBase::OnFocus();
33 UpdateTextInputType();
34 }
35
36 void InputMethodMandoline::OnBlur() {
37 InputMethodBase::OnBlur();
38 UpdateTextInputType();
39 }
40
25 bool InputMethodMandoline::OnUntranslatedIMEMessage( 41 bool InputMethodMandoline::OnUntranslatedIMEMessage(
26 const base::NativeEvent& event, 42 const base::NativeEvent& event,
27 NativeEventResult* result) { 43 NativeEventResult* result) {
28 return false; 44 return false;
29 } 45 }
30 46
31 void InputMethodMandoline::DispatchKeyEvent(ui::KeyEvent* event) { 47 void InputMethodMandoline::DispatchKeyEvent(ui::KeyEvent* event) {
32 DCHECK(event->type() == ui::ET_KEY_PRESSED || 48 DCHECK(event->type() == ui::ET_KEY_PRESSED ||
33 event->type() == ui::ET_KEY_RELEASED); 49 event->type() == ui::ET_KEY_RELEASED);
34 50
35 // If no text input client, do nothing. 51 // If no text input client, do nothing.
36 if (!GetTextInputClient()) { 52 if (!GetTextInputClient()) {
37 ignore_result(DispatchKeyEventPostIME(event)); 53 ignore_result(DispatchKeyEventPostIME(event));
38 return; 54 return;
39 } 55 }
40 56
41 // Here is where we change the differ from our base class's logic. Instead of 57 // Here is where we change the differ from our base class's logic. Instead of
42 // always dispatching a key down event, and then sending a synthesized 58 // always dispatching a key down event, and then sending a synthesized
43 // character event, we instead check to see if this is a character event and 59 // character event, we instead check to see if this is a character event and
44 // send out the key if it is. (We fallback to normal dispatch if it isn't.) 60 // send out the key if it is. (We fallback to normal dispatch if it isn't.)
45 if (event->is_char()) { 61 if (event->is_char()) {
46 GetTextInputClient()->InsertChar(event->GetCharacter(), event->flags()); 62 GetTextInputClient()->InsertChar(event->GetCharacter(), event->flags());
47 event->StopPropagation(); 63 event->StopPropagation();
48 return; 64 return;
49 } 65 }
50 66
51 ignore_result(DispatchKeyEventPostIME(event)); 67 ignore_result(DispatchKeyEventPostIME(event));
52 } 68 }
53 69
70 void InputMethodMandoline::OnTextInputTypeChanged(
71 const ui::TextInputClient* client) {
72 if (IsTextInputClientFocused(client))
73 UpdateTextInputType();
74 InputMethodBase::OnTextInputTypeChanged(client);
75 }
76
54 void InputMethodMandoline::OnCaretBoundsChanged( 77 void InputMethodMandoline::OnCaretBoundsChanged(
55 const ui::TextInputClient* client) { 78 const ui::TextInputClient* client) {
56 } 79 }
57 80
58 void InputMethodMandoline::CancelComposition( 81 void InputMethodMandoline::CancelComposition(
59 const ui::TextInputClient* client) { 82 const ui::TextInputClient* client) {
60 } 83 }
61 84
62 void InputMethodMandoline::OnInputLocaleChanged() { 85 void InputMethodMandoline::OnInputLocaleChanged() {
63 } 86 }
64 87
65 std::string InputMethodMandoline::GetInputLocale() { 88 std::string InputMethodMandoline::GetInputLocale() {
66 return ""; 89 return "";
67 } 90 }
68 91
69 bool InputMethodMandoline::IsCandidatePopupOpen() const { 92 bool InputMethodMandoline::IsCandidatePopupOpen() const {
70 return false; 93 return false;
71 } 94 }
72 95
96 void InputMethodMandoline::OnWillChangeFocusedClient(
sky 2015/08/14 19:59:23 nit: remove this as it's the same as that of the b
Peng 2015/08/17 13:26:49 Done.
97 ui::TextInputClient* focused_before,
98 ui::TextInputClient* focused) {
99 InputMethodBase::OnWillChangeFocusedClient(focused_before, focused);
100 }
101
102 void InputMethodMandoline::OnDidChangeFocusedClient(
103 ui::TextInputClient* focused_before,
104 ui::TextInputClient* focused) {
105 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
106 UpdateTextInputType();
107 }
108
109 void InputMethodMandoline::UpdateTextInputType() {
110 ui::TextInputType type = GetTextInputType();
111 mojo::TextInputStatePtr state = mojo::TextInputState::New();
112 state->type = mojo::ConvertTo<mojo::TextInputType>(type);
113 if (type != ui::TEXT_INPUT_TYPE_NONE)
114 view_->SetImeVisibility(true, state.Pass());
115 else
116 view_->SetTextInputState(state.Pass());
117 }
118
73 } // namespace mandoline 119 } // namespace mandoline
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698