Chromium Code Reviews| 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_mozc_window_(false) { | |
| 837 } | 838 } |
| 838 | 839 |
| 839 CandidateWindowView::~CandidateWindowView() { | 840 CandidateWindowView::~CandidateWindowView() { |
| 840 } | 841 } |
| 841 | 842 |
| 842 void CandidateWindowView::Init() { | 843 void CandidateWindowView::Init() { |
| 843 // Set the background and the border of the view. | 844 // Set the background and the border of the view. |
| 844 set_background( | 845 set_background( |
| 845 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); | 846 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); |
| 846 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); | 847 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 | 929 |
| 929 void CandidateWindowView::ShowLookupTable() { | 930 void CandidateWindowView::ShowLookupTable() { |
| 930 candidate_area_->Show(); | 931 candidate_area_->Show(); |
| 931 ResizeAndMoveParentFrame(); | 932 ResizeAndMoveParentFrame(); |
| 932 parent_frame_->Show(); | 933 parent_frame_->Show(); |
| 933 } | 934 } |
| 934 | 935 |
| 935 bool CandidateWindowView::ShouldUpdateCandidateViews( | 936 bool CandidateWindowView::ShouldUpdateCandidateViews( |
| 936 const InputMethodLookupTable& old_table, | 937 const InputMethodLookupTable& old_table, |
| 937 const InputMethodLookupTable& new_table) { | 938 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 std::string old_serialized_msg; | |
|
Yusuke Sato
2011/11/30 13:38:20
nit: move these two variables to L.952.
Seigo Nonaka
2011/12/01 07:10:01
Done.
| |
| 944 std::string new_serialized_msg; | |
| 945 | |
| 946 if (!old_table.mozc_candidates.IsInitialized()) { | |
|
Yusuke Sato
2011/11/30 13:38:20
if (!old.. ||
!new..) {
return true;
}
woul
Seigo Nonaka
2011/12/01 07:10:01
Done.
| |
| 947 return true; | |
| 948 } | |
| 949 if (!new_table.mozc_candidates.IsInitialized()) { | |
| 950 return true; | |
| 951 } | |
| 952 | |
| 953 old_table.mozc_candidates.SerializeToString(&old_serialized_msg); | |
| 954 new_table.mozc_candidates.SerializeToString(&new_serialized_msg); | |
| 955 return old_serialized_msg != new_serialized_msg; | |
| 956 } | |
| 957 | |
| 938 // Check if most table contents are identical. | 958 // Check if most table contents are identical. |
| 939 if (old_table.page_size == new_table.page_size && | 959 if (old_table.page_size == new_table.page_size && |
| 940 old_table.orientation == new_table.orientation && | 960 old_table.orientation == new_table.orientation && |
| 941 old_table.candidates == new_table.candidates && | 961 old_table.candidates == new_table.candidates && |
| 942 old_table.labels == new_table.labels && | 962 old_table.labels == new_table.labels && |
| 943 old_table.annotations == new_table.annotations && | 963 old_table.annotations == new_table.annotations && |
| 944 // Check if the page indexes are identical. | 964 // Check if the page indexes are identical. |
| 945 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { | 965 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { |
| 946 // If all of the conditions are met, we don't have to update candidate | 966 // If all of the conditions are met, we don't have to update candidate |
| 947 // views. | 967 // views. |
| 948 return false; | 968 return false; |
| 949 } | 969 } |
| 950 return true; | 970 return true; |
| 951 } | 971 } |
| 952 | 972 |
| 953 void CandidateWindowView::UpdateCandidates( | 973 void CandidateWindowView::UpdateCandidates( |
| 954 const InputMethodLookupTable& new_lookup_table) { | 974 const InputMethodLookupTable& new_lookup_table) { |
| 955 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, | 975 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, |
| 956 new_lookup_table); | 976 new_lookup_table); |
| 957 // Updating the candidate views is expensive. We'll skip this if possible. | 977 // Updating the candidate views is expensive. We'll skip this if possible. |
| 958 if (should_update) { | 978 if (should_update) { |
| 959 // Initialize candidate views if necessary. | 979 // Initialize candidate views if necessary. |
| 960 MaybeInitializeCandidateViews(new_lookup_table); | 980 MaybeInitializeCandidateViews(new_lookup_table); |
| 961 | 981 |
| 982 // Stores mozc specific window location. | |
|
Yusuke Sato
2011/11/30 13:38:20
nit: Store
Seigo Nonaka
2011/12/01 07:10:01
Done.
| |
| 983 if (new_lookup_table.mozc_candidates.has_window_location()) { | |
| 984 if (new_lookup_table.mozc_candidates.window_location() == | |
| 985 mozc::commands::Candidates::CARET) { | |
|
Yusuke Sato
2011/11/30 13:38:20
nit: what's are possible values of window_location
Seigo Nonaka
2011/12/01 07:10:01
I change my mind to use mozc specific location onl
| |
| 986 DCHECK(new_lookup_table.mozc_candidates.has_caret_rectangle()); | |
| 987 window_location_for_mozc_engine_.set_x( | |
| 988 new_lookup_table.mozc_candidates.caret_rectangle().x()); | |
| 989 window_location_for_mozc_engine_.set_y( | |
| 990 new_lookup_table.mozc_candidates.caret_rectangle().y()); | |
| 991 window_location_for_mozc_engine_.set_width( | |
| 992 new_lookup_table.mozc_candidates.caret_rectangle().width()); | |
| 993 window_location_for_mozc_engine_.set_height( | |
| 994 new_lookup_table.mozc_candidates.caret_rectangle().height()); | |
| 995 } else { | |
| 996 DCHECK(new_lookup_table.mozc_candidates.has_composition_rectangle()); | |
| 997 window_location_for_mozc_engine_.set_x( | |
| 998 new_lookup_table.mozc_candidates.composition_rectangle().x()); | |
| 999 window_location_for_mozc_engine_.set_y( | |
| 1000 new_lookup_table.mozc_candidates.composition_rectangle().y()); | |
| 1001 window_location_for_mozc_engine_.set_width( | |
| 1002 new_lookup_table.mozc_candidates.composition_rectangle().width()); | |
| 1003 window_location_for_mozc_engine_.set_height( | |
| 1004 new_lookup_table.mozc_candidates.composition_rectangle().height()); | |
| 1005 } | |
| 1006 is_mozc_window_ = true; | |
| 1007 } else { | |
| 1008 is_mozc_window_ = false; | |
| 1009 } | |
| 1010 | |
| 1011 | |
| 962 // Compute the index of the current page. | 1012 // Compute the index of the current page. |
| 963 const int current_page_index = ComputePageIndex(new_lookup_table); | 1013 const int current_page_index = ComputePageIndex(new_lookup_table); |
| 964 if (current_page_index < 0) { | 1014 if (current_page_index < 0) { |
| 965 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); | 1015 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); |
| 966 return; | 1016 return; |
| 967 } | 1017 } |
| 968 | 1018 |
| 969 // Update the candidates in the current page. | 1019 // Update the candidates in the current page. |
| 970 const size_t start_from = current_page_index * new_lookup_table.page_size; | 1020 const size_t start_from = current_page_index * new_lookup_table.page_size; |
| 971 | 1021 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1176 // For now, we don't distinguish left and right clicks. | 1226 // For now, we don't distinguish left and right clicks. |
| 1177 const int button = 1; // Left button. | 1227 const int button = 1; // Left button. |
| 1178 const int key_modifilers = 0; | 1228 const int key_modifilers = 0; |
| 1179 FOR_EACH_OBSERVER(Observer, observers_, | 1229 FOR_EACH_OBSERVER(Observer, observers_, |
| 1180 OnCandidateCommitted(selected_candidate_index_in_page_, | 1230 OnCandidateCommitted(selected_candidate_index_in_page_, |
| 1181 button, | 1231 button, |
| 1182 key_modifilers)); | 1232 key_modifilers)); |
| 1183 } | 1233 } |
| 1184 | 1234 |
| 1185 void CandidateWindowView::ResizeAndMoveParentFrame() { | 1235 void CandidateWindowView::ResizeAndMoveParentFrame() { |
| 1186 const int x = cursor_location_.x(); | 1236 // If rendering operation comes from mozc-engine, uses mozc specific location, |
| 1187 const int y = cursor_location_.y(); | 1237 // otherwise lookup table is shown under the cursor. |
| 1238 const int x = is_mozc_window_ ? | |
| 1239 window_location_for_mozc_engine_.x() : cursor_location_.x(); | |
| 1240 // To avoid lookup-table overlapping, uses maximum y-position of mozc specific | |
| 1241 // location and cursor location, because mozc-engine does not consider about | |
| 1242 // multi-line composition. | |
| 1243 const int y = is_mozc_window_ ? | |
| 1244 std::max(window_location_for_mozc_engine_.y(), cursor_location_.y()) : | |
| 1245 cursor_location_.y(); | |
| 1188 const int height = cursor_location_.height(); | 1246 const int height = cursor_location_.height(); |
| 1189 const int horizontal_offset = GetHorizontalOffset(); | 1247 const int horizontal_offset = GetHorizontalOffset(); |
| 1190 | 1248 |
| 1191 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); | 1249 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); |
| 1192 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( | 1250 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
| 1193 parent_frame_->GetNativeView()); | 1251 parent_frame_->GetNativeView()); |
| 1194 // The size. | 1252 // The size. |
| 1195 gfx::Rect frame_bounds = old_bounds; | 1253 gfx::Rect frame_bounds = old_bounds; |
| 1196 frame_bounds.set_size(GetPreferredSize()); | 1254 frame_bounds.set_size(GetPreferredSize()); |
| 1197 | 1255 |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1678 CandidateWindowController::~CandidateWindowController() { | 1736 CandidateWindowController::~CandidateWindowController() { |
| 1679 delete impl_; | 1737 delete impl_; |
| 1680 } | 1738 } |
| 1681 | 1739 |
| 1682 bool CandidateWindowController::Init() { | 1740 bool CandidateWindowController::Init() { |
| 1683 return impl_->Init(); | 1741 return impl_->Init(); |
| 1684 } | 1742 } |
| 1685 | 1743 |
| 1686 } // namespace input_method | 1744 } // namespace input_method |
| 1687 } // namespace chromeos | 1745 } // namespace chromeos |
| OLD | NEW |