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 "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 params.parent = ash::Shell::GetContainer( | 55 params.parent = ash::Shell::GetContainer( |
56 ash::Shell::GetTargetRootWindow(), | 56 ash::Shell::GetTargetRootWindow(), |
57 ash::internal::kShellWindowId_InputMethodContainer); | 57 ash::internal::kShellWindowId_InputMethodContainer); |
58 frame_->Init(params); | 58 frame_->Init(params); |
59 | 59 |
60 views::corewm::SetWindowVisibilityAnimationType( | 60 views::corewm::SetWindowVisibilityAnimationType( |
61 frame_->GetNativeView(), | 61 frame_->GetNativeView(), |
62 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 62 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
63 | 63 |
64 // Create the candidate window. | 64 // Create the candidate window. |
65 candidate_window_ = new CandidateWindowView(frame_.get()); | 65 candidate_window_view_ = new CandidateWindowView(frame_.get()); |
66 candidate_window_->Init(); | 66 candidate_window_view_->Init(); |
67 candidate_window_->AddObserver(this); | 67 candidate_window_view_->AddObserver(this); |
68 | 68 |
69 frame_->SetContentsView(candidate_window_); | 69 frame_->SetContentsView(candidate_window_view_); |
70 | 70 |
71 | 71 |
72 // Create the infolist window. | 72 // Create the infolist window. |
73 infolist_window_.reset(new DelayableWidget); | 73 infolist_window_.reset(new DelayableWidget); |
74 infolist_window_->Init(params); | 74 infolist_window_->Init(params); |
75 | 75 |
76 views::corewm::SetWindowVisibilityAnimationType( | 76 views::corewm::SetWindowVisibilityAnimationType( |
77 infolist_window_->GetNativeView(), | 77 infolist_window_->GetNativeView(), |
78 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 78 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
79 | 79 |
80 InfolistWindowView* infolist_view = new InfolistWindowView; | 80 InfolistWindowView* infolist_view = new InfolistWindowView; |
81 infolist_view->Init(); | 81 infolist_view->Init(); |
82 infolist_window_->SetContentsView(infolist_view); | 82 infolist_window_->SetContentsView(infolist_view); |
83 } | 83 } |
84 | 84 |
85 CandidateWindowControllerImpl::CandidateWindowControllerImpl() | 85 CandidateWindowControllerImpl::CandidateWindowControllerImpl() |
86 : candidate_window_(NULL), | 86 : candidate_window_view_(NULL), |
87 latest_infolist_focused_index_(InfolistWindowView::InvalidFocusIndex()) { | 87 latest_infolist_focused_index_(InfolistWindowView::InvalidFocusIndex()) { |
88 IBusBridge::Get()->SetCandidateWindowHandler(this); | 88 IBusBridge::Get()->SetCandidateWindowHandler(this); |
89 } | 89 } |
90 | 90 |
91 CandidateWindowControllerImpl::~CandidateWindowControllerImpl() { | 91 CandidateWindowControllerImpl::~CandidateWindowControllerImpl() { |
92 IBusBridge::Get()->SetCandidateWindowHandler(NULL); | 92 IBusBridge::Get()->SetCandidateWindowHandler(NULL); |
93 candidate_window_->RemoveObserver(this); | 93 candidate_window_view_->RemoveObserver(this); |
94 } | 94 } |
95 | 95 |
96 void CandidateWindowControllerImpl::HideAuxiliaryText() { | 96 void CandidateWindowControllerImpl::HideAuxiliaryText() { |
97 candidate_window_->HideAuxiliaryText(); | 97 candidate_window_view_->HideAuxiliaryText(); |
98 } | 98 } |
99 | 99 |
100 void CandidateWindowControllerImpl::HideLookupTable() { | 100 void CandidateWindowControllerImpl::HideLookupTable() { |
101 candidate_window_->HideLookupTable(); | 101 candidate_window_view_->HideLookupTable(); |
102 infolist_window_->Hide(); | 102 infolist_window_->Hide(); |
103 } | 103 } |
104 | 104 |
105 void CandidateWindowControllerImpl::HidePreeditText() { | 105 void CandidateWindowControllerImpl::HidePreeditText() { |
106 candidate_window_->HidePreeditText(); | 106 candidate_window_view_->HidePreeditText(); |
107 } | 107 } |
108 | 108 |
109 void CandidateWindowControllerImpl::SetCursorLocation( | 109 void CandidateWindowControllerImpl::SetCursorLocation( |
110 const ibus::Rect& cursor_location, | 110 const ibus::Rect& cursor_location, |
111 const ibus::Rect& composition_head) { | 111 const ibus::Rect& composition_head) { |
112 // A workaround for http://crosbug.com/6460. We should ignore very short Y | 112 // A workaround for http://crosbug.com/6460. We should ignore very short Y |
113 // move to prevent the window from shaking up and down. | 113 // move to prevent the window from shaking up and down. |
114 const int kKeepPositionThreshold = 2; // px | 114 const int kKeepPositionThreshold = 2; // px |
115 const gfx::Rect& last_location = | 115 const gfx::Rect& last_location = |
116 candidate_window_->cursor_location(); | 116 candidate_window_view_->cursor_location(); |
117 const int delta_y = abs(last_location.y() - cursor_location.y); | 117 const int delta_y = abs(last_location.y() - cursor_location.y); |
118 if ((last_location.x() == cursor_location.x) && | 118 if ((last_location.x() == cursor_location.x) && |
119 (delta_y <= kKeepPositionThreshold)) { | 119 (delta_y <= kKeepPositionThreshold)) { |
120 DVLOG(1) << "Ignored set_cursor_location signal to prevent window shake"; | 120 DVLOG(1) << "Ignored set_cursor_location signal to prevent window shake"; |
121 return; | 121 return; |
122 } | 122 } |
123 | 123 |
124 // Remember the cursor location. | 124 // Remember the cursor location. |
125 candidate_window_->set_cursor_location(IBusRectToGfxRect(cursor_location)); | 125 candidate_window_view_->set_cursor_location( |
126 candidate_window_->set_composition_head_location( | 126 IBusRectToGfxRect(cursor_location)); |
| 127 candidate_window_view_->set_composition_head_location( |
127 IBusRectToGfxRect(composition_head)); | 128 IBusRectToGfxRect(composition_head)); |
128 // Move the window per the cursor location. | 129 // Move the window per the cursor location. |
129 candidate_window_->ResizeAndMoveParentFrame(); | 130 candidate_window_view_->ResizeAndMoveParentFrame(); |
130 UpdateInfolistBounds(); | 131 UpdateInfolistBounds(); |
131 } | 132 } |
132 | 133 |
133 void CandidateWindowControllerImpl::UpdateAuxiliaryText( | 134 void CandidateWindowControllerImpl::UpdateAuxiliaryText( |
134 const std::string& utf8_text, | 135 const std::string& utf8_text, |
135 bool visible) { | 136 bool visible) { |
136 // If it's not visible, hide the auxiliary text and return. | 137 // If it's not visible, hide the auxiliary text and return. |
137 if (!visible) { | 138 if (!visible) { |
138 candidate_window_->HideAuxiliaryText(); | 139 candidate_window_view_->HideAuxiliaryText(); |
139 return; | 140 return; |
140 } | 141 } |
141 candidate_window_->UpdateAuxiliaryText(utf8_text); | 142 candidate_window_view_->UpdateAuxiliaryText(utf8_text); |
142 candidate_window_->ShowAuxiliaryText(); | 143 candidate_window_view_->ShowAuxiliaryText(); |
143 } | 144 } |
144 | 145 |
145 // static | 146 // static |
146 void CandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( | 147 void CandidateWindowControllerImpl::ConvertLookupTableToInfolistEntry( |
147 const IBusLookupTable& lookup_table, | 148 const CandidateWindow& candidate_window, |
148 std::vector<InfolistWindowView::Entry>* infolist_entries, | 149 std::vector<InfolistWindowView::Entry>* infolist_entries, |
149 size_t* focused_index) { | 150 size_t* focused_index) { |
150 DCHECK(focused_index); | 151 DCHECK(focused_index); |
151 DCHECK(infolist_entries); | 152 DCHECK(infolist_entries); |
152 *focused_index = InfolistWindowView::InvalidFocusIndex(); | 153 *focused_index = InfolistWindowView::InvalidFocusIndex(); |
153 infolist_entries->clear(); | 154 infolist_entries->clear(); |
154 | 155 |
155 const size_t cursor_index_in_page = | 156 const size_t cursor_index_in_page = |
156 lookup_table.cursor_position() % lookup_table.page_size(); | 157 candidate_window.cursor_position() % candidate_window.page_size(); |
157 | 158 |
158 for (size_t i = 0; i < lookup_table.candidates().size(); ++i) { | 159 for (size_t i = 0; i < candidate_window.candidates().size(); ++i) { |
159 const IBusLookupTable::Entry& ibus_entry = | 160 const CandidateWindow::Entry& ibus_entry = |
160 lookup_table.candidates()[i]; | 161 candidate_window.candidates()[i]; |
161 if (ibus_entry.description_title.empty() && | 162 if (ibus_entry.description_title.empty() && |
162 ibus_entry.description_body.empty()) | 163 ibus_entry.description_body.empty()) |
163 continue; | 164 continue; |
164 InfolistWindowView::Entry entry; | 165 InfolistWindowView::Entry entry; |
165 entry.title = ibus_entry.description_title; | 166 entry.title = ibus_entry.description_title; |
166 entry.body = ibus_entry.description_body; | 167 entry.body = ibus_entry.description_body; |
167 infolist_entries->push_back(entry); | 168 infolist_entries->push_back(entry); |
168 if (i == cursor_index_in_page) | 169 if (i == cursor_index_in_page) |
169 *focused_index = infolist_entries->size() - 1; | 170 *focused_index = infolist_entries->size() - 1; |
170 } | 171 } |
(...skipping 15 matching lines...) Expand all Loading... |
186 for (size_t i = 0; i < old_entries.size(); ++i) { | 187 for (size_t i = 0; i < old_entries.size(); ++i) { |
187 if (old_entries[i].title != new_entries[i].title || | 188 if (old_entries[i].title != new_entries[i].title || |
188 old_entries[i].body != new_entries[i].body ) { | 189 old_entries[i].body != new_entries[i].body ) { |
189 return true; | 190 return true; |
190 } | 191 } |
191 } | 192 } |
192 return false; | 193 return false; |
193 } | 194 } |
194 | 195 |
195 void CandidateWindowControllerImpl::UpdateLookupTable( | 196 void CandidateWindowControllerImpl::UpdateLookupTable( |
196 const IBusLookupTable& lookup_table, | 197 const CandidateWindow& candidate_window, |
197 bool visible) { | 198 bool visible) { |
198 // If it's not visible, hide the lookup table and return. | 199 // If it's not visible, hide the lookup table and return. |
199 if (!visible) { | 200 if (!visible) { |
200 candidate_window_->HideLookupTable(); | 201 candidate_window_view_->HideLookupTable(); |
201 infolist_window_->Hide(); | 202 infolist_window_->Hide(); |
202 // TODO(nona): Introduce unittests for crbug.com/170036. | 203 // TODO(nona): Introduce unittests for crbug.com/170036. |
203 latest_infolist_entries_.clear(); | 204 latest_infolist_entries_.clear(); |
204 return; | 205 return; |
205 } | 206 } |
206 | 207 |
207 candidate_window_->UpdateCandidates(lookup_table); | 208 candidate_window_view_->UpdateCandidates(candidate_window); |
208 candidate_window_->ShowLookupTable(); | 209 candidate_window_view_->ShowLookupTable(); |
209 | 210 |
210 size_t focused_index = 0; | 211 size_t focused_index = 0; |
211 std::vector<InfolistWindowView::Entry> infolist_entries; | 212 std::vector<InfolistWindowView::Entry> infolist_entries; |
212 ConvertLookupTableToInfolistEntry(lookup_table, &infolist_entries, | 213 ConvertLookupTableToInfolistEntry(candidate_window, &infolist_entries, |
213 &focused_index); | 214 &focused_index); |
214 | 215 |
215 // If there is no infolist entry, just hide. | 216 // If there is no infolist entry, just hide. |
216 if (infolist_entries.empty()) { | 217 if (infolist_entries.empty()) { |
217 infolist_window_->Hide(); | 218 infolist_window_->Hide(); |
218 return; | 219 return; |
219 } | 220 } |
220 | 221 |
221 // If there is no change, just return. | 222 // If there is no change, just return. |
222 if (!ShouldUpdateInfolist(latest_infolist_entries_, | 223 if (!ShouldUpdateInfolist(latest_infolist_entries_, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 new_bounds.size())); | 263 new_bounds.size())); |
263 | 264 |
264 if (current_bounds != new_bounds) | 265 if (current_bounds != new_bounds) |
265 infolist_window_->SetBounds(new_bounds); | 266 infolist_window_->SetBounds(new_bounds); |
266 } | 267 } |
267 | 268 |
268 void CandidateWindowControllerImpl::UpdatePreeditText( | 269 void CandidateWindowControllerImpl::UpdatePreeditText( |
269 const std::string& utf8_text, unsigned int cursor, bool visible) { | 270 const std::string& utf8_text, unsigned int cursor, bool visible) { |
270 // If it's not visible, hide the preedit text and return. | 271 // If it's not visible, hide the preedit text and return. |
271 if (!visible || utf8_text.empty()) { | 272 if (!visible || utf8_text.empty()) { |
272 candidate_window_->HidePreeditText(); | 273 candidate_window_view_->HidePreeditText(); |
273 return; | 274 return; |
274 } | 275 } |
275 candidate_window_->UpdatePreeditText(utf8_text); | 276 candidate_window_view_->UpdatePreeditText(utf8_text); |
276 candidate_window_->ShowPreeditText(); | 277 candidate_window_view_->ShowPreeditText(); |
277 } | 278 } |
278 | 279 |
279 void CandidateWindowControllerImpl::OnCandidateCommitted(int index, | 280 void CandidateWindowControllerImpl::OnCandidateCommitted(int index, |
280 int button, | 281 int button, |
281 int flags) { | 282 int flags) { |
282 IBusEngineHandlerInterface* engine = IBusBridge::Get()->GetEngineHandler(); | 283 IBusEngineHandlerInterface* engine = IBusBridge::Get()->GetEngineHandler(); |
283 if (engine) | 284 if (engine) |
284 engine->CandidateClicked(index, | 285 engine->CandidateClicked(index, |
285 static_cast<ibus::IBusMouseButton>(button), | 286 static_cast<ibus::IBusMouseButton>(button), |
286 flags); | 287 flags); |
(...skipping 14 matching lines...) Expand all Loading... |
301 observers_.AddObserver(observer); | 302 observers_.AddObserver(observer); |
302 } | 303 } |
303 | 304 |
304 void CandidateWindowControllerImpl::RemoveObserver( | 305 void CandidateWindowControllerImpl::RemoveObserver( |
305 CandidateWindowController::Observer* observer) { | 306 CandidateWindowController::Observer* observer) { |
306 observers_.RemoveObserver(observer); | 307 observers_.RemoveObserver(observer); |
307 } | 308 } |
308 | 309 |
309 // static | 310 // static |
310 gfx::Point CandidateWindowControllerImpl::GetInfolistWindowPosition( | 311 gfx::Point CandidateWindowControllerImpl::GetInfolistWindowPosition( |
311 const gfx::Rect& candidate_window_rect, | 312 const gfx::Rect& candidate_window_view_rect, |
312 const gfx::Rect& screen_rect, | 313 const gfx::Rect& screen_rect, |
313 const gfx::Size& infolist_window_size) { | 314 const gfx::Size& infolist_window_size) { |
314 gfx::Point result(candidate_window_rect.right(), candidate_window_rect.y()); | 315 gfx::Point result(candidate_window_view_rect.right(), |
| 316 candidate_window_view_rect.y()); |
315 | 317 |
316 if (candidate_window_rect.right() + infolist_window_size.width() > | 318 if (candidate_window_view_rect.right() + infolist_window_size.width() > |
317 screen_rect.right()) | 319 screen_rect.right()) |
318 result.set_x(candidate_window_rect.x() - infolist_window_size.width()); | 320 result.set_x(candidate_window_view_rect.x() - infolist_window_size.width()); |
319 | 321 |
320 if (candidate_window_rect.y() + infolist_window_size.height() > | 322 if (candidate_window_view_rect.y() + infolist_window_size.height() > |
321 screen_rect.bottom()) | 323 screen_rect.bottom()) |
322 result.set_y(screen_rect.bottom() - infolist_window_size.height()); | 324 result.set_y(screen_rect.bottom() - infolist_window_size.height()); |
323 | 325 |
324 return result; | 326 return result; |
325 } | 327 } |
326 | 328 |
327 } // namespace input_method | 329 } // namespace input_method |
328 } // namespace chromeos | 330 } // namespace chromeos |
OLD | NEW |