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 <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 26 matching lines...) Expand all Loading... |
37 bool Initialize(); | 37 bool Initialize(); |
38 | 38 |
39 // TsfBridge: | 39 // TsfBridge: |
40 virtual void Shutdown() OVERRIDE; | 40 virtual void Shutdown() OVERRIDE; |
41 virtual void OnTextInputTypeChanged(TextInputClient* client) OVERRIDE; | 41 virtual void OnTextInputTypeChanged(TextInputClient* client) OVERRIDE; |
42 virtual bool CancelComposition() OVERRIDE; | 42 virtual bool CancelComposition() OVERRIDE; |
43 virtual void SetFocusedClient(HWND focused_window, | 43 virtual void SetFocusedClient(HWND focused_window, |
44 TextInputClient* client) OVERRIDE; | 44 TextInputClient* client) OVERRIDE; |
45 virtual void RemoveFocusedClient(TextInputClient* client) OVERRIDE; | 45 virtual void RemoveFocusedClient(TextInputClient* client) OVERRIDE; |
46 virtual base::win::ScopedComPtr<ITfThreadMgr> GetThreadManager() OVERRIDE; | 46 virtual base::win::ScopedComPtr<ITfThreadMgr> GetThreadManager() OVERRIDE; |
| 47 virtual TextInputClient* GetFocusedTextInputClient() const OVERRIDE; |
47 | 48 |
48 private: | 49 private: |
49 friend struct DefaultSingletonTraits<TSFBridgeDelegate>; | 50 friend struct DefaultSingletonTraits<TSFBridgeDelegate>; |
50 | 51 |
51 // Returns true if |tsf_document_map_| is successfully initialized. This | 52 // Returns true if |tsf_document_map_| is successfully initialized. This |
52 // method should be called from and only from Initialize(). | 53 // method should be called from and only from Initialize(). |
53 bool InitializeDocumentMapInternal(); | 54 bool InitializeDocumentMapInternal(); |
54 | 55 |
55 // Returns true if |context| is successfully updated to be a disabled | 56 // Returns true if |context| is successfully updated to be a disabled |
56 // context, where an IME should be deactivated. This is suitable for some | 57 // context, where an IME should be deactivated. This is suitable for some |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return; | 266 return; |
266 client_ = NULL; | 267 client_ = NULL; |
267 for (TSFDocumentMap::iterator it = tsf_document_map_.begin(); | 268 for (TSFDocumentMap::iterator it = tsf_document_map_.begin(); |
268 it != tsf_document_map_.end(); ++it) { | 269 it != tsf_document_map_.end(); ++it) { |
269 if (it->second.text_store.get() == NULL) | 270 if (it->second.text_store.get() == NULL) |
270 continue; | 271 continue; |
271 it->second.text_store->SetFocusedTextInputClient(NULL, NULL); | 272 it->second.text_store->SetFocusedTextInputClient(NULL, NULL); |
272 } | 273 } |
273 } | 274 } |
274 | 275 |
| 276 TextInputClient* TSFBridgeDelegate::GetFocusedTextInputClient() const { |
| 277 return client_; |
| 278 } |
| 279 |
275 base::win::ScopedComPtr<ITfThreadMgr> TSFBridgeDelegate::GetThreadManager() { | 280 base::win::ScopedComPtr<ITfThreadMgr> TSFBridgeDelegate::GetThreadManager() { |
276 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); | 281 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
277 DCHECK(IsInitialized()); | 282 DCHECK(IsInitialized()); |
278 return thread_manager_; | 283 return thread_manager_; |
279 } | 284 } |
280 | 285 |
281 bool TSFBridgeDelegate::CreateDocumentManager(TSFTextStore* text_store, | 286 bool TSFBridgeDelegate::CreateDocumentManager(TSFTextStore* text_store, |
282 ITfDocumentMgr** document_manager, | 287 ITfDocumentMgr** document_manager, |
283 ITfContext** context, | 288 ITfContext** context, |
284 DWORD* source_cookie) { | 289 DWORD* source_cookie) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 436 |
432 TSFBridge::~TSFBridge() { | 437 TSFBridge::~TSFBridge() { |
433 } | 438 } |
434 | 439 |
435 // static | 440 // static |
436 bool TSFBridge::Initialize() { | 441 bool TSFBridge::Initialize() { |
437 if (MessageLoop::current()->type() != MessageLoop::TYPE_UI) { | 442 if (MessageLoop::current()->type() != MessageLoop::TYPE_UI) { |
438 DVLOG(1) << "Do not use TSFBridge without UI thread."; | 443 DVLOG(1) << "Do not use TSFBridge without UI thread."; |
439 return false; | 444 return false; |
440 } | 445 } |
441 tls_tsf_bridge.Initialize(TSFBridge::Finalize); | 446 if (!tls_tsf_bridge.initialized()) { |
442 TSFBridgeDelegate* delegate = new TSFBridgeDelegate(); | 447 tls_tsf_bridge.Initialize(TSFBridge::Finalize); |
443 tls_tsf_bridge.Set(delegate); | 448 TSFBridgeDelegate* delegate = new TSFBridgeDelegate(); |
444 return delegate->Initialize(); | 449 tls_tsf_bridge.Set(delegate); |
| 450 return delegate->Initialize(); |
| 451 } |
| 452 return true; |
445 } | 453 } |
446 | 454 |
447 // static | 455 // static |
448 TSFBridge* TSFBridge::ReplaceForTesting(TSFBridge* bridge) { | 456 TSFBridge* TSFBridge::ReplaceForTesting(TSFBridge* bridge) { |
449 if (MessageLoop::current()->type() != MessageLoop::TYPE_UI) { | 457 if (MessageLoop::current()->type() != MessageLoop::TYPE_UI) { |
450 DVLOG(1) << "Do not use TSFBridge without UI thread."; | 458 DVLOG(1) << "Do not use TSFBridge without UI thread."; |
451 return NULL; | 459 return NULL; |
452 } | 460 } |
453 TSFBridge* old_bridge = TSFBridge::GetInstance(); | 461 TSFBridge* old_bridge = TSFBridge::GetInstance(); |
454 tls_tsf_bridge.Set(bridge); | 462 tls_tsf_bridge.Set(bridge); |
(...skipping 12 matching lines...) Expand all Loading... |
467 return delegate; | 475 return delegate; |
468 } | 476 } |
469 | 477 |
470 // static | 478 // static |
471 void TSFBridge::Finalize(void* data) { | 479 void TSFBridge::Finalize(void* data) { |
472 TSFBridgeDelegate* delegate = static_cast<TSFBridgeDelegate*>(data); | 480 TSFBridgeDelegate* delegate = static_cast<TSFBridgeDelegate*>(data); |
473 delete delegate; | 481 delete delegate; |
474 } | 482 } |
475 | 483 |
476 } // namespace ui | 484 } // namespace ui |
OLD | NEW |