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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" | 13 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" |
14 #include "chrome/browser/chromeos/input_method/delayable_widget.h" | 14 #include "chrome/browser/chromeos/input_method/delayable_widget.h" |
15 #include "chrome/browser/chromeos/input_method/infolist_window_view.h" | 15 #include "chrome/browser/chromeos/input_method/infolist_window_view.h" |
| 16 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
17 | 18 |
18 #if defined(USE_ASH) | 19 #if defined(USE_ASH) |
19 #include "ash/shell.h" | 20 #include "ash/shell.h" |
20 #include "ash/shell_window_ids.h" | 21 #include "ash/shell_window_ids.h" |
21 #include "ash/wm/window_animations.h" | 22 #include "ash/wm/window_animations.h" |
22 #endif // USE_ASH | 23 #endif // USE_ASH |
23 | 24 |
24 namespace chromeos { | 25 namespace chromeos { |
25 namespace input_method { | 26 namespace input_method { |
26 | 27 |
27 namespace { | 28 namespace { |
28 // The milliseconds of the delay to show the infolist window. | 29 // The milliseconds of the delay to show the infolist window. |
29 const int kInfolistShowDelayMilliSeconds = 500; | 30 const int kInfolistShowDelayMilliSeconds = 500; |
30 // The milliseconds of the delay to hide the infolist window. | 31 // The milliseconds of the delay to hide the infolist window. |
31 const int kInfolistHideDelayMilliSeconds = 500; | 32 const int kInfolistHideDelayMilliSeconds = 500; |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 bool CandidateWindowControllerImpl::Init() { | 35 bool CandidateWindowControllerImpl::Init() { |
35 // Create the candidate window view. | 36 // Create the candidate window view. |
36 CreateView(); | 37 CreateView(); |
37 | 38 |
38 // The observer should be added before Connect() so we can capture the | 39 // The observer should be added before Connect() so we can capture the |
39 // initial connection change. | 40 // initial connection change. |
40 ibus_ui_controller_->AddObserver(this); | 41 ibus_ui_controller_->AddObserver(this); |
41 ibus_ui_controller_->Connect(); | |
42 return true; | 42 return true; |
43 } | 43 } |
44 | 44 |
45 void CandidateWindowControllerImpl::CreateView() { | 45 void CandidateWindowControllerImpl::CreateView() { |
46 // Create a non-decorated frame. | 46 // Create a non-decorated frame. |
47 frame_.reset(new views::Widget); | 47 frame_.reset(new views::Widget); |
48 // The size is initially zero. | 48 // The size is initially zero. |
49 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 49 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
50 // |frame_| and |infolist_window_| are owned by controller impl so | 50 // |frame_| and |infolist_window_| are owned by controller impl so |
51 // they should use WIDGET_OWNS_NATIVE_WIDGET ownership. | 51 // they should use WIDGET_OWNS_NATIVE_WIDGET ownership. |
(...skipping 29 matching lines...) Expand all Loading... |
81 infolist_window_->GetNativeView(), | 81 infolist_window_->GetNativeView(), |
82 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 82 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
83 #endif // USE_ASH | 83 #endif // USE_ASH |
84 | 84 |
85 InfolistWindowView* infolist_view = new InfolistWindowView; | 85 InfolistWindowView* infolist_view = new InfolistWindowView; |
86 infolist_view->Init(); | 86 infolist_view->Init(); |
87 infolist_window_->SetContentsView(infolist_view); | 87 infolist_window_->SetContentsView(infolist_view); |
88 } | 88 } |
89 | 89 |
90 CandidateWindowControllerImpl::CandidateWindowControllerImpl() | 90 CandidateWindowControllerImpl::CandidateWindowControllerImpl() |
91 : ibus_ui_controller_(IBusUiController::Create()), | 91 : ibus_ui_controller_(new IBusUiController), |
92 candidate_window_(NULL), | 92 candidate_window_(NULL), |
93 infolist_window_(NULL), | 93 infolist_window_(NULL), |
94 latest_infolist_focused_index_(InfolistWindowView::InvalidFocusIndex()) { | 94 latest_infolist_focused_index_(InfolistWindowView::InvalidFocusIndex()) { |
95 } | 95 } |
96 | 96 |
97 CandidateWindowControllerImpl::~CandidateWindowControllerImpl() { | 97 CandidateWindowControllerImpl::~CandidateWindowControllerImpl() { |
98 ibus_ui_controller_->RemoveObserver(this); | 98 ibus_ui_controller_->RemoveObserver(this); |
99 candidate_window_->RemoveObserver(this); | 99 candidate_window_->RemoveObserver(this); |
100 // ibus_ui_controller_'s destructor will close the connection. | 100 // ibus_ui_controller_'s destructor will close the connection. |
101 } | 101 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 void CandidateWindowControllerImpl::AddObserver( | 296 void CandidateWindowControllerImpl::AddObserver( |
297 CandidateWindowController::Observer* observer) { | 297 CandidateWindowController::Observer* observer) { |
298 observers_.AddObserver(observer); | 298 observers_.AddObserver(observer); |
299 } | 299 } |
300 | 300 |
301 void CandidateWindowControllerImpl::RemoveObserver( | 301 void CandidateWindowControllerImpl::RemoveObserver( |
302 CandidateWindowController::Observer* observer) { | 302 CandidateWindowController::Observer* observer) { |
303 observers_.RemoveObserver(observer); | 303 observers_.RemoveObserver(observer); |
304 } | 304 } |
305 | 305 |
306 void CandidateWindowControllerImpl::OnConnectionChange(bool connected) { | 306 void CandidateWindowControllerImpl::PropertyChanged() { |
307 if (!connected) { | 307 } |
308 candidate_window_->HideAll(); | 308 |
309 infolist_window_->Hide(); | 309 void CandidateWindowControllerImpl::OnConnected() { |
310 } | 310 DBusThreadManager::Get()->GetIBusPanelService()->SetUpCandidateWindowHandler( |
| 311 ibus_ui_controller_.get()); |
| 312 } |
| 313 |
| 314 void CandidateWindowControllerImpl::OnDisconnected() { |
| 315 candidate_window_->HideAll(); |
| 316 infolist_window_->Hide(); |
| 317 DBusThreadManager::Get()->GetIBusPanelService()->SetUpCandidateWindowHandler( |
| 318 NULL); |
311 } | 319 } |
312 | 320 |
313 // static | 321 // static |
314 gfx::Point CandidateWindowControllerImpl::GetInfolistWindowPosition( | 322 gfx::Point CandidateWindowControllerImpl::GetInfolistWindowPosition( |
315 const gfx::Rect& candidate_window_rect, | 323 const gfx::Rect& candidate_window_rect, |
316 const gfx::Rect& screen_rect, | 324 const gfx::Rect& screen_rect, |
317 const gfx::Size& infolist_window_size) { | 325 const gfx::Size& infolist_window_size) { |
318 gfx::Point result(candidate_window_rect.right(), candidate_window_rect.y()); | 326 gfx::Point result(candidate_window_rect.right(), candidate_window_rect.y()); |
319 | 327 |
320 if (candidate_window_rect.right() + infolist_window_size.width() > | 328 if (candidate_window_rect.right() + infolist_window_size.width() > |
321 screen_rect.right()) | 329 screen_rect.right()) |
322 result.set_x(candidate_window_rect.x() - infolist_window_size.width()); | 330 result.set_x(candidate_window_rect.x() - infolist_window_size.width()); |
323 | 331 |
324 if (candidate_window_rect.y() + infolist_window_size.height() > | 332 if (candidate_window_rect.y() + infolist_window_size.height() > |
325 screen_rect.bottom()) | 333 screen_rect.bottom()) |
326 result.set_y(screen_rect.bottom() - infolist_window_size.height()); | 334 result.set_y(screen_rect.bottom() - infolist_window_size.height()); |
327 | 335 |
328 return result; | 336 return result; |
329 } | 337 } |
330 | 338 |
331 } // namespace input_method | 339 } // namespace input_method |
332 } // namespace chromeos | 340 } // namespace chromeos |
OLD | NEW |