Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / ime / chromeos / ime_bridge.cc
bloba5c660c36a900d6acdea29390f11ddc9023e6e00
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.
5 #include "ui/base/ime/chromeos/ime_bridge.h"
7 #include <map>
8 #include "base/logging.h"
9 #include "base/memory/singleton.h"
11 namespace chromeos {
13 static IMEBridge* g_ime_bridge = NULL;
15 // An implementation of IMEBridge.
16 class IMEBridgeImpl : public IMEBridge {
17 public:
18 IMEBridgeImpl()
19 : input_context_handler_(NULL),
20 engine_handler_(NULL),
21 candidate_window_handler_(NULL),
22 current_input_context_(ui::TEXT_INPUT_TYPE_NONE,
23 ui::TEXT_INPUT_MODE_DEFAULT,
24 0) {}
26 ~IMEBridgeImpl() override {}
28 // IMEBridge override.
29 IMEInputContextHandlerInterface* GetInputContextHandler() const override {
30 return input_context_handler_;
33 // IMEBridge override.
34 void SetInputContextHandler(
35 IMEInputContextHandlerInterface* handler) override {
36 input_context_handler_ = handler;
39 // IMEBridge override.
40 void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) override {
41 engine_handler_ = handler;
44 // IMEBridge override.
45 IMEEngineHandlerInterface* GetCurrentEngineHandler() const override {
46 return engine_handler_;
49 // IMEBridge override.
50 IMECandidateWindowHandlerInterface* GetCandidateWindowHandler()
51 const override {
52 return candidate_window_handler_;
55 // IMEBridge override.
56 void SetCandidateWindowHandler(
57 IMECandidateWindowHandlerInterface* handler) override {
58 candidate_window_handler_ = handler;
61 // IMEBridge override.
62 void SetCurrentInputContext(
63 const IMEEngineHandlerInterface::InputContext& input_context) override {
64 current_input_context_ = input_context;
67 // IMEBridge override.
68 const IMEEngineHandlerInterface::InputContext& GetCurrentInputContext()
69 const override {
70 return current_input_context_;
73 private:
74 IMEInputContextHandlerInterface* input_context_handler_;
75 IMEEngineHandlerInterface* engine_handler_;
76 IMECandidateWindowHandlerInterface* candidate_window_handler_;
77 IMEEngineHandlerInterface::InputContext current_input_context_;
79 DISALLOW_COPY_AND_ASSIGN(IMEBridgeImpl);
82 ///////////////////////////////////////////////////////////////////////////////
83 // IMEBridge
84 IMEBridge::IMEBridge() {
87 IMEBridge::~IMEBridge() {
90 // static.
91 void IMEBridge::Initialize() {
92 if (!g_ime_bridge)
93 g_ime_bridge = new IMEBridgeImpl();
96 // static.
97 void IMEBridge::Shutdown() {
98 delete g_ime_bridge;
99 g_ime_bridge = NULL;
102 // static.
103 IMEBridge* IMEBridge::Get() {
104 return g_ime_bridge;
107 } // namespace chromeos