| 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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 | 826 |
| 827 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) | 827 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) |
| 828 : selected_candidate_index_in_page_(0), | 828 : selected_candidate_index_in_page_(0), |
| 829 parent_frame_(parent_frame), | 829 parent_frame_(parent_frame), |
| 830 preedit_area_(NULL), | 830 preedit_area_(NULL), |
| 831 header_area_(NULL), | 831 header_area_(NULL), |
| 832 candidate_area_(NULL), | 832 candidate_area_(NULL), |
| 833 footer_area_(NULL), | 833 footer_area_(NULL), |
| 834 previous_shortcut_column_width_(0), | 834 previous_shortcut_column_width_(0), |
| 835 previous_candidate_column_width_(0), | 835 previous_candidate_column_width_(0), |
| 836 previous_annotation_column_width_(0), | 836 previous_annotation_column_width_(0) { |
| 837 is_suggestion_window_location_available_(false) { | |
| 838 } | 837 } |
| 839 | 838 |
| 840 CandidateWindowView::~CandidateWindowView() { | 839 CandidateWindowView::~CandidateWindowView() { |
| 841 } | 840 } |
| 842 | 841 |
| 843 void CandidateWindowView::Init() { | 842 void CandidateWindowView::Init() { |
| 844 // Set the background and the border of the view. | 843 // Set the background and the border of the view. |
| 845 set_background( | 844 set_background( |
| 846 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); | 845 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); |
| 847 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); | 846 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 | 928 |
| 930 void CandidateWindowView::ShowLookupTable() { | 929 void CandidateWindowView::ShowLookupTable() { |
| 931 candidate_area_->Show(); | 930 candidate_area_->Show(); |
| 932 ResizeAndMoveParentFrame(); | 931 ResizeAndMoveParentFrame(); |
| 933 parent_frame_->Show(); | 932 parent_frame_->Show(); |
| 934 } | 933 } |
| 935 | 934 |
| 936 bool CandidateWindowView::ShouldUpdateCandidateViews( | 935 bool CandidateWindowView::ShouldUpdateCandidateViews( |
| 937 const InputMethodLookupTable& old_table, | 936 const InputMethodLookupTable& old_table, |
| 938 const InputMethodLookupTable& new_table) { | 937 const InputMethodLookupTable& new_table) { |
| 939 | |
| 940 // Check if mozc lookup table location is changed. | |
| 941 if (old_table.mozc_candidates.has_window_location() || | |
| 942 new_table.mozc_candidates.has_window_location()) { | |
| 943 | |
| 944 if (!old_table.mozc_candidates.IsInitialized() || | |
| 945 !new_table.mozc_candidates.IsInitialized()) { | |
| 946 return true; | |
| 947 } | |
| 948 | |
| 949 std::string old_serialized_msg; | |
| 950 std::string new_serialized_msg; | |
| 951 | |
| 952 old_table.mozc_candidates.SerializeToString(&old_serialized_msg); | |
| 953 new_table.mozc_candidates.SerializeToString(&new_serialized_msg); | |
| 954 return old_serialized_msg != new_serialized_msg; | |
| 955 } | |
| 956 | |
| 957 // Check if most table contents are identical. | 938 // Check if most table contents are identical. |
| 958 if (old_table.page_size == new_table.page_size && | 939 if (old_table.page_size == new_table.page_size && |
| 959 old_table.orientation == new_table.orientation && | 940 old_table.orientation == new_table.orientation && |
| 960 old_table.candidates == new_table.candidates && | 941 old_table.candidates == new_table.candidates && |
| 961 old_table.labels == new_table.labels && | 942 old_table.labels == new_table.labels && |
| 962 old_table.annotations == new_table.annotations && | 943 old_table.annotations == new_table.annotations && |
| 963 // Check if the page indexes are identical. | 944 // Check if the page indexes are identical. |
| 964 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { | 945 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { |
| 965 // If all of the conditions are met, we don't have to update candidate | 946 // If all of the conditions are met, we don't have to update candidate |
| 966 // views. | 947 // views. |
| 967 return false; | 948 return false; |
| 968 } | 949 } |
| 969 return true; | 950 return true; |
| 970 } | 951 } |
| 971 | 952 |
| 972 void CandidateWindowView::UpdateCandidates( | 953 void CandidateWindowView::UpdateCandidates( |
| 973 const InputMethodLookupTable& new_lookup_table) { | 954 const InputMethodLookupTable& new_lookup_table) { |
| 974 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, | 955 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, |
| 975 new_lookup_table); | 956 new_lookup_table); |
| 976 // Updating the candidate views is expensive. We'll skip this if possible. | 957 // Updating the candidate views is expensive. We'll skip this if possible. |
| 977 if (should_update) { | 958 if (should_update) { |
| 978 // Initialize candidate views if necessary. | 959 // Initialize candidate views if necessary. |
| 979 MaybeInitializeCandidateViews(new_lookup_table); | 960 MaybeInitializeCandidateViews(new_lookup_table); |
| 980 | 961 |
| 981 // Store mozc specific window location. | |
| 982 if (new_lookup_table.mozc_candidates.has_window_location() && | |
| 983 new_lookup_table.mozc_candidates.window_location() == | |
| 984 mozc::commands::Candidates::COMPOSITION) { | |
| 985 DCHECK(new_lookup_table.mozc_candidates.has_composition_rectangle()); | |
| 986 suggestion_window_location_.set_x( | |
| 987 new_lookup_table.mozc_candidates.composition_rectangle().x()); | |
| 988 suggestion_window_location_.set_y( | |
| 989 new_lookup_table.mozc_candidates.composition_rectangle().y()); | |
| 990 suggestion_window_location_.set_width( | |
| 991 new_lookup_table.mozc_candidates.composition_rectangle().width()); | |
| 992 suggestion_window_location_.set_height( | |
| 993 new_lookup_table.mozc_candidates.composition_rectangle().height()); | |
| 994 is_suggestion_window_location_available_ = true; | |
| 995 } else { | |
| 996 is_suggestion_window_location_available_ = false; | |
| 997 } | |
| 998 | |
| 999 // Compute the index of the current page. | 962 // Compute the index of the current page. |
| 1000 const int current_page_index = ComputePageIndex(new_lookup_table); | 963 const int current_page_index = ComputePageIndex(new_lookup_table); |
| 1001 if (current_page_index < 0) { | 964 if (current_page_index < 0) { |
| 1002 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); | 965 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); |
| 1003 return; | 966 return; |
| 1004 } | 967 } |
| 1005 | 968 |
| 1006 // Update the candidates in the current page. | 969 // Update the candidates in the current page. |
| 1007 const size_t start_from = current_page_index * new_lookup_table.page_size; | 970 const size_t start_from = current_page_index * new_lookup_table.page_size; |
| 1008 | 971 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 // For now, we don't distinguish left and right clicks. | 1176 // For now, we don't distinguish left and right clicks. |
| 1214 const int button = 1; // Left button. | 1177 const int button = 1; // Left button. |
| 1215 const int key_modifilers = 0; | 1178 const int key_modifilers = 0; |
| 1216 FOR_EACH_OBSERVER(Observer, observers_, | 1179 FOR_EACH_OBSERVER(Observer, observers_, |
| 1217 OnCandidateCommitted(selected_candidate_index_in_page_, | 1180 OnCandidateCommitted(selected_candidate_index_in_page_, |
| 1218 button, | 1181 button, |
| 1219 key_modifilers)); | 1182 key_modifilers)); |
| 1220 } | 1183 } |
| 1221 | 1184 |
| 1222 void CandidateWindowView::ResizeAndMoveParentFrame() { | 1185 void CandidateWindowView::ResizeAndMoveParentFrame() { |
| 1223 // If rendering operation comes from mozc-engine, uses mozc specific location, | 1186 const int x = cursor_location_.x(); |
| 1224 // otherwise lookup table is shown under the cursor. | 1187 const int y = cursor_location_.y(); |
| 1225 const int x = is_suggestion_window_location_available_ ? | |
| 1226 suggestion_window_location_.x() : cursor_location_.x(); | |
| 1227 // To avoid lookup-table overlapping, uses maximum y-position of mozc specific | |
| 1228 // location and cursor location, because mozc-engine does not consider about | |
| 1229 // multi-line composition. | |
| 1230 const int y = is_suggestion_window_location_available_ ? | |
| 1231 std::max(suggestion_window_location_.y(), cursor_location_.y()) : | |
| 1232 cursor_location_.y(); | |
| 1233 const int height = cursor_location_.height(); | 1188 const int height = cursor_location_.height(); |
| 1234 const int horizontal_offset = GetHorizontalOffset(); | 1189 const int horizontal_offset = GetHorizontalOffset(); |
| 1235 | 1190 |
| 1236 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); | 1191 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); |
| 1237 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( | 1192 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
| 1238 parent_frame_->GetNativeView()); | 1193 parent_frame_->GetNativeView()); |
| 1239 // The size. | 1194 // The size. |
| 1240 gfx::Rect frame_bounds = old_bounds; | 1195 gfx::Rect frame_bounds = old_bounds; |
| 1241 frame_bounds.set_size(GetPreferredSize()); | 1196 frame_bounds.set_size(GetPreferredSize()); |
| 1242 | 1197 |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 CandidateWindowController::~CandidateWindowController() { | 1678 CandidateWindowController::~CandidateWindowController() { |
| 1724 delete impl_; | 1679 delete impl_; |
| 1725 } | 1680 } |
| 1726 | 1681 |
| 1727 bool CandidateWindowController::Init() { | 1682 bool CandidateWindowController::Init() { |
| 1728 return impl_->Init(); | 1683 return impl_->Init(); |
| 1729 } | 1684 } |
| 1730 | 1685 |
| 1731 } // namespace input_method | 1686 } // namespace input_method |
| 1732 } // namespace chromeos | 1687 } // namespace chromeos |
| OLD | NEW |