OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // TODO(nona): Remvoe IBusUiController | 4 // TODO(nona): Remvoe IBusUiController |
5 | 5 |
6 #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h" | 6 #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h" |
7 | 7 |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace chromeos { | 24 namespace chromeos { |
25 namespace input_method { | 25 namespace input_method { |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Returns pointer of IBusPanelService. This function returns NULL if it is not | 28 // Returns pointer of IBusPanelService. This function returns NULL if it is not |
29 // ready. | 29 // ready. |
30 ibus::IBusPanelService* GetIBusPanelService() { | 30 ibus::IBusPanelService* GetIBusPanelService() { |
31 return DBusThreadManager::Get()->GetIBusPanelService(); | 31 return DBusThreadManager::Get()->GetIBusPanelService(); |
32 } | 32 } |
33 | 33 |
34 // Returns a ui::InputMethodIBus object which is associated with the root | |
35 // window. Returns NULL if the Ash shell has already been destructed. | |
36 static ui::InputMethodIBus* GetChromeInputMethod() { | |
37 if (!ash::Shell::HasInstance()) | |
38 return NULL; | |
39 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); | |
40 if (!root_window) | |
41 return NULL; | |
42 return static_cast<ui::InputMethodIBus*>(root_window->GetProperty( | |
43 aura::client::kRootWindowInputMethodKey)); | |
44 } | |
45 | |
46 } // namespace | 34 } // namespace |
47 | 35 |
48 // A class for customizing the behavior of ui::InputMethodIBus for Chrome OS. | |
49 class IBusChromeOSClientImpl : public ui::internal::IBusClient { | |
50 public: | |
51 explicit IBusChromeOSClientImpl(IBusUiController* ui) : ui_(ui) {} | |
52 | |
53 // ui::IBusClient override. | |
54 virtual InputMethodType GetInputMethodType() OVERRIDE { | |
55 InputMethodManager* manager = GetInputMethodManager(); | |
56 DCHECK(manager); | |
57 return InputMethodUtil::IsKeyboardLayout( | |
58 manager->GetCurrentInputMethod().id()) ? | |
59 INPUT_METHOD_XKB_LAYOUT : INPUT_METHOD_NORMAL; | |
60 } | |
61 | |
62 virtual void SetCursorLocation(const gfx::Rect& cursor_location, | |
63 const gfx::Rect& composition_head) OVERRIDE { | |
64 if (!ui_) | |
65 return; | |
66 // We don't have to call ibus_input_context_set_cursor_location() on | |
67 // Chrome OS because the candidate window for IBus is integrated with | |
68 // Chrome. | |
69 ui_->SetCursorLocation(cursor_location, composition_head); | |
70 } | |
71 | |
72 void set_ui(IBusUiController* ui) { | |
73 ui_ = ui; | |
74 } | |
75 | |
76 private: | |
77 IBusUiController* ui_; | |
78 DISALLOW_COPY_AND_ASSIGN(IBusChromeOSClientImpl); | |
79 }; | |
80 | |
81 // The real implementation of the IBusUiController. | 36 // The real implementation of the IBusUiController. |
82 IBusUiController::IBusUiController() { | 37 IBusUiController::IBusUiController() { |
83 ui::InputMethodIBus* input_method = GetChromeInputMethod(); | |
84 DCHECK(input_method); | |
85 input_method->set_ibus_client(scoped_ptr<ui::internal::IBusClient>( | |
86 new IBusChromeOSClientImpl(this)).Pass()); | |
87 } | 38 } |
88 | 39 |
89 IBusUiController::~IBusUiController() { | 40 IBusUiController::~IBusUiController() { |
90 ui::InputMethodIBus* input_method = GetChromeInputMethod(); | |
91 if (input_method) { | |
92 ui::internal::IBusClient* client = input_method->ibus_client(); | |
93 // We assume that no objects other than |this| set an IBus client. | |
94 DCHECK(client); | |
95 static_cast<IBusChromeOSClientImpl*>(client)->set_ui(NULL); | |
96 } | |
97 } | 41 } |
98 | 42 |
99 void IBusUiController::NotifyCandidateClicked(int index, int button, | 43 void IBusUiController::NotifyCandidateClicked(int index, int button, |
100 int flags) { | 44 int flags) { |
101 ibus::IBusPanelService* service = GetIBusPanelService(); | 45 ibus::IBusPanelService* service = GetIBusPanelService(); |
102 if (service) { | 46 if (service) { |
103 service->CandidateClicked( | 47 service->CandidateClicked( |
104 index, | 48 index, |
105 static_cast<ibus::IBusMouseButton>(button), | 49 static_cast<ibus::IBusMouseButton>(button), |
106 flags); | 50 flags); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void IBusUiController::HideLookupTable() { | 90 void IBusUiController::HideLookupTable() { |
147 FOR_EACH_OBSERVER(Observer, observers_, OnHideLookupTable()); | 91 FOR_EACH_OBSERVER(Observer, observers_, OnHideLookupTable()); |
148 } | 92 } |
149 | 93 |
150 void IBusUiController::UpdateAuxiliaryText(const std::string& text, | 94 void IBusUiController::UpdateAuxiliaryText(const std::string& text, |
151 bool visible) { | 95 bool visible) { |
152 FOR_EACH_OBSERVER(Observer, observers_, | 96 FOR_EACH_OBSERVER(Observer, observers_, |
153 OnUpdateAuxiliaryText(text, visible)); | 97 OnUpdateAuxiliaryText(text, visible)); |
154 } | 98 } |
155 | 99 |
156 void IBusUiController::SetCursorLocation(const gfx::Rect& cursor_location, | |
157 const gfx::Rect& composition_head) { | |
158 FOR_EACH_OBSERVER(Observer, observers_, | |
159 OnSetCursorLocation(cursor_location, composition_head)); | |
160 } | |
161 | |
162 void IBusUiController::UpdatePreeditText(const std::string& text, | 100 void IBusUiController::UpdatePreeditText(const std::string& text, |
163 uint32 cursor_pos, | 101 uint32 cursor_pos, |
164 bool visible) { | 102 bool visible) { |
165 FOR_EACH_OBSERVER(Observer, observers_, | 103 FOR_EACH_OBSERVER(Observer, observers_, |
166 OnUpdatePreeditText(text, cursor_pos, visible)); | 104 OnUpdatePreeditText(text, cursor_pos, visible)); |
167 } | 105 } |
168 | 106 |
169 void IBusUiController::HidePreeditText() { | 107 void IBusUiController::HidePreeditText() { |
170 FOR_EACH_OBSERVER(Observer, observers_, OnHidePreeditText()); | 108 FOR_EACH_OBSERVER(Observer, observers_, OnHidePreeditText()); |
171 } | 109 } |
172 | 110 |
173 void IBusUiController::UpdateLookupTable(const ibus::IBusLookupTable& table, | 111 void IBusUiController::UpdateLookupTable(const ibus::IBusLookupTable& table, |
174 bool visible) { | 112 bool visible) { |
175 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateLookupTable(table, visible)); | 113 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateLookupTable(table, visible)); |
176 } | 114 } |
177 | 115 |
| 116 void IBusUiController::SetCursorLocation(const ibus::Rect& cursor_location, |
| 117 const ibus::Rect& composition_head) { |
| 118 FOR_EACH_OBSERVER(Observer, |
| 119 observers_, |
| 120 OnSetCursorLocation(cursor_location, composition_head)); |
| 121 } |
| 122 |
178 } // namespace input_method | 123 } // namespace input_method |
179 } // namespace chromeos | 124 } // namespace chromeos |
OLD | NEW |