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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 // showing candidate number information like 2/19. | 570 // showing candidate number information like 2/19. |
| 571 InformationTextArea* footer_area_; | 571 InformationTextArea* footer_area_; |
| 572 | 572 |
| 573 // Current columns width in |candidate_area_|. | 573 // Current columns width in |candidate_area_|. |
| 574 int previous_shortcut_column_width_; | 574 int previous_shortcut_column_width_; |
| 575 int previous_candidate_column_width_; | 575 int previous_candidate_column_width_; |
| 576 int previous_annotation_column_width_; | 576 int previous_annotation_column_width_; |
| 577 | 577 |
| 578 // The last cursor location. | 578 // The last cursor location. |
| 579 gfx::Rect cursor_location_; | 579 gfx::Rect cursor_location_; |
| 580 | |
| 581 // This location is used by mozc window rendereing, The mozc-engine have two | |
|
Hiro Komatsu
2011/11/15 08:50:20
typo: the mozc-engine has
Seigo Nonaka
2011/11/15 11:59:22
Done.
| |
| 582 // types of lookup-table, suggestion window and candidate window(this is | |
| 583 // ordinal look-up table). The location of these two windows is different | |
|
Hiro Komatsu
2011/11/15 08:50:20
locations / are?
Seigo Nonaka
2011/11/15 11:59:22
Done.
| |
| 584 // and which is managed by mozc-engine now. | |
| 585 gfx::Rect window_location_for_mozc_engine_; | |
| 586 | |
| 587 // If rendering operation comes from mozc-engine, this value becomes true. | |
| 588 // Otherwise this value becomes false. | |
| 589 bool is_mozc_window_; | |
| 580 }; | 590 }; |
| 581 | 591 |
| 582 // CandidateRow renderes a row of a candidate. | 592 // CandidateRow renderes a row of a candidate. |
| 583 class CandidateView : public views::View { | 593 class CandidateView : public views::View { |
| 584 public: | 594 public: |
| 585 CandidateView(CandidateWindowView* parent_candidate_window, | 595 CandidateView(CandidateWindowView* parent_candidate_window, |
| 586 int index_in_page, | 596 int index_in_page, |
| 587 InputMethodLookupTable::Orientation orientation); | 597 InputMethodLookupTable::Orientation orientation); |
| 588 virtual ~CandidateView() {} | 598 virtual ~CandidateView() {} |
| 589 // Initializes the candidate view with the given column widths. | 599 // Initializes the candidate view with the given column widths. |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 | 983 |
| 974 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) | 984 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) |
| 975 : selected_candidate_index_in_page_(0), | 985 : selected_candidate_index_in_page_(0), |
| 976 parent_frame_(parent_frame), | 986 parent_frame_(parent_frame), |
| 977 preedit_area_(NULL), | 987 preedit_area_(NULL), |
| 978 header_area_(NULL), | 988 header_area_(NULL), |
| 979 candidate_area_(NULL), | 989 candidate_area_(NULL), |
| 980 footer_area_(NULL), | 990 footer_area_(NULL), |
| 981 previous_shortcut_column_width_(0), | 991 previous_shortcut_column_width_(0), |
| 982 previous_candidate_column_width_(0), | 992 previous_candidate_column_width_(0), |
| 983 previous_annotation_column_width_(0) { | 993 previous_annotation_column_width_(0), |
| 994 is_mozc_window_(false) { | |
| 984 } | 995 } |
| 985 | 996 |
| 986 void CandidateWindowView::Init() { | 997 void CandidateWindowView::Init() { |
| 987 // Set the background and the border of the view. | 998 // Set the background and the border of the view. |
| 988 set_background( | 999 set_background( |
| 989 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); | 1000 views::Background::CreateSolidBackground(kDefaultBackgroundColor)); |
| 990 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); | 1001 set_border(views::Border::CreateSolidBorder(1, kFrameColor)); |
| 991 | 1002 |
| 992 // Create areas. | 1003 // Create areas. |
| 993 preedit_area_ = new InformationTextArea(views::Label::ALIGN_LEFT, | 1004 preedit_area_ = new InformationTextArea(views::Label::ALIGN_LEFT, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 | 1083 |
| 1073 void CandidateWindowView::ShowLookupTable() { | 1084 void CandidateWindowView::ShowLookupTable() { |
| 1074 candidate_area_->Show(); | 1085 candidate_area_->Show(); |
| 1075 ResizeAndMoveParentFrame(); | 1086 ResizeAndMoveParentFrame(); |
| 1076 parent_frame_->Show(); | 1087 parent_frame_->Show(); |
| 1077 } | 1088 } |
| 1078 | 1089 |
| 1079 bool CandidateWindowView::ShouldUpdateCandidateViews( | 1090 bool CandidateWindowView::ShouldUpdateCandidateViews( |
| 1080 const InputMethodLookupTable& old_table, | 1091 const InputMethodLookupTable& old_table, |
| 1081 const InputMethodLookupTable& new_table) { | 1092 const InputMethodLookupTable& new_table) { |
| 1093 | |
| 1094 // Check if mozc lookup table location is changed. | |
| 1095 if (old_table.mozc_candidates.has_window_location() || | |
| 1096 new_table.mozc_candidates.has_window_location()) { | |
| 1097 std::string old_serialized_msg; | |
| 1098 std::string new_serialized_msg; | |
| 1099 if (old_table.mozc_candidates.SerializeToString(&old_serialized_msg)) { | |
|
Hiro Komatsu
2011/11/15 08:50:20
Please make sure if this is your intention.
Seigo Nonaka
2011/11/15 11:59:22
Sorry this logic is wrong. If old protobuf is wron
| |
| 1100 return true; | |
| 1101 } | |
| 1102 if (new_table.mozc_candidates.SerializeToString(&new_serialized_msg)) { | |
| 1103 // It might be safe to avoid update if the protocol buffer sent from | |
| 1104 // mozc-engine is broken. | |
| 1105 return false; | |
| 1106 } | |
| 1107 return old_serialized_msg != new_serialized_msg; | |
| 1108 } | |
| 1109 | |
| 1082 // Check if most table contents are identical. | 1110 // Check if most table contents are identical. |
| 1083 if (old_table.page_size == new_table.page_size && | 1111 if (old_table.page_size == new_table.page_size && |
| 1084 old_table.orientation == new_table.orientation && | 1112 old_table.orientation == new_table.orientation && |
| 1085 old_table.candidates == new_table.candidates && | 1113 old_table.candidates == new_table.candidates && |
| 1086 old_table.labels == new_table.labels && | 1114 old_table.labels == new_table.labels && |
| 1087 old_table.annotations == new_table.annotations && | 1115 old_table.annotations == new_table.annotations && |
| 1088 // Check if the page indexes are identical. | 1116 // Check if the page indexes are identical. |
| 1089 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { | 1117 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { |
| 1090 // If all of the conditions are met, we don't have to update candidate | 1118 // If all of the conditions are met, we don't have to update candidate |
| 1091 // views. | 1119 // views. |
| 1092 return false; | 1120 return false; |
| 1093 } | 1121 } |
| 1094 return true; | 1122 return true; |
| 1095 } | 1123 } |
| 1096 | 1124 |
| 1097 void CandidateWindowView::UpdateCandidates( | 1125 void CandidateWindowView::UpdateCandidates( |
| 1098 const InputMethodLookupTable& new_lookup_table) { | 1126 const InputMethodLookupTable& new_lookup_table) { |
| 1099 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, | 1127 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, |
| 1100 new_lookup_table); | 1128 new_lookup_table); |
| 1101 // Updating the candidate views is expensive. We'll skip this if possible. | 1129 // Updating the candidate views is expensive. We'll skip this if possible. |
| 1102 if (should_update) { | 1130 if (should_update) { |
| 1103 // Initialize candidate views if necessary. | 1131 // Initialize candidate views if necessary. |
| 1104 MaybeInitializeCandidateViews(new_lookup_table); | 1132 MaybeInitializeCandidateViews(new_lookup_table); |
| 1105 | 1133 |
| 1134 // Stores mozc specific window location. | |
| 1135 if (new_lookup_table.mozc_candidates.has_window_location()) { | |
| 1136 if (new_lookup_table.mozc_candidates.window_location() == | |
| 1137 mozc::commands::Candidates::CARET) { | |
| 1138 DCHECK(new_lookup_table.mozc_candidates.has_caret_rectangle()); | |
| 1139 window_location_for_mozc_engine_.set_x( | |
| 1140 new_lookup_table.mozc_candidates.caret_rectangle().x()); | |
| 1141 window_location_for_mozc_engine_.set_y( | |
| 1142 new_lookup_table.mozc_candidates.caret_rectangle().y()); | |
| 1143 window_location_for_mozc_engine_.set_width( | |
| 1144 new_lookup_table.mozc_candidates.caret_rectangle().width()); | |
| 1145 window_location_for_mozc_engine_.set_height( | |
| 1146 new_lookup_table.mozc_candidates.caret_rectangle().height()); | |
| 1147 } else { | |
| 1148 DCHECK(new_lookup_table.mozc_candidates.has_composition_rectangle()); | |
| 1149 window_location_for_mozc_engine_.set_x( | |
| 1150 new_lookup_table.mozc_candidates.composition_rectangle().x()); | |
| 1151 window_location_for_mozc_engine_.set_y( | |
| 1152 new_lookup_table.mozc_candidates.composition_rectangle().y()); | |
| 1153 window_location_for_mozc_engine_.set_width( | |
| 1154 new_lookup_table.mozc_candidates.composition_rectangle().width()); | |
| 1155 window_location_for_mozc_engine_.set_height( | |
| 1156 new_lookup_table.mozc_candidates.composition_rectangle().height()); | |
| 1157 } | |
| 1158 is_mozc_window_ = true; | |
| 1159 } else { | |
| 1160 is_mozc_window_ = false; | |
| 1161 } | |
| 1162 | |
| 1163 | |
| 1106 // Compute the index of the current page. | 1164 // Compute the index of the current page. |
| 1107 const int current_page_index = ComputePageIndex(new_lookup_table); | 1165 const int current_page_index = ComputePageIndex(new_lookup_table); |
| 1108 if (current_page_index < 0) { | 1166 if (current_page_index < 0) { |
| 1109 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); | 1167 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); |
| 1110 return; | 1168 return; |
| 1111 } | 1169 } |
| 1112 | 1170 |
| 1113 // Update the candidates in the current page. | 1171 // Update the candidates in the current page. |
| 1114 const size_t start_from = current_page_index * new_lookup_table.page_size; | 1172 const size_t start_from = current_page_index * new_lookup_table.page_size; |
| 1115 | 1173 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1320 // For now, we don't distinguish left and right clicks. | 1378 // For now, we don't distinguish left and right clicks. |
| 1321 const int button = 1; // Left button. | 1379 const int button = 1; // Left button. |
| 1322 const int key_modifilers = 0; | 1380 const int key_modifilers = 0; |
| 1323 FOR_EACH_OBSERVER(Observer, observers_, | 1381 FOR_EACH_OBSERVER(Observer, observers_, |
| 1324 OnCandidateCommitted(selected_candidate_index_in_page_, | 1382 OnCandidateCommitted(selected_candidate_index_in_page_, |
| 1325 button, | 1383 button, |
| 1326 key_modifilers)); | 1384 key_modifilers)); |
| 1327 } | 1385 } |
| 1328 | 1386 |
| 1329 void CandidateWindowView::ResizeAndMoveParentFrame() { | 1387 void CandidateWindowView::ResizeAndMoveParentFrame() { |
| 1330 const int x = cursor_location_.x(); | 1388 // If rendering operation comes from mozc-engine, uses mozc specific location, |
| 1331 const int y = cursor_location_.y(); | 1389 // otherwise lookup table is shown under the cursor. |
| 1390 const int x = is_mozc_window_ ? | |
| 1391 window_location_for_mozc_engine_.x() : cursor_location_.x(); | |
| 1392 // To avoid lookup-table overlapping, uses maximum y-position of mozc specific | |
| 1393 // location and cursor location, because mozc-engine does not concern about | |
| 1394 // multi-line composition, | |
| 1395 const int y = is_mozc_window_ ? | |
| 1396 std::max(window_location_for_mozc_engine_.y(), cursor_location_.y()) : | |
| 1397 cursor_location_.y(); | |
| 1332 const int height = cursor_location_.height(); | 1398 const int height = cursor_location_.height(); |
| 1333 const int horizontal_offset = GetHorizontalOffset(); | 1399 const int horizontal_offset = GetHorizontalOffset(); |
| 1334 | 1400 |
| 1335 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); | 1401 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); |
| 1336 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( | 1402 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
| 1337 parent_frame_->GetNativeView()); | 1403 parent_frame_->GetNativeView()); |
| 1338 // The size. | 1404 // The size. |
| 1339 gfx::Rect frame_bounds = old_bounds; | 1405 gfx::Rect frame_bounds = old_bounds; |
| 1340 frame_bounds.set_size(GetPreferredSize()); | 1406 frame_bounds.set_size(GetPreferredSize()); |
| 1341 | 1407 |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1821 CandidateWindowController::~CandidateWindowController() { | 1887 CandidateWindowController::~CandidateWindowController() { |
| 1822 delete impl_; | 1888 delete impl_; |
| 1823 } | 1889 } |
| 1824 | 1890 |
| 1825 bool CandidateWindowController::Init() { | 1891 bool CandidateWindowController::Init() { |
| 1826 return impl_->Init(); | 1892 return impl_->Init(); |
| 1827 } | 1893 } |
| 1828 | 1894 |
| 1829 } // namespace input_method | 1895 } // namespace input_method |
| 1830 } // namespace chromeos | 1896 } // namespace chromeos |
| OLD | NEW |