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

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

Issue 11783053: Clean Up: Remove ibus namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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 "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/input_method/candidate_view.h" 10 #include "chrome/browser/chromeos/input_method/candidate_view.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 views::GridLayout::FILL, views::GridLayout::FILL, 61 views::GridLayout::FILL, views::GridLayout::FILL,
62 1, views::GridLayout::USE_PREF, 0, 0); 62 1, views::GridLayout::USE_PREF, 0, 0);
63 layout->StartRow(0, 0); 63 layout->StartRow(0, 0);
64 64
65 // Add the view contents. 65 // Add the view contents.
66 layout->AddView(view); // |view| is owned by |wraper|, not |layout|. 66 layout->AddView(view); // |view| is owned by |wraper|, not |layout|.
67 return wrapper; 67 return wrapper;
68 } 68 }
69 69
70 // Creates shortcut text from the given index and the orientation. 70 // Creates shortcut text from the given index and the orientation.
71 string16 CreateShortcutText(size_t index, const ibus::IBusLookupTable& table) { 71 string16 CreateShortcutText(size_t index, const IBusLookupTable& table) {
72 if (index >= table.candidates().size()) 72 if (index >= table.candidates().size())
73 return UTF8ToUTF16(""); 73 return UTF8ToUTF16("");
74 std::string shortcut_text = table.candidates()[index].label; 74 std::string shortcut_text = table.candidates()[index].label;
75 if (!shortcut_text.empty() && 75 if (!shortcut_text.empty() &&
76 table.orientation() != ibus::IBusLookupTable::VERTICAL) 76 table.orientation() != IBusLookupTable::VERTICAL)
77 shortcut_text += '.'; 77 shortcut_text += '.';
78 return UTF8ToUTF16(shortcut_text); 78 return UTF8ToUTF16(shortcut_text);
79 } 79 }
80 80
81 // Creates the shortcut label, and returns it (never returns NULL). 81 // Creates the shortcut label, and returns it (never returns NULL).
82 // The label text is not set in this function. 82 // The label text is not set in this function.
83 views::Label* CreateShortcutLabel( 83 views::Label* CreateShortcutLabel(
84 ibus::IBusLookupTable::Orientation orientation) { 84 IBusLookupTable::Orientation orientation) {
85 // Create the shortcut label. The label will be owned by 85 // Create the shortcut label. The label will be owned by
86 // |wrapped_shortcut_label|, hence it's deleted when 86 // |wrapped_shortcut_label|, hence it's deleted when
87 // |wrapped_shortcut_label| is deleted. 87 // |wrapped_shortcut_label| is deleted.
88 views::Label* shortcut_label = new views::Label; 88 views::Label* shortcut_label = new views::Label;
89 89
90 if (orientation == ibus::IBusLookupTable::VERTICAL) { 90 if (orientation == IBusLookupTable::VERTICAL) {
91 shortcut_label->SetFont( 91 shortcut_label->SetFont(
92 shortcut_label->font().DeriveFont(kFontSizeDelta, gfx::Font::BOLD)); 92 shortcut_label->font().DeriveFont(kFontSizeDelta, gfx::Font::BOLD));
93 } else { 93 } else {
94 shortcut_label->SetFont( 94 shortcut_label->SetFont(
95 shortcut_label->font().DeriveFont(kFontSizeDelta)); 95 shortcut_label->font().DeriveFont(kFontSizeDelta));
96 } 96 }
97 // TODO(satorux): Maybe we need to use language specific fonts for 97 // TODO(satorux): Maybe we need to use language specific fonts for
98 // candidate_label, like Chinese font for Chinese input method? 98 // candidate_label, like Chinese font for Chinese input method?
99 shortcut_label->SetEnabledColor(kShortcutColor); 99 shortcut_label->SetEnabledColor(kShortcutColor);
100 shortcut_label->SetDisabledColor(kDisabledShortcutColor); 100 shortcut_label->SetDisabledColor(kDisabledShortcutColor);
101 101
102 return shortcut_label; 102 return shortcut_label;
103 } 103 }
104 104
105 // Wraps the shortcut label, then decorates wrapped shortcut label 105 // Wraps the shortcut label, then decorates wrapped shortcut label
106 // and returns it (never returns NULL). 106 // and returns it (never returns NULL).
107 // The label text is not set in this function. 107 // The label text is not set in this function.
108 views::View* CreateWrappedShortcutLabel( 108 views::View* CreateWrappedShortcutLabel(
109 views::Label* shortcut_label, 109 views::Label* shortcut_label,
110 ibus::IBusLookupTable::Orientation orientation) { 110 IBusLookupTable::Orientation orientation) {
111 // Wrap it with padding. 111 // Wrap it with padding.
112 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6); 112 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6);
113 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0); 113 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0);
114 const gfx::Insets insets = 114 const gfx::Insets insets =
115 (orientation == ibus::IBusLookupTable::VERTICAL ? 115 (orientation == IBusLookupTable::VERTICAL ?
116 kVerticalShortcutLabelInsets : 116 kVerticalShortcutLabelInsets :
117 kHorizontalShortcutLabelInsets); 117 kHorizontalShortcutLabelInsets);
118 views::View* wrapped_shortcut_label = 118 views::View* wrapped_shortcut_label =
119 WrapWithPadding(shortcut_label, insets); 119 WrapWithPadding(shortcut_label, insets);
120 120
121 // Add decoration based on the orientation. 121 // Add decoration based on the orientation.
122 if (orientation == ibus::IBusLookupTable::VERTICAL) { 122 if (orientation == IBusLookupTable::VERTICAL) {
123 // Set the background color. 123 // Set the background color.
124 wrapped_shortcut_label->set_background( 124 wrapped_shortcut_label->set_background(
125 views::Background::CreateSolidBackground( 125 views::Background::CreateSolidBackground(
126 kShortcutBackgroundColor)); 126 kShortcutBackgroundColor));
127 shortcut_label->SetBackgroundColor( 127 shortcut_label->SetBackgroundColor(
128 wrapped_shortcut_label->background()->get_color()); 128 wrapped_shortcut_label->background()->get_color());
129 } 129 }
130 130
131 return wrapped_shortcut_label; 131 return wrapped_shortcut_label;
132 } 132 }
133 133
134 // Creates the candidate label, and returns it (never returns NULL). 134 // Creates the candidate label, and returns it (never returns NULL).
135 // The label text is not set in this function. 135 // The label text is not set in this function.
136 views::Label* CreateCandidateLabel( 136 views::Label* CreateCandidateLabel(
137 ibus::IBusLookupTable::Orientation orientation) { 137 IBusLookupTable::Orientation orientation) {
138 views::Label* candidate_label = NULL; 138 views::Label* candidate_label = NULL;
139 139
140 // Create the candidate label. The label will be added to |this| as a 140 // Create the candidate label. The label will be added to |this| as a
141 // child view, hence it's deleted when |this| is deleted. 141 // child view, hence it's deleted when |this| is deleted.
142 if (orientation == ibus::IBusLookupTable::VERTICAL) { 142 if (orientation == IBusLookupTable::VERTICAL) {
143 candidate_label = new VerticalCandidateLabel; 143 candidate_label = new VerticalCandidateLabel;
144 } else { 144 } else {
145 candidate_label = new views::Label; 145 candidate_label = new views::Label;
146 } 146 }
147 147
148 // Change the font size. 148 // Change the font size.
149 candidate_label->SetFont( 149 candidate_label->SetFont(
150 candidate_label->font().DeriveFont(kFontSizeDelta)); 150 candidate_label->font().DeriveFont(kFontSizeDelta));
151 candidate_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 151 candidate_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
152 152
153 return candidate_label; 153 return candidate_label;
154 } 154 }
155 155
156 // Creates the annotation label, and return it (never returns NULL). 156 // Creates the annotation label, and return it (never returns NULL).
157 // The label text is not set in this function. 157 // The label text is not set in this function.
158 views::Label* CreateAnnotationLabel( 158 views::Label* CreateAnnotationLabel(
159 ibus::IBusLookupTable::Orientation orientation) { 159 IBusLookupTable::Orientation orientation) {
160 // Create the annotation label. 160 // Create the annotation label.
161 views::Label* annotation_label = new views::Label; 161 views::Label* annotation_label = new views::Label;
162 162
163 // Change the font size and color. 163 // Change the font size and color.
164 annotation_label->SetFont( 164 annotation_label->SetFont(
165 annotation_label->font().DeriveFont(kFontSizeDelta)); 165 annotation_label->font().DeriveFont(kFontSizeDelta));
166 annotation_label->SetEnabledColor(kAnnotationColor); 166 annotation_label->SetEnabledColor(kAnnotationColor);
167 annotation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 167 annotation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
168 168
169 return annotation_label; 169 return annotation_label;
170 } 170 }
171 171
172 // Computes shortcut column size. 172 // Computes shortcut column size.
173 gfx::Size ComputeShortcutColumnSize( 173 gfx::Size ComputeShortcutColumnSize(
174 const ibus::IBusLookupTable& lookup_table) { 174 const IBusLookupTable& lookup_table) {
175 int shortcut_column_width = 0; 175 int shortcut_column_width = 0;
176 int shortcut_column_height = 0; 176 int shortcut_column_height = 0;
177 // Create the shortcut label. The label will be owned by 177 // Create the shortcut label. The label will be owned by
178 // |wrapped_shortcut_label|, hence it's deleted when 178 // |wrapped_shortcut_label|, hence it's deleted when
179 // |wrapped_shortcut_label| is deleted. 179 // |wrapped_shortcut_label| is deleted.
180 views::Label* shortcut_label = CreateShortcutLabel( 180 views::Label* shortcut_label = CreateShortcutLabel(
181 lookup_table.orientation()); 181 lookup_table.orientation());
182 scoped_ptr<views::View> wrapped_shortcut_label( 182 scoped_ptr<views::View> wrapped_shortcut_label(
183 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation())); 183 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation()));
184 184
185 // Compute the max width and height in shortcut labels. 185 // Compute the max width and height in shortcut labels.
186 // We'll create temporary shortcut labels, and choose the largest width and 186 // We'll create temporary shortcut labels, and choose the largest width and
187 // height. 187 // height.
188 for (size_t i = 0; i < lookup_table.page_size(); ++i) { 188 for (size_t i = 0; i < lookup_table.page_size(); ++i) {
189 shortcut_label->SetText(CreateShortcutText(i, lookup_table)); 189 shortcut_label->SetText(CreateShortcutText(i, lookup_table));
190 gfx::Size text_size = wrapped_shortcut_label->GetPreferredSize(); 190 gfx::Size text_size = wrapped_shortcut_label->GetPreferredSize();
191 shortcut_column_width = std::max(shortcut_column_width, text_size.width()); 191 shortcut_column_width = std::max(shortcut_column_width, text_size.width());
192 shortcut_column_height = std::max(shortcut_column_height, 192 shortcut_column_height = std::max(shortcut_column_height,
193 text_size.height()); 193 text_size.height());
194 } 194 }
195 195
196 return gfx::Size(shortcut_column_width, shortcut_column_height); 196 return gfx::Size(shortcut_column_width, shortcut_column_height);
197 } 197 }
198 198
199 // Computes the page index. For instance, if the page size is 9, and the 199 // Computes the page index. For instance, if the page size is 9, and the
200 // cursor is pointing to 13th candidate, the page index will be 1 (2nd 200 // cursor is pointing to 13th candidate, the page index will be 1 (2nd
201 // page, as the index is zero-origin). Returns -1 on error. 201 // page, as the index is zero-origin). Returns -1 on error.
202 int ComputePageIndex(const ibus::IBusLookupTable& lookup_table) { 202 int ComputePageIndex(const IBusLookupTable& lookup_table) {
203 if (lookup_table.page_size() > 0) 203 if (lookup_table.page_size() > 0)
204 return lookup_table.cursor_position() / lookup_table.page_size(); 204 return lookup_table.cursor_position() / lookup_table.page_size();
205 return -1; 205 return -1;
206 } 206 }
207 207
208 // Computes candidate column size. 208 // Computes candidate column size.
209 gfx::Size ComputeCandidateColumnSize( 209 gfx::Size ComputeCandidateColumnSize(
210 const ibus::IBusLookupTable& lookup_table) { 210 const IBusLookupTable& lookup_table) {
211 int candidate_column_width = 0; 211 int candidate_column_width = 0;
212 int candidate_column_height = 0; 212 int candidate_column_height = 0;
213 scoped_ptr<views::Label> candidate_label( 213 scoped_ptr<views::Label> candidate_label(
214 CreateCandidateLabel(lookup_table.orientation())); 214 CreateCandidateLabel(lookup_table.orientation()));
215 215
216 // Compute the start index of |lookup_table_|. 216 // Compute the start index of |lookup_table_|.
217 const int current_page_index = ComputePageIndex(lookup_table); 217 const int current_page_index = ComputePageIndex(lookup_table);
218 if (current_page_index < 0) 218 if (current_page_index < 0)
219 return gfx::Size(0, 0); 219 return gfx::Size(0, 0);
220 const size_t start_from = current_page_index * lookup_table.page_size(); 220 const size_t start_from = current_page_index * lookup_table.page_size();
(...skipping 11 matching lines...) Expand all
232 text_size.width()); 232 text_size.width());
233 candidate_column_height = std::max(candidate_column_height, 233 candidate_column_height = std::max(candidate_column_height,
234 text_size.height()); 234 text_size.height());
235 } 235 }
236 236
237 return gfx::Size(candidate_column_width, candidate_column_height); 237 return gfx::Size(candidate_column_width, candidate_column_height);
238 } 238 }
239 239
240 // Computes annotation column size. 240 // Computes annotation column size.
241 gfx::Size ComputeAnnotationColumnSize( 241 gfx::Size ComputeAnnotationColumnSize(
242 const ibus::IBusLookupTable& lookup_table) { 242 const IBusLookupTable& lookup_table) {
243 int annotation_column_width = 0; 243 int annotation_column_width = 0;
244 int annotation_column_height = 0; 244 int annotation_column_height = 0;
245 scoped_ptr<views::Label> annotation_label( 245 scoped_ptr<views::Label> annotation_label(
246 CreateAnnotationLabel(lookup_table.orientation())); 246 CreateAnnotationLabel(lookup_table.orientation()));
247 247
248 // Compute the start index of |lookup_table_|. 248 // Compute the start index of |lookup_table_|.
249 const int current_page_index = ComputePageIndex(lookup_table); 249 const int current_page_index = ComputePageIndex(lookup_table);
250 if (current_page_index < 0) 250 if (current_page_index < 0)
251 return gfx::Size(0, 0); 251 return gfx::Size(0, 0);
252 const size_t start_from = current_page_index * lookup_table.page_size(); 252 const size_t start_from = current_page_index * lookup_table.page_size();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 private: 311 private:
312 views::Label* label_; 312 views::Label* label_;
313 int minWidth_; 313 int minWidth_;
314 314
315 DISALLOW_COPY_AND_ASSIGN(InformationTextArea); 315 DISALLOW_COPY_AND_ASSIGN(InformationTextArea);
316 }; 316 };
317 317
318 CandidateView::CandidateView( 318 CandidateView::CandidateView(
319 CandidateWindowView* parent_candidate_window, 319 CandidateWindowView* parent_candidate_window,
320 int index_in_page, 320 int index_in_page,
321 ibus::IBusLookupTable::Orientation orientation) 321 IBusLookupTable::Orientation orientation)
322 : index_in_page_(index_in_page), 322 : index_in_page_(index_in_page),
323 orientation_(orientation), 323 orientation_(orientation),
324 parent_candidate_window_(parent_candidate_window), 324 parent_candidate_window_(parent_candidate_window),
325 shortcut_label_(NULL), 325 shortcut_label_(NULL),
326 candidate_label_(NULL), 326 candidate_label_(NULL),
327 annotation_label_(NULL), 327 annotation_label_(NULL),
328 infolist_icon_(NULL), 328 infolist_icon_(NULL),
329 infolist_icon_enabled_(false) { 329 infolist_icon_enabled_(false) {
330 } 330 }
331 331
(...skipping 10 matching lines...) Expand all
342 CreateWrappedShortcutLabel(shortcut_label_, orientation_); 342 CreateWrappedShortcutLabel(shortcut_label_, orientation_);
343 candidate_label_ = CreateCandidateLabel(orientation_); 343 candidate_label_ = CreateCandidateLabel(orientation_);
344 annotation_label_ = CreateAnnotationLabel(orientation_); 344 annotation_label_ = CreateAnnotationLabel(orientation_);
345 345
346 // Initialize the column set with three columns. 346 // Initialize the column set with three columns.
347 views::ColumnSet* column_set = layout->AddColumnSet(0); 347 views::ColumnSet* column_set = layout->AddColumnSet(0);
348 348
349 // If orientation is vertical, each column width is fixed. 349 // If orientation is vertical, each column width is fixed.
350 // Otherwise the width is resizable. 350 // Otherwise the width is resizable.
351 const views::GridLayout::SizeType column_type = 351 const views::GridLayout::SizeType column_type =
352 orientation_ == ibus::IBusLookupTable::VERTICAL ? 352 orientation_ == IBusLookupTable::VERTICAL ?
353 views::GridLayout::FIXED : views::GridLayout::USE_PREF; 353 views::GridLayout::FIXED : views::GridLayout::USE_PREF;
354 354
355 const int padding_column_width = 355 const int padding_column_width =
356 orientation_ == ibus::IBusLookupTable::VERTICAL ? 4 : 6; 356 orientation_ == IBusLookupTable::VERTICAL ? 4 : 6;
357 357
358 // Set shortcut column type and width. 358 // Set shortcut column type and width.
359 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 359 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
360 0, column_type, shortcut_column_width, 0); 360 0, column_type, shortcut_column_width, 0);
361 column_set->AddPaddingColumn(0, padding_column_width); 361 column_set->AddPaddingColumn(0, padding_column_width);
362 362
363 // Set candidate column type and width. 363 // Set candidate column type and width.
364 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 364 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
365 1, views::GridLayout::USE_PREF, 0, 365 1, views::GridLayout::USE_PREF, 0,
366 orientation_ == ibus::IBusLookupTable::VERTICAL ? 366 orientation_ == IBusLookupTable::VERTICAL ?
367 candidate_column_width : 0); 367 candidate_column_width : 0);
368 column_set->AddPaddingColumn(0, padding_column_width); 368 column_set->AddPaddingColumn(0, padding_column_width);
369 369
370 // Set annotation column type and width. 370 // Set annotation column type and width.
371 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 371 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
372 0, column_type, annotation_column_width, 0); 372 0, column_type, annotation_column_width, 0);
373 373
374 if (orientation_ == ibus::IBusLookupTable::VERTICAL) { 374 if (orientation_ == IBusLookupTable::VERTICAL) {
375 column_set->AddPaddingColumn(0, 1); 375 column_set->AddPaddingColumn(0, 1);
376 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 376 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
377 views::GridLayout::FIXED, kInfolistIndicatorIconWidth, 377 views::GridLayout::FIXED, kInfolistIndicatorIconWidth,
378 0); 378 0);
379 column_set->AddPaddingColumn(0, 2); 379 column_set->AddPaddingColumn(0, 2);
380 } else { 380 } else {
381 column_set->AddPaddingColumn(0, padding_column_width); 381 column_set->AddPaddingColumn(0, padding_column_width);
382 } 382 }
383 383
384 // Add the shortcut label, the candidate label, and annotation label. 384 // Add the shortcut label, the candidate label, and annotation label.
(...skipping 14 matching lines...) Expand all
399 views::GridLayout::FILL, // Vertical alignment. 399 views::GridLayout::FILL, // Vertical alignment.
400 -1, // Preferred width, not specified. 400 -1, // Preferred width, not specified.
401 column_height); // Preferred height. 401 column_height); // Preferred height.
402 layout->AddView(annotation_label_, 402 layout->AddView(annotation_label_,
403 1, // Column span. 403 1, // Column span.
404 1, // Row span. 404 1, // Row span.
405 views::GridLayout::FILL, // Horizontal alignment. 405 views::GridLayout::FILL, // Horizontal alignment.
406 views::GridLayout::FILL, // Vertical alignemnt. 406 views::GridLayout::FILL, // Vertical alignemnt.
407 -1, // Preferred width, not specified. 407 -1, // Preferred width, not specified.
408 column_height); // Preferred height. 408 column_height); // Preferred height.
409 if (orientation_ == ibus::IBusLookupTable::VERTICAL) { 409 if (orientation_ == IBusLookupTable::VERTICAL) {
410 infolist_icon_ = new views::View; 410 infolist_icon_ = new views::View;
411 views::View* infolist_icon_wrapper = new views::View; 411 views::View* infolist_icon_wrapper = new views::View;
412 views::GridLayout* infolist_icon_layout = 412 views::GridLayout* infolist_icon_layout =
413 new views::GridLayout(infolist_icon_wrapper); 413 new views::GridLayout(infolist_icon_wrapper);
414 // |infolist_icon_layout| is owned by |infolist_icon_wrapper|. 414 // |infolist_icon_layout| is owned by |infolist_icon_wrapper|.
415 infolist_icon_wrapper->SetLayoutManager(infolist_icon_layout); 415 infolist_icon_wrapper->SetLayoutManager(infolist_icon_layout);
416 infolist_icon_layout->AddColumnSet(0)->AddColumn( 416 infolist_icon_layout->AddColumnSet(0)->AddColumn(
417 views::GridLayout::FILL, views::GridLayout::FILL, 417 views::GridLayout::FILL, views::GridLayout::FILL,
418 0, views::GridLayout::FIXED, kInfolistIndicatorIconWidth, 0); 418 0, views::GridLayout::FIXED, kInfolistIndicatorIconWidth, 0);
419 infolist_icon_layout->AddPaddingRow(0, kInfolistIndicatorIconPadding); 419 infolist_icon_layout->AddPaddingRow(0, kInfolistIndicatorIconPadding);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 views::View::ConvertPointToTarget(this, parent_candidate_window_, 512 views::View::ConvertPointToTarget(this, parent_candidate_window_,
513 &location_in_candidate_window); 513 &location_in_candidate_window);
514 parent_candidate_window_->OnCandidatePressed(location_in_candidate_window); 514 parent_candidate_window_->OnCandidatePressed(location_in_candidate_window);
515 parent_candidate_window_->CommitCandidate(); 515 parent_candidate_window_->CommitCandidate();
516 return false; 516 return false;
517 } 517 }
518 518
519 void CandidateView::UpdateLabelBackgroundColors() { 519 void CandidateView::UpdateLabelBackgroundColors() {
520 SkColor color = background() ? 520 SkColor color = background() ?
521 background()->get_color() : kDefaultBackgroundColor; 521 background()->get_color() : kDefaultBackgroundColor;
522 if (orientation_ != ibus::IBusLookupTable::VERTICAL) 522 if (orientation_ != IBusLookupTable::VERTICAL)
523 shortcut_label_->SetBackgroundColor(color); 523 shortcut_label_->SetBackgroundColor(color);
524 candidate_label_->SetBackgroundColor(color); 524 candidate_label_->SetBackgroundColor(color);
525 annotation_label_->SetBackgroundColor(color); 525 annotation_label_->SetBackgroundColor(color);
526 } 526 }
527 527
528 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) 528 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame)
529 : selected_candidate_index_in_page_(0), 529 : selected_candidate_index_in_page_(0),
530 parent_frame_(parent_frame), 530 parent_frame_(parent_frame),
531 preedit_area_(NULL), 531 preedit_area_(NULL),
532 header_area_(NULL), 532 header_area_(NULL),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 611 }
612 612
613 void CandidateWindowView::ShowAuxiliaryText() { 613 void CandidateWindowView::ShowAuxiliaryText() {
614 // If candidate_area is not shown, shows auxiliary text at header_area. 614 // If candidate_area is not shown, shows auxiliary text at header_area.
615 // We expect both header_area_ and footer_area_ contain same value. 615 // We expect both header_area_ and footer_area_ contain same value.
616 if (!candidate_area_->IsShown()) { 616 if (!candidate_area_->IsShown()) {
617 header_area_->Show(); 617 header_area_->Show();
618 footer_area_->Hide(); 618 footer_area_->Hide();
619 } else { 619 } else {
620 // If candidate_area is shown, shows auxiliary text with orientation. 620 // If candidate_area is shown, shows auxiliary text with orientation.
621 if (lookup_table_.orientation() == ibus::IBusLookupTable::HORIZONTAL) { 621 if (lookup_table_.orientation() == IBusLookupTable::HORIZONTAL) {
622 header_area_->Show(); 622 header_area_->Show();
623 footer_area_->Hide(); 623 footer_area_->Hide();
624 } else { 624 } else {
625 footer_area_->Show(); 625 footer_area_->Show();
626 header_area_->Hide(); 626 header_area_->Hide();
627 } 627 }
628 } 628 }
629 UpdateParentArea(); 629 UpdateParentArea();
630 } 630 }
631 631
(...skipping 28 matching lines...) Expand all
660 bool is_open = IsCandidateWindowOpen(); 660 bool is_open = IsCandidateWindowOpen();
661 if (!was_candidate_window_open_ && is_open) { 661 if (!was_candidate_window_open_ && is_open) {
662 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened()); 662 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened());
663 } else if (was_candidate_window_open_ && !is_open) { 663 } else if (was_candidate_window_open_ && !is_open) {
664 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); 664 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed());
665 } 665 }
666 was_candidate_window_open_ = is_open; 666 was_candidate_window_open_ = is_open;
667 } 667 }
668 668
669 bool CandidateWindowView::ShouldUpdateCandidateViews( 669 bool CandidateWindowView::ShouldUpdateCandidateViews(
670 const ibus::IBusLookupTable& old_table, 670 const IBusLookupTable& old_table,
671 const ibus::IBusLookupTable& new_table) { 671 const IBusLookupTable& new_table) {
672 return !old_table.IsEqual(new_table); 672 return !old_table.IsEqual(new_table);
673 } 673 }
674 674
675 void CandidateWindowView::UpdateCandidates( 675 void CandidateWindowView::UpdateCandidates(
676 const ibus::IBusLookupTable& new_lookup_table) { 676 const IBusLookupTable& new_lookup_table) {
677 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, 677 const bool should_update = ShouldUpdateCandidateViews(lookup_table_,
678 new_lookup_table); 678 new_lookup_table);
679 // Updating the candidate views is expensive. We'll skip this if possible. 679 // Updating the candidate views is expensive. We'll skip this if possible.
680 if (should_update) { 680 if (should_update) {
681 // Initialize candidate views if necessary. 681 // Initialize candidate views if necessary.
682 MaybeInitializeCandidateViews(new_lookup_table); 682 MaybeInitializeCandidateViews(new_lookup_table);
683 683
684 should_show_at_composition_head_ 684 should_show_at_composition_head_
685 = new_lookup_table.show_window_at_composition(); 685 = new_lookup_table.show_window_at_composition();
686 // Compute the index of the current page. 686 // Compute the index of the current page.
(...skipping 27 matching lines...) Expand all
714 // At this moment, we don't use labels sent from engines for UX 714 // At this moment, we don't use labels sent from engines for UX
715 // reasons. First, we want to show shortcut labels in empty rows 715 // reasons. First, we want to show shortcut labels in empty rows
716 // (ex. show 6, 7, 8, ... in empty rows when the number of 716 // (ex. show 6, 7, 8, ... in empty rows when the number of
717 // candidates is 5). Second, we want to add a period after each 717 // candidates is 5). Second, we want to add a period after each
718 // shortcut label when the candidate window is horizontal. 718 // shortcut label when the candidate window is horizontal.
719 candidate_view->SetShortcutText( 719 candidate_view->SetShortcutText(
720 CreateShortcutText(i, new_lookup_table)); 720 CreateShortcutText(i, new_lookup_table));
721 } 721 }
722 // Set the candidate text. 722 // Set the candidate text.
723 if (candidate_index < new_lookup_table.candidates().size()) { 723 if (candidate_index < new_lookup_table.candidates().size()) {
724 const ibus::IBusLookupTable::Entry& entry = 724 const IBusLookupTable::Entry& entry =
725 new_lookup_table.candidates()[candidate_index]; 725 new_lookup_table.candidates()[candidate_index];
726 candidate_view->SetCandidateText(UTF8ToUTF16(entry.value)); 726 candidate_view->SetCandidateText(UTF8ToUTF16(entry.value));
727 candidate_view->SetAnnotationText(UTF8ToUTF16(entry.annotation)); 727 candidate_view->SetAnnotationText(UTF8ToUTF16(entry.annotation));
728 candidate_view->SetRowEnabled(true); 728 candidate_view->SetRowEnabled(true);
729 candidate_view->SetInfolistIcon(!entry.description_title.empty()); 729 candidate_view->SetInfolistIcon(!entry.description_title.empty());
730 } else { 730 } else {
731 // Disable the empty row. 731 // Disable the empty row.
732 candidate_view->SetCandidateText(string16()); 732 candidate_view->SetCandidateText(string16());
733 candidate_view->SetAnnotationText(string16()); 733 candidate_view->SetAnnotationText(string16());
734 candidate_view->SetRowEnabled(false); 734 candidate_view->SetRowEnabled(false);
735 candidate_view->SetInfolistIcon(false); 735 candidate_view->SetInfolistIcon(false);
736 } 736 }
737 } 737 }
738 } 738 }
739 // Update the current lookup table. We'll use lookup_table_ from here. 739 // Update the current lookup table. We'll use lookup_table_ from here.
740 // Note that SelectCandidateAt() uses lookup_table_. 740 // Note that SelectCandidateAt() uses lookup_table_.
741 lookup_table_.CopyFrom(new_lookup_table); 741 lookup_table_.CopyFrom(new_lookup_table);
742 742
743 // Select the current candidate in the page. 743 // Select the current candidate in the page.
744 const int current_candidate_in_page = 744 const int current_candidate_in_page =
745 lookup_table_.cursor_position() % lookup_table_.page_size(); 745 lookup_table_.cursor_position() % lookup_table_.page_size();
746 SelectCandidateAt(current_candidate_in_page); 746 SelectCandidateAt(current_candidate_in_page);
747 } 747 }
748 748
749 void CandidateWindowView::MaybeInitializeCandidateViews( 749 void CandidateWindowView::MaybeInitializeCandidateViews(
750 const ibus::IBusLookupTable& lookup_table) { 750 const IBusLookupTable& lookup_table) {
751 const ibus::IBusLookupTable::Orientation orientation = 751 const IBusLookupTable::Orientation orientation =
752 lookup_table.orientation(); 752 lookup_table.orientation();
753 const int page_size = lookup_table.page_size(); 753 const int page_size = lookup_table.page_size();
754 views::View* candidate_area_contents = candidate_area_->contents(); 754 views::View* candidate_area_contents = candidate_area_->contents();
755 755
756 // Current column width. 756 // Current column width.
757 gfx::Size shortcut_column_size(0, 0); 757 gfx::Size shortcut_column_size(0, 0);
758 gfx::Size candidate_column_size(0,0); 758 gfx::Size candidate_column_size(0,0);
759 gfx::Size annotation_column_size(0, 0); 759 gfx::Size annotation_column_size(0, 0);
760 760
761 // If orientation is horizontal, don't need to compute width, 761 // If orientation is horizontal, don't need to compute width,
762 // because each label is left aligned. 762 // because each label is left aligned.
763 if (orientation == ibus::IBusLookupTable::VERTICAL) { 763 if (orientation == IBusLookupTable::VERTICAL) {
764 shortcut_column_size = ComputeShortcutColumnSize(lookup_table); 764 shortcut_column_size = ComputeShortcutColumnSize(lookup_table);
765 candidate_column_size = ComputeCandidateColumnSize(lookup_table); 765 candidate_column_size = ComputeCandidateColumnSize(lookup_table);
766 annotation_column_size = ComputeAnnotationColumnSize(lookup_table); 766 annotation_column_size = ComputeAnnotationColumnSize(lookup_table);
767 } 767 }
768 768
769 // If the requested number of views matches the number of current views, and 769 // If the requested number of views matches the number of current views, and
770 // previous and current column width are same, just reuse these. 770 // previous and current column width are same, just reuse these.
771 // 771 //
772 // Note that the early exit logic is not only useful for improving 772 // Note that the early exit logic is not only useful for improving
773 // performance, but also necessary for the horizontal candidate window 773 // performance, but also necessary for the horizontal candidate window
(...skipping 20 matching lines...) Expand all
794 // Delete the view after getting out the current message loop iteration. 794 // Delete the view after getting out the current message loop iteration.
795 MessageLoop::current()->DeleteSoon(FROM_HERE, candidate_views_[i]); 795 MessageLoop::current()->DeleteSoon(FROM_HERE, candidate_views_[i]);
796 } 796 }
797 candidate_views_.clear(); 797 candidate_views_.clear();
798 798
799 views::GridLayout* layout = new views::GridLayout(candidate_area_contents); 799 views::GridLayout* layout = new views::GridLayout(candidate_area_contents);
800 // |candidate_area_contents| owns |layout|. 800 // |candidate_area_contents| owns |layout|.
801 candidate_area_contents->SetLayoutManager(layout); 801 candidate_area_contents->SetLayoutManager(layout);
802 // Initialize the column set. 802 // Initialize the column set.
803 views::ColumnSet* column_set = layout->AddColumnSet(0); 803 views::ColumnSet* column_set = layout->AddColumnSet(0);
804 if (orientation == ibus::IBusLookupTable::VERTICAL) { 804 if (orientation == IBusLookupTable::VERTICAL) {
805 column_set->AddColumn(views::GridLayout::FILL, 805 column_set->AddColumn(views::GridLayout::FILL,
806 views::GridLayout::FILL, 806 views::GridLayout::FILL,
807 1, views::GridLayout::USE_PREF, 0, 0); 807 1, views::GridLayout::USE_PREF, 0, 0);
808 } else { 808 } else {
809 for (int i = 0; i < page_size; ++i) { 809 for (int i = 0; i < page_size; ++i) {
810 column_set->AddColumn(views::GridLayout::FILL, 810 column_set->AddColumn(views::GridLayout::FILL,
811 views::GridLayout::FILL, 811 views::GridLayout::FILL,
812 0, views::GridLayout::USE_PREF, 0, 0); 812 0, views::GridLayout::USE_PREF, 0, 0);
813 } 813 }
814 } 814 }
815 815
816 // Set insets so the border of the selected candidate is drawn inside of 816 // Set insets so the border of the selected candidate is drawn inside of
817 // the border of the main candidate window, but we don't have the inset 817 // the border of the main candidate window, but we don't have the inset
818 // at the top and the bottom as we have the borders of the header and 818 // at the top and the bottom as we have the borders of the header and
819 // footer areas. 819 // footer areas.
820 const gfx::Insets kCandidateAreaInsets(0, 1, 0, 1); 820 const gfx::Insets kCandidateAreaInsets(0, 1, 0, 1);
821 layout->SetInsets(kCandidateAreaInsets.top(), 821 layout->SetInsets(kCandidateAreaInsets.top(),
822 kCandidateAreaInsets.left(), 822 kCandidateAreaInsets.left(),
823 kCandidateAreaInsets.bottom(), 823 kCandidateAreaInsets.bottom(),
824 kCandidateAreaInsets.right()); 824 kCandidateAreaInsets.right());
825 825
826 // Use maximum height for all rows in candidate area. 826 // Use maximum height for all rows in candidate area.
827 const int kColumnHeight = std::max(shortcut_column_size.height(), 827 const int kColumnHeight = std::max(shortcut_column_size.height(),
828 std::max(candidate_column_size.height(), 828 std::max(candidate_column_size.height(),
829 annotation_column_size.height())); 829 annotation_column_size.height()));
830 830
831 // Add views to the candidate area. 831 // Add views to the candidate area.
832 if (orientation == ibus::IBusLookupTable::HORIZONTAL) { 832 if (orientation == IBusLookupTable::HORIZONTAL) {
833 layout->StartRow(0, 0); 833 layout->StartRow(0, 0);
834 } 834 }
835 835
836 for (int i = 0; i < page_size; ++i) { 836 for (int i = 0; i < page_size; ++i) {
837 CandidateView* candidate_row = new CandidateView(this, i, orientation); 837 CandidateView* candidate_row = new CandidateView(this, i, orientation);
838 candidate_row->Init(shortcut_column_size.width(), 838 candidate_row->Init(shortcut_column_size.width(),
839 candidate_column_size.width(), 839 candidate_column_size.width(),
840 annotation_column_size.width(), 840 annotation_column_size.width(),
841 kColumnHeight); 841 kColumnHeight);
842 candidate_views_.push_back(candidate_row); 842 candidate_views_.push_back(candidate_row);
843 if (orientation == ibus::IBusLookupTable::VERTICAL) { 843 if (orientation == IBusLookupTable::VERTICAL) {
844 layout->StartRow(0, 0); 844 layout->StartRow(0, 0);
845 } 845 }
846 // |candidate_row| will be owned by |candidate_area_contents|. 846 // |candidate_row| will be owned by |candidate_area_contents|.
847 layout->AddView(candidate_row, 847 layout->AddView(candidate_row,
848 1, // Column span. 848 1, // Column span.
849 1, // Row span. 849 1, // Row span.
850 // Horizontal alignment. 850 // Horizontal alignment.
851 orientation == ibus::IBusLookupTable::VERTICAL ? 851 orientation == IBusLookupTable::VERTICAL ?
852 views::GridLayout::FILL : views::GridLayout::CENTER, 852 views::GridLayout::FILL : views::GridLayout::CENTER,
853 views::GridLayout::CENTER, // Vertical alignment. 853 views::GridLayout::CENTER, // Vertical alignment.
854 -1, // Preferred width, not specified. 854 -1, // Preferred width, not specified.
855 kColumnHeight); // Preferred height. 855 kColumnHeight); // Preferred height.
856 } 856 }
857 857
858 // Compute views size in |layout|. 858 // Compute views size in |layout|.
859 // If we don't call this function, GetHorizontalOffset() often 859 // If we don't call this function, GetHorizontalOffset() often
860 // returns invalid value (returns 0), then candidate window 860 // returns invalid value (returns 0), then candidate window
861 // moves right from the correct position in ResizeAndMoveParentFrame(). 861 // moves right from the correct position in ResizeAndMoveParentFrame().
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 968
969 // Move the window per the cursor location. 969 // Move the window per the cursor location.
970 // SetBounds() is not cheap. Only call this when it is really changed. 970 // SetBounds() is not cheap. Only call this when it is really changed.
971 if (frame_bounds != old_bounds) 971 if (frame_bounds != old_bounds)
972 parent_frame_->SetBounds(frame_bounds); 972 parent_frame_->SetBounds(frame_bounds);
973 } 973 }
974 974
975 int CandidateWindowView::GetHorizontalOffset() { 975 int CandidateWindowView::GetHorizontalOffset() {
976 // Compute the horizontal offset if the lookup table is vertical. 976 // Compute the horizontal offset if the lookup table is vertical.
977 if (!candidate_views_.empty() && 977 if (!candidate_views_.empty() &&
978 lookup_table_.orientation() == ibus::IBusLookupTable::VERTICAL) { 978 lookup_table_.orientation() == IBusLookupTable::VERTICAL) {
979 return - candidate_views_[0]->GetCandidateLabelPosition().x(); 979 return - candidate_views_[0]->GetCandidateLabelPosition().x();
980 } 980 }
981 return 0; 981 return 0;
982 } 982 }
983 983
984 void CandidateWindowView::VisibilityChanged(View* starting_from, 984 void CandidateWindowView::VisibilityChanged(View* starting_from,
985 bool is_visible) { 985 bool is_visible) {
986 if (is_visible) { 986 if (is_visible) {
987 // If the visibility of candidate window is changed, 987 // If the visibility of candidate window is changed,
988 // we should move the frame to the right position. 988 // we should move the frame to the right position.
989 ResizeAndMoveParentFrame(); 989 ResizeAndMoveParentFrame();
990 } 990 }
991 } 991 }
992 992
993 void CandidateWindowView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 993 void CandidateWindowView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
994 // If the bounds(size) of candidate window is changed, 994 // If the bounds(size) of candidate window is changed,
995 // we should move the frame to the right position. 995 // we should move the frame to the right position.
996 View::OnBoundsChanged(previous_bounds); 996 View::OnBoundsChanged(previous_bounds);
997 ResizeAndMoveParentFrame(); 997 ResizeAndMoveParentFrame();
998 } 998 }
999 999
1000 } // namespace input_method 1000 } // namespace input_method
1001 } // namespace chromeos 1001 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698