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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) | 834 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) |
835 : selected_candidate_index_in_page_(0), | 835 : selected_candidate_index_in_page_(0), |
836 parent_frame_(parent_frame), | 836 parent_frame_(parent_frame), |
837 preedit_area_(NULL), | 837 preedit_area_(NULL), |
838 header_area_(NULL), | 838 header_area_(NULL), |
839 candidate_area_(NULL), | 839 candidate_area_(NULL), |
840 footer_area_(NULL), | 840 footer_area_(NULL), |
841 previous_shortcut_column_width_(0), | 841 previous_shortcut_column_width_(0), |
842 previous_candidate_column_width_(0), | 842 previous_candidate_column_width_(0), |
843 previous_annotation_column_width_(0), | 843 previous_annotation_column_width_(0), |
844 is_suggestion_window_location_available_(false) { | 844 is_suggestion_window_location_available_(false), |
| 845 was_candidate_window_open_(false) { |
845 } | 846 } |
846 | 847 |
847 CandidateWindowView::~CandidateWindowView() { | 848 CandidateWindowView::~CandidateWindowView() { |
848 } | 849 } |
849 | 850 |
850 void CandidateWindowView::Init() { | 851 void CandidateWindowView::Init() { |
851 // Set the background and the border of the view. | 852 // Set the background and the border of the view. |
852 set_background( | 853 set_background( |
853 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); | 854 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); |
854 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); | 855 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); |
(...skipping 24 matching lines...) Expand all Loading... |
879 // Add the candidate area. | 880 // Add the candidate area. |
880 layout->StartRow(0, 0); | 881 layout->StartRow(0, 0); |
881 layout->AddView(candidate_area_); // |candidate_area_| is owned by |this|. | 882 layout->AddView(candidate_area_); // |candidate_area_| is owned by |this|. |
882 | 883 |
883 // Add the footer area. | 884 // Add the footer area. |
884 layout->StartRow(0, 0); | 885 layout->StartRow(0, 0); |
885 layout->AddView(footer_area_); // |footer_area_| is owned by |this|. | 886 layout->AddView(footer_area_); // |footer_area_| is owned by |this|. |
886 } | 887 } |
887 | 888 |
888 void CandidateWindowView::HideAll() { | 889 void CandidateWindowView::HideAll() { |
889 bool was_visible = IsCandidateWindowOpen(); | |
890 parent_frame_->Hide(); | 890 parent_frame_->Hide(); |
891 if (was_visible) { | 891 NotifyIfCandidateWindowOpenedOrClosed(); |
892 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); | |
893 } | |
894 } | 892 } |
895 | 893 |
896 void CandidateWindowView::HideLookupTable() { | 894 void CandidateWindowView::HideLookupTable() { |
897 bool was_visible = IsCandidateWindowOpen(); | |
898 candidate_area_->Hide(); | 895 candidate_area_->Hide(); |
899 if (preedit_area_->IsShown()) | 896 if (preedit_area_->IsShown()) |
900 ResizeAndMoveParentFrame(); | 897 ResizeAndMoveParentFrame(); |
901 else | 898 else |
902 parent_frame_->Hide(); | 899 parent_frame_->Hide(); |
903 if (was_visible) { | 900 |
904 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); | 901 NotifyIfCandidateWindowOpenedOrClosed(); |
905 } | |
906 } | 902 } |
907 | 903 |
908 InformationTextArea* CandidateWindowView::GetAuxiliaryTextArea() { | 904 InformationTextArea* CandidateWindowView::GetAuxiliaryTextArea() { |
909 return (lookup_table_.orientation == InputMethodLookupTable::kHorizontal ? | 905 return (lookup_table_.orientation == InputMethodLookupTable::kHorizontal ? |
910 header_area_ : footer_area_); | 906 header_area_ : footer_area_); |
911 } | 907 } |
912 | 908 |
913 void CandidateWindowView::HideAuxiliaryText() { | 909 void CandidateWindowView::HideAuxiliaryText() { |
914 GetAuxiliaryTextArea()->Hide(); | 910 GetAuxiliaryTextArea()->Hide(); |
915 ResizeAndMoveParentFrame(); | 911 ResizeAndMoveParentFrame(); |
(...skipping 20 matching lines...) Expand all Loading... |
936 preedit_area_->Show(); | 932 preedit_area_->Show(); |
937 ResizeAndMoveParentFrame(); | 933 ResizeAndMoveParentFrame(); |
938 parent_frame_->Show(); | 934 parent_frame_->Show(); |
939 } | 935 } |
940 | 936 |
941 void CandidateWindowView::UpdatePreeditText(const std::string& utf8_text) { | 937 void CandidateWindowView::UpdatePreeditText(const std::string& utf8_text) { |
942 preedit_area_->SetText(utf8_text); | 938 preedit_area_->SetText(utf8_text); |
943 } | 939 } |
944 | 940 |
945 void CandidateWindowView::ShowLookupTable() { | 941 void CandidateWindowView::ShowLookupTable() { |
946 bool was_visible = IsCandidateWindowOpen(); | |
947 candidate_area_->Show(); | 942 candidate_area_->Show(); |
948 ResizeAndMoveParentFrame(); | 943 ResizeAndMoveParentFrame(); |
949 parent_frame_->Show(); | 944 parent_frame_->Show(); |
950 if (!was_visible) { | 945 |
| 946 NotifyIfCandidateWindowOpenedOrClosed(); |
| 947 } |
| 948 |
| 949 void CandidateWindowView::NotifyIfCandidateWindowOpenedOrClosed() { |
| 950 bool is_open = IsCandidateWindowOpen(); |
| 951 if (!was_candidate_window_open_ && is_open) { |
951 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened()); | 952 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened()); |
| 953 } else if (was_candidate_window_open_ && !is_open) { |
| 954 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); |
952 } | 955 } |
| 956 was_candidate_window_open_ = is_open; |
953 } | 957 } |
954 | 958 |
955 bool CandidateWindowView::ShouldUpdateCandidateViews( | 959 bool CandidateWindowView::ShouldUpdateCandidateViews( |
956 const InputMethodLookupTable& old_table, | 960 const InputMethodLookupTable& old_table, |
957 const InputMethodLookupTable& new_table) { | 961 const InputMethodLookupTable& new_table) { |
958 | 962 |
959 // Check if mozc lookup table location is changed. | 963 // Check if mozc lookup table location is changed. |
960 if (old_table.mozc_candidates.has_window_location() || | 964 if (old_table.mozc_candidates.has_window_location() || |
961 new_table.mozc_candidates.has_window_location()) { | 965 new_table.mozc_candidates.has_window_location()) { |
962 | 966 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 // Compute views size in |layout|. | 1185 // Compute views size in |layout|. |
1182 // If we don't call this function, GetHorizontalOffset() often | 1186 // If we don't call this function, GetHorizontalOffset() often |
1183 // returns invalid value (returns 0), then candidate window | 1187 // returns invalid value (returns 0), then candidate window |
1184 // moves right from the correct position in ResizeAndMoveParentFrame(). | 1188 // moves right from the correct position in ResizeAndMoveParentFrame(). |
1185 // TODO(nhiroki): Figure out why it returns invalid value. | 1189 // TODO(nhiroki): Figure out why it returns invalid value. |
1186 // It seems that the x-position of the candidate labels is not set. | 1190 // It seems that the x-position of the candidate labels is not set. |
1187 layout->Layout(candidate_area_contents); | 1191 layout->Layout(candidate_area_contents); |
1188 } | 1192 } |
1189 | 1193 |
1190 bool CandidateWindowView::IsCandidateWindowOpen() const { | 1194 bool CandidateWindowView::IsCandidateWindowOpen() const { |
1191 return candidate_area_->IsVisible() && candidate_area_->IsShown(); | 1195 return !is_suggestion_window_location_available_ && |
| 1196 candidate_area_->IsVisible() && candidate_area_->IsShown(); |
1192 } | 1197 } |
1193 | 1198 |
1194 void CandidateWindowView::SelectCandidateAt(int index_in_page) { | 1199 void CandidateWindowView::SelectCandidateAt(int index_in_page) { |
1195 const int current_page_index = ComputePageIndex(lookup_table_); | 1200 const int current_page_index = ComputePageIndex(lookup_table_); |
1196 if (current_page_index < 0) { | 1201 if (current_page_index < 0) { |
1197 LOG(ERROR) << "Invalid lookup_table: " << lookup_table_.ToString(); | 1202 LOG(ERROR) << "Invalid lookup_table: " << lookup_table_.ToString(); |
1198 return; | 1203 return; |
1199 } | 1204 } |
1200 | 1205 |
1201 const int cursor_absolute_index = | 1206 const int cursor_absolute_index = |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 impl_->AddObserver(observer); | 1781 impl_->AddObserver(observer); |
1777 } | 1782 } |
1778 | 1783 |
1779 void CandidateWindowController::RemoveObserver( | 1784 void CandidateWindowController::RemoveObserver( |
1780 CandidateWindowController::Observer* observer) { | 1785 CandidateWindowController::Observer* observer) { |
1781 impl_->RemoveObserver(observer); | 1786 impl_->RemoveObserver(observer); |
1782 } | 1787 } |
1783 | 1788 |
1784 } // namespace input_method | 1789 } // namespace input_method |
1785 } // namespace chromeos | 1790 } // namespace chromeos |
OLD | NEW |