| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 void set_ui(IBusUiController* ui) { | 72 void set_ui(IBusUiController* ui) { |
| 73 ui_ = ui; | 73 ui_ = ui; |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 IBusUiController* ui_; | 77 IBusUiController* ui_; |
| 78 DISALLOW_COPY_AND_ASSIGN(IBusChromeOSClientImpl); | 78 DISALLOW_COPY_AND_ASSIGN(IBusChromeOSClientImpl); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 InputMethodLookupTable::InputMethodLookupTable() | |
| 82 : visible(false), | |
| 83 cursor_absolute_index(0), | |
| 84 page_size(0), | |
| 85 orientation(kHorizontal) { | |
| 86 } | |
| 87 | |
| 88 InputMethodLookupTable::~InputMethodLookupTable() { | |
| 89 } | |
| 90 | |
| 91 std::string InputMethodLookupTable::ToString() const { | |
| 92 std::stringstream stream; | |
| 93 stream << "visible: " << visible << "\n"; | |
| 94 stream << "cursor_absolute_index: " << cursor_absolute_index << "\n"; | |
| 95 stream << "page_size: " << page_size << "\n"; | |
| 96 stream << "orientation: " << orientation << "\n"; | |
| 97 stream << "candidates:"; | |
| 98 for (size_t i = 0; i < candidates.size(); ++i) { | |
| 99 stream << " [" << candidates[i] << "]"; | |
| 100 } | |
| 101 stream << "\nlabels:"; | |
| 102 for (size_t i = 0; i < labels.size(); ++i) { | |
| 103 stream << " [" << labels[i] << "]"; | |
| 104 } | |
| 105 return stream.str(); | |
| 106 } | |
| 107 | |
| 108 // The real implementation of the IBusUiController. | 81 // The real implementation of the IBusUiController. |
| 109 IBusUiController::IBusUiController() { | 82 IBusUiController::IBusUiController() { |
| 110 ui::InputMethodIBus* input_method = GetChromeInputMethod(); | 83 ui::InputMethodIBus* input_method = GetChromeInputMethod(); |
| 111 DCHECK(input_method); | 84 DCHECK(input_method); |
| 112 input_method->set_ibus_client(scoped_ptr<ui::internal::IBusClient>( | 85 input_method->set_ibus_client(scoped_ptr<ui::internal::IBusClient>( |
| 113 new IBusChromeOSClientImpl(this)).Pass()); | 86 new IBusChromeOSClientImpl(this)).Pass()); |
| 114 } | 87 } |
| 115 | 88 |
| 116 IBusUiController::~IBusUiController() { | 89 IBusUiController::~IBusUiController() { |
| 117 ui::InputMethodIBus* input_method = GetChromeInputMethod(); | 90 ui::InputMethodIBus* input_method = GetChromeInputMethod(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 FOR_EACH_OBSERVER(Observer, observers_, | 165 FOR_EACH_OBSERVER(Observer, observers_, |
| 193 OnUpdatePreeditText(text, cursor_pos, visible)); | 166 OnUpdatePreeditText(text, cursor_pos, visible)); |
| 194 } | 167 } |
| 195 | 168 |
| 196 void IBusUiController::HidePreeditText() { | 169 void IBusUiController::HidePreeditText() { |
| 197 FOR_EACH_OBSERVER(Observer, observers_, OnHidePreeditText()); | 170 FOR_EACH_OBSERVER(Observer, observers_, OnHidePreeditText()); |
| 198 } | 171 } |
| 199 | 172 |
| 200 void IBusUiController::UpdateLookupTable(const ibus::IBusLookupTable& table, | 173 void IBusUiController::UpdateLookupTable(const ibus::IBusLookupTable& table, |
| 201 bool visible) { | 174 bool visible) { |
| 202 // TODO(nona): Use ibus::IBusLookupTable instead. | 175 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateLookupTable(table, visible)); |
| 203 InputMethodLookupTable lookup_table; | |
| 204 lookup_table.visible = visible; | |
| 205 | |
| 206 // Copy the orientation information. | |
| 207 if (table.orientation() == ibus::IBusLookupTable::VERTICAL) { | |
| 208 lookup_table.orientation = InputMethodLookupTable::kVertical; | |
| 209 } else { | |
| 210 lookup_table.orientation = InputMethodLookupTable::kHorizontal; | |
| 211 } | |
| 212 | |
| 213 lookup_table.show_at_composition_head = table.show_window_at_composition(); | |
| 214 | |
| 215 // Copy candidates and annotations to |lookup_table|. | |
| 216 for (size_t i = 0; i < table.candidates().size(); ++i) { | |
| 217 const ibus::IBusLookupTable::Entry& entry = table.candidates()[i]; | |
| 218 lookup_table.candidates.push_back(entry.value); | |
| 219 lookup_table.labels.push_back(entry.label); | |
| 220 lookup_table.annotations.push_back(entry.annotation); | |
| 221 | |
| 222 InputMethodLookupTable::Description description; | |
| 223 description.title = entry.description_title; | |
| 224 description.body = entry.description_body; | |
| 225 lookup_table.descriptions.push_back(description); | |
| 226 } | |
| 227 | |
| 228 lookup_table.cursor_absolute_index = table.cursor_position(); | |
| 229 lookup_table.page_size = table.page_size(); | |
| 230 // Ensure that the page_size is non-zero to avoid div-by-zero error. | |
| 231 if (lookup_table.page_size <= 0) { | |
| 232 DVLOG(1) << "Invalid page size: " << lookup_table.page_size; | |
| 233 lookup_table.page_size = 1; | |
| 234 } | |
| 235 | |
| 236 FOR_EACH_OBSERVER(Observer, observers_, | |
| 237 OnUpdateLookupTable(lookup_table)); | |
| 238 } | 176 } |
| 239 | 177 |
| 240 } // namespace input_method | 178 } // namespace input_method |
| 241 } // namespace chromeos | 179 } // namespace chromeos |
| OLD | NEW |