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

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: rebase Created 9 years 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 | « DEPS ('k') | chrome/browser/chromeos/input_method/candidate_window_view.h » ('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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
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
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
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
938 // Check if most table contents are identical. 957 // Check if most table contents are identical.
939 if (old_table.page_size == new_table.page_size && 958 if (old_table.page_size == new_table.page_size &&
940 old_table.orientation == new_table.orientation && 959 old_table.orientation == new_table.orientation &&
941 old_table.candidates == new_table.candidates && 960 old_table.candidates == new_table.candidates &&
942 old_table.labels == new_table.labels && 961 old_table.labels == new_table.labels &&
943 old_table.annotations == new_table.annotations && 962 old_table.annotations == new_table.annotations &&
944 // Check if the page indexes are identical. 963 // Check if the page indexes are identical.
945 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { 964 ComputePageIndex(old_table) == ComputePageIndex(new_table)) {
946 // If all of the conditions are met, we don't have to update candidate 965 // If all of the conditions are met, we don't have to update candidate
947 // views. 966 // views.
948 return false; 967 return false;
949 } 968 }
950 return true; 969 return true;
951 } 970 }
952 971
953 void CandidateWindowView::UpdateCandidates( 972 void CandidateWindowView::UpdateCandidates(
954 const InputMethodLookupTable& new_lookup_table) { 973 const InputMethodLookupTable& new_lookup_table) {
955 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, 974 const bool should_update = ShouldUpdateCandidateViews(lookup_table_,
956 new_lookup_table); 975 new_lookup_table);
957 // Updating the candidate views is expensive. We'll skip this if possible. 976 // Updating the candidate views is expensive. We'll skip this if possible.
958 if (should_update) { 977 if (should_update) {
959 // Initialize candidate views if necessary. 978 // Initialize candidate views if necessary.
960 MaybeInitializeCandidateViews(new_lookup_table); 979 MaybeInitializeCandidateViews(new_lookup_table);
961 980
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
962 // Compute the index of the current page. 999 // Compute the index of the current page.
963 const int current_page_index = ComputePageIndex(new_lookup_table); 1000 const int current_page_index = ComputePageIndex(new_lookup_table);
964 if (current_page_index < 0) { 1001 if (current_page_index < 0) {
965 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString(); 1002 LOG(ERROR) << "Invalid lookup_table: " << new_lookup_table.ToString();
966 return; 1003 return;
967 } 1004 }
968 1005
969 // Update the candidates in the current page. 1006 // Update the candidates in the current page.
970 const size_t start_from = current_page_index * new_lookup_table.page_size; 1007 const size_t start_from = current_page_index * new_lookup_table.page_size;
971 1008
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 // For now, we don't distinguish left and right clicks. 1213 // For now, we don't distinguish left and right clicks.
1177 const int button = 1; // Left button. 1214 const int button = 1; // Left button.
1178 const int key_modifilers = 0; 1215 const int key_modifilers = 0;
1179 FOR_EACH_OBSERVER(Observer, observers_, 1216 FOR_EACH_OBSERVER(Observer, observers_,
1180 OnCandidateCommitted(selected_candidate_index_in_page_, 1217 OnCandidateCommitted(selected_candidate_index_in_page_,
1181 button, 1218 button,
1182 key_modifilers)); 1219 key_modifilers));
1183 } 1220 }
1184 1221
1185 void CandidateWindowView::ResizeAndMoveParentFrame() { 1222 void CandidateWindowView::ResizeAndMoveParentFrame() {
1186 const int x = cursor_location_.x(); 1223 // If rendering operation comes from mozc-engine, uses mozc specific location,
1187 const int y = cursor_location_.y(); 1224 // otherwise lookup table is shown under the cursor.
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();
1188 const int height = cursor_location_.height(); 1233 const int height = cursor_location_.height();
1189 const int horizontal_offset = GetHorizontalOffset(); 1234 const int horizontal_offset = GetHorizontalOffset();
1190 1235
1191 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); 1236 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds();
1192 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( 1237 gfx::Rect screen_bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow(
1193 parent_frame_->GetNativeView()); 1238 parent_frame_->GetNativeView());
1194 // The size. 1239 // The size.
1195 gfx::Rect frame_bounds = old_bounds; 1240 gfx::Rect frame_bounds = old_bounds;
1196 frame_bounds.set_size(GetPreferredSize()); 1241 frame_bounds.set_size(GetPreferredSize());
1197 1242
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 CandidateWindowController::~CandidateWindowController() { 1723 CandidateWindowController::~CandidateWindowController() {
1679 delete impl_; 1724 delete impl_;
1680 } 1725 }
1681 1726
1682 bool CandidateWindowController::Init() { 1727 bool CandidateWindowController::Init() {
1683 return impl_->Init(); 1728 return impl_->Init();
1684 } 1729 }
1685 1730
1686 } // namespace input_method 1731 } // namespace input_method
1687 } // namespace chromeos 1732 } // namespace chromeos
OLDNEW
« no previous file with comments | « DEPS ('k') | chrome/browser/chromeos/input_method/candidate_window_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698