Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: chrome/browser/chromeos/input_method/candidate_window_controller_impl.cc

Issue 11931011: Remove IBusUiController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17 matching lines...) Expand all
28 namespace { 28 namespace {
29 // The milliseconds of the delay to show the infolist window. 29 // The milliseconds of the delay to show the infolist window.
30 const int kInfolistShowDelayMilliSeconds = 500; 30 const int kInfolistShowDelayMilliSeconds = 500;
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
39 // Returns pointer of IBusPanelService. This function returns NULL if it is not
40 // ready.
41 ibus::IBusPanelService* GetIBusPanelService() {
42 return DBusThreadManager::Get()->GetIBusPanelService();
43 }
38 } // namespace 44 } // namespace
39 45
40 bool CandidateWindowControllerImpl::Init(IBusController* controller) { 46 bool CandidateWindowControllerImpl::Init(IBusController* controller) {
41 if (controller) 47 if (controller)
42 controller->AddObserver(this); 48 controller->AddObserver(this);
43 // Create the candidate window view. 49 // Create the candidate window view.
44 CreateView(); 50 CreateView();
45
46 // The observer should be added before Connect() so we can capture the
47 // initial connection change.
48 ibus_ui_controller_->AddObserver(this);
49 return true; 51 return true;
50 } 52 }
51 53
52 void CandidateWindowControllerImpl::Shutdown(IBusController* controller) { 54 void CandidateWindowControllerImpl::Shutdown(IBusController* controller) {
53 if (controller) 55 if (controller)
54 controller->RemoveObserver(this); 56 controller->RemoveObserver(this);
55 } 57 }
56 58
57 void CandidateWindowControllerImpl::CreateView() { 59 void CandidateWindowControllerImpl::CreateView() {
58 // Create a non-decorated frame. 60 // Create a non-decorated frame.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 infolist_window_->GetNativeView(), 95 infolist_window_->GetNativeView(),
94 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 96 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
95 #endif // USE_ASH 97 #endif // USE_ASH
96 98
97 InfolistWindowView* infolist_view = new InfolistWindowView; 99 InfolistWindowView* infolist_view = new InfolistWindowView;
98 infolist_view->Init(); 100 infolist_view->Init();
99 infolist_window_->SetContentsView(infolist_view); 101 infolist_window_->SetContentsView(infolist_view);
100 } 102 }
101 103
102 CandidateWindowControllerImpl::CandidateWindowControllerImpl() 104 CandidateWindowControllerImpl::CandidateWindowControllerImpl()
103 : ibus_ui_controller_(new IBusUiController), 105 : candidate_window_(NULL),
104 candidate_window_(NULL),
105 infolist_window_(NULL), 106 infolist_window_(NULL),
106 latest_infolist_focused_index_(InfolistWindowView::InvalidFocusIndex()) { 107 latest_infolist_focused_index_(InfolistWindowView::InvalidFocusIndex()) {
107 } 108 }
108 109
109 CandidateWindowControllerImpl::~CandidateWindowControllerImpl() { 110 CandidateWindowControllerImpl::~CandidateWindowControllerImpl() {
110 if (DBusThreadManager::Get()->GetIBusPanelService()) 111 if (DBusThreadManager::Get()->GetIBusPanelService())
111 DBusThreadManager::Get()->GetIBusPanelService()-> 112 DBusThreadManager::Get()->GetIBusPanelService()->
112 SetUpCandidateWindowHandler(NULL); 113 SetUpCandidateWindowHandler(NULL);
113 ibus_ui_controller_->RemoveObserver(this);
114 candidate_window_->RemoveObserver(this); 114 candidate_window_->RemoveObserver(this);
115 // ibus_ui_controller_'s destructor will close the connection.
116 } 115 }
117 116
118 void CandidateWindowControllerImpl::OnHideAuxiliaryText() { 117 void CandidateWindowControllerImpl::HideAuxiliaryText() {
119 candidate_window_->HideAuxiliaryText(); 118 candidate_window_->HideAuxiliaryText();
120 } 119 }
121 120
122 void CandidateWindowControllerImpl::OnHideLookupTable() { 121 void CandidateWindowControllerImpl::HideLookupTable() {
123 candidate_window_->HideLookupTable(); 122 candidate_window_->HideLookupTable();
124 infolist_window_->Hide(); 123 infolist_window_->Hide();
125 } 124 }
126 125
127 void CandidateWindowControllerImpl::OnHidePreeditText() { 126 void CandidateWindowControllerImpl::HidePreeditText() {
128 candidate_window_->HidePreeditText(); 127 candidate_window_->HidePreeditText();
129 } 128 }
130 129
131 void CandidateWindowControllerImpl::OnSetCursorLocation( 130 void CandidateWindowControllerImpl::SetCursorLocation(
132 const ibus::Rect& cursor_location, 131 const ibus::Rect& cursor_location,
133 const ibus::Rect& composition_head) { 132 const ibus::Rect& composition_head) {
134 // A workaround for http://crosbug.com/6460. We should ignore very short Y 133 // A workaround for http://crosbug.com/6460. We should ignore very short Y
135 // move to prevent the window from shaking up and down. 134 // move to prevent the window from shaking up and down.
136 const int kKeepPositionThreshold = 2; // px 135 const int kKeepPositionThreshold = 2; // px
137 const gfx::Rect& last_location = 136 const gfx::Rect& last_location =
138 candidate_window_->cursor_location(); 137 candidate_window_->cursor_location();
139 const int delta_y = abs(last_location.y() - cursor_location.y); 138 const int delta_y = abs(last_location.y() - cursor_location.y);
140 if ((last_location.x() == cursor_location.x) && 139 if ((last_location.x() == cursor_location.x) &&
141 (delta_y <= kKeepPositionThreshold)) { 140 (delta_y <= kKeepPositionThreshold)) {
142 DVLOG(1) << "Ignored set_cursor_location signal to prevent window shake"; 141 DVLOG(1) << "Ignored set_cursor_location signal to prevent window shake";
143 return; 142 return;
144 } 143 }
145 144
146 // Remember the cursor location. 145 // Remember the cursor location.
147 candidate_window_->set_cursor_location(IBusRectToGfxRect(cursor_location)); 146 candidate_window_->set_cursor_location(IBusRectToGfxRect(cursor_location));
148 candidate_window_->set_composition_head_location( 147 candidate_window_->set_composition_head_location(
149 IBusRectToGfxRect(composition_head)); 148 IBusRectToGfxRect(composition_head));
150 // Move the window per the cursor location. 149 // Move the window per the cursor location.
151 candidate_window_->ResizeAndMoveParentFrame(); 150 candidate_window_->ResizeAndMoveParentFrame();
152 UpdateInfolistBounds(); 151 UpdateInfolistBounds();
153 } 152 }
154 153
155 void CandidateWindowControllerImpl::OnUpdateAuxiliaryText( 154 void CandidateWindowControllerImpl::UpdateAuxiliaryText(
156 const std::string& utf8_text, 155 const std::string& utf8_text,
157 bool visible) { 156 bool visible) {
158 // If it's not visible, hide the auxiliary text and return. 157 // If it's not visible, hide the auxiliary text and return.
159 if (!visible) { 158 if (!visible) {
160 candidate_window_->HideAuxiliaryText(); 159 candidate_window_->HideAuxiliaryText();
161 return; 160 return;
162 } 161 }
163 candidate_window_->UpdateAuxiliaryText(utf8_text); 162 candidate_window_->UpdateAuxiliaryText(utf8_text);
164 candidate_window_->ShowAuxiliaryText(); 163 candidate_window_->ShowAuxiliaryText();
165 } 164 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 206
208 for (size_t i = 0; i < old_entries.size(); ++i) { 207 for (size_t i = 0; i < old_entries.size(); ++i) {
209 if (old_entries[i].title != new_entries[i].title || 208 if (old_entries[i].title != new_entries[i].title ||
210 old_entries[i].body != new_entries[i].body ) { 209 old_entries[i].body != new_entries[i].body ) {
211 return true; 210 return true;
212 } 211 }
213 } 212 }
214 return false; 213 return false;
215 } 214 }
216 215
217 void CandidateWindowControllerImpl::OnUpdateLookupTable( 216 void CandidateWindowControllerImpl::UpdateLookupTable(
218 const ibus::IBusLookupTable& lookup_table, 217 const ibus::IBusLookupTable& lookup_table,
219 bool visible) { 218 bool visible) {
220 // If it's not visible, hide the lookup table and return. 219 // If it's not visible, hide the lookup table and return.
221 if (!visible) { 220 if (!visible) {
222 candidate_window_->HideLookupTable(); 221 candidate_window_->HideLookupTable();
223 infolist_window_->Hide(); 222 infolist_window_->Hide();
224 // TODO(nona): Introduce unittests for crbug.com/170036. 223 // TODO(nona): Introduce unittests for crbug.com/170036.
225 latest_infolist_entries_.clear(); 224 latest_infolist_entries_.clear();
226 return; 225 return;
227 } 226 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 new_bounds.set_origin(GetInfolistWindowPosition( 279 new_bounds.set_origin(GetInfolistWindowPosition(
281 frame_->GetClientAreaBoundsInScreen(), 280 frame_->GetClientAreaBoundsInScreen(),
282 ash::Shell::GetScreen()->GetDisplayNearestWindow( 281 ash::Shell::GetScreen()->GetDisplayNearestWindow(
283 infolist_window_->GetNativeView()).work_area(), 282 infolist_window_->GetNativeView()).work_area(),
284 new_bounds.size())); 283 new_bounds.size()));
285 284
286 if (current_bounds != new_bounds) 285 if (current_bounds != new_bounds)
287 infolist_window_->SetBounds(new_bounds); 286 infolist_window_->SetBounds(new_bounds);
288 } 287 }
289 288
290 void CandidateWindowControllerImpl::OnUpdatePreeditText( 289 void CandidateWindowControllerImpl::UpdatePreeditText(
291 const std::string& utf8_text, unsigned int cursor, bool visible) { 290 const std::string& utf8_text, unsigned int cursor, bool visible) {
292 // If it's not visible, hide the preedit text and return. 291 // If it's not visible, hide the preedit text and return.
293 if (!visible || utf8_text.empty()) { 292 if (!visible || utf8_text.empty()) {
294 candidate_window_->HidePreeditText(); 293 candidate_window_->HidePreeditText();
295 return; 294 return;
296 } 295 }
297 candidate_window_->UpdatePreeditText(utf8_text); 296 candidate_window_->UpdatePreeditText(utf8_text);
298 candidate_window_->ShowPreeditText(); 297 candidate_window_->ShowPreeditText();
299 } 298 }
300 299
301 void CandidateWindowControllerImpl::OnCandidateCommitted(int index, 300 void CandidateWindowControllerImpl::OnCandidateCommitted(int index,
302 int button, 301 int button,
303 int flags) { 302 int flags) {
304 ibus_ui_controller_->NotifyCandidateClicked(index, button, flags); 303 GetIBusPanelService()->CandidateClicked(
304 index,
305 static_cast<ibus::IBusMouseButton>(button),
306 flags);
305 } 307 }
306 308
307 void CandidateWindowControllerImpl::OnCandidateWindowOpened() { 309 void CandidateWindowControllerImpl::OnCandidateWindowOpened() {
308 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, 310 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_,
309 CandidateWindowOpened()); 311 CandidateWindowOpened());
310 } 312 }
311 313
312 void CandidateWindowControllerImpl::OnCandidateWindowClosed() { 314 void CandidateWindowControllerImpl::OnCandidateWindowClosed() {
313 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, 315 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_,
314 CandidateWindowClosed()); 316 CandidateWindowClosed());
315 } 317 }
316 318
317 void CandidateWindowControllerImpl::AddObserver( 319 void CandidateWindowControllerImpl::AddObserver(
318 CandidateWindowController::Observer* observer) { 320 CandidateWindowController::Observer* observer) {
319 observers_.AddObserver(observer); 321 observers_.AddObserver(observer);
320 } 322 }
321 323
322 void CandidateWindowControllerImpl::RemoveObserver( 324 void CandidateWindowControllerImpl::RemoveObserver(
323 CandidateWindowController::Observer* observer) { 325 CandidateWindowController::Observer* observer) {
324 observers_.RemoveObserver(observer); 326 observers_.RemoveObserver(observer);
325 } 327 }
326 328
327 void CandidateWindowControllerImpl::PropertyChanged() { 329 void CandidateWindowControllerImpl::PropertyChanged() {
328 } 330 }
329 331
330 void CandidateWindowControllerImpl::OnConnected() { 332 void CandidateWindowControllerImpl::OnConnected() {
331 DBusThreadManager::Get()->GetIBusPanelService()->SetUpCandidateWindowHandler( 333 DBusThreadManager::Get()->GetIBusPanelService()->SetUpCandidateWindowHandler(
332 ibus_ui_controller_.get()); 334 this);
333 } 335 }
334 336
335 void CandidateWindowControllerImpl::OnDisconnected() { 337 void CandidateWindowControllerImpl::OnDisconnected() {
336 candidate_window_->HideAll(); 338 candidate_window_->HideAll();
337 infolist_window_->Hide(); 339 infolist_window_->Hide();
338 DBusThreadManager::Get()->GetIBusPanelService()->SetUpCandidateWindowHandler( 340 DBusThreadManager::Get()->GetIBusPanelService()->SetUpCandidateWindowHandler(
339 NULL); 341 NULL);
340 } 342 }
341 343
342 // static 344 // static
343 gfx::Point CandidateWindowControllerImpl::GetInfolistWindowPosition( 345 gfx::Point CandidateWindowControllerImpl::GetInfolistWindowPosition(
344 const gfx::Rect& candidate_window_rect, 346 const gfx::Rect& candidate_window_rect,
345 const gfx::Rect& screen_rect, 347 const gfx::Rect& screen_rect,
346 const gfx::Size& infolist_window_size) { 348 const gfx::Size& infolist_window_size) {
347 gfx::Point result(candidate_window_rect.right(), candidate_window_rect.y()); 349 gfx::Point result(candidate_window_rect.right(), candidate_window_rect.y());
348 350
349 if (candidate_window_rect.right() + infolist_window_size.width() > 351 if (candidate_window_rect.right() + infolist_window_size.width() >
350 screen_rect.right()) 352 screen_rect.right())
351 result.set_x(candidate_window_rect.x() - infolist_window_size.width()); 353 result.set_x(candidate_window_rect.x() - infolist_window_size.width());
352 354
353 if (candidate_window_rect.y() + infolist_window_size.height() > 355 if (candidate_window_rect.y() + infolist_window_size.height() >
354 screen_rect.bottom()) 356 screen_rect.bottom())
355 result.set_y(screen_rect.bottom() - infolist_window_size.height()); 357 result.set_y(screen_rect.bottom() - infolist_window_size.height());
356 358
357 return result; 359 return result;
358 } 360 }
359 361
360 } // namespace input_method 362 } // namespace input_method
361 } // namespace chromeos 363 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698