Home | History | Annotate | Download | only in input_method
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_BASE_H_
      6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_BASE_H_
      7 
      8 #include <map>
      9 #include <utility>
     10 
     11 #include "base/observer_list.h"
     12 #include "chrome/browser/chromeos/input_method/ibus_controller.h"
     13 #include "chromeos/ime/input_method_config.h"
     14 #include "chromeos/ime/input_method_property.h"
     15 
     16 namespace chromeos {
     17 namespace input_method {
     18 
     19 // The common implementation of the IBusController. This file does not depend on
     20 // libibus, hence is unit-testable.
     21 class IBusControllerBase : public IBusController {
     22  public:
     23   IBusControllerBase();
     24   virtual ~IBusControllerBase();
     25 
     26   // IBusController overrides. Derived classes should not override these 4
     27   // functions.
     28   virtual void AddObserver(Observer* observer) OVERRIDE;
     29   virtual void RemoveObserver(Observer* observer) OVERRIDE;
     30   virtual bool SetInputMethodConfig(
     31       const std::string& section,
     32       const std::string& config_name,
     33       const InputMethodConfigValue& value) OVERRIDE;
     34   virtual const InputMethodPropertyList& GetCurrentProperties() const OVERRIDE;
     35   virtual void ClearProperties() OVERRIDE;
     36 
     37   // Gets the current input method configuration.
     38   bool GetInputMethodConfigForTesting(const std::string& section,
     39                                       const std::string& config_name,
     40                                       InputMethodConfigValue* out_value);
     41 
     42   // Notifies all |observers_|.
     43   void NotifyPropertyChangedForTesting();
     44 
     45   // Updates |current_property_list_|.
     46   void SetCurrentPropertiesForTesting(
     47       const InputMethodPropertyList& current_property_list);
     48 
     49  protected:
     50   typedef std::pair<std::string, std::string> ConfigKeyType;
     51   typedef std::map<
     52     ConfigKeyType, InputMethodConfigValue> InputMethodConfigRequests;
     53 
     54   virtual bool SetInputMethodConfigInternal(
     55       const ConfigKeyType& key,
     56       const InputMethodConfigValue& value) = 0;
     57 
     58   ObserverList<Observer> observers_;
     59 
     60   // Values that have been set via SetInputMethodConfig(). We keep a copy
     61   // available to (re)send when the system input method framework (re)starts.
     62   InputMethodConfigRequests current_config_values_;
     63 
     64   // The value which will be returned by GetCurrentProperties(). Derived classes
     65   // should update this variable when needed.
     66   InputMethodPropertyList current_property_list_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(IBusControllerBase);
     69 };
     70 
     71 }  // namespace input_method
     72 }  // namespace chromeos
     73 
     74 #endif  // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_BASE_H_
     75