diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 22:16:23 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 22:16:23 +0000 |
commit | 393a331ee18d32236436805a3a41d786d39b1204 (patch) | |
tree | 98497cdf5d71b53c0a023eeead68f7c8b5ddae62 /chromeos | |
parent | 12e74bbd334775bd1961464e22085c551703ecb2 (diff) | |
download | chromium_src-393a331ee18d32236436805a3a41d786d39b1204.zip chromium_src-393a331ee18d32236436805a3a41d786d39b1204.tar.gz chromium_src-393a331ee18d32236436805a3a41d786d39b1204.tar.bz2 |
Introduce IBusBridge for ibus-less implementation.
IBusBridge provides access of each ibus event handler.
This patch is second try of https://codereview.chromium.org/11956041/
Using singleton in chromeos/ directory breaks component build.
BUG=170671
TEST=None
Review URL: https://chromiumcodereview.appspot.com/12088085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181372 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-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_ |