diff options
-rw-r--r-- | chromeos/chromeos.gyp | 2 | ||||
-rw-r--r-- | chromeos/ime/ibus_bridge.cc | 107 | ||||
-rw-r--r-- | chromeos/ime/ibus_bridge.h | 79 |
3 files changed, 188 insertions, 0 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 2139970..7c4c241 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -127,6 +127,8 @@ 'disks/disk_mount_manager.h', 'display/output_configurator.cc', 'display/output_configurator.h', + 'ime/ibus_bridge.cc', + 'ime/ibus_bridge.h', 'ime/ibus_daemon_controller.cc', 'ime/ibus_daemon_controller.h', 'network/cros_network_functions.cc', diff --git a/chromeos/ime/ibus_bridge.cc b/chromeos/ime/ibus_bridge.cc new file mode 100644 index 0000000..52b5423 --- /dev/null +++ b/chromeos/ime/ibus_bridge.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromeos/ime/ibus_bridge.h" + +#include "base/logging.h" +#include "base/memory/singleton.h" + +namespace chromeos { + +static IBusBridge* g_ibus_bridge = NULL; + +// An implementation of IBusBridge. +class IBusBridgeImpl : public IBusBridge { + public: + IBusBridgeImpl() + : input_context_handler_(NULL), + engine_handler_(NULL), + candidate_window_handler_(NULL), + panel_handler_(NULL) { + } + + virtual ~IBusBridgeImpl() { + } + + // IBusBridge override. + virtual IBusInputContextHandlerInterface* + GetInputContextHandler() const OVERRIDE { + return input_context_handler_; + } + + // IBusBridge override. + void SetInputContextHandler( + IBusInputContextHandlerInterface* handler) OVERRIDE { + input_context_handler_ = handler; + } + + // IBusBridge override. + IBusEngineHandlerInterface* GetEngineHandler() const { + return engine_handler_; + } + + // IBusBridge override. + void SetEngineHandler(IBusEngineHandlerInterface* handler) { + engine_handler_ = handler; + } + + // IBusBridge override. + IBusPanelCandidateWindowHandlerInterface* GetCandidateWindowHandler() const { + return candidate_window_handler_; + } + + // IBusBridge override. + void SetCandidateWindowHandler( + IBusPanelCandidateWindowHandlerInterface* handler) { + candidate_window_handler_ = handler; + } + + // IBusBridge override. + IBusPanelPropertyHandlerInterface* GetPanelHandler() const { + return panel_handler_; + } + + // IBusBridge override. + void SetPanelHandler(IBusPanelPropertyHandlerInterface* handler) { + panel_handler_ = handler; + } + + private: + IBusInputContextHandlerInterface* input_context_handler_; + IBusEngineHandlerInterface* engine_handler_; + IBusPanelCandidateWindowHandlerInterface* candidate_window_handler_; + IBusPanelPropertyHandlerInterface* panel_handler_; + + DISALLOW_COPY_AND_ASSIGN(IBusBridgeImpl); +}; + +/////////////////////////////////////////////////////////////////////////////// +// IBusBridge +IBusBridge::IBusBridge() { +} + +IBusBridge::~IBusBridge() { +} + +// static. +void IBusBridge::Initialize() { + CHECK(!g_ibus_bridge) << "Already initialized."; + g_ibus_bridge = new IBusBridgeImpl(); +} + +// static. +void IBusBridge::Shutdown() { + CHECK(g_ibus_bridge) << "Shutdown called before Initialize()."; + delete g_ibus_bridge; + g_ibus_bridge = NULL; +} + +// static. +IBusBridge* IBusBridge::Get() { + CHECK(g_ibus_bridge) + << "IBusBrige::Get() called before Initialized() or after Shutdown()."; + return g_ibus_bridge; +} + +} // namespace chromeos diff --git a/chromeos/ime/ibus_bridge.h b/chromeos/ime/ibus_bridge.h new file mode 100644 index 0000000..075bcd0 --- /dev/null +++ b/chromeos/ime/ibus_bridge.h @@ -0,0 +1,79 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMEOS_IME_IBUS_BRIDGE_H_ +#define CHROMEOS_IME_IBUS_BRIDGE_H_ + +#include <string> +#include "base/basictypes.h" + +namespace chromeos { +class IBusInputContextHandlerInterface; +class IBusEngineHandlerInterface; +class IBusPanelCandidateWindowHandlerInterface; +class IBusPanelPropertyHandlerInterface; + +// IBusBridge provides access of each IME related handler. This class is used +// for IME implementation without ibus-daemon. The legacy ibus IME communicates +// their engine with dbus protocol, but new implementation doesn't. Instead of +// dbus communcation, new implementation calls target service(e.g. PanelService +// or EngineService) directly by using this class. +class IBusBridge { + public: + virtual ~IBusBridge(); + + // Allocates the global instance. Must be called before any calls to Get(). + static void Initialize(); + + // Releases the global instance. + static void Shutdown(); + + // Returns IBusBridge global instance. Initialize() must be called first. + static IBusBridge* Get(); + + // Returns current InputContextHandler. This function returns NULL if input + // context is not ready to use. + virtual IBusInputContextHandlerInterface* GetInputContextHandler() const = 0; + + // Updates current InputContextHandler. If there is no active input context, + // pass NULL for |handler|. Caller must release |handler|. + virtual void SetInputContextHandler( + IBusInputContextHandlerInterface* handler) = 0; + + // Returns current EngineHandler. This function returns NULL if current engine + // is not ready to use. + virtual IBusEngineHandlerInterface* GetEngineHandler() const = 0; + + // Updates current EngineHandler. If there is no active engine service, pass + // NULL for |handler|. Caller must release |handler|. + virtual void SetEngineHandler(IBusEngineHandlerInterface* handler) = 0; + + // Returns current CandidateWindowHandler. This function returns NULL if + // current candidate window is not ready to use. + virtual IBusPanelCandidateWindowHandlerInterface* + GetCandidateWindowHandler() const = 0; + + // Updates current CandidatWindowHandler. If there is no active candidate + // window service, pass NULL for |handler|. Caller must release |handler|. + virtual void SetCandidateWindowHandler( + IBusPanelCandidateWindowHandlerInterface* handler) = 0; + + // Returns current PropertyHandler. This function returns NULL if panel window + // is not ready to use. + virtual IBusPanelPropertyHandlerInterface* GetPanelHandler() const = 0; + + // Updates current PropertyHandler. If there is no active property service, + // pass NULL for |handler|. Caller must release |handler|. + virtual void SetPanelHandler(IBusPanelPropertyHandlerInterface* handler) = 0; + + protected: + IBusBridge(); + + private: + DISALLOW_COPY_AND_ASSIGN(IBusBridge); +}; + +} // namespace chromeos + +#endif // CHROMEOS_IME_IBUS_BRIDGE_H_ |