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

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

Issue 80583002: [FYI] All-in-one OnCandidateWindow{Show,Update,Hide} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update Created 7 years 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/ime/win/tsf_bridge.h ('k') | ui/views/ime/input_method_bridge.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/bind.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
13 #include "base/threading/thread_local_storage.h" 15 #include "base/threading/thread_local_storage.h"
14 #include "base/win/scoped_comptr.h" 16 #include "base/win/scoped_comptr.h"
15 #include "base/win/scoped_variant.h" 17 #include "base/win/scoped_variant.h"
16 #include "ui/base/ime/text_input_client.h" 18 #include "ui/base/ime/text_input_client.h"
17 #include "ui/base/ime/win/tsf_bridge.h" 19 #include "ui/base/ime/win/tsf_bridge.h"
18 #include "ui/base/ime/win/tsf_text_store.h" 20 #include "ui/base/ime/win/tsf_text_store.h"
19 21
20 namespace ui { 22 namespace ui {
21 23
22 namespace { 24 namespace {
23 25
24 // We use thread local storage for TSFBridge lifespan management. 26 // We use thread local storage for TSFBridge lifespan management.
25 base::ThreadLocalStorage::StaticSlot tls_tsf_bridge = TLS_INITIALIZER; 27 base::ThreadLocalStorage::StaticSlot tls_tsf_bridge = TLS_INITIALIZER;
26 28
27 29
28 // TsfBridgeDelegate ----------------------------------------------------------- 30 // TsfBridgeDelegate -----------------------------------------------------------
29 31
30 // A TLS implementation of TSFBridge. 32 // A TLS implementation of TSFBridge.
31 class TSFBridgeDelegate : public TSFBridge { 33 class TSFBridgeDelegate : public TSFBridge,
34 public base::SupportsWeakPtr<TSFBridgeDelegate> {
32 public: 35 public:
33 TSFBridgeDelegate(); 36 TSFBridgeDelegate();
34 virtual ~TSFBridgeDelegate(); 37 virtual ~TSFBridgeDelegate();
35 38
36 bool Initialize(); 39 bool Initialize();
37 40
38 // TsfBridge: 41 // TsfBridge:
39 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE; 42 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE;
40 virtual void OnTextLayoutChanged() OVERRIDE; 43 virtual void OnTextLayoutChanged() OVERRIDE;
41 virtual bool CancelComposition() OVERRIDE; 44 virtual bool CancelComposition() OVERRIDE;
42 virtual bool ConfirmComposition() OVERRIDE; 45 virtual bool ConfirmComposition() OVERRIDE;
43 virtual void SetFocusedClient(HWND focused_window, 46 virtual void SetFocusedClient(HWND focused_window,
44 TextInputClient* client) OVERRIDE; 47 TextInputClient* client) OVERRIDE;
45 virtual void RemoveFocusedClient(TextInputClient* client) OVERRIDE; 48 virtual void RemoveFocusedClient(TextInputClient* client) OVERRIDE;
46 virtual base::win::ScopedComPtr<ITfThreadMgr> GetThreadManager() OVERRIDE; 49 virtual base::win::ScopedComPtr<ITfThreadMgr> GetThreadManager() OVERRIDE;
47 virtual TextInputClient* GetFocusedTextInputClient() const OVERRIDE; 50 virtual TextInputClient* GetFocusedTextInputClient() const OVERRIDE;
48 51
52 // See also *Callback functions below. To avoid reentrancy issue that
53 // TextInputClient manipulates IME state during even handling, these methods
54 // defer sending actual signals to renderer.
55 virtual void OnCandidateWindowShown() OVERRIDE;
56 virtual void OnCandidateWindowUpdated() OVERRIDE;
57 virtual void OnCandidateWindowHidden() OVERRIDE;
58
49 private: 59 private:
50 // Returns true if |tsf_document_map_| is successfully initialized. This 60 // Returns true if |tsf_document_map_| is successfully initialized. This
51 // method should be called from and only from Initialize(). 61 // method should be called from and only from Initialize().
52 bool InitializeDocumentMapInternal(); 62 bool InitializeDocumentMapInternal();
53 63
54 // Returns true if |context| is successfully updated to be a disabled 64 // Returns true if |context| is successfully updated to be a disabled
55 // context, where an IME should be deactivated. This is suitable for some 65 // context, where an IME should be deactivated. This is suitable for some
56 // special input context such as password fields. 66 // special input context such as password fields.
57 bool InitializeDisabledContext(ITfContext* context); 67 bool InitializeDisabledContext(ITfContext* context);
58 68
(...skipping 24 matching lines...) Expand all
83 // TSFBridge::SetFocusedClient is called first then the target window 93 // TSFBridge::SetFocusedClient is called first then the target window
84 // receives WM_ACTIVATE. This actually occurs in Aura environment where 94 // receives WM_ACTIVATE. This actually occurs in Aura environment where
85 // WM_NCACTIVATE is used as a trigger to restore text input focus. 95 // WM_NCACTIVATE is used as a trigger to restore text input focus.
86 // Caveats: 96 // Caveats:
87 // TSF runtime does not increment the reference count of the attached 97 // TSF runtime does not increment the reference count of the attached
88 // document manager. See the comment inside the method body for 98 // document manager. See the comment inside the method body for
89 // details. 99 // details.
90 void UpdateAssociateFocus(); 100 void UpdateAssociateFocus();
91 void ClearAssociateFocus(); 101 void ClearAssociateFocus();
92 102
103 // Deferred callbacks for signalling TextInputClient about candidate window
104 // appearance changes.
105 void CandidateWindowShownCallback();
106 void CandidateWindowUpdatedCallback();
107 void CandidateWindowHiddenCallback();
108
93 // A triple of document manager, text store and binding cookie between 109 // A triple of document manager, text store and binding cookie between
94 // a context owned by the document manager and the text store. This is a 110 // a context owned by the document manager and the text store. This is a
95 // minimum working set of an editable document in TSF. 111 // minimum working set of an editable document in TSF.
96 struct TSFDocument { 112 struct TSFDocument {
97 public: 113 public:
98 TSFDocument() : cookie(TF_INVALID_COOKIE) {} 114 TSFDocument() : cookie(TF_INVALID_COOKIE) {}
99 TSFDocument(const TSFDocument& src) 115 TSFDocument(const TSFDocument& src)
100 : document_manager(src.document_manager), 116 : document_manager(src.document_manager),
101 cookie(src.cookie) {} 117 cookie(src.cookie) {}
102 base::win::ScopedComPtr<ITfDocumentMgr> document_manager; 118 base::win::ScopedComPtr<ITfDocumentMgr> document_manager;
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 if (it == tsf_document_map_.end()) { 493 if (it == tsf_document_map_.end()) {
478 it = tsf_document_map_.find(TEXT_INPUT_TYPE_TEXT); 494 it = tsf_document_map_.find(TEXT_INPUT_TYPE_TEXT);
479 // This check is necessary because it's possible that we failed to 495 // This check is necessary because it's possible that we failed to
480 // initialize |tsf_document_map_| and it has no TEXT_INPUT_TYPE_TEXT. 496 // initialize |tsf_document_map_| and it has no TEXT_INPUT_TYPE_TEXT.
481 if (it == tsf_document_map_.end()) 497 if (it == tsf_document_map_.end())
482 return NULL; 498 return NULL;
483 } 499 }
484 return &it->second; 500 return &it->second;
485 } 501 }
486 502
503 void TSFBridgeDelegate::OnCandidateWindowShown() {
504 base::MessageLoop::current()->PostTask(
505 FROM_HERE,
506 base::Bind(&TSFBridgeDelegate::CandidateWindowShownCallback,
507 AsWeakPtr()));
508 }
509
510 void TSFBridgeDelegate::OnCandidateWindowUpdated() {
511 base::MessageLoop::current()->PostTask(
512 FROM_HERE,
513 base::Bind(&TSFBridgeDelegate::CandidateWindowUpdatedCallback,
514 AsWeakPtr()));
515 }
516
517 void TSFBridgeDelegate::OnCandidateWindowHidden() {
518 base::MessageLoop::current()->PostTask(
519 FROM_HERE,
520 base::Bind(&TSFBridgeDelegate::CandidateWindowHiddenCallback,
521 AsWeakPtr()));
522 }
523
524 void TSFBridgeDelegate::CandidateWindowShownCallback() {
525 TextInputClient* client = GetFocusedTextInputClient();
526 if (client)
527 client->OnCandidateWindowShown();
528 }
529
530 void TSFBridgeDelegate::CandidateWindowUpdatedCallback() {
531 TextInputClient* client = GetFocusedTextInputClient();
532 if (client)
533 client->OnCandidateWindowUpdated();
534 }
535
536 void TSFBridgeDelegate::CandidateWindowHiddenCallback() {
537 TextInputClient* client = GetFocusedTextInputClient();
538 if (client)
539 client->OnCandidateWindowHidden();
540 }
541
487 } // namespace 542 } // namespace
488 543
489 544
490 // TsfBridge ----------------------------------------------------------------- 545 // TsfBridge -----------------------------------------------------------------
491 546
492 TSFBridge::TSFBridge() { 547 TSFBridge::TSFBridge() {
493 } 548 }
494 549
495 TSFBridge::~TSFBridge() { 550 TSFBridge::~TSFBridge() {
496 } 551 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return delegate; 604 return delegate;
550 } 605 }
551 606
552 // static 607 // static
553 void TSFBridge::Finalize(void* data) { 608 void TSFBridge::Finalize(void* data) {
554 TSFBridgeDelegate* delegate = static_cast<TSFBridgeDelegate*>(data); 609 TSFBridgeDelegate* delegate = static_cast<TSFBridgeDelegate*>(data);
555 delete delegate; 610 delete delegate;
556 } 611 }
557 612
558 } // namespace ui 613 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/win/tsf_bridge.h ('k') | ui/views/ime/input_method_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698