• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "ui/base/ime/chromeos/ime_bridge.h"
6 
7 #include <map>
8 #include "base/logging.h"
9 #include "base/memory/singleton.h"
10 
11 namespace chromeos {
12 
13 static IMEBridge* g_ime_bridge = NULL;
14 
15 // An implementation of IMEBridge.
16 class IMEBridgeImpl : public IMEBridge {
17  public:
IMEBridgeImpl()18   IMEBridgeImpl()
19     : input_context_handler_(NULL),
20       engine_handler_(NULL),
21       candidate_window_handler_(NULL),
22       current_text_input_(ui::TEXT_INPUT_TYPE_NONE) {
23   }
24 
~IMEBridgeImpl()25   virtual ~IMEBridgeImpl() {
26   }
27 
28   // IMEBridge override.
29   virtual IMEInputContextHandlerInterface*
GetInputContextHandler() const30       GetInputContextHandler() const OVERRIDE {
31     return input_context_handler_;
32   }
33 
34   // IMEBridge override.
SetInputContextHandler(IMEInputContextHandlerInterface * handler)35   virtual void SetInputContextHandler(
36       IMEInputContextHandlerInterface* handler) OVERRIDE {
37     input_context_handler_ = handler;
38   }
39 
40   // IMEBridge override.
SetCurrentEngineHandler(IMEEngineHandlerInterface * handler)41   virtual void SetCurrentEngineHandler(
42       IMEEngineHandlerInterface* handler) OVERRIDE {
43     engine_handler_ = handler;
44   }
45 
46   // IMEBridge override.
GetCurrentEngineHandler() const47   virtual IMEEngineHandlerInterface* GetCurrentEngineHandler() const OVERRIDE {
48     return engine_handler_;
49   }
50 
51   // IMEBridge override.
GetCandidateWindowHandler() const52   virtual IMECandidateWindowHandlerInterface* GetCandidateWindowHandler() const
53       OVERRIDE {
54     return candidate_window_handler_;
55   }
56 
57   // IMEBridge override.
SetCandidateWindowHandler(IMECandidateWindowHandlerInterface * handler)58   virtual void SetCandidateWindowHandler(
59       IMECandidateWindowHandlerInterface* handler) OVERRIDE {
60     candidate_window_handler_ = handler;
61   }
62 
63   // IMEBridge override.
SetCurrentTextInputType(ui::TextInputType input_type)64   virtual void SetCurrentTextInputType(ui::TextInputType input_type) OVERRIDE {
65     current_text_input_ = input_type;
66   }
67 
68   // IMEBridge override.
GetCurrentTextInputType() const69   virtual ui::TextInputType GetCurrentTextInputType() const OVERRIDE {
70     return current_text_input_;
71   }
72 
73  private:
74   IMEInputContextHandlerInterface* input_context_handler_;
75   IMEEngineHandlerInterface* engine_handler_;
76   IMECandidateWindowHandlerInterface* candidate_window_handler_;
77   ui::TextInputType current_text_input_;
78 
79   DISALLOW_COPY_AND_ASSIGN(IMEBridgeImpl);
80 };
81 
82 ///////////////////////////////////////////////////////////////////////////////
83 // IMEBridge
IMEBridge()84 IMEBridge::IMEBridge() {
85 }
86 
~IMEBridge()87 IMEBridge::~IMEBridge() {
88 }
89 
90 // static.
Initialize()91 void IMEBridge::Initialize() {
92   if (!g_ime_bridge)
93     g_ime_bridge = new IMEBridgeImpl();
94 }
95 
96 // static.
Shutdown()97 void IMEBridge::Shutdown() {
98   delete g_ime_bridge;
99   g_ime_bridge = NULL;
100 }
101 
102 // static.
Get()103 IMEBridge* IMEBridge::Get() {
104   return g_ime_bridge;
105 }
106 
107 }  // namespace chromeos
108