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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 // CandidateWindowController controls the CandidateWindow. | 595 // CandidateWindowController controls the CandidateWindow. |
596 class CandidateWindowController::Impl : public CandidateWindowView::Observer, | 596 class CandidateWindowController::Impl : public CandidateWindowView::Observer, |
597 public IBusUiController::Observer { | 597 public IBusUiController::Observer { |
598 public: | 598 public: |
599 Impl(); | 599 Impl(); |
600 virtual ~Impl(); | 600 virtual ~Impl(); |
601 | 601 |
602 // Initializes the candidate window. Returns true on success. | 602 // Initializes the candidate window. Returns true on success. |
603 bool Init(); | 603 bool Init(); |
604 | 604 |
| 605 void AddObserver(CandidateWindowController::Observer* observer); |
| 606 void RemoveObserver(CandidateWindowController::Observer* observer); |
| 607 |
605 private: | 608 private: |
606 // CandidateWindowView::Observer implementation. | 609 // CandidateWindowView::Observer implementation. |
607 virtual void OnCandidateCommitted(int index, | 610 virtual void OnCandidateCommitted(int index, |
608 int button, | 611 int button, |
609 int flags); | 612 int flags); |
| 613 virtual void OnCandidateWindowOpened(); |
| 614 virtual void OnCandidateWindowClosed(); |
610 | 615 |
611 // Creates the candidate window view. | 616 // Creates the candidate window view. |
612 void CreateView(); | 617 void CreateView(); |
613 | 618 |
614 // IBusUiController::Observer overrides. | 619 // IBusUiController::Observer overrides. |
615 virtual void OnHideAuxiliaryText(); | 620 virtual void OnHideAuxiliaryText(); |
616 virtual void OnHideLookupTable(); | 621 virtual void OnHideLookupTable(); |
617 virtual void OnHidePreeditText(); | 622 virtual void OnHidePreeditText(); |
618 virtual void OnSetCursorLocation(int x, int y, int width, int height); | 623 virtual void OnSetCursorLocation(int x, int y, int width, int height); |
619 virtual void OnUpdateAuxiliaryText(const std::string& utf8_text, | 624 virtual void OnUpdateAuxiliaryText(const std::string& utf8_text, |
(...skipping 13 matching lines...) Expand all Loading... |
633 // own |candidate_window_|. | 638 // own |candidate_window_|. |
634 scoped_ptr<views::Widget> frame_; | 639 scoped_ptr<views::Widget> frame_; |
635 | 640 |
636 // The infolist window view. | 641 // The infolist window view. |
637 InfolistWindowView* infolist_window_; | 642 InfolistWindowView* infolist_window_; |
638 | 643 |
639 // This is the outer frame of the infolist window view. The frame will | 644 // This is the outer frame of the infolist window view. The frame will |
640 // own |infolist_window_|. | 645 // own |infolist_window_|. |
641 scoped_ptr<views::Widget> infolist_frame_; | 646 scoped_ptr<views::Widget> infolist_frame_; |
642 | 647 |
| 648 ObserverList<CandidateWindowController::Observer> observers_; |
| 649 |
643 DISALLOW_COPY_AND_ASSIGN(Impl); | 650 DISALLOW_COPY_AND_ASSIGN(Impl); |
644 }; | 651 }; |
645 | 652 |
646 CandidateView::CandidateView( | 653 CandidateView::CandidateView( |
647 CandidateWindowView* parent_candidate_window, | 654 CandidateWindowView* parent_candidate_window, |
648 int index_in_page, | 655 int index_in_page, |
649 InputMethodLookupTable::Orientation orientation) | 656 InputMethodLookupTable::Orientation orientation) |
650 : index_in_page_(index_in_page), | 657 : index_in_page_(index_in_page), |
651 orientation_(orientation), | 658 orientation_(orientation), |
652 parent_candidate_window_(parent_candidate_window), | 659 parent_candidate_window_(parent_candidate_window), |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 // Add the candidate area. | 879 // Add the candidate area. |
873 layout->StartRow(0, 0); | 880 layout->StartRow(0, 0); |
874 layout->AddView(candidate_area_); // |candidate_area_| is owned by |this|. | 881 layout->AddView(candidate_area_); // |candidate_area_| is owned by |this|. |
875 | 882 |
876 // Add the footer area. | 883 // Add the footer area. |
877 layout->StartRow(0, 0); | 884 layout->StartRow(0, 0); |
878 layout->AddView(footer_area_); // |footer_area_| is owned by |this|. | 885 layout->AddView(footer_area_); // |footer_area_| is owned by |this|. |
879 } | 886 } |
880 | 887 |
881 void CandidateWindowView::HideAll() { | 888 void CandidateWindowView::HideAll() { |
| 889 bool was_visible = IsCandidateWindowOpen(); |
882 parent_frame_->Hide(); | 890 parent_frame_->Hide(); |
| 891 if (was_visible) { |
| 892 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); |
| 893 } |
883 } | 894 } |
884 | 895 |
885 void CandidateWindowView::HideLookupTable() { | 896 void CandidateWindowView::HideLookupTable() { |
| 897 bool was_visible = IsCandidateWindowOpen(); |
886 candidate_area_->Hide(); | 898 candidate_area_->Hide(); |
887 if (preedit_area_->IsShown()) | 899 if (preedit_area_->IsShown()) |
888 ResizeAndMoveParentFrame(); | 900 ResizeAndMoveParentFrame(); |
889 else | 901 else |
890 parent_frame_->Hide(); | 902 parent_frame_->Hide(); |
| 903 if (was_visible) { |
| 904 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); |
| 905 } |
891 } | 906 } |
892 | 907 |
893 InformationTextArea* CandidateWindowView::GetAuxiliaryTextArea() { | 908 InformationTextArea* CandidateWindowView::GetAuxiliaryTextArea() { |
894 return (lookup_table_.orientation == InputMethodLookupTable::kHorizontal ? | 909 return (lookup_table_.orientation == InputMethodLookupTable::kHorizontal ? |
895 header_area_ : footer_area_); | 910 header_area_ : footer_area_); |
896 } | 911 } |
897 | 912 |
898 void CandidateWindowView::HideAuxiliaryText() { | 913 void CandidateWindowView::HideAuxiliaryText() { |
899 GetAuxiliaryTextArea()->Hide(); | 914 GetAuxiliaryTextArea()->Hide(); |
900 ResizeAndMoveParentFrame(); | 915 ResizeAndMoveParentFrame(); |
(...skipping 20 matching lines...) Expand all Loading... |
921 preedit_area_->Show(); | 936 preedit_area_->Show(); |
922 ResizeAndMoveParentFrame(); | 937 ResizeAndMoveParentFrame(); |
923 parent_frame_->Show(); | 938 parent_frame_->Show(); |
924 } | 939 } |
925 | 940 |
926 void CandidateWindowView::UpdatePreeditText(const std::string& utf8_text) { | 941 void CandidateWindowView::UpdatePreeditText(const std::string& utf8_text) { |
927 preedit_area_->SetText(utf8_text); | 942 preedit_area_->SetText(utf8_text); |
928 } | 943 } |
929 | 944 |
930 void CandidateWindowView::ShowLookupTable() { | 945 void CandidateWindowView::ShowLookupTable() { |
| 946 bool was_visible = IsCandidateWindowOpen(); |
931 candidate_area_->Show(); | 947 candidate_area_->Show(); |
932 ResizeAndMoveParentFrame(); | 948 ResizeAndMoveParentFrame(); |
933 parent_frame_->Show(); | 949 parent_frame_->Show(); |
| 950 if (!was_visible) { |
| 951 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened()); |
| 952 } |
934 } | 953 } |
935 | 954 |
936 bool CandidateWindowView::ShouldUpdateCandidateViews( | 955 bool CandidateWindowView::ShouldUpdateCandidateViews( |
937 const InputMethodLookupTable& old_table, | 956 const InputMethodLookupTable& old_table, |
938 const InputMethodLookupTable& new_table) { | 957 const InputMethodLookupTable& new_table) { |
939 | 958 |
940 // Check if mozc lookup table location is changed. | 959 // Check if mozc lookup table location is changed. |
941 if (old_table.mozc_candidates.has_window_location() || | 960 if (old_table.mozc_candidates.has_window_location() || |
942 new_table.mozc_candidates.has_window_location()) { | 961 new_table.mozc_candidates.has_window_location()) { |
943 | 962 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 | 1180 |
1162 // Compute views size in |layout|. | 1181 // Compute views size in |layout|. |
1163 // If we don't call this function, GetHorizontalOffset() often | 1182 // If we don't call this function, GetHorizontalOffset() often |
1164 // returns invalid value (returns 0), then candidate window | 1183 // returns invalid value (returns 0), then candidate window |
1165 // moves right from the correct position in ResizeAndMoveParentFrame(). | 1184 // moves right from the correct position in ResizeAndMoveParentFrame(). |
1166 // TODO(nhiroki): Figure out why it returns invalid value. | 1185 // TODO(nhiroki): Figure out why it returns invalid value. |
1167 // It seems that the x-position of the candidate labels is not set. | 1186 // It seems that the x-position of the candidate labels is not set. |
1168 layout->Layout(candidate_area_contents); | 1187 layout->Layout(candidate_area_contents); |
1169 } | 1188 } |
1170 | 1189 |
| 1190 bool CandidateWindowView::IsCandidateWindowOpen() const { |
| 1191 return candidate_area_->IsVisible() && candidate_area_->IsShown(); |
| 1192 } |
| 1193 |
1171 void CandidateWindowView::SelectCandidateAt(int index_in_page) { | 1194 void CandidateWindowView::SelectCandidateAt(int index_in_page) { |
1172 const int current_page_index = ComputePageIndex(lookup_table_); | 1195 const int current_page_index = ComputePageIndex(lookup_table_); |
1173 if (current_page_index < 0) { | 1196 if (current_page_index < 0) { |
1174 LOG(ERROR) << "Invalid lookup_table: " << lookup_table_.ToString(); | 1197 LOG(ERROR) << "Invalid lookup_table: " << lookup_table_.ToString(); |
1175 return; | 1198 return; |
1176 } | 1199 } |
1177 | 1200 |
1178 const int cursor_absolute_index = | 1201 const int cursor_absolute_index = |
1179 lookup_table_.page_size * current_page_index + index_in_page; | 1202 lookup_table_.page_size * current_page_index + index_in_page; |
1180 // Ignore click on out of range views. | 1203 // Ignore click on out of range views. |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 candidate_window_->UpdatePreeditText(utf8_text); | 1725 candidate_window_->UpdatePreeditText(utf8_text); |
1703 candidate_window_->ShowPreeditText(); | 1726 candidate_window_->ShowPreeditText(); |
1704 } | 1727 } |
1705 | 1728 |
1706 void CandidateWindowController::Impl::OnCandidateCommitted(int index, | 1729 void CandidateWindowController::Impl::OnCandidateCommitted(int index, |
1707 int button, | 1730 int button, |
1708 int flags) { | 1731 int flags) { |
1709 ibus_ui_controller_->NotifyCandidateClicked(index, button, flags); | 1732 ibus_ui_controller_->NotifyCandidateClicked(index, button, flags); |
1710 } | 1733 } |
1711 | 1734 |
| 1735 void CandidateWindowController::Impl::OnCandidateWindowOpened() { |
| 1736 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, |
| 1737 CandidateWindowOpened()); |
| 1738 } |
| 1739 |
| 1740 void CandidateWindowController::Impl::OnCandidateWindowClosed() { |
| 1741 FOR_EACH_OBSERVER(CandidateWindowController::Observer, observers_, |
| 1742 CandidateWindowClosed()); |
| 1743 } |
| 1744 |
| 1745 void CandidateWindowController::Impl::AddObserver( |
| 1746 CandidateWindowController::Observer* observer) { |
| 1747 observers_.AddObserver(observer); |
| 1748 } |
| 1749 |
| 1750 void CandidateWindowController::Impl::RemoveObserver( |
| 1751 CandidateWindowController::Observer* observer) { |
| 1752 observers_.RemoveObserver(observer); |
| 1753 } |
| 1754 |
1712 void CandidateWindowController::Impl::OnConnectionChange(bool connected) { | 1755 void CandidateWindowController::Impl::OnConnectionChange(bool connected) { |
1713 if (!connected) { | 1756 if (!connected) { |
1714 candidate_window_->HideAll(); | 1757 candidate_window_->HideAll(); |
1715 infolist_window_->Hide(); | 1758 infolist_window_->Hide(); |
1716 } | 1759 } |
1717 } | 1760 } |
1718 | 1761 |
1719 CandidateWindowController::CandidateWindowController() | 1762 CandidateWindowController::CandidateWindowController() |
1720 : impl_(new CandidateWindowController::Impl) { | 1763 : impl_(new CandidateWindowController::Impl) { |
1721 } | 1764 } |
1722 | 1765 |
1723 CandidateWindowController::~CandidateWindowController() { | 1766 CandidateWindowController::~CandidateWindowController() { |
1724 delete impl_; | 1767 delete impl_; |
1725 } | 1768 } |
1726 | 1769 |
1727 bool CandidateWindowController::Init() { | 1770 bool CandidateWindowController::Init() { |
1728 return impl_->Init(); | 1771 return impl_->Init(); |
1729 } | 1772 } |
1730 | 1773 |
| 1774 void CandidateWindowController::AddObserver( |
| 1775 CandidateWindowController::Observer* observer) { |
| 1776 impl_->AddObserver(observer); |
| 1777 } |
| 1778 |
| 1779 void CandidateWindowController::RemoveObserver( |
| 1780 CandidateWindowController::Observer* observer) { |
| 1781 impl_->RemoveObserver(observer); |
| 1782 } |
| 1783 |
1731 } // namespace input_method | 1784 } // namespace input_method |
1732 } // namespace chromeos | 1785 } // namespace chromeos |
OLD | NEW |