| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 scoped_ptr<views::View> place_holder_; | 380 scoped_ptr<views::View> place_holder_; |
| 381 | 381 |
| 382 DISALLOW_COPY_AND_ASSIGN(HidableArea); | 382 DISALLOW_COPY_AND_ASSIGN(HidableArea); |
| 383 }; | 383 }; |
| 384 | 384 |
| 385 // InformationTextArea is a HidableArea having a single Label in it. | 385 // InformationTextArea is a HidableArea having a single Label in it. |
| 386 class InformationTextArea : public HidableArea { | 386 class InformationTextArea : public HidableArea { |
| 387 public: | 387 public: |
| 388 // Specify the alignment and initialize the control. | 388 // Specify the alignment and initialize the control. |
| 389 InformationTextArea(views::Label::Alignment align, int minWidth) | 389 InformationTextArea(views::Label::Alignment align, int minWidth) |
| 390 : minWidth_(minWidth) { | 390 : minWidth_(minWidth) { |
| 391 label_ = new views::Label; | 391 label_ = new views::Label; |
| 392 label_->SetHorizontalAlignment(align); | 392 label_->SetHorizontalAlignment(align); |
| 393 | 393 |
| 394 const gfx::Insets kInsets(2, 2, 2, 4); | 394 const gfx::Insets kInsets(2, 2, 2, 4); |
| 395 views::View* contents = WrapWithPadding(label_, kInsets); | 395 views::View* contents = WrapWithPadding(label_, kInsets); |
| 396 SetContents(contents); | 396 SetContents(contents); |
| 397 contents->set_border( | 397 contents->set_border( |
| 398 views::Border::CreateSolidBorder(1, kFrameColor)); | 398 views::Border::CreateSolidBorder(1, kFrameColor)); |
| 399 contents->set_background( | 399 contents->set_background( |
| 400 views::Background::CreateVerticalGradientBackground( | 400 views::Background::CreateVerticalGradientBackground( |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 | 647 |
| 648 // Add the shortcut label, the candidate label, and annotation label. | 648 // Add the shortcut label, the candidate label, and annotation label. |
| 649 layout->StartRow(0, 0); | 649 layout->StartRow(0, 0); |
| 650 // |wrapped_shortcut_label|, |candidate_label_|, and |annotation_label_| | 650 // |wrapped_shortcut_label|, |candidate_label_|, and |annotation_label_| |
| 651 // will be owned by |this|. | 651 // will be owned by |this|. |
| 652 layout->AddView(wrapped_shortcut_label); | 652 layout->AddView(wrapped_shortcut_label); |
| 653 layout->AddView(candidate_label_); | 653 layout->AddView(candidate_label_); |
| 654 layout->AddView(annotation_label_); | 654 layout->AddView(annotation_label_); |
| 655 if (orientation_ == InputMethodLookupTable::kVertical) { | 655 if (orientation_ == InputMethodLookupTable::kVertical) { |
| 656 layout->AddView(WrapWithPadding(infolist_label_, | 656 layout->AddView(WrapWithPadding(infolist_label_, |
| 657 gfx::Insets(2, 0, 2, 0))); | 657 gfx::Insets(2, 0, 2, 0))); |
| 658 } | 658 } |
| 659 UpdateLabelBackgroundColors(); | 659 UpdateLabelBackgroundColors(); |
| 660 } | 660 } |
| 661 | 661 |
| 662 void CandidateView::SetCandidateText(const string16& text) { | 662 void CandidateView::SetCandidateText(const string16& text) { |
| 663 candidate_label_->SetText(text); | 663 candidate_label_->SetText(text); |
| 664 } | 664 } |
| 665 | 665 |
| 666 void CandidateView::SetShortcutText(const string16& text) { | 666 void CandidateView::SetShortcutText(const string16& text) { |
| 667 shortcut_label_->SetText(text); | 667 shortcut_label_->SetText(text); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 suggestion_window_location_.set_height( | 958 suggestion_window_location_.set_height( |
| 959 new_lookup_table.mozc_candidates.composition_rectangle().height()); | 959 new_lookup_table.mozc_candidates.composition_rectangle().height()); |
| 960 is_suggestion_window_location_available_ = true; | 960 is_suggestion_window_location_available_ = true; |
| 961 } else { | 961 } else { |
| 962 is_suggestion_window_location_available_ = false; | 962 is_suggestion_window_location_available_ = false; |
| 963 } | 963 } |
| 964 | 964 |
| 965 // Compute the index of the current page. | 965 // Compute the index of the current page. |
| 966 const int current_page_index = ComputePageIndex(new_lookup_table); | 966 const int current_page_index = ComputePageIndex(new_lookup_table); |
| 967 if (current_page_index < 0) { | 967 if (current_page_index < 0) { |
| 968 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); | 968 DVLOG(1) << "Invalid lookup_table: " << new_lookup_table.ToString(); |
| 969 return; | 969 return; |
| 970 } | 970 } |
| 971 | 971 |
| 972 // Update the candidates in the current page. | 972 // Update the candidates in the current page. |
| 973 const size_t start_from = current_page_index * new_lookup_table.page_size; | 973 const size_t start_from = current_page_index * new_lookup_table.page_size; |
| 974 | 974 |
| 975 // In some cases, engines send empty shortcut labels. For instance, | 975 // In some cases, engines send empty shortcut labels. For instance, |
| 976 // ibus-mozc sends empty labels when they show suggestions. In this | 976 // ibus-mozc sends empty labels when they show suggestions. In this |
| 977 // case, we should not show shortcut labels. | 977 // case, we should not show shortcut labels. |
| 978 const bool no_shortcut_mode = | 978 const bool no_shortcut_mode = |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 bool CandidateWindowView::IsCandidateWindowOpen() const { | 1137 bool CandidateWindowView::IsCandidateWindowOpen() const { |
| 1138 return !is_suggestion_window_location_available_ && | 1138 return !is_suggestion_window_location_available_ && |
| 1139 candidate_area_->visible() && candidate_area_->IsShown(); | 1139 candidate_area_->visible() && candidate_area_->IsShown(); |
| 1140 } | 1140 } |
| 1141 | 1141 |
| 1142 void CandidateWindowView::SelectCandidateAt(int index_in_page) { | 1142 void CandidateWindowView::SelectCandidateAt(int index_in_page) { |
| 1143 const int current_page_index = ComputePageIndex(lookup_table_); | 1143 const int current_page_index = ComputePageIndex(lookup_table_); |
| 1144 if (current_page_index < 0) { | 1144 if (current_page_index < 0) { |
| 1145 LOG(ERROR) << "Invalid lookup_table: " << lookup_table_.ToString(); | 1145 DVLOG(1) << "Invalid lookup_table: " << lookup_table_.ToString(); |
| 1146 return; | 1146 return; |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 const int cursor_absolute_index = | 1149 const int cursor_absolute_index = |
| 1150 lookup_table_.page_size * current_page_index + index_in_page; | 1150 lookup_table_.page_size * current_page_index + index_in_page; |
| 1151 // Ignore click on out of range views. | 1151 // Ignore click on out of range views. |
| 1152 if (cursor_absolute_index < 0 || | 1152 if (cursor_absolute_index < 0 || |
| 1153 cursor_absolute_index >= | 1153 cursor_absolute_index >= |
| 1154 static_cast<int>(lookup_table_.candidates.size())) { | 1154 static_cast<int>(lookup_table_.candidates.size())) { |
| 1155 return; | 1155 return; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 description_label_->SetFont( | 1284 description_label_->SetFont( |
| 1285 description_label_->font().DeriveFont(kFontSizeDelta - 2)); | 1285 description_label_->font().DeriveFont(kFontSizeDelta - 2)); |
| 1286 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 1286 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 1287 description_label_->SetMultiLine(true); | 1287 description_label_->SetMultiLine(true); |
| 1288 views::View* wrapped_description_label = | 1288 views::View* wrapped_description_label = |
| 1289 WrapWithPadding(description_label_, gfx::Insets(2, 17, 4, 4)); | 1289 WrapWithPadding(description_label_, gfx::Insets(2, 17, 4, 4)); |
| 1290 | 1290 |
| 1291 // Initialize the column set with three columns. | 1291 // Initialize the column set with three columns. |
| 1292 views::ColumnSet* column_set = layout->AddColumnSet(0); | 1292 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 1293 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 1293 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 1294 0, views::GridLayout::FIXED, 200, 0); | 1294 0, views::GridLayout::FIXED, 200, 0); |
| 1295 | 1295 |
| 1296 layout->StartRow(0, 0); | 1296 layout->StartRow(0, 0); |
| 1297 layout->AddView(wrapped_title_label); | 1297 layout->AddView(wrapped_title_label); |
| 1298 layout->StartRow(0, 0); | 1298 layout->StartRow(0, 0); |
| 1299 layout->AddView(wrapped_description_label); | 1299 layout->AddView(wrapped_description_label); |
| 1300 UpdateLabelBackgroundColors(); | 1300 UpdateLabelBackgroundColors(); |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 | 1303 |
| 1304 void InfolistView::SetTitleText(const std::wstring& text) { | 1304 void InfolistView::SetTitleText(const std::wstring& text) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 views::ColumnSet* column_set = layout->AddColumnSet(0); | 1451 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 1452 column_set->AddColumn(views::GridLayout::FILL, | 1452 column_set->AddColumn(views::GridLayout::FILL, |
| 1453 views::GridLayout::FILL, | 1453 views::GridLayout::FILL, |
| 1454 0, views::GridLayout::USE_PREF, 0, 0); | 1454 0, views::GridLayout::USE_PREF, 0, 0); |
| 1455 layout->SetInsets(0, 0, 0, 0); | 1455 layout->SetInsets(0, 0, 0, 0); |
| 1456 | 1456 |
| 1457 for (int i = 0; i < usages.information_size(); ++i) { | 1457 for (int i = 0; i < usages.information_size(); ++i) { |
| 1458 InfolistView* infolist_row = new InfolistView(this); | 1458 InfolistView* infolist_row = new InfolistView(this); |
| 1459 infolist_row->Init(); | 1459 infolist_row->Init(); |
| 1460 infolist_row->SetTitleText( | 1460 infolist_row->SetTitleText( |
| 1461 UTF8ToWide(usages.information(i).title())); | 1461 UTF8ToWide(usages.information(i).title())); |
| 1462 infolist_row->SetDescriptionText( | 1462 infolist_row->SetDescriptionText( |
| 1463 UTF8ToWide(usages.information(i).description())); | 1463 UTF8ToWide(usages.information(i).description())); |
| 1464 if (usages.has_focused_index() && | 1464 if (usages.has_focused_index() && |
| 1465 (static_cast<int>(usages.focused_index()) == i)) { | 1465 (static_cast<int>(usages.focused_index()) == i)) { |
| 1466 infolist_row->Select(); | 1466 infolist_row->Select(); |
| 1467 } else { | 1467 } else { |
| 1468 infolist_row->Unselect(); | 1468 infolist_row->Unselect(); |
| 1469 } | 1469 } |
| 1470 infolist_views_.push_back(infolist_row); | 1470 infolist_views_.push_back(infolist_row); |
| 1471 layout->StartRow(0, 0); | 1471 layout->StartRow(0, 0); |
| 1472 layout->AddView(infolist_row); | 1472 layout->AddView(infolist_row); |
| 1473 } | 1473 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 int y, | 1600 int y, |
| 1601 int width, | 1601 int width, |
| 1602 int height) { | 1602 int height) { |
| 1603 // A workaround for http://crosbug.com/6460. We should ignore very short Y | 1603 // A workaround for http://crosbug.com/6460. We should ignore very short Y |
| 1604 // move to prevent the window from shaking up and down. | 1604 // move to prevent the window from shaking up and down. |
| 1605 const int kKeepPositionThreshold = 2; // px | 1605 const int kKeepPositionThreshold = 2; // px |
| 1606 const gfx::Rect& last_location = | 1606 const gfx::Rect& last_location = |
| 1607 candidate_window_->cursor_location(); | 1607 candidate_window_->cursor_location(); |
| 1608 const int delta_y = abs(last_location.y() - y); | 1608 const int delta_y = abs(last_location.y() - y); |
| 1609 if ((last_location.x() == x) && (delta_y <= kKeepPositionThreshold)) { | 1609 if ((last_location.x() == x) && (delta_y <= kKeepPositionThreshold)) { |
| 1610 DLOG(INFO) << "Ignored set_cursor_location signal to prevent window shake"; | 1610 DVLOG(1) << "Ignored set_cursor_location signal to prevent window shake"; |
| 1611 return; | 1611 return; |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 // Remember the cursor location. | 1614 // Remember the cursor location. |
| 1615 candidate_window_->set_cursor_location( | 1615 candidate_window_->set_cursor_location( |
| 1616 gfx::Rect(x, y, width, height)); | 1616 gfx::Rect(x, y, width, height)); |
| 1617 // Move the window per the cursor location. | 1617 // Move the window per the cursor location. |
| 1618 candidate_window_->ResizeAndMoveParentFrame(); | 1618 candidate_window_->ResizeAndMoveParentFrame(); |
| 1619 infolist_window_->ResizeAndMoveParentFrame(); | 1619 infolist_window_->ResizeAndMoveParentFrame(); |
| 1620 } | 1620 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1644 candidate_window_->ShowLookupTable(); | 1644 candidate_window_->ShowLookupTable(); |
| 1645 | 1645 |
| 1646 const mozc::commands::Candidates& candidates = lookup_table.mozc_candidates; | 1646 const mozc::commands::Candidates& candidates = lookup_table.mozc_candidates; |
| 1647 | 1647 |
| 1648 if (lookup_table.mozc_candidates.has_usages() && | 1648 if (lookup_table.mozc_candidates.has_usages() && |
| 1649 lookup_table.mozc_candidates.usages().information_size() > 0) { | 1649 lookup_table.mozc_candidates.usages().information_size() > 0) { |
| 1650 infolist_window_->UpdateCandidates(lookup_table); | 1650 infolist_window_->UpdateCandidates(lookup_table); |
| 1651 infolist_window_->ResizeAndMoveParentFrame(); | 1651 infolist_window_->ResizeAndMoveParentFrame(); |
| 1652 if (candidates.has_focused_index() && candidates.candidate_size() > 0) { | 1652 if (candidates.has_focused_index() && candidates.candidate_size() > 0) { |
| 1653 const int focused_row = | 1653 const int focused_row = |
| 1654 candidates.focused_index() - candidates.candidate(0).index(); | 1654 candidates.focused_index() - candidates.candidate(0).index(); |
| 1655 if (candidates.candidate_size() >= focused_row && | 1655 if (candidates.candidate_size() >= focused_row && |
| 1656 candidates.candidate(focused_row).has_information_id()) { | 1656 candidates.candidate(focused_row).has_information_id()) { |
| 1657 infolist_window_->DelayShow(kInfolistShowDelayMilliSeconds); | 1657 infolist_window_->DelayShow(kInfolistShowDelayMilliSeconds); |
| 1658 } else { | 1658 } else { |
| 1659 infolist_window_->DelayHide(kInfolistHideDelayMilliSeconds); | 1659 infolist_window_->DelayHide(kInfolistHideDelayMilliSeconds); |
| 1660 } | 1660 } |
| 1661 } else { | 1661 } else { |
| 1662 infolist_window_->DelayHide(kInfolistHideDelayMilliSeconds); | 1662 infolist_window_->DelayHide(kInfolistHideDelayMilliSeconds); |
| 1663 } | 1663 } |
| 1664 } else { | 1664 } else { |
| 1665 infolist_window_->Hide(); | 1665 infolist_window_->Hide(); |
| 1666 } | 1666 } |
| 1667 } | 1667 } |
| 1668 | 1668 |
| 1669 void CandidateWindowControllerImpl::OnUpdatePreeditText( | 1669 void CandidateWindowControllerImpl::OnUpdatePreeditText( |
| 1670 const std::string& utf8_text, unsigned int cursor, bool visible) { | 1670 const std::string& utf8_text, unsigned int cursor, bool visible) { |
| 1671 // If it's not visible, hide the preedit text and return. | 1671 // If it's not visible, hide the preedit text and return. |
| 1672 if (!visible || utf8_text.empty()) { | 1672 if (!visible || utf8_text.empty()) { |
| 1673 candidate_window_->HidePreeditText(); | 1673 candidate_window_->HidePreeditText(); |
| 1674 return; | 1674 return; |
| 1675 } | 1675 } |
| 1676 candidate_window_->UpdatePreeditText(utf8_text); | 1676 candidate_window_->UpdatePreeditText(utf8_text); |
| 1677 candidate_window_->ShowPreeditText(); | 1677 candidate_window_->ShowPreeditText(); |
| 1678 } | 1678 } |
| 1679 | 1679 |
| 1680 void CandidateWindowControllerImpl::OnCandidateCommitted(int index, | 1680 void CandidateWindowControllerImpl::OnCandidateCommitted(int index, |
| 1681 int button, | 1681 int button, |
| 1682 int flags) { | 1682 int flags) { |
| 1683 ibus_ui_controller_->NotifyCandidateClicked(index, button, flags); | 1683 ibus_ui_controller_->NotifyCandidateClicked(index, button, flags); |
| 1684 } | 1684 } |
| 1685 | 1685 |
| 1686 void CandidateWindowControllerImpl::OnCandidateWindowOpened() { | 1686 void CandidateWindowControllerImpl::OnCandidateWindowOpened() { |
| 1687 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, | 1687 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, |
| 1688 CandidateWindowOpened()); | 1688 CandidateWindowOpened()); |
| 1689 } | 1689 } |
| 1690 | 1690 |
| 1691 void CandidateWindowControllerImpl::OnCandidateWindowClosed() { | 1691 void CandidateWindowControllerImpl::OnCandidateWindowClosed() { |
| 1692 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, | 1692 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1711 } | 1711 } |
| 1712 | 1712 |
| 1713 // static | 1713 // static |
| 1714 CandidateWindowController* | 1714 CandidateWindowController* |
| 1715 CandidateWindowController::CreateCandidateWindowController() { | 1715 CandidateWindowController::CreateCandidateWindowController() { |
| 1716 return new CandidateWindowControllerImpl; | 1716 return new CandidateWindowControllerImpl; |
| 1717 } | 1717 } |
| 1718 | 1718 |
| 1719 } // namespace input_method | 1719 } // namespace input_method |
| 1720 } // namespace chromeos | 1720 } // namespace chromeos |
| OLD | NEW |