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

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: address review issues 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
« no previous file with comments | « mandoline/ui/aura/input_method_mandoline.h ('k') | mandoline/ui/aura/window_tree_host_mojo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/view_manager/public/cpp/view.h"
8 #include "mojo/converters/ime/ime_type_converters.h"
7 #include "ui/base/ime/text_input_client.h" 9 #include "ui/base/ime/text_input_client.h"
8 #include "ui/events/event.h" 10 #include "ui/events/event.h"
11 #include "ui/mojo/ime/text_input_state.mojom.h"
9 12
10 namespace mandoline { 13 namespace mandoline {
11 14
12 //////////////////////////////////////////////////////////////////////////////// 15 ////////////////////////////////////////////////////////////////////////////////
13 // InputMethodMandoline, public: 16 // InputMethodMandoline, public:
14 17
15 InputMethodMandoline::InputMethodMandoline( 18 InputMethodMandoline::InputMethodMandoline(
16 ui::internal::InputMethodDelegate* delegate) { 19 ui::internal::InputMethodDelegate* delegate,
20 mojo::View* view)
21 : view_(view) {
17 SetDelegate(delegate); 22 SetDelegate(delegate);
18 } 23 }
19 24
20 InputMethodMandoline::~InputMethodMandoline() {} 25 InputMethodMandoline::~InputMethodMandoline() {}
21 26
22 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
23 // InputMethodMandoline, ui::InputMethod implementation: 28 // InputMethodMandoline, ui::InputMethod implementation:
24 29
30 void InputMethodMandoline::OnFocus() {
31 InputMethodBase::OnFocus();
32 UpdateTextInputType();
33 }
34
35 void InputMethodMandoline::OnBlur() {
36 InputMethodBase::OnBlur();
37 UpdateTextInputType();
38 }
39
25 bool InputMethodMandoline::OnUntranslatedIMEMessage( 40 bool InputMethodMandoline::OnUntranslatedIMEMessage(
26 const base::NativeEvent& event, 41 const base::NativeEvent& event,
27 NativeEventResult* result) { 42 NativeEventResult* result) {
28 return false; 43 return false;
29 } 44 }
30 45
31 void InputMethodMandoline::DispatchKeyEvent(ui::KeyEvent* event) { 46 void InputMethodMandoline::DispatchKeyEvent(ui::KeyEvent* event) {
32 DCHECK(event->type() == ui::ET_KEY_PRESSED || 47 DCHECK(event->type() == ui::ET_KEY_PRESSED ||
33 event->type() == ui::ET_KEY_RELEASED); 48 event->type() == ui::ET_KEY_RELEASED);
34 49
35 // If no text input client, do nothing. 50 // If no text input client, do nothing.
36 if (!GetTextInputClient()) { 51 if (!GetTextInputClient()) {
37 ignore_result(DispatchKeyEventPostIME(event)); 52 ignore_result(DispatchKeyEventPostIME(event));
38 return; 53 return;
39 } 54 }
40 55
41 // Here is where we change the differ from our base class's logic. Instead of 56 // 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 57 // 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 58 // 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.) 59 // send out the key if it is. (We fallback to normal dispatch if it isn't.)
45 if (event->is_char()) { 60 if (event->is_char()) {
46 GetTextInputClient()->InsertChar(event->GetCharacter(), event->flags()); 61 GetTextInputClient()->InsertChar(event->GetCharacter(), event->flags());
47 event->StopPropagation(); 62 event->StopPropagation();
48 return; 63 return;
49 } 64 }
50 65
51 ignore_result(DispatchKeyEventPostIME(event)); 66 ignore_result(DispatchKeyEventPostIME(event));
52 } 67 }
53 68
69 void InputMethodMandoline::OnTextInputTypeChanged(
70 const ui::TextInputClient* client) {
71 if (IsTextInputClientFocused(client))
72 UpdateTextInputType();
73 InputMethodBase::OnTextInputTypeChanged(client);
74 }
75
54 void InputMethodMandoline::OnCaretBoundsChanged( 76 void InputMethodMandoline::OnCaretBoundsChanged(
55 const ui::TextInputClient* client) { 77 const ui::TextInputClient* client) {
56 } 78 }
57 79
58 void InputMethodMandoline::CancelComposition( 80 void InputMethodMandoline::CancelComposition(
59 const ui::TextInputClient* client) { 81 const ui::TextInputClient* client) {
60 } 82 }
61 83
62 void InputMethodMandoline::OnInputLocaleChanged() { 84 void InputMethodMandoline::OnInputLocaleChanged() {
63 } 85 }
64 86
65 std::string InputMethodMandoline::GetInputLocale() { 87 std::string InputMethodMandoline::GetInputLocale() {
66 return ""; 88 return "";
67 } 89 }
68 90
69 bool InputMethodMandoline::IsCandidatePopupOpen() const { 91 bool InputMethodMandoline::IsCandidatePopupOpen() const {
70 return false; 92 return false;
71 } 93 }
72 94
95 void InputMethodMandoline::OnDidChangeFocusedClient(
96 ui::TextInputClient* focused_before,
97 ui::TextInputClient* focused) {
98 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
99 UpdateTextInputType();
100 }
101
102 void InputMethodMandoline::UpdateTextInputType() {
103 ui::TextInputType type = GetTextInputType();
104 mojo::TextInputStatePtr state = mojo::TextInputState::New();
105 state->type = mojo::ConvertTo<mojo::TextInputType>(type);
106 if (type != ui::TEXT_INPUT_TYPE_NONE)
107 view_->SetImeVisibility(true, state.Pass());
108 else
109 view_->SetTextInputState(state.Pass());
110 }
111
73 } // namespace mandoline 112 } // namespace mandoline
OLDNEW
« no previous file with comments | « mandoline/ui/aura/input_method_mandoline.h ('k') | mandoline/ui/aura/window_tree_host_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698