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

Side by Side Diff: ui/base/ime/input_method_base.cc

Issue 1778693004: Set the current input context handler when the toplevel window is activated instead of when the inp… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | no next file » | 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) 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/input_method_base.h" 5 #include "ui/base/ime/input_method_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/base/ime/ime_bridge.h" 11 #include "ui/base/ime/ime_bridge.h"
12 #include "ui/base/ime/input_method_delegate.h" 12 #include "ui/base/ime/input_method_delegate.h"
13 #include "ui/base/ime/input_method_observer.h" 13 #include "ui/base/ime/input_method_observer.h"
14 #include "ui/base/ime/text_input_client.h" 14 #include "ui/base/ime/text_input_client.h"
15 #include "ui/events/event.h" 15 #include "ui/events/event.h"
16 16
17 namespace ui { 17 namespace ui {
18 18
19 InputMethodBase::InputMethodBase() 19 InputMethodBase::InputMethodBase()
20 : delegate_(NULL), text_input_client_(NULL) {} 20 : delegate_(nullptr), text_input_client_(nullptr) {}
21 21
22 InputMethodBase::~InputMethodBase() { 22 InputMethodBase::~InputMethodBase() {
23 FOR_EACH_OBSERVER(InputMethodObserver, 23 FOR_EACH_OBSERVER(InputMethodObserver,
24 observer_list_, 24 observer_list_,
25 OnInputMethodDestroyed(this)); 25 OnInputMethodDestroyed(this));
26 if (ui::IMEBridge::Get() && 26 if (ui::IMEBridge::Get() &&
27 ui::IMEBridge::Get()->GetInputContextHandler() == this) 27 ui::IMEBridge::Get()->GetInputContextHandler() == this)
28 ui::IMEBridge::Get()->SetInputContextHandler(nullptr); 28 ui::IMEBridge::Get()->SetInputContextHandler(nullptr);
29 } 29 }
30 30
31 void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { 31 void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) {
32 delegate_ = delegate; 32 delegate_ = delegate;
33 } 33 }
34 34
35 void InputMethodBase::OnFocus() {} 35 void InputMethodBase::OnFocus() {
36 if (ui::IMEBridge::Get())
37 ui::IMEBridge::Get()->SetInputContextHandler(this);
38 }
36 39
37 void InputMethodBase::OnBlur() {} 40 void InputMethodBase::OnBlur() {
41 if (ui::IMEBridge::Get() &&
42 ui::IMEBridge::Get()->GetInputContextHandler() == this)
43 ui::IMEBridge::Get()->SetInputContextHandler(nullptr);
44 }
38 45
39 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) { 46 void InputMethodBase::SetFocusedTextInputClient(TextInputClient* client) {
40 SetFocusedTextInputClientInternal(client); 47 SetFocusedTextInputClientInternal(client);
41 if (ui::IMEBridge::Get())
42 ui::IMEBridge::Get()->SetInputContextHandler(this);
43 } 48 }
44 49
45 void InputMethodBase::DetachTextInputClient(TextInputClient* client) { 50 void InputMethodBase::DetachTextInputClient(TextInputClient* client) {
46 if (text_input_client_ != client) 51 if (text_input_client_ != client)
47 return; 52 return;
48 SetFocusedTextInputClientInternal(NULL); 53 SetFocusedTextInputClientInternal(nullptr);
49 } 54 }
50 55
51 TextInputClient* InputMethodBase::GetTextInputClient() const { 56 TextInputClient* InputMethodBase::GetTextInputClient() const {
52 return text_input_client_; 57 return text_input_client_;
53 } 58 }
54 59
55 void InputMethodBase::OnTextInputTypeChanged(const TextInputClient* client) { 60 void InputMethodBase::OnTextInputTypeChanged(const TextInputClient* client) {
56 if (!IsTextInputClientFocused(client)) 61 if (!IsTextInputClientFocused(client))
57 return; 62 return;
58 NotifyTextInputStateChanged(client); 63 NotifyTextInputStateChanged(client);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 FOR_EACH_OBSERVER( 129 FOR_EACH_OBSERVER(
125 InputMethodObserver, observer_list_, OnCaretBoundsChanged(client)); 130 InputMethodObserver, observer_list_, OnCaretBoundsChanged(client));
126 } 131 }
127 132
128 void InputMethodBase::SetFocusedTextInputClientInternal( 133 void InputMethodBase::SetFocusedTextInputClientInternal(
129 TextInputClient* client) { 134 TextInputClient* client) {
130 TextInputClient* old = text_input_client_; 135 TextInputClient* old = text_input_client_;
131 if (old == client) 136 if (old == client)
132 return; 137 return;
133 OnWillChangeFocusedClient(old, client); 138 OnWillChangeFocusedClient(old, client);
134 text_input_client_ = client; // NULL allowed. 139 text_input_client_ = client; // nullptr allowed.
135 OnDidChangeFocusedClient(old, client); 140 OnDidChangeFocusedClient(old, client);
136 NotifyTextInputStateChanged(text_input_client_); 141 NotifyTextInputStateChanged(text_input_client_);
137 } 142 }
138 143
139 std::vector<gfx::Rect> InputMethodBase::GetCompositionBounds( 144 std::vector<gfx::Rect> InputMethodBase::GetCompositionBounds(
140 const TextInputClient* client) { 145 const TextInputClient* client) {
141 std::vector<gfx::Rect> bounds; 146 std::vector<gfx::Rect> bounds;
142 if (client->HasCompositionText()) { 147 if (client->HasCompositionText()) {
143 uint32_t i = 0; 148 uint32_t i = 0;
144 gfx::Rect rect; 149 gfx::Rect rect;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 GetTextInputClient()->SetCompositionText(composition_); 189 GetTextInputClient()->SetCompositionText(composition_);
185 else 190 else
186 GetTextInputClient()->ClearCompositionText(); 191 GetTextInputClient()->ClearCompositionText();
187 } 192 }
188 SendFakeProcessKeyEvent(false); 193 SendFakeProcessKeyEvent(false);
189 } 194 }
190 195
191 void InputMethodBase::DeleteSurroundingText(int32_t offset, uint32_t length) {} 196 void InputMethodBase::DeleteSurroundingText(int32_t offset, uint32_t length) {}
192 197
193 } // namespace ui 198 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698