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

Side by Side Diff: ui/base/ime/win/tsf_bridge.cc

Issue 14061025: ui: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/clipboard/clipboard_win.cc ('k') | ui/base/models/simple_menu_model.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) 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 <msctf.h> 5 #include <msctf.h>
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 TSFBridgeDelegate::TSFBridgeDelegate() 118 TSFBridgeDelegate::TSFBridgeDelegate()
119 : client_id_(TF_CLIENTID_NULL), 119 : client_id_(TF_CLIENTID_NULL),
120 client_(NULL) { 120 client_(NULL) {
121 } 121 }
122 122
123 TSFBridgeDelegate::~TSFBridgeDelegate() { 123 TSFBridgeDelegate::~TSFBridgeDelegate() {
124 } 124 }
125 125
126 bool TSFBridgeDelegate::Initialize() { 126 bool TSFBridgeDelegate::Initialize() {
127 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 127 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
128 if (client_id_ != TF_CLIENTID_NULL) { 128 if (client_id_ != TF_CLIENTID_NULL) {
129 DVLOG(1) << "Already initialized."; 129 DVLOG(1) << "Already initialized.";
130 return false; 130 return false;
131 } 131 }
132 132
133 if (FAILED(thread_manager_.CreateInstance(CLSID_TF_ThreadMgr))) { 133 if (FAILED(thread_manager_.CreateInstance(CLSID_TF_ThreadMgr))) {
134 DVLOG(1) << "Failed to create ThreadManager instance."; 134 DVLOG(1) << "Failed to create ThreadManager instance.";
135 return false; 135 return false;
136 } 136 }
137 137
(...skipping 27 matching lines...) Expand all
165 sentence_variant.Set(TF_SENTENCEMODE_PHRASEPREDICT); 165 sentence_variant.Set(TF_SENTENCEMODE_PHRASEPREDICT);
166 if (FAILED(sentence_compartment->SetValue(client_id_, &sentence_variant))) { 166 if (FAILED(sentence_compartment->SetValue(client_id_, &sentence_variant))) {
167 DVLOG(1) << "Failed to change the sentence mode."; 167 DVLOG(1) << "Failed to change the sentence mode.";
168 return false; 168 return false;
169 } 169 }
170 170
171 return true; 171 return true;
172 } 172 }
173 173
174 void TSFBridgeDelegate::Shutdown() { 174 void TSFBridgeDelegate::Shutdown() {
175 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 175 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
176 if (!IsInitialized()) 176 if (!IsInitialized())
177 return; 177 return;
178 for (TSFDocumentMap::iterator it = tsf_document_map_.begin(); 178 for (TSFDocumentMap::iterator it = tsf_document_map_.begin();
179 it != tsf_document_map_.end(); ++it) { 179 it != tsf_document_map_.end(); ++it) {
180 base::win::ScopedComPtr<ITfContext> context; 180 base::win::ScopedComPtr<ITfContext> context;
181 base::win::ScopedComPtr<ITfSource> source; 181 base::win::ScopedComPtr<ITfSource> source;
182 if (it->second.cookie != TF_INVALID_COOKIE && 182 if (it->second.cookie != TF_INVALID_COOKIE &&
183 SUCCEEDED(it->second.document_manager->GetBase(context.Receive())) && 183 SUCCEEDED(it->second.document_manager->GetBase(context.Receive())) &&
184 SUCCEEDED(source.QueryFrom(context))) { 184 SUCCEEDED(source.QueryFrom(context))) {
185 source->UnadviseSink(it->second.cookie); 185 source->UnadviseSink(it->second.cookie);
186 } 186 }
187 } 187 }
188 tsf_document_map_.clear(); 188 tsf_document_map_.clear();
189 189
190 client_id_ = TF_CLIENTID_NULL; 190 client_id_ = TF_CLIENTID_NULL;
191 } 191 }
192 192
193 void TSFBridgeDelegate::OnTextInputTypeChanged(TextInputClient* client) { 193 void TSFBridgeDelegate::OnTextInputTypeChanged(TextInputClient* client) {
194 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 194 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
195 DCHECK(IsInitialized()); 195 DCHECK(IsInitialized());
196 196
197 if (client != client_) { 197 if (client != client_) {
198 // Called from not focusing client. Do nothing. 198 // Called from not focusing client. Do nothing.
199 return; 199 return;
200 } 200 }
201 201
202 thread_manager_->SetFocus(GetAssociatedDocumentManager().get()); 202 thread_manager_->SetFocus(GetAssociatedDocumentManager().get());
203 } 203 }
204 204
205 bool TSFBridgeDelegate::CancelComposition() { 205 bool TSFBridgeDelegate::CancelComposition() {
206 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 206 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
207 DCHECK(IsInitialized()); 207 DCHECK(IsInitialized());
208 208
209 base::win::ScopedComPtr<ITfDocumentMgr> focused_document_manager; 209 base::win::ScopedComPtr<ITfDocumentMgr> focused_document_manager;
210 for (TSFDocumentMap::iterator it = tsf_document_map_.begin(); 210 for (TSFDocumentMap::iterator it = tsf_document_map_.begin();
211 it != tsf_document_map_.end(); ++it) { 211 it != tsf_document_map_.end(); ++it) {
212 if (IsFocused(it->second.document_manager.get())) { 212 if (IsFocused(it->second.document_manager.get())) {
213 focused_document_manager = it->second.document_manager.get(); 213 focused_document_manager = it->second.document_manager.get();
214 break; 214 break;
215 } 215 }
216 } 216 }
(...skipping 18 matching lines...) Expand all
235 DVLOG(1) << "Failed to get ITfContextOwnerCompositionService."; 235 DVLOG(1) << "Failed to get ITfContextOwnerCompositionService.";
236 return false; 236 return false;
237 } 237 }
238 // Cancel all compositions. 238 // Cancel all compositions.
239 owner->TerminateComposition(NULL); 239 owner->TerminateComposition(NULL);
240 return true; 240 return true;
241 } 241 }
242 242
243 void TSFBridgeDelegate::SetFocusedClient(HWND focused_window, 243 void TSFBridgeDelegate::SetFocusedClient(HWND focused_window,
244 TextInputClient* client) { 244 TextInputClient* client) {
245 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 245 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
246 DCHECK(client); 246 DCHECK(client);
247 DCHECK(IsInitialized()); 247 DCHECK(IsInitialized());
248 client_ = client; 248 client_ = client;
249 249
250 for (TSFDocumentMap::iterator it = tsf_document_map_.begin(); 250 for (TSFDocumentMap::iterator it = tsf_document_map_.begin();
251 it != tsf_document_map_.end(); ++it) { 251 it != tsf_document_map_.end(); ++it) {
252 if (it->second.text_store.get() == NULL) 252 if (it->second.text_store.get() == NULL)
253 continue; 253 continue;
254 it->second.text_store->SetFocusedTextInputClient(focused_window, 254 it->second.text_store->SetFocusedTextInputClient(focused_window,
255 client); 255 client);
256 } 256 }
257 257
258 // Synchronize text input type state. 258 // Synchronize text input type state.
259 OnTextInputTypeChanged(client); 259 OnTextInputTypeChanged(client);
260 } 260 }
261 261
262 void TSFBridgeDelegate::RemoveFocusedClient(TextInputClient* client) { 262 void TSFBridgeDelegate::RemoveFocusedClient(TextInputClient* client) {
263 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 263 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
264 DCHECK(IsInitialized()); 264 DCHECK(IsInitialized());
265 if (client_ != client) 265 if (client_ != client)
266 return; 266 return;
267 client_ = NULL; 267 client_ = NULL;
268 for (TSFDocumentMap::iterator it = tsf_document_map_.begin(); 268 for (TSFDocumentMap::iterator it = tsf_document_map_.begin();
269 it != tsf_document_map_.end(); ++it) { 269 it != tsf_document_map_.end(); ++it) {
270 if (it->second.text_store.get() == NULL) 270 if (it->second.text_store.get() == NULL)
271 continue; 271 continue;
272 it->second.text_store->SetFocusedTextInputClient(NULL, NULL); 272 it->second.text_store->SetFocusedTextInputClient(NULL, NULL);
273 } 273 }
274 } 274 }
275 275
276 TextInputClient* TSFBridgeDelegate::GetFocusedTextInputClient() const { 276 TextInputClient* TSFBridgeDelegate::GetFocusedTextInputClient() const {
277 return client_; 277 return client_;
278 } 278 }
279 279
280 base::win::ScopedComPtr<ITfThreadMgr> TSFBridgeDelegate::GetThreadManager() { 280 base::win::ScopedComPtr<ITfThreadMgr> TSFBridgeDelegate::GetThreadManager() {
281 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 281 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
282 DCHECK(IsInitialized()); 282 DCHECK(IsInitialized());
283 return thread_manager_; 283 return thread_manager_;
284 } 284 }
285 285
286 bool TSFBridgeDelegate::CreateDocumentManager(TSFTextStore* text_store, 286 bool TSFBridgeDelegate::CreateDocumentManager(TSFTextStore* text_store,
287 ITfDocumentMgr** document_manager, 287 ITfDocumentMgr** document_manager,
288 ITfContext** context, 288 ITfContext** context,
289 DWORD* source_cookie) { 289 DWORD* source_cookie) {
290 if (FAILED(thread_manager_->CreateDocumentMgr(document_manager))) { 290 if (FAILED(thread_manager_->CreateDocumentMgr(document_manager))) {
291 DVLOG(1) << "Failed to create Document Manager."; 291 DVLOG(1) << "Failed to create Document Manager.";
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 // TsfBridge ----------------------------------------------------------------- 432 // TsfBridge -----------------------------------------------------------------
433 433
434 TSFBridge::TSFBridge() { 434 TSFBridge::TSFBridge() {
435 } 435 }
436 436
437 TSFBridge::~TSFBridge() { 437 TSFBridge::~TSFBridge() {
438 } 438 }
439 439
440 // static 440 // static
441 bool TSFBridge::Initialize() { 441 bool TSFBridge::Initialize() {
442 if (MessageLoop::current()->type() != MessageLoop::TYPE_UI) { 442 if (base::MessageLoop::current()->type() != base::MessageLoop::TYPE_UI) {
443 DVLOG(1) << "Do not use TSFBridge without UI thread."; 443 DVLOG(1) << "Do not use TSFBridge without UI thread.";
444 return false; 444 return false;
445 } 445 }
446 if (!tls_tsf_bridge.initialized()) { 446 if (!tls_tsf_bridge.initialized()) {
447 tls_tsf_bridge.Initialize(TSFBridge::Finalize); 447 tls_tsf_bridge.Initialize(TSFBridge::Finalize);
448 TSFBridgeDelegate* delegate = new TSFBridgeDelegate(); 448 TSFBridgeDelegate* delegate = new TSFBridgeDelegate();
449 tls_tsf_bridge.Set(delegate); 449 tls_tsf_bridge.Set(delegate);
450 return delegate->Initialize(); 450 return delegate->Initialize();
451 } 451 }
452 return true; 452 return true;
453 } 453 }
454 454
455 // static 455 // static
456 TSFBridge* TSFBridge::ReplaceForTesting(TSFBridge* bridge) { 456 TSFBridge* TSFBridge::ReplaceForTesting(TSFBridge* bridge) {
457 if (MessageLoop::current()->type() != MessageLoop::TYPE_UI) { 457 if (base::MessageLoop::current()->type() != base::MessageLoop::TYPE_UI) {
458 DVLOG(1) << "Do not use TSFBridge without UI thread."; 458 DVLOG(1) << "Do not use TSFBridge without UI thread.";
459 return NULL; 459 return NULL;
460 } 460 }
461 TSFBridge* old_bridge = TSFBridge::GetInstance(); 461 TSFBridge* old_bridge = TSFBridge::GetInstance();
462 tls_tsf_bridge.Set(bridge); 462 tls_tsf_bridge.Set(bridge);
463 return old_bridge; 463 return old_bridge;
464 } 464 }
465 465
466 // static 466 // static
467 TSFBridge* TSFBridge::GetInstance() { 467 TSFBridge* TSFBridge::GetInstance() {
468 if (MessageLoop::current()->type() != MessageLoop::TYPE_UI) { 468 if (base::MessageLoop::current()->type() != base::MessageLoop::TYPE_UI) {
469 DVLOG(1) << "Do not use TSFBridge without UI thread."; 469 DVLOG(1) << "Do not use TSFBridge without UI thread.";
470 return NULL; 470 return NULL;
471 } 471 }
472 TSFBridgeDelegate* delegate = 472 TSFBridgeDelegate* delegate =
473 static_cast<TSFBridgeDelegate*>(tls_tsf_bridge.Get()); 473 static_cast<TSFBridgeDelegate*>(tls_tsf_bridge.Get());
474 DCHECK(delegate) << "Do no call GetInstance before TSFBridge::Initialize."; 474 DCHECK(delegate) << "Do no call GetInstance before TSFBridge::Initialize.";
475 return delegate; 475 return delegate;
476 } 476 }
477 477
478 // static 478 // static
479 void TSFBridge::Finalize(void* data) { 479 void TSFBridge::Finalize(void* data) {
480 TSFBridgeDelegate* delegate = static_cast<TSFBridgeDelegate*>(data); 480 TSFBridgeDelegate* delegate = static_cast<TSFBridgeDelegate*>(data);
481 delete delegate; 481 delete delegate;
482 } 482 }
483 483
484 } // namespace ui 484 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_win.cc ('k') | ui/base/models/simple_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698