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

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

Issue 132453002: Moves CandidateWindow model to ui/base/ime (2nd) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" 4 #include "chrome/browser/chromeos/input_method/candidate_window_view.h"
5 5
6 #include <string> 6 #include <string>
7 7
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chromeos/input_method/candidate_view.h" 9 #include "chrome/browser/chromeos/input_method/candidate_view.h"
10 #include "chrome/browser/chromeos/input_method/candidate_window_constants.h" 10 #include "chrome/browser/chromeos/input_method/candidate_window_constants.h"
11 #include "chromeos/ime/candidate_window.h"
12 #include "ui/gfx/color_utils.h" 11 #include "ui/gfx/color_utils.h"
13 #include "ui/gfx/screen.h" 12 #include "ui/gfx/screen.h"
14 #include "ui/native_theme/native_theme.h" 13 #include "ui/native_theme/native_theme.h"
15 #include "ui/views/background.h" 14 #include "ui/views/background.h"
16 #include "ui/views/border.h" 15 #include "ui/views/border.h"
17 #include "ui/views/bubble/bubble_frame_view.h" 16 #include "ui/views/bubble/bubble_frame_view.h"
18 #include "ui/views/controls/label.h" 17 #include "ui/views/controls/label.h"
19 #include "ui/views/corewm/window_animations.h" 18 #include "ui/views/corewm/window_animations.h"
20 #include "ui/views/layout/box_layout.h" 19 #include "ui/views/layout/box_layout.h"
21 #include "ui/views/layout/fill_layout.h" 20 #include "ui/views/layout/fill_layout.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 67
69 gfx::NativeView parent_; 68 gfx::NativeView parent_;
70 int offset_; 69 int offset_;
71 70
72 DISALLOW_COPY_AND_ASSIGN(CandidateWindowBorder); 71 DISALLOW_COPY_AND_ASSIGN(CandidateWindowBorder);
73 }; 72 };
74 73
75 // Computes the page index. For instance, if the page size is 9, and the 74 // Computes the page index. For instance, if the page size is 9, and the
76 // cursor is pointing to 13th candidate, the page index will be 1 (2nd 75 // cursor is pointing to 13th candidate, the page index will be 1 (2nd
77 // page, as the index is zero-origin). Returns -1 on error. 76 // page, as the index is zero-origin). Returns -1 on error.
78 int ComputePageIndex(const CandidateWindow& candidate_window) { 77 int ComputePageIndex(const ui::CandidateWindow& candidate_window) {
79 if (candidate_window.page_size() > 0) 78 if (candidate_window.page_size() > 0)
80 return candidate_window.cursor_position() / candidate_window.page_size(); 79 return candidate_window.cursor_position() / candidate_window.page_size();
81 return -1; 80 return -1;
82 } 81 }
83 82
84 } // namespace 83 } // namespace
85 84
86 class InformationTextArea : public views::View { 85 class InformationTextArea : public views::View {
87 public: 86 public:
88 // InformationTextArea's border is drawn as a separator, it should appear 87 // InformationTextArea's border is drawn as a separator, it should appear
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 1, theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBorderColor))); 156 1, theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBorderColor)));
158 157
159 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 158 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
160 auxiliary_text_ = new InformationTextArea(gfx::ALIGN_RIGHT, 0); 159 auxiliary_text_ = new InformationTextArea(gfx::ALIGN_RIGHT, 0);
161 preedit_ = new InformationTextArea(gfx::ALIGN_LEFT, kMinPreeditAreaWidth); 160 preedit_ = new InformationTextArea(gfx::ALIGN_LEFT, kMinPreeditAreaWidth);
162 candidate_area_ = new views::View; 161 candidate_area_ = new views::View;
163 auxiliary_text_->SetVisible(false); 162 auxiliary_text_->SetVisible(false);
164 preedit_->SetVisible(false); 163 preedit_->SetVisible(false);
165 candidate_area_->SetVisible(false); 164 candidate_area_->SetVisible(false);
166 preedit_->SetBorder(InformationTextArea::BOTTOM); 165 preedit_->SetBorder(InformationTextArea::BOTTOM);
167 if (candidate_window_.orientation() == CandidateWindow::VERTICAL) { 166 if (candidate_window_.orientation() == ui::CandidateWindow::VERTICAL) {
168 AddChildView(preedit_); 167 AddChildView(preedit_);
169 AddChildView(candidate_area_); 168 AddChildView(candidate_area_);
170 AddChildView(auxiliary_text_); 169 AddChildView(auxiliary_text_);
171 auxiliary_text_->SetBorder(InformationTextArea::TOP); 170 auxiliary_text_->SetBorder(InformationTextArea::TOP);
172 candidate_area_->SetLayoutManager(new views::BoxLayout( 171 candidate_area_->SetLayoutManager(new views::BoxLayout(
173 views::BoxLayout::kVertical, 0, 0, 0)); 172 views::BoxLayout::kVertical, 0, 0, 0));
174 } else { 173 } else {
175 AddChildView(preedit_); 174 AddChildView(preedit_);
176 AddChildView(auxiliary_text_); 175 AddChildView(auxiliary_text_);
177 AddChildView(candidate_area_); 176 AddChildView(candidate_area_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 preedit_->SetText(utf8_text); 225 preedit_->SetText(utf8_text);
227 } 226 }
228 227
229 void CandidateWindowView::ShowLookupTable() { 228 void CandidateWindowView::ShowLookupTable() {
230 candidate_area_->SetVisible(true); 229 candidate_area_->SetVisible(true);
231 auxiliary_text_->SetVisible(candidate_window_.is_auxiliary_text_visible()); 230 auxiliary_text_->SetVisible(candidate_window_.is_auxiliary_text_visible());
232 UpdateVisibility(); 231 UpdateVisibility();
233 } 232 }
234 233
235 void CandidateWindowView::UpdateCandidates( 234 void CandidateWindowView::UpdateCandidates(
236 const CandidateWindow& new_candidate_window) { 235 const ui::CandidateWindow& new_candidate_window) {
237 // Updating the candidate views is expensive. We'll skip this if possible. 236 // Updating the candidate views is expensive. We'll skip this if possible.
238 if (!candidate_window_.IsEqual(new_candidate_window)) { 237 if (!candidate_window_.IsEqual(new_candidate_window)) {
239 if (candidate_window_.orientation() != new_candidate_window.orientation()) { 238 if (candidate_window_.orientation() != new_candidate_window.orientation()) {
240 // If the new layout is vertical, the aux text should appear at the 239 // If the new layout is vertical, the aux text should appear at the
241 // bottom. If horizontal, it should appear between preedit and candidates. 240 // bottom. If horizontal, it should appear between preedit and candidates.
242 if (new_candidate_window.orientation() == CandidateWindow::VERTICAL) { 241 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) {
243 ReorderChildView(auxiliary_text_, -1); 242 ReorderChildView(auxiliary_text_, -1);
244 auxiliary_text_->SetAlignment(gfx::ALIGN_RIGHT); 243 auxiliary_text_->SetAlignment(gfx::ALIGN_RIGHT);
245 auxiliary_text_->SetBorder(InformationTextArea::TOP); 244 auxiliary_text_->SetBorder(InformationTextArea::TOP);
246 candidate_area_->SetLayoutManager(new views::BoxLayout( 245 candidate_area_->SetLayoutManager(new views::BoxLayout(
247 views::BoxLayout::kVertical, 0, 0, 0)); 246 views::BoxLayout::kVertical, 0, 0, 0));
248 } else { 247 } else {
249 ReorderChildView(auxiliary_text_, 1); 248 ReorderChildView(auxiliary_text_, 1);
250 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT); 249 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT);
251 auxiliary_text_->SetBorder(InformationTextArea::BOTTOM); 250 auxiliary_text_->SetBorder(InformationTextArea::BOTTOM);
252 candidate_area_->SetLayoutManager(new views::BoxLayout( 251 candidate_area_->SetLayoutManager(new views::BoxLayout(
(...skipping 16 matching lines...) Expand all
269 current_page_index * new_candidate_window.page_size(); 268 current_page_index * new_candidate_window.page_size();
270 269
271 int max_shortcut_width = 0; 270 int max_shortcut_width = 0;
272 int max_candidate_width = 0; 271 int max_candidate_width = 0;
273 for (size_t i = 0; i < candidate_views_.size(); ++i) { 272 for (size_t i = 0; i < candidate_views_.size(); ++i) {
274 const size_t index_in_page = i; 273 const size_t index_in_page = i;
275 const size_t candidate_index = start_from + index_in_page; 274 const size_t candidate_index = start_from + index_in_page;
276 CandidateView* candidate_view = candidate_views_[index_in_page]; 275 CandidateView* candidate_view = candidate_views_[index_in_page];
277 // Set the candidate text. 276 // Set the candidate text.
278 if (candidate_index < new_candidate_window.candidates().size()) { 277 if (candidate_index < new_candidate_window.candidates().size()) {
279 const CandidateWindow::Entry& entry = 278 const ui::CandidateWindow::Entry& entry =
280 new_candidate_window.candidates()[candidate_index]; 279 new_candidate_window.candidates()[candidate_index];
281 candidate_view->SetEntry(entry); 280 candidate_view->SetEntry(entry);
282 candidate_view->SetState(views::Button::STATE_NORMAL); 281 candidate_view->SetState(views::Button::STATE_NORMAL);
283 candidate_view->SetInfolistIcon(!entry.description_title.empty()); 282 candidate_view->SetInfolistIcon(!entry.description_title.empty());
284 } else { 283 } else {
285 // Disable the empty row. 284 // Disable the empty row.
286 candidate_view->SetEntry(CandidateWindow::Entry()); 285 candidate_view->SetEntry(ui::CandidateWindow::Entry());
287 candidate_view->SetState(views::Button::STATE_DISABLED); 286 candidate_view->SetState(views::Button::STATE_DISABLED);
288 candidate_view->SetInfolistIcon(false); 287 candidate_view->SetInfolistIcon(false);
289 } 288 }
290 if (new_candidate_window.orientation() == CandidateWindow::VERTICAL) { 289 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) {
291 int shortcut_width = 0; 290 int shortcut_width = 0;
292 int candidate_width = 0; 291 int candidate_width = 0;
293 candidate_views_[i]->GetPreferredWidths( 292 candidate_views_[i]->GetPreferredWidths(
294 &shortcut_width, &candidate_width); 293 &shortcut_width, &candidate_width);
295 max_shortcut_width = std::max(max_shortcut_width, shortcut_width); 294 max_shortcut_width = std::max(max_shortcut_width, shortcut_width);
296 max_candidate_width = std::max(max_candidate_width, candidate_width); 295 max_candidate_width = std::max(max_candidate_width, candidate_width);
297 } 296 }
298 } 297 }
299 if (new_candidate_window.orientation() == CandidateWindow::VERTICAL) { 298 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) {
300 for (size_t i = 0; i < candidate_views_.size(); ++i) 299 for (size_t i = 0; i < candidate_views_.size(); ++i)
301 candidate_views_[i]->SetWidths(max_shortcut_width, max_candidate_width); 300 candidate_views_[i]->SetWidths(max_shortcut_width, max_candidate_width);
302 } 301 }
303 302
304 CandidateWindowBorder* border = static_cast<CandidateWindowBorder*>( 303 CandidateWindowBorder* border = static_cast<CandidateWindowBorder*>(
305 GetBubbleFrameView()->bubble_border()); 304 GetBubbleFrameView()->bubble_border());
306 if (new_candidate_window.orientation() == CandidateWindow::VERTICAL) 305 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL)
307 border->set_offset(max_shortcut_width); 306 border->set_offset(max_shortcut_width);
308 else 307 else
309 border->set_offset(0); 308 border->set_offset(0);
310 } 309 }
311 // Update the current candidate window. We'll use candidate_window_ from here. 310 // Update the current candidate window. We'll use candidate_window_ from here.
312 // Note that SelectCandidateAt() uses candidate_window_. 311 // Note that SelectCandidateAt() uses candidate_window_.
313 candidate_window_.CopyFrom(new_candidate_window); 312 candidate_window_.CopyFrom(new_candidate_window);
314 313
315 // Select the current candidate in the page. 314 // Select the current candidate in the page.
316 if (candidate_window_.is_cursor_visible()) { 315 if (candidate_window_.is_cursor_visible()) {
(...skipping 20 matching lines...) Expand all
337 336
338 void CandidateWindowView::SetCursorBounds(const gfx::Rect& cursor_bounds, 337 void CandidateWindowView::SetCursorBounds(const gfx::Rect& cursor_bounds,
339 const gfx::Rect& composition_head) { 338 const gfx::Rect& composition_head) {
340 if (candidate_window_.show_window_at_composition()) 339 if (candidate_window_.show_window_at_composition())
341 SetAnchorRect(composition_head); 340 SetAnchorRect(composition_head);
342 else 341 else
343 SetAnchorRect(cursor_bounds); 342 SetAnchorRect(cursor_bounds);
344 } 343 }
345 344
346 void CandidateWindowView::MaybeInitializeCandidateViews( 345 void CandidateWindowView::MaybeInitializeCandidateViews(
347 const CandidateWindow& candidate_window) { 346 const ui::CandidateWindow& candidate_window) {
348 const CandidateWindow::Orientation orientation = 347 const ui::CandidateWindow::Orientation orientation =
349 candidate_window.orientation(); 348 candidate_window.orientation();
350 const size_t page_size = candidate_window.page_size(); 349 const size_t page_size = candidate_window.page_size();
351 350
352 // Reset all candidate_views_ when orientation changes. 351 // Reset all candidate_views_ when orientation changes.
353 if (orientation != candidate_window_.orientation()) 352 if (orientation != candidate_window_.orientation())
354 STLDeleteElements(&candidate_views_); 353 STLDeleteElements(&candidate_views_);
355 354
356 while (page_size < candidate_views_.size()) { 355 while (page_size < candidate_views_.size()) {
357 delete candidate_views_.back(); 356 delete candidate_views_.back();
358 candidate_views_.pop_back(); 357 candidate_views_.pop_back();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 for (size_t i = 0; i < candidate_views_.size(); ++i) { 393 for (size_t i = 0; i < candidate_views_.size(); ++i) {
395 if (sender == candidate_views_[i]) { 394 if (sender == candidate_views_[i]) {
396 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateCommitted(i)); 395 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateCommitted(i));
397 return; 396 return;
398 } 397 }
399 } 398 }
400 } 399 }
401 400
402 } // namespace input_method 401 } // namespace input_method
403 } // namespace chromeos 402 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698