| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 // |wrapped_shortcut_label|, hence it's deleted when | 237 // |wrapped_shortcut_label|, hence it's deleted when |
| 238 // |wrapped_shortcut_label| is deleted. | 238 // |wrapped_shortcut_label| is deleted. |
| 239 views::Label* shortcut_label = CreateShortcutLabel(lookup_table.orientation); | 239 views::Label* shortcut_label = CreateShortcutLabel(lookup_table.orientation); |
| 240 scoped_ptr<views::View> wrapped_shortcut_label( | 240 scoped_ptr<views::View> wrapped_shortcut_label( |
| 241 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation)); | 241 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation)); |
| 242 | 242 |
| 243 // Compute the max width in shortcut labels. | 243 // Compute the max width in shortcut labels. |
| 244 // We'll create temporary shortcut labels, and choose the largest width. | 244 // We'll create temporary shortcut labels, and choose the largest width. |
| 245 for (int i = 0; i < lookup_table.page_size; ++i) { | 245 for (int i = 0; i < lookup_table.page_size; ++i) { |
| 246 shortcut_label->SetText( | 246 shortcut_label->SetText( |
| 247 CreateShortcutText(i, lookup_table.orientation)); | 247 WideToUTF16Hack(CreateShortcutText(i, lookup_table.orientation))); |
| 248 shortcut_column_width = | 248 shortcut_column_width = |
| 249 std::max(shortcut_column_width, | 249 std::max(shortcut_column_width, |
| 250 wrapped_shortcut_label->GetPreferredSize().width()); | 250 wrapped_shortcut_label->GetPreferredSize().width()); |
| 251 } | 251 } |
| 252 | 252 |
| 253 return shortcut_column_width; | 253 return shortcut_column_width; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Computes the page index. For instance, if the page size is 9, and the | 256 // Computes the page index. For instance, if the page size is 9, and the |
| 257 // cursor is pointing to 13th candidate, the page index will be 1 (2nd | 257 // cursor is pointing to 13th candidate, the page index will be 1 (2nd |
| (...skipping 16 matching lines...) Expand all Loading... |
| 274 if (current_page_index < 0) | 274 if (current_page_index < 0) |
| 275 return 0; | 275 return 0; |
| 276 const size_t start_from = current_page_index * lookup_table.page_size; | 276 const size_t start_from = current_page_index * lookup_table.page_size; |
| 277 | 277 |
| 278 // Compute the max width in candidate labels. | 278 // Compute the max width in candidate labels. |
| 279 // We'll create temporary candidate labels, and choose the largest width. | 279 // We'll create temporary candidate labels, and choose the largest width. |
| 280 for (size_t i = 0; i + start_from < lookup_table.candidates.size(); ++i) { | 280 for (size_t i = 0; i + start_from < lookup_table.candidates.size(); ++i) { |
| 281 const size_t index = start_from + i; | 281 const size_t index = start_from + i; |
| 282 | 282 |
| 283 candidate_label->SetText( | 283 candidate_label->SetText( |
| 284 UTF8ToWide(lookup_table.candidates[index])); | 284 UTF8ToUTF16(lookup_table.candidates[index])); |
| 285 candidate_column_width = | 285 candidate_column_width = |
| 286 std::max(candidate_column_width, | 286 std::max(candidate_column_width, |
| 287 candidate_label->GetPreferredSize().width()); | 287 candidate_label->GetPreferredSize().width()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 return candidate_column_width; | 290 return candidate_column_width; |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Computes annotation column width. | 293 // Computes annotation column width. |
| 294 int ComputeAnnotationColumnWidth(const InputMethodLookupTable& lookup_table) { | 294 int ComputeAnnotationColumnWidth(const InputMethodLookupTable& lookup_table) { |
| 295 int annotation_column_width = 0; | 295 int annotation_column_width = 0; |
| 296 scoped_ptr<views::Label> annotation_label( | 296 scoped_ptr<views::Label> annotation_label( |
| 297 CreateAnnotationLabel(lookup_table.orientation)); | 297 CreateAnnotationLabel(lookup_table.orientation)); |
| 298 | 298 |
| 299 // Compute the start index of |lookup_table_|. | 299 // Compute the start index of |lookup_table_|. |
| 300 const int current_page_index = ComputePageIndex(lookup_table); | 300 const int current_page_index = ComputePageIndex(lookup_table); |
| 301 if (current_page_index < 0) | 301 if (current_page_index < 0) |
| 302 return 0; | 302 return 0; |
| 303 const size_t start_from = current_page_index * lookup_table.page_size; | 303 const size_t start_from = current_page_index * lookup_table.page_size; |
| 304 | 304 |
| 305 // Compute max width in annotation labels. | 305 // Compute max width in annotation labels. |
| 306 // We'll create temporary annotation labels, and choose the largest width. | 306 // We'll create temporary annotation labels, and choose the largest width. |
| 307 for (size_t i = 0; i + start_from < lookup_table.annotations.size(); ++i) { | 307 for (size_t i = 0; i + start_from < lookup_table.annotations.size(); ++i) { |
| 308 const size_t index = start_from + i; | 308 const size_t index = start_from + i; |
| 309 | 309 |
| 310 annotation_label->SetText( | 310 annotation_label->SetText( |
| 311 UTF8ToWide(lookup_table.annotations[index])); | 311 UTF8ToUTF16(lookup_table.annotations[index])); |
| 312 annotation_column_width = | 312 annotation_column_width = |
| 313 std::max(annotation_column_width, | 313 std::max(annotation_column_width, |
| 314 annotation_label->GetPreferredSize().width()); | 314 annotation_label->GetPreferredSize().width()); |
| 315 } | 315 } |
| 316 | 316 |
| 317 return annotation_column_width; | 317 return annotation_column_width; |
| 318 } | 318 } |
| 319 | 319 |
| 320 // HidableArea is used as an area to place optional information that can be | 320 // HidableArea is used as an area to place optional information that can be |
| 321 // turned displaying off if it is unnecessary. | 321 // turned displaying off if it is unnecessary. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 contents->set_border( | 389 contents->set_border( |
| 390 views::Border::CreateSolidBorder(1, kFrameColor)); | 390 views::Border::CreateSolidBorder(1, kFrameColor)); |
| 391 contents->set_background( | 391 contents->set_background( |
| 392 views::Background::CreateVerticalGradientBackground( | 392 views::Background::CreateVerticalGradientBackground( |
| 393 kFooterTopColor, | 393 kFooterTopColor, |
| 394 kFooterBottomColor)); | 394 kFooterBottomColor)); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // Set the displayed text. | 397 // Set the displayed text. |
| 398 void SetText(const std::string& utf8_text) { | 398 void SetText(const std::string& utf8_text) { |
| 399 label_->SetText(UTF8ToWide(utf8_text)); | 399 label_->SetText(UTF8ToUTF16(utf8_text)); |
| 400 } | 400 } |
| 401 | 401 |
| 402 protected: | 402 protected: |
| 403 virtual gfx::Size GetPreferredSize() OVERRIDE { | 403 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 404 gfx::Size size = HidableArea::GetPreferredSize(); | 404 gfx::Size size = HidableArea::GetPreferredSize(); |
| 405 // Hack. +2 is needed as the same reason as in VerticalCandidateLabel | 405 // Hack. +2 is needed as the same reason as in VerticalCandidateLabel |
| 406 size.set_width(size.width() + 2); | 406 size.set_width(size.width() + 2); |
| 407 if (size.width() < minWidth_) { | 407 if (size.width() < minWidth_) { |
| 408 size.set_width(minWidth_); | 408 size.set_width(minWidth_); |
| 409 } | 409 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 // The infolist icon. | 648 // The infolist icon. |
| 649 views::Label* infolist_label_; | 649 views::Label* infolist_label_; |
| 650 bool infolist_icon_enabled_; | 650 bool infolist_icon_enabled_; |
| 651 }; | 651 }; |
| 652 | 652 |
| 653 class InfolistView; | 653 class InfolistView; |
| 654 | 654 |
| 655 // InfolistWindowView is the main container of the infolist window UI. | 655 // InfolistWindowView is the main container of the infolist window UI. |
| 656 class InfolistWindowView : public views::View { | 656 class InfolistWindowView : public views::View { |
| 657 public: | 657 public: |
| 658 | |
| 659 InfolistWindowView( | 658 InfolistWindowView( |
| 660 views::Widget* parent_frame, views::Widget* candidate_window_frame); | 659 views::Widget* parent_frame, views::Widget* candidate_window_frame); |
| 661 virtual ~InfolistWindowView(); | 660 virtual ~InfolistWindowView(); |
| 662 void Init(); | 661 void Init(); |
| 663 void Show(); | 662 void Show(); |
| 664 void DelayShow(unsigned int milliseconds); | 663 void DelayShow(unsigned int milliseconds); |
| 665 void Hide(); | 664 void Hide(); |
| 666 void DelayHide(unsigned int milliseconds); | 665 void DelayHide(unsigned int milliseconds); |
| 667 void UpdateCandidates(const InputMethodLookupTable& lookup_table); | 666 void UpdateCandidates(const InputMethodLookupTable& lookup_table); |
| 668 | 667 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 layout->AddView(wrapped_shortcut_label); | 857 layout->AddView(wrapped_shortcut_label); |
| 859 layout->AddView(candidate_label_); | 858 layout->AddView(candidate_label_); |
| 860 layout->AddView(annotation_label_); | 859 layout->AddView(annotation_label_); |
| 861 if (orientation_ == InputMethodLookupTable::kVertical) { | 860 if (orientation_ == InputMethodLookupTable::kVertical) { |
| 862 layout->AddView(WrapWithPadding(infolist_label_, | 861 layout->AddView(WrapWithPadding(infolist_label_, |
| 863 gfx::Insets(2, 0, 2, 0))); | 862 gfx::Insets(2, 0, 2, 0))); |
| 864 } | 863 } |
| 865 } | 864 } |
| 866 | 865 |
| 867 void CandidateView::SetCandidateText(const std::wstring& text) { | 866 void CandidateView::SetCandidateText(const std::wstring& text) { |
| 868 candidate_label_->SetText(text); | 867 candidate_label_->SetText(WideToUTF16Hack(text)); |
| 869 } | 868 } |
| 870 | 869 |
| 871 void CandidateView::SetShortcutText(const std::wstring& text) { | 870 void CandidateView::SetShortcutText(const std::wstring& text) { |
| 872 shortcut_label_->SetText(text); | 871 shortcut_label_->SetText(WideToUTF16Hack(text)); |
| 873 } | 872 } |
| 874 | 873 |
| 875 void CandidateView::SetAnnotationText(const std::wstring& text) { | 874 void CandidateView::SetAnnotationText(const std::wstring& text) { |
| 876 annotation_label_->SetText(text); | 875 annotation_label_->SetText(WideToUTF16Hack(text)); |
| 877 } | 876 } |
| 878 | 877 |
| 879 void CandidateView::SetInfolistIcon(bool enable) { | 878 void CandidateView::SetInfolistIcon(bool enable) { |
| 880 if (!infolist_label_) { | 879 if (!infolist_label_) { |
| 881 return; | 880 return; |
| 882 } | 881 } |
| 883 if (enable) { | 882 if (enable) { |
| 884 infolist_label_->set_background( | 883 infolist_label_->set_background( |
| 885 views::Background::CreateSolidBackground(kSelectedRowFrameColor)); | 884 views::Background::CreateSolidBackground(kSelectedRowFrameColor)); |
| 886 } else { | 885 } else { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 0, views::GridLayout::FIXED, 200, 0); | 1409 0, views::GridLayout::FIXED, 200, 0); |
| 1411 | 1410 |
| 1412 layout->StartRow(0, 0); | 1411 layout->StartRow(0, 0); |
| 1413 layout->AddView(wrapped_title_label); | 1412 layout->AddView(wrapped_title_label); |
| 1414 layout->StartRow(0, 0); | 1413 layout->StartRow(0, 0); |
| 1415 layout->AddView(wrapped_description_label); | 1414 layout->AddView(wrapped_description_label); |
| 1416 } | 1415 } |
| 1417 | 1416 |
| 1418 | 1417 |
| 1419 void InfolistView::SetTitleText(const std::wstring& text) { | 1418 void InfolistView::SetTitleText(const std::wstring& text) { |
| 1420 title_label_->SetText(text); | 1419 title_label_->SetText(WideToUTF16Hack(text)); |
| 1421 } | 1420 } |
| 1422 | 1421 |
| 1423 void InfolistView::SetDescriptionText(const std::wstring& text) { | 1422 void InfolistView::SetDescriptionText(const std::wstring& text) { |
| 1424 description_label_->SetText(text); | 1423 description_label_->SetText(WideToUTF16Hack(text)); |
| 1425 } | 1424 } |
| 1426 | 1425 |
| 1427 void InfolistView::Select() { | 1426 void InfolistView::Select() { |
| 1428 set_background( | 1427 set_background( |
| 1429 views::Background::CreateSolidBackground( | 1428 views::Background::CreateSolidBackground( |
| 1430 kSelectedInfolistRowBackgroundColor)); | 1429 kSelectedInfolistRowBackgroundColor)); |
| 1431 set_border( | 1430 set_border( |
| 1432 views::Border::CreateSolidBorder(1, kSelectedInfolistRowFrameColor)); | 1431 views::Border::CreateSolidBorder(1, kSelectedInfolistRowFrameColor)); |
| 1433 // Need to call SchedulePaint() for background and border color changes. | 1432 // Need to call SchedulePaint() for background and border color changes. |
| 1434 SchedulePaint(); | 1433 SchedulePaint(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 0, views::GridLayout::USE_PREF, 0, 0); | 1472 0, views::GridLayout::USE_PREF, 0, 0); |
| 1474 layout->SetInsets(1, 1, 1, 1); | 1473 layout->SetInsets(1, 1, 1, 1); |
| 1475 | 1474 |
| 1476 // Add the infolist area | 1475 // Add the infolist area |
| 1477 layout->StartRow(0, 0); | 1476 layout->StartRow(0, 0); |
| 1478 views::Label* caption_label = NULL; | 1477 views::Label* caption_label = NULL; |
| 1479 caption_label = new views::Label; | 1478 caption_label = new views::Label; |
| 1480 caption_label->SetFont(caption_label->font().DeriveFont(kFontSizeDelta - 2)); | 1479 caption_label->SetFont(caption_label->font().DeriveFont(kFontSizeDelta - 2)); |
| 1481 caption_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 1480 caption_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 1482 caption_label->SetText( | 1481 caption_label->SetText( |
| 1483 UTF16ToWide( | 1482 l10n_util::GetStringUTF16(IDS_INPUT_METHOD_INFOLIST_WINDOW_TITLE)); |
| 1484 l10n_util::GetStringUTF16(IDS_INPUT_METHOD_INFOLIST_WINDOW_TITLE))); | |
| 1485 views::View* wrapped_caption_label = | 1483 views::View* wrapped_caption_label = |
| 1486 WrapWithPadding(caption_label, gfx::Insets(2, 2, 2, 2)); | 1484 WrapWithPadding(caption_label, gfx::Insets(2, 2, 2, 2)); |
| 1487 wrapped_caption_label->set_background( | 1485 wrapped_caption_label->set_background( |
| 1488 views::Background::CreateSolidBackground(kInfolistTitleBackgroundColor)); | 1486 views::Background::CreateSolidBackground(kInfolistTitleBackgroundColor)); |
| 1489 layout->AddView(wrapped_caption_label); | 1487 layout->AddView(wrapped_caption_label); |
| 1490 | 1488 |
| 1491 layout->StartRow(0, 0); | 1489 layout->StartRow(0, 0); |
| 1492 layout->AddView(infolist_area_); // |infolist_area_| is owned by |this|. | 1490 layout->AddView(infolist_area_); // |infolist_area_| is owned by |this|. |
| 1493 } | 1491 } |
| 1494 | 1492 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 CandidateWindowController::~CandidateWindowController() { | 1797 CandidateWindowController::~CandidateWindowController() { |
| 1800 delete impl_; | 1798 delete impl_; |
| 1801 } | 1799 } |
| 1802 | 1800 |
| 1803 bool CandidateWindowController::Init() { | 1801 bool CandidateWindowController::Init() { |
| 1804 return impl_->Init(); | 1802 return impl_->Init(); |
| 1805 } | 1803 } |
| 1806 | 1804 |
| 1807 } // namespace input_method | 1805 } // namespace input_method |
| 1808 } // namespace chromeos | 1806 } // namespace chromeos |
| OLD | NEW |