Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: chrome/browser/chromeos/input_method/candidate_window.cc

Issue 8505051: Support mozc suggest window on ChromeOS. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed wrong condition and some typo Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/input_method.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 has two
582 // types of lookup-table, suggestion window and candidate window(this is
583 // ordinal look-up table). The locations of these two windows are different
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
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
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 old_table.mozc_candidates.SerializeToString(&old_serialized_msg);
1100 if (new_table.mozc_candidates.SerializeToString(&new_serialized_msg)) {
Hiro Komatsu 2011/11/16 02:15:57 Isn't this condition inverted? Is it possible to
Seigo Nonaka 2011/11/16 08:48:11 Yes we need precise unit test. So before implement
1101 // It might be safe to avoid update if the protocol buffer sent from
1102 // mozc-engine is broken.
1103 return false;
1104 }
1105 return old_serialized_msg != new_serialized_msg;
1106 }
1107
1082 // Check if most table contents are identical. 1108 // Check if most table contents are identical.
1083 if (old_table.page_size == new_table.page_size && 1109 if (old_table.page_size == new_table.page_size &&
1084 old_table.orientation == new_table.orientation && 1110 old_table.orientation == new_table.orientation &&
1085 old_table.candidates == new_table.candidates && 1111 old_table.candidates == new_table.candidates &&
1086 old_table.labels == new_table.labels && 1112 old_table.labels == new_table.labels &&
1087 old_table.annotations == new_table.annotations && 1113 old_table.annotations == new_table.annotations &&
1088 // Check if the page indexes are identical. 1114 // Check if the page indexes are identical.
1089 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { 1115 ComputePageIndex(old_table) == ComputePageIndex(new_table)) {
1090 // If all of the conditions are met, we don't have to update candidate 1116 // If all of the conditions are met, we don't have to update candidate
1091 // views. 1117 // views.
1092 return false; 1118 return false;
1093 } 1119 }
1094 return true; 1120 return true;
1095 } 1121 }
1096 1122
1097 void CandidateWindowView::UpdateCandidates( 1123 void CandidateWindowView::UpdateCandidates(
1098 const InputMethodLookupTable& new_lookup_table) { 1124 const InputMethodLookupTable& new_lookup_table) {
1099 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, 1125 const bool should_update = ShouldUpdateCandidateViews(lookup_table_,
1100 new_lookup_table); 1126 new_lookup_table);
1101 // Updating the candidate views is expensive. We'll skip this if possible. 1127 // Updating the candidate views is expensive. We'll skip this if possible.
1102 if (should_update) { 1128 if (should_update) {
1103 // Initialize candidate views if necessary. 1129 // Initialize candidate views if necessary.
1104 MaybeInitializeCandidateViews(new_lookup_table); 1130 MaybeInitializeCandidateViews(new_lookup_table);
1105 1131
1132 // Stores mozc specific window location.
1133 if (new_lookup_table.mozc_candidates.has_window_location()) {
1134 if (new_lookup_table.mozc_candidates.window_location() ==
1135 mozc::commands::Candidates::CARET) {
1136 DCHECK(new_lookup_table.mozc_candidates.has_caret_rectangle());
1137 window_location_for_mozc_engine_.set_x(
1138 new_lookup_table.mozc_candidates.caret_rectangle().x());
1139 window_location_for_mozc_engine_.set_y(
1140 new_lookup_table.mozc_candidates.caret_rectangle().y());
1141 window_location_for_mozc_engine_.set_width(
1142 new_lookup_table.mozc_candidates.caret_rectangle().width());
1143 window_location_for_mozc_engine_.set_height(
1144 new_lookup_table.mozc_candidates.caret_rectangle().height());
1145 } else {
1146 DCHECK(new_lookup_table.mozc_candidates.has_composition_rectangle());
1147 window_location_for_mozc_engine_.set_x(
1148 new_lookup_table.mozc_candidates.composition_rectangle().x());
1149 window_location_for_mozc_engine_.set_y(
1150 new_lookup_table.mozc_candidates.composition_rectangle().y());
1151 window_location_for_mozc_engine_.set_width(
1152 new_lookup_table.mozc_candidates.composition_rectangle().width());
1153 window_location_for_mozc_engine_.set_height(
1154 new_lookup_table.mozc_candidates.composition_rectangle().height());
1155 }
1156 is_mozc_window_ = true;
1157 } else {
1158 is_mozc_window_ = false;
1159 }
1160
1161
1106 // Compute the index of the current page. 1162 // Compute the index of the current page.
1107 const int current_page_index = ComputePageIndex(new_lookup_table); 1163 const int current_page_index = ComputePageIndex(new_lookup_table);
1108 if (current_page_index < 0) { 1164 if (current_page_index < 0) {
1109 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); 1165 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString();
1110 return; 1166 return;
1111 } 1167 }
1112 1168
1113 // Update the candidates in the current page. 1169 // Update the candidates in the current page.
1114 const size_t start_from = current_page_index * new_lookup_table.page_size; 1170 const size_t start_from = current_page_index * new_lookup_table.page_size;
1115 1171
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 // For now, we don't distinguish left and right clicks. 1376 // For now, we don't distinguish left and right clicks.
1321 const int button = 1; // Left button. 1377 const int button = 1; // Left button.
1322 const int key_modifilers = 0; 1378 const int key_modifilers = 0;
1323 FOR_EACH_OBSERVER(Observer, observers_, 1379 FOR_EACH_OBSERVER(Observer, observers_,
1324 OnCandidateCommitted(selected_candidate_index_in_page_, 1380 OnCandidateCommitted(selected_candidate_index_in_page_,
1325 button, 1381 button,
1326 key_modifilers)); 1382 key_modifilers));
1327 } 1383 }
1328 1384
1329 void CandidateWindowView::ResizeAndMoveParentFrame() { 1385 void CandidateWindowView::ResizeAndMoveParentFrame() {
1330 const int x = cursor_location_.x(); 1386 // If rendering operation comes from mozc-engine, uses mozc specific location,
1331 const int y = cursor_location_.y(); 1387 // otherwise lookup table is shown under the cursor.
1388 const int x = is_mozc_window_ ?
1389 window_location_for_mozc_engine_.x() : cursor_location_.x();
1390 // To avoid lookup-table overlapping, uses maximum y-position of mozc specific
1391 // location and cursor location, because mozc-engine does not concern about
Hiro Komatsu 2011/11/16 02:15:57 concern -> consider? Is it possible to make mozc-
Seigo Nonaka 2011/11/16 08:48:11 As talked offline, we decide to implement this wor
1392 // multi-line composition,
Hiro Komatsu 2011/11/16 02:15:57 The last comma should be period. (, -> .).
Seigo Nonaka 2011/11/16 08:48:11 Done.
1393 const int y = is_mozc_window_ ?
1394 std::max(window_location_for_mozc_engine_.y(), cursor_location_.y()) :
1395 cursor_location_.y();
1332 const int height = cursor_location_.height(); 1396 const int height = cursor_location_.height();
1333 const int horizontal_offset = GetHorizontalOffset(); 1397 const int horizontal_offset = GetHorizontalOffset();
1334 1398
1335 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); 1399 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds();
1336 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( 1400 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow(
1337 parent_frame_->GetNativeView()); 1401 parent_frame_->GetNativeView());
1338 // The size. 1402 // The size.
1339 gfx::Rect frame_bounds = old_bounds; 1403 gfx::Rect frame_bounds = old_bounds;
1340 frame_bounds.set_size(GetPreferredSize()); 1404 frame_bounds.set_size(GetPreferredSize());
1341 1405
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 CandidateWindowController::~CandidateWindowController() { 1885 CandidateWindowController::~CandidateWindowController() {
1822 delete impl_; 1886 delete impl_;
1823 } 1887 }
1824 1888
1825 bool CandidateWindowController::Init() { 1889 bool CandidateWindowController::Init() {
1826 return impl_->Init(); 1890 return impl_->Init();
1827 } 1891 }
1828 1892
1829 } // namespace input_method 1893 } // namespace input_method
1830 } // namespace chromeos 1894 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/input_method.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698