| 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.h" | 5 #include "chrome/browser/chromeos/input_method/candidate_window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 1, views::GridLayout::USE_PREF, 0, 0); | 134 1, views::GridLayout::USE_PREF, 0, 0); |
| 135 layout->StartRow(0, 0); | 135 layout->StartRow(0, 0); |
| 136 | 136 |
| 137 // Add the view contents. | 137 // Add the view contents. |
| 138 layout->AddView(view); // |view| is owned by |wraper|, not |layout|. | 138 layout->AddView(view); // |view| is owned by |wraper|, not |layout|. |
| 139 return wrapper; | 139 return wrapper; |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Creates shortcut text from the given index and the orientation. | 142 // Creates shortcut text from the given index and the orientation. |
| 143 string16 CreateShortcutText(int index, | 143 string16 CreateShortcutText(int index, |
| 144 InputMethodLookupTable::Orientation orientation) { | 144 const InputMethodLookupTable& table) { |
| 145 // Choose the character used for the shortcut label. | 145 // Choose the character used for the shortcut label. |
| 146 const char kShortcutCharacters[] = "1234567890ABCDEF"; | 146 const char kShortcutCharacters[] = "1234567890ABCDEF"; |
| 147 // The default character should not be used but just in case. | 147 // The default character should not be used but just in case. |
| 148 char shortcut_character = L'?'; | 148 std::string shortcut_text = " "; |
| 149 // -1 to exclude the null character at the end. | 149 if (table.labels.empty()) { |
| 150 if (index < static_cast<int>(arraysize(kShortcutCharacters) - 1)) | 150 // -1 to exclude the null character at the end. |
| 151 shortcut_character = kShortcutCharacters[index]; | 151 if (index < static_cast<int>(arraysize(kShortcutCharacters) - 1)) |
| 152 shortcut_text = std::string(1, kShortcutCharacters[index]); |
| 153 } else { |
| 154 if (index < static_cast<int>(table.labels.size())) |
| 155 shortcut_text = table.labels[index]; |
| 156 } |
| 152 | 157 |
| 153 std::string shortcut_text(1, shortcut_character); | 158 if (table.orientation != InputMethodLookupTable::kVertical) |
| 154 if (orientation != InputMethodLookupTable::kVertical) | |
| 155 shortcut_text += '.'; | 159 shortcut_text += '.'; |
| 156 return ASCIIToUTF16(shortcut_text); | 160 return UTF8ToUTF16(shortcut_text); |
| 157 } | 161 } |
| 158 | 162 |
| 159 // Creates the shortcut label, and returns it (never returns NULL). | 163 // Creates the shortcut label, and returns it (never returns NULL). |
| 160 // The label text is not set in this function. | 164 // The label text is not set in this function. |
| 161 views::Label* CreateShortcutLabel( | 165 views::Label* CreateShortcutLabel( |
| 162 InputMethodLookupTable::Orientation orientation) { | 166 InputMethodLookupTable::Orientation orientation) { |
| 163 // Create the shortcut label. The label will be owned by | 167 // Create the shortcut label. The label will be owned by |
| 164 // |wrapped_shortcut_label|, hence it's deleted when | 168 // |wrapped_shortcut_label|, hence it's deleted when |
| 165 // |wrapped_shortcut_label| is deleted. | 169 // |wrapped_shortcut_label| is deleted. |
| 166 views::Label* shortcut_label = new views::Label; | 170 views::Label* shortcut_label = new views::Label; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // |wrapped_shortcut_label|, hence it's deleted when | 260 // |wrapped_shortcut_label|, hence it's deleted when |
| 257 // |wrapped_shortcut_label| is deleted. | 261 // |wrapped_shortcut_label| is deleted. |
| 258 views::Label* shortcut_label = CreateShortcutLabel(lookup_table.orientation); | 262 views::Label* shortcut_label = CreateShortcutLabel(lookup_table.orientation); |
| 259 scoped_ptr<views::View> wrapped_shortcut_label( | 263 scoped_ptr<views::View> wrapped_shortcut_label( |
| 260 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation)); | 264 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation)); |
| 261 | 265 |
| 262 // Compute the max width and height in shortcut labels. | 266 // Compute the max width and height in shortcut labels. |
| 263 // We'll create temporary shortcut labels, and choose the largest width and | 267 // We'll create temporary shortcut labels, and choose the largest width and |
| 264 // height. | 268 // height. |
| 265 for (int i = 0; i < lookup_table.page_size; ++i) { | 269 for (int i = 0; i < lookup_table.page_size; ++i) { |
| 266 shortcut_label->SetText(CreateShortcutText(i, lookup_table.orientation)); | 270 shortcut_label->SetText(CreateShortcutText(i, lookup_table)); |
| 267 gfx::Size text_size = wrapped_shortcut_label->GetPreferredSize(); | 271 gfx::Size text_size = wrapped_shortcut_label->GetPreferredSize(); |
| 268 shortcut_column_width = std::max(shortcut_column_width, text_size.width()); | 272 shortcut_column_width = std::max(shortcut_column_width, text_size.width()); |
| 269 shortcut_column_height = std::max(shortcut_column_height, | 273 shortcut_column_height = std::max(shortcut_column_height, |
| 270 text_size.height()); | 274 text_size.height()); |
| 271 } | 275 } |
| 272 | 276 |
| 273 return gfx::Size(shortcut_column_width, shortcut_column_height); | 277 return gfx::Size(shortcut_column_width, shortcut_column_height); |
| 274 } | 278 } |
| 275 | 279 |
| 276 // Computes the page index. For instance, if the page size is 9, and the | 280 // Computes the page index. For instance, if the page size is 9, and the |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 // Set the shortcut text. | 984 // Set the shortcut text. |
| 981 if (no_shortcut_mode) { | 985 if (no_shortcut_mode) { |
| 982 candidate_view->SetShortcutText(string16()); | 986 candidate_view->SetShortcutText(string16()); |
| 983 } else { | 987 } else { |
| 984 // At this moment, we don't use labels sent from engines for UX | 988 // At this moment, we don't use labels sent from engines for UX |
| 985 // reasons. First, we want to show shortcut labels in empty rows | 989 // reasons. First, we want to show shortcut labels in empty rows |
| 986 // (ex. show 6, 7, 8, ... in empty rows when the number of | 990 // (ex. show 6, 7, 8, ... in empty rows when the number of |
| 987 // candidates is 5). Second, we want to add a period after each | 991 // candidates is 5). Second, we want to add a period after each |
| 988 // shortcut label when the candidate window is horizontal. | 992 // shortcut label when the candidate window is horizontal. |
| 989 candidate_view->SetShortcutText( | 993 candidate_view->SetShortcutText( |
| 990 CreateShortcutText(i, new_lookup_table.orientation)); | 994 CreateShortcutText(i, new_lookup_table)); |
| 991 } | 995 } |
| 992 // Set the candidate text. | 996 // Set the candidate text. |
| 993 if (candidate_index < new_lookup_table.candidates.size() && | 997 if (candidate_index < new_lookup_table.candidates.size() && |
| 994 candidate_index < new_lookup_table.annotations.size()) { | 998 candidate_index < new_lookup_table.annotations.size()) { |
| 995 candidate_view->SetCandidateText( | 999 candidate_view->SetCandidateText( |
| 996 UTF8ToUTF16(new_lookup_table.candidates[candidate_index])); | 1000 UTF8ToUTF16(new_lookup_table.candidates[candidate_index])); |
| 997 candidate_view->SetAnnotationText( | 1001 candidate_view->SetAnnotationText( |
| 998 UTF8ToUTF16(new_lookup_table.annotations[candidate_index])); | 1002 UTF8ToUTF16(new_lookup_table.annotations[candidate_index])); |
| 999 candidate_view->SetRowEnabled(true); | 1003 candidate_view->SetRowEnabled(true); |
| 1000 | 1004 |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1765 } | 1769 } |
| 1766 | 1770 |
| 1767 // static | 1771 // static |
| 1768 CandidateWindowController* | 1772 CandidateWindowController* |
| 1769 CandidateWindowController::CreateCandidateWindowController() { | 1773 CandidateWindowController::CreateCandidateWindowController() { |
| 1770 return new CandidateWindowControllerImpl; | 1774 return new CandidateWindowControllerImpl; |
| 1771 } | 1775 } |
| 1772 | 1776 |
| 1773 } // namespace input_method | 1777 } // namespace input_method |
| 1774 } // namespace chromeos | 1778 } // namespace chromeos |
| OLD | NEW |