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 | 4 |
5 #include "chrome/browser/chromeos/input_method/candidate_window_controller_impl.
h" | 5 #include "chrome/browser/chromeos/input_method/candidate_window_controller_impl.
h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // The milliseconds of the delay to hide the infolist window. | 31 // The milliseconds of the delay to hide the infolist window. |
32 const int kInfolistHideDelayMilliSeconds = 500; | 32 const int kInfolistHideDelayMilliSeconds = 500; |
33 | 33 |
34 // Converts from ibus::Rect to gfx::Rect. | 34 // Converts from ibus::Rect to gfx::Rect. |
35 gfx::Rect IBusRectToGfxRect(const ibus::Rect& rect) { | 35 gfx::Rect IBusRectToGfxRect(const ibus::Rect& rect) { |
36 return gfx::Rect(rect.x, rect.y, rect.width, rect.height); | 36 return gfx::Rect(rect.x, rect.y, rect.width, rect.height); |
37 } | 37 } |
38 | 38 |
39 // Returns pointer of IBusPanelService. This function returns NULL if it is not | 39 // Returns pointer of IBusPanelService. This function returns NULL if it is not |
40 // ready. | 40 // ready. |
41 ibus::IBusPanelService* GetIBusPanelService() { | 41 IBusPanelService* GetIBusPanelService() { |
42 return DBusThreadManager::Get()->GetIBusPanelService(); | 42 return DBusThreadManager::Get()->GetIBusPanelService(); |
43 } | 43 } |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 bool CandidateWindowControllerImpl::Init(IBusController* controller) { | 46 bool CandidateWindowControllerImpl::Init(IBusController* controller) { |
47 if (controller) | 47 if (controller) |
48 controller->AddObserver(this); | 48 controller->AddObserver(this); |
49 // Create the candidate window view. | 49 // Create the candidate window view. |
50 CreateView(); | 50 CreateView(); |
51 return true; | 51 return true; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (!visible) { | 158 if (!visible) { |
159 candidate_window_->HideAuxiliaryText(); | 159 candidate_window_->HideAuxiliaryText(); |
160 return; | 160 return; |
161 } | 161 } |
162 candidate_window_->UpdateAuxiliaryText(utf8_text); | 162 candidate_window_->UpdateAuxiliaryText(utf8_text); |
163 candidate_window_->ShowAuxiliaryText(); | 163 candidate_window_->ShowAuxiliaryText(); |
164 } | 164 } |
165 | 165 |
166 // static | 166 // static |
167 void CandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 167 void CandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
168 const ibus::IBusLookupTable& lookup_table, | 168 const IBusLookupTable& lookup_table, |
169 std::vector<InfolistWindowView::Entry>* infolist_entries, | 169 std::vector<InfolistWindowView::Entry>* infolist_entries, |
170 size_t* focused_index) { | 170 size_t* focused_index) { |
171 DCHECK(focused_index); | 171 DCHECK(focused_index); |
172 DCHECK(infolist_entries); | 172 DCHECK(infolist_entries); |
173 *focused_index = InfolistWindowView::InvalidFocusIndex(); | 173 *focused_index = InfolistWindowView::InvalidFocusIndex(); |
174 infolist_entries->clear(); | 174 infolist_entries->clear(); |
175 | 175 |
176 const size_t cursor_index_in_page = | 176 const size_t cursor_index_in_page = |
177 lookup_table.cursor_position() % lookup_table.page_size(); | 177 lookup_table.cursor_position() % lookup_table.page_size(); |
178 | 178 |
179 for (size_t i = 0; i < lookup_table.candidates().size(); ++i) { | 179 for (size_t i = 0; i < lookup_table.candidates().size(); ++i) { |
180 const ibus::IBusLookupTable::Entry& ibus_entry = | 180 const IBusLookupTable::Entry& ibus_entry = |
181 lookup_table.candidates()[i]; | 181 lookup_table.candidates()[i]; |
182 if (ibus_entry.description_title.empty() && | 182 if (ibus_entry.description_title.empty() && |
183 ibus_entry.description_body.empty()) | 183 ibus_entry.description_body.empty()) |
184 continue; | 184 continue; |
185 InfolistWindowView::Entry entry; | 185 InfolistWindowView::Entry entry; |
186 entry.title = ibus_entry.description_title; | 186 entry.title = ibus_entry.description_title; |
187 entry.body = ibus_entry.description_body; | 187 entry.body = ibus_entry.description_body; |
188 infolist_entries->push_back(entry); | 188 infolist_entries->push_back(entry); |
189 if (i == cursor_index_in_page) | 189 if (i == cursor_index_in_page) |
190 *focused_index = infolist_entries->size() - 1; | 190 *focused_index = infolist_entries->size() - 1; |
(...skipping 16 matching lines...) Expand all Loading... |
207 for (size_t i = 0; i < old_entries.size(); ++i) { | 207 for (size_t i = 0; i < old_entries.size(); ++i) { |
208 if (old_entries[i].title != new_entries[i].title || | 208 if (old_entries[i].title != new_entries[i].title || |
209 old_entries[i].body != new_entries[i].body ) { | 209 old_entries[i].body != new_entries[i].body ) { |
210 return true; | 210 return true; |
211 } | 211 } |
212 } | 212 } |
213 return false; | 213 return false; |
214 } | 214 } |
215 | 215 |
216 void CandidateWindowControllerImpl::UpdateLookupTable( | 216 void CandidateWindowControllerImpl::UpdateLookupTable( |
217 const ibus::IBusLookupTable& lookup_table, | 217 const IBusLookupTable& lookup_table, |
218 bool visible) { | 218 bool visible) { |
219 // If it's not visible, hide the lookup table and return. | 219 // If it's not visible, hide the lookup table and return. |
220 if (!visible) { | 220 if (!visible) { |
221 candidate_window_->HideLookupTable(); | 221 candidate_window_->HideLookupTable(); |
222 infolist_window_->Hide(); | 222 infolist_window_->Hide(); |
223 // TODO(nona): Introduce unittests for crbug.com/170036. | 223 // TODO(nona): Introduce unittests for crbug.com/170036. |
224 latest_infolist_entries_.clear(); | 224 latest_infolist_entries_.clear(); |
225 return; | 225 return; |
226 } | 226 } |
227 | 227 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 354 |
355 if (candidate_window_rect.y() + infolist_window_size.height() > | 355 if (candidate_window_rect.y() + infolist_window_size.height() > |
356 screen_rect.bottom()) | 356 screen_rect.bottom()) |
357 result.set_y(screen_rect.bottom() - infolist_window_size.height()); | 357 result.set_y(screen_rect.bottom() - infolist_window_size.height()); |
358 | 358 |
359 return result; | 359 return result; |
360 } | 360 } |
361 | 361 |
362 } // namespace input_method | 362 } // namespace input_method |
363 } // namespace chromeos | 363 } // namespace chromeos |
OLD | NEW |