- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / input_method / ibus_controller_impl.cc
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 #include "chrome/browser/chromeos/input_method/ibus_controller_impl.h"
6
7 #include <algorithm>  // for std::reverse.
8 #include <cstdio>
9 #include <cstring>  // for std::strcmp.
10 #include <set>
11 #include <sstream>
12 #include <stack>
13 #include <utility>
14
15 #include "ash/shell.h"
16 #include "base/bind.h"
17 #include "base/environment.h"
18 #include "base/files/file_path_watcher.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/message_loop/message_loop.h"
21 #include "base/rand_util.h"
22 #include "base/strings/string_split.h"
23 #include "base/strings/stringprintf.h"
24 #include "chrome/browser/chromeos/input_method/input_method_util.h"
25 #include "chromeos/ime/component_extension_ime_manager.h"
26 #include "chromeos/ime/extension_ime_util.h"
27 #include "chromeos/ime/ibus_bridge.h"
28 #include "chromeos/ime/ime_constants.h"
29 #include "chromeos/ime/input_method_config.h"
30 #include "chromeos/ime/input_method_property.h"
31 #include "ui/aura/client/aura_constants.h"
32 #include "ui/aura/root_window.h"
33 #include "ui/base/ime/input_method_ibus.h"
34
35 namespace chromeos {
36 namespace input_method {
37
38 IBusControllerImpl::IBusControllerImpl() {
39   IBusBridge::Get()->SetPropertyHandler(this);
40 }
41
42 IBusControllerImpl::~IBusControllerImpl() {
43   IBusBridge::Get()->SetPropertyHandler(NULL);
44 }
45
46 bool IBusControllerImpl::ActivateInputMethodProperty(const std::string& key) {
47   // The third parameter of ibus_input_context_property_activate() has to be
48   // true when the |key| points to a radio button. false otherwise.
49   bool found = false;
50   for (size_t i = 0; i < current_property_list_.size(); ++i) {
51     if (current_property_list_[i].key == key) {
52       found = true;
53       break;
54     }
55   }
56   if (!found) {
57     DVLOG(1) << "ActivateInputMethodProperty: unknown key: " << key;
58     return false;
59   }
60
61   IBusEngineHandlerInterface* engine = IBusBridge::Get()->GetEngineHandler();
62   if (engine)
63     engine->PropertyActivate(key);
64   return true;
65 }
66
67 void IBusControllerImpl::AddObserver(Observer* observer) {
68   observers_.AddObserver(observer);
69 }
70
71 void IBusControllerImpl::RemoveObserver(Observer* observer) {
72   observers_.RemoveObserver(observer);
73 }
74
75 const InputMethodPropertyList&
76 IBusControllerImpl::GetCurrentProperties() const {
77   return current_property_list_;
78 }
79
80 void IBusControllerImpl::ClearProperties() {
81   current_property_list_.clear();
82 }
83
84 void IBusControllerImpl::RegisterProperties(
85     const InputMethodPropertyList& property_list) {
86   current_property_list_ = property_list;
87   FOR_EACH_OBSERVER(IBusController::Observer, observers_, PropertyChanged());
88 }
89
90 }  // namespace input_method
91 }  // namespace chromeos