Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / base / ime / candidate_window.cc
blob6cb32e2d77f18ee915a87f1069a045a48d4f4fec
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
3 // found in the LICENSE file.
5 #include "ui/base/ime/candidate_window.h"
7 #include <string>
8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h"
12 namespace ui {
14 namespace {
15 // The default entry number of a page in CandidateWindow.
16 const int kDefaultPageSize = 9;
17 } // namespace
19 CandidateWindow::CandidateWindow()
20 : property_(new CandidateWindowProperty) {
23 CandidateWindow::~CandidateWindow() {
26 bool CandidateWindow::IsEqual(const CandidateWindow& cw) const {
27 if (page_size() != cw.page_size() ||
28 cursor_position() != cw.cursor_position() ||
29 is_cursor_visible() != cw.is_cursor_visible() ||
30 orientation() != cw.orientation() ||
31 show_window_at_composition() != cw.show_window_at_composition() ||
32 is_auxiliary_text_visible() != cw.is_auxiliary_text_visible() ||
33 auxiliary_text() != cw.auxiliary_text() ||
34 candidates_.size() != cw.candidates_.size())
35 return false;
37 for (size_t i = 0; i < candidates_.size(); ++i) {
38 const Entry& left = candidates_[i];
39 const Entry& right = cw.candidates_[i];
40 if (left.value != right.value ||
41 left.label != right.label ||
42 left.annotation != right.annotation ||
43 left.description_title != right.description_title ||
44 left.description_body != right.description_body)
45 return false;
47 return true;
50 void CandidateWindow::CopyFrom(const CandidateWindow& cw) {
51 SetProperty(cw.GetProperty());
52 candidates_.clear();
53 candidates_ = cw.candidates_;
57 void CandidateWindow::GetInfolistEntries(
58 std::vector<ui::InfolistEntry>* infolist_entries,
59 bool* has_highlighted) const {
60 DCHECK(infolist_entries);
61 DCHECK(has_highlighted);
62 infolist_entries->clear();
63 *has_highlighted = false;
65 const size_t cursor_index_in_page = cursor_position() % page_size();
67 for (size_t i = 0; i < candidates().size(); ++i) {
68 const CandidateWindow::Entry& candidate_entry = candidates()[i];
69 if (candidate_entry.description_title.empty() &&
70 candidate_entry.description_body.empty())
71 continue;
73 InfolistEntry entry(candidate_entry.description_title,
74 candidate_entry.description_body);
75 if (i == cursor_index_in_page) {
76 entry.highlighted = true;
77 *has_highlighted = true;
79 infolist_entries->push_back(entry);
83 // When the default values are changed, please modify
84 // InputMethodEngineInterface::CandidateWindowProperty too.
85 CandidateWindow::CandidateWindowProperty::CandidateWindowProperty()
86 : page_size(kDefaultPageSize),
87 cursor_position(0),
88 is_cursor_visible(true),
89 is_vertical(false),
90 show_window_at_composition(false),
91 is_auxiliary_text_visible(false) {
94 CandidateWindow::CandidateWindowProperty::~CandidateWindowProperty() {
97 CandidateWindow::Entry::Entry() {
100 CandidateWindow::Entry::~Entry() {
103 } // namespace ui