| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/chromeos/ime/candidate_window_view.h" | 5 #include "ui/chromeos/ime/candidate_window_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "ui/chromeos/ime/candidate_view.h" | 14 #include "ui/chromeos/ime/candidate_view.h" |
| 14 #include "ui/chromeos/ime/candidate_window_constants.h" | 15 #include "ui/chromeos/ime/candidate_window_constants.h" |
| 15 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 16 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
| 17 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
| 18 #include "ui/native_theme/native_theme.h" | 19 #include "ui/native_theme/native_theme.h" |
| 19 #include "ui/views/background.h" | 20 #include "ui/views/background.h" |
| 20 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
| 21 #include "ui/views/bubble/bubble_frame_view.h" | 22 #include "ui/views/bubble/bubble_frame_view.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 274 |
| 274 // Update the candidates in the current page. | 275 // Update the candidates in the current page. |
| 275 const size_t start_from = | 276 const size_t start_from = |
| 276 current_page_index * new_candidate_window.page_size(); | 277 current_page_index * new_candidate_window.page_size(); |
| 277 | 278 |
| 278 int max_shortcut_width = 0; | 279 int max_shortcut_width = 0; |
| 279 int max_candidate_width = 0; | 280 int max_candidate_width = 0; |
| 280 for (size_t i = 0; i < candidate_views_.size(); ++i) { | 281 for (size_t i = 0; i < candidate_views_.size(); ++i) { |
| 281 const size_t index_in_page = i; | 282 const size_t index_in_page = i; |
| 282 const size_t candidate_index = start_from + index_in_page; | 283 const size_t candidate_index = start_from + index_in_page; |
| 283 CandidateView* candidate_view = candidate_views_[index_in_page]; | 284 CandidateView* candidate_view = candidate_views_[index_in_page].get(); |
| 284 // Set the candidate text. | 285 // Set the candidate text. |
| 285 if (candidate_index < new_candidate_window.candidates().size()) { | 286 if (candidate_index < new_candidate_window.candidates().size()) { |
| 286 const ui::CandidateWindow::Entry& entry = | 287 const ui::CandidateWindow::Entry& entry = |
| 287 new_candidate_window.candidates()[candidate_index]; | 288 new_candidate_window.candidates()[candidate_index]; |
| 288 candidate_view->SetEntry(entry); | 289 candidate_view->SetEntry(entry); |
| 289 candidate_view->SetEnabled(true); | 290 candidate_view->SetEnabled(true); |
| 290 candidate_view->SetInfolistIcon(!entry.description_title.empty()); | 291 candidate_view->SetInfolistIcon(!entry.description_title.empty()); |
| 291 } else { | 292 } else { |
| 292 // Disable the empty row. | 293 // Disable the empty row. |
| 293 candidate_view->SetEntry(ui::CandidateWindow::Entry()); | 294 candidate_view->SetEntry(ui::CandidateWindow::Entry()); |
| 294 candidate_view->SetEnabled(false); | 295 candidate_view->SetEnabled(false); |
| 295 candidate_view->SetInfolistIcon(false); | 296 candidate_view->SetInfolistIcon(false); |
| 296 } | 297 } |
| 297 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) { | 298 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) { |
| 298 int shortcut_width = 0; | 299 int shortcut_width = 0; |
| 299 int candidate_width = 0; | 300 int candidate_width = 0; |
| 300 candidate_views_[i]->GetPreferredWidths( | 301 candidate_views_[i]->GetPreferredWidths( |
| 301 &shortcut_width, &candidate_width); | 302 &shortcut_width, &candidate_width); |
| 302 max_shortcut_width = std::max(max_shortcut_width, shortcut_width); | 303 max_shortcut_width = std::max(max_shortcut_width, shortcut_width); |
| 303 max_candidate_width = std::max(max_candidate_width, candidate_width); | 304 max_candidate_width = std::max(max_candidate_width, candidate_width); |
| 304 } | 305 } |
| 305 } | 306 } |
| 306 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) { | 307 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) { |
| 307 for (size_t i = 0; i < candidate_views_.size(); ++i) | 308 for (const auto& view : candidate_views_) |
| 308 candidate_views_[i]->SetWidths(max_shortcut_width, max_candidate_width); | 309 view->SetWidths(max_shortcut_width, max_candidate_width); |
| 309 } | 310 } |
| 310 | 311 |
| 311 CandidateWindowBorder* border = static_cast<CandidateWindowBorder*>( | 312 CandidateWindowBorder* border = static_cast<CandidateWindowBorder*>( |
| 312 GetBubbleFrameView()->bubble_border()); | 313 GetBubbleFrameView()->bubble_border()); |
| 313 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) | 314 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) |
| 314 border->set_offset(max_shortcut_width); | 315 border->set_offset(max_shortcut_width); |
| 315 else | 316 else |
| 316 border->set_offset(0); | 317 border->set_offset(0); |
| 317 } | 318 } |
| 318 // Update the current candidate window. We'll use candidate_window_ from here. | 319 // Update the current candidate window. We'll use candidate_window_ from here. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 353 } |
| 353 | 354 |
| 354 void CandidateWindowView::MaybeInitializeCandidateViews( | 355 void CandidateWindowView::MaybeInitializeCandidateViews( |
| 355 const ui::CandidateWindow& candidate_window) { | 356 const ui::CandidateWindow& candidate_window) { |
| 356 const ui::CandidateWindow::Orientation orientation = | 357 const ui::CandidateWindow::Orientation orientation = |
| 357 candidate_window.orientation(); | 358 candidate_window.orientation(); |
| 358 const size_t page_size = candidate_window.page_size(); | 359 const size_t page_size = candidate_window.page_size(); |
| 359 | 360 |
| 360 // Reset all candidate_views_ when orientation changes. | 361 // Reset all candidate_views_ when orientation changes. |
| 361 if (orientation != candidate_window_.orientation()) | 362 if (orientation != candidate_window_.orientation()) |
| 362 base::STLDeleteElements(&candidate_views_); | 363 candidate_views_.clear(); |
| 363 | 364 |
| 364 while (page_size < candidate_views_.size()) { | 365 while (page_size < candidate_views_.size()) |
| 365 delete candidate_views_.back(); | |
| 366 candidate_views_.pop_back(); | 366 candidate_views_.pop_back(); |
| 367 } | 367 |
| 368 while (page_size > candidate_views_.size()) { | 368 while (page_size > candidate_views_.size()) { |
| 369 CandidateView* new_candidate = new CandidateView(this, orientation); | 369 std::unique_ptr<CandidateView> new_candidate = |
| 370 candidate_area_->AddChildView(new_candidate); | 370 base::MakeUnique<CandidateView>(this, orientation); |
| 371 candidate_views_.push_back(new_candidate); | 371 candidate_area_->AddChildView(new_candidate.get()); |
| 372 candidate_views_.push_back(std::move(new_candidate)); |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| 375 void CandidateWindowView::SelectCandidateAt(int index_in_page) { | 376 void CandidateWindowView::SelectCandidateAt(int index_in_page) { |
| 376 const int current_page_index = ComputePageIndex(candidate_window_); | 377 const int current_page_index = ComputePageIndex(candidate_window_); |
| 377 if (current_page_index < 0) { | 378 if (current_page_index < 0) { |
| 378 return; | 379 return; |
| 379 } | 380 } |
| 380 | 381 |
| 381 const int cursor_absolute_index = | 382 const int cursor_absolute_index = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 401 return "CandidateWindowView"; | 402 return "CandidateWindowView"; |
| 402 } | 403 } |
| 403 | 404 |
| 404 int CandidateWindowView::GetDialogButtons() const { | 405 int CandidateWindowView::GetDialogButtons() const { |
| 405 return ui::DIALOG_BUTTON_NONE; | 406 return ui::DIALOG_BUTTON_NONE; |
| 406 } | 407 } |
| 407 | 408 |
| 408 void CandidateWindowView::ButtonPressed(views::Button* sender, | 409 void CandidateWindowView::ButtonPressed(views::Button* sender, |
| 409 const ui::Event& event) { | 410 const ui::Event& event) { |
| 410 for (size_t i = 0; i < candidate_views_.size(); ++i) { | 411 for (size_t i = 0; i < candidate_views_.size(); ++i) { |
| 411 if (sender == candidate_views_[i]) { | 412 if (sender == candidate_views_[i].get()) { |
| 412 for (Observer& observer : observers_) | 413 for (Observer& observer : observers_) |
| 413 observer.OnCandidateCommitted(i); | 414 observer.OnCandidateCommitted(i); |
| 414 return; | 415 return; |
| 415 } | 416 } |
| 416 } | 417 } |
| 417 } | 418 } |
| 418 | 419 |
| 419 } // namespace ime | 420 } // namespace ime |
| 420 } // namespace ui | 421 } // namespace ui |
| OLD | NEW |