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

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

Issue 10534134: Fix candidate window position issue. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 8 years, 6 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 virtual void OnCandidateWindowOpened(); 527 virtual void OnCandidateWindowOpened();
528 virtual void OnCandidateWindowClosed(); 528 virtual void OnCandidateWindowClosed();
529 529
530 // Creates the candidate window view. 530 // Creates the candidate window view.
531 void CreateView(); 531 void CreateView();
532 532
533 // IBusUiController::Observer overrides. 533 // IBusUiController::Observer overrides.
534 virtual void OnHideAuxiliaryText(); 534 virtual void OnHideAuxiliaryText();
535 virtual void OnHideLookupTable(); 535 virtual void OnHideLookupTable();
536 virtual void OnHidePreeditText(); 536 virtual void OnHidePreeditText();
537 virtual void OnSetCursorLocation(int x, int y, int width, int height); 537 virtual void OnSetCursorLocation(int x, int y, int width, int height,
Yusuke Sato 2012/06/13 14:31:26 any reason not to use gfx::Rect instead of the fir
Seigo Nonaka 2012/06/13 15:07:18 Okay remove now. On 2012/06/13 14:31:26, Yusuke Sa
538 const gfx::Rect& composition_head);
538 virtual void OnUpdateAuxiliaryText(const std::string& utf8_text, 539 virtual void OnUpdateAuxiliaryText(const std::string& utf8_text,
539 bool visible); 540 bool visible);
540 virtual void OnUpdateLookupTable(const InputMethodLookupTable& lookup_table); 541 virtual void OnUpdateLookupTable(const InputMethodLookupTable& lookup_table);
541 virtual void OnUpdatePreeditText(const std::string& utf8_text, 542 virtual void OnUpdatePreeditText(const std::string& utf8_text,
542 unsigned int cursor, bool visible); 543 unsigned int cursor, bool visible);
543 virtual void OnConnectionChange(bool connected); 544 virtual void OnConnectionChange(bool connected);
544 545
545 // The controller is used for communicating with the IBus daemon. 546 // The controller is used for communicating with the IBus daemon.
546 scoped_ptr<IBusUiController> ibus_ui_controller_; 547 scoped_ptr<IBusUiController> ibus_ui_controller_;
547 548
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) 776 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame)
776 : selected_candidate_index_in_page_(0), 777 : selected_candidate_index_in_page_(0),
777 parent_frame_(parent_frame), 778 parent_frame_(parent_frame),
778 preedit_area_(NULL), 779 preedit_area_(NULL),
779 header_area_(NULL), 780 header_area_(NULL),
780 candidate_area_(NULL), 781 candidate_area_(NULL),
781 footer_area_(NULL), 782 footer_area_(NULL),
782 previous_shortcut_column_size_(0, 0), 783 previous_shortcut_column_size_(0, 0),
783 previous_candidate_column_size_(0, 0), 784 previous_candidate_column_size_(0, 0),
784 previous_annotation_column_size_(0, 0), 785 previous_annotation_column_size_(0, 0),
785 is_suggestion_window_location_available_(false), 786 should_show_at_composition_head_(false),
786 should_show_upper_side_(false), 787 should_show_upper_side_(false),
787 was_candidate_window_open_(false) { 788 was_candidate_window_open_(false) {
788 } 789 }
789 790
790 CandidateWindowView::~CandidateWindowView() { 791 CandidateWindowView::~CandidateWindowView() {
791 } 792 }
792 793
793 void CandidateWindowView::Init() { 794 void CandidateWindowView::Init() {
794 // Set the background and the border of the view. 795 // Set the background and the border of the view.
795 set_background( 796 set_background(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 } else if (was_candidate_window_open_ && !is_open) { 911 } else if (was_candidate_window_open_ && !is_open) {
911 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); 912 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed());
912 } 913 }
913 was_candidate_window_open_ = is_open; 914 was_candidate_window_open_ = is_open;
914 } 915 }
915 916
916 bool CandidateWindowView::ShouldUpdateCandidateViews( 917 bool CandidateWindowView::ShouldUpdateCandidateViews(
917 const InputMethodLookupTable& old_table, 918 const InputMethodLookupTable& old_table,
918 const InputMethodLookupTable& new_table) { 919 const InputMethodLookupTable& new_table) {
919 920
920 // Check if mozc lookup table location is changed. 921 // Check only candidate category because other fields are not used in
921 if (old_table.mozc_candidates.has_window_location() || 922 // CandidateWindowView.
922 new_table.mozc_candidates.has_window_location()) { 923 // TODO(nona): Remove mozc_candidates(crbug.com/129403).
923 924 if (old_table.mozc_candidates.has_category() ||
924 if (!old_table.mozc_candidates.IsInitialized() || 925 new_table.mozc_candidates.has_category()) {
925 !new_table.mozc_candidates.IsInitialized()) { 926 if (old_table.mozc_candidates.category() !=
927 new_table.mozc_candidates.category())
926 return true; 928 return true;
927 }
928
929 std::string old_serialized_msg;
930 std::string new_serialized_msg;
931
932 old_table.mozc_candidates.SerializeToString(&old_serialized_msg);
933 new_table.mozc_candidates.SerializeToString(&new_serialized_msg);
934 return old_serialized_msg != new_serialized_msg;
935 } 929 }
936 930
937 // Check if most table contents are identical. 931 // Check if most table contents are identical.
938 if (old_table.page_size == new_table.page_size && 932 if (old_table.page_size == new_table.page_size &&
939 old_table.orientation == new_table.orientation && 933 old_table.orientation == new_table.orientation &&
940 old_table.candidates == new_table.candidates && 934 old_table.candidates == new_table.candidates &&
941 old_table.labels == new_table.labels && 935 old_table.labels == new_table.labels &&
942 old_table.annotations == new_table.annotations && 936 old_table.annotations == new_table.annotations &&
943 // Check if the page indexes are identical. 937 // Check if the page indexes are identical.
944 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { 938 ComputePageIndex(old_table) == ComputePageIndex(new_table)) {
945 // If all of the conditions are met, we don't have to update candidate 939 // If all of the conditions are met, we don't have to update candidate
946 // views. 940 // views.
947 return false; 941 return false;
948 } 942 }
949 return true; 943 return true;
950 } 944 }
951 945
952 void CandidateWindowView::UpdateCandidates( 946 void CandidateWindowView::UpdateCandidates(
953 const InputMethodLookupTable& new_lookup_table) { 947 const InputMethodLookupTable& new_lookup_table) {
954 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, 948 const bool should_update = ShouldUpdateCandidateViews(lookup_table_,
955 new_lookup_table); 949 new_lookup_table);
956 // Updating the candidate views is expensive. We'll skip this if possible. 950 // Updating the candidate views is expensive. We'll skip this if possible.
957 if (should_update) { 951 if (should_update) {
958 // Initialize candidate views if necessary. 952 // Initialize candidate views if necessary.
959 MaybeInitializeCandidateViews(new_lookup_table); 953 MaybeInitializeCandidateViews(new_lookup_table);
960 954
961 // Store mozc specific window location. 955 if (new_lookup_table.mozc_candidates.has_category() &&
962 if (new_lookup_table.mozc_candidates.has_window_location() && 956 new_lookup_table.mozc_candidates.category() ==
963 new_lookup_table.mozc_candidates.window_location() == 957 mozc::commands::SUGGESTION) {
964 mozc::commands::Candidates::COMPOSITION) { 958 should_show_at_composition_head_ = true;
965 DCHECK(new_lookup_table.mozc_candidates.has_composition_rectangle());
966 suggestion_window_location_.set_x(
967 new_lookup_table.mozc_candidates.composition_rectangle().x());
968 suggestion_window_location_.set_y(
969 new_lookup_table.mozc_candidates.composition_rectangle().y());
970 suggestion_window_location_.set_width(
971 new_lookup_table.mozc_candidates.composition_rectangle().width());
972 suggestion_window_location_.set_height(
973 new_lookup_table.mozc_candidates.composition_rectangle().height());
974 is_suggestion_window_location_available_ = true;
975 } else { 959 } else {
976 is_suggestion_window_location_available_ = false; 960 should_show_at_composition_head_ = false;
977 } 961 }
978 962
979 // Compute the index of the current page. 963 // Compute the index of the current page.
980 const int current_page_index = ComputePageIndex(new_lookup_table); 964 const int current_page_index = ComputePageIndex(new_lookup_table);
981 if (current_page_index < 0) { 965 if (current_page_index < 0) {
982 DVLOG(1) << "Invalid lookup_table: " << new_lookup_table.ToString(); 966 DVLOG(1) << "Invalid lookup_table: " << new_lookup_table.ToString();
983 return; 967 return;
984 } 968 }
985 969
986 // Update the candidates in the current page. 970 // Update the candidates in the current page.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 // Compute views size in |layout|. 1138 // Compute views size in |layout|.
1155 // If we don't call this function, GetHorizontalOffset() often 1139 // If we don't call this function, GetHorizontalOffset() often
1156 // returns invalid value (returns 0), then candidate window 1140 // returns invalid value (returns 0), then candidate window
1157 // moves right from the correct position in ResizeAndMoveParentFrame(). 1141 // moves right from the correct position in ResizeAndMoveParentFrame().
1158 // TODO(nhiroki): Figure out why it returns invalid value. 1142 // TODO(nhiroki): Figure out why it returns invalid value.
1159 // It seems that the x-position of the candidate labels is not set. 1143 // It seems that the x-position of the candidate labels is not set.
1160 layout->Layout(candidate_area_contents); 1144 layout->Layout(candidate_area_contents);
1161 } 1145 }
1162 1146
1163 bool CandidateWindowView::IsCandidateWindowOpen() const { 1147 bool CandidateWindowView::IsCandidateWindowOpen() const {
1164 return !is_suggestion_window_location_available_ && 1148 return !should_show_at_composition_head_ &&
1165 candidate_area_->visible() && candidate_area_->IsShown(); 1149 candidate_area_->visible() && candidate_area_->IsShown();
1166 } 1150 }
1167 1151
1168 void CandidateWindowView::SelectCandidateAt(int index_in_page) { 1152 void CandidateWindowView::SelectCandidateAt(int index_in_page) {
1169 const int current_page_index = ComputePageIndex(lookup_table_); 1153 const int current_page_index = ComputePageIndex(lookup_table_);
1170 if (current_page_index < 0) { 1154 if (current_page_index < 0) {
1171 DVLOG(1) << "Invalid lookup_table: " << lookup_table_.ToString(); 1155 DVLOG(1) << "Invalid lookup_table: " << lookup_table_.ToString();
1172 return; 1156 return;
1173 } 1157 }
1174 1158
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 const int key_modifilers = 0; 1196 const int key_modifilers = 0;
1213 FOR_EACH_OBSERVER(Observer, observers_, 1197 FOR_EACH_OBSERVER(Observer, observers_,
1214 OnCandidateCommitted(selected_candidate_index_in_page_, 1198 OnCandidateCommitted(selected_candidate_index_in_page_,
1215 button, 1199 button,
1216 key_modifilers)); 1200 key_modifilers));
1217 } 1201 }
1218 1202
1219 void CandidateWindowView::ResizeAndMoveParentFrame() { 1203 void CandidateWindowView::ResizeAndMoveParentFrame() {
1220 // If rendering operation comes from mozc-engine, uses mozc specific location, 1204 // If rendering operation comes from mozc-engine, uses mozc specific location,
1221 // otherwise lookup table is shown under the cursor. 1205 // otherwise lookup table is shown under the cursor.
1222 const int x = is_suggestion_window_location_available_ ? 1206 const int x = should_show_at_composition_head_?
1223 suggestion_window_location_.x() : cursor_location_.x(); 1207 composition_head_location_.x() : cursor_location_.x();
1224 // To avoid lookup-table overlapping, uses maximum y-position of mozc specific 1208 // To avoid lookup-table overlapping, uses maximum y-position of mozc specific
1225 // location and cursor location, because mozc-engine does not consider about 1209 // location and cursor location, because mozc-engine does not consider about
1226 // multi-line composition. 1210 // multi-line composition.
1227 const int y = is_suggestion_window_location_available_ ? 1211 const int y = should_show_at_composition_head_?
1228 std::max(suggestion_window_location_.y(), cursor_location_.y()) : 1212 std::max(composition_head_location_.y(), cursor_location_.y()) :
1229 cursor_location_.y(); 1213 cursor_location_.y();
1230 const int height = cursor_location_.height(); 1214 const int height = cursor_location_.height();
1231 const int horizontal_offset = GetHorizontalOffset(); 1215 const int horizontal_offset = GetHorizontalOffset();
1232 1216
1233 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds(); 1217 gfx::Rect old_bounds = parent_frame_->GetClientAreaScreenBounds();
1234 gfx::Rect screen_bounds = gfx::Screen::GetMonitorNearestWindow( 1218 gfx::Rect screen_bounds = gfx::Screen::GetMonitorNearestWindow(
1235 parent_frame_->GetNativeView()).work_area(); 1219 parent_frame_->GetNativeView()).work_area();
1236 // The size. 1220 // The size.
1237 gfx::Rect frame_bounds = old_bounds; 1221 gfx::Rect frame_bounds = old_bounds;
1238 frame_bounds.set_size(GetPreferredSize()); 1222 frame_bounds.set_size(GetPreferredSize());
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 } 1644 }
1661 1645
1662 void CandidateWindowControllerImpl::OnHidePreeditText() { 1646 void CandidateWindowControllerImpl::OnHidePreeditText() {
1663 candidate_window_->HidePreeditText(); 1647 candidate_window_->HidePreeditText();
1664 } 1648 }
1665 1649
1666 void CandidateWindowControllerImpl::OnSetCursorLocation( 1650 void CandidateWindowControllerImpl::OnSetCursorLocation(
1667 int x, 1651 int x,
1668 int y, 1652 int y,
1669 int width, 1653 int width,
1670 int height) { 1654 int height,
1655 const gfx::Rect& composition_head) {
1671 // A workaround for http://crosbug.com/6460. We should ignore very short Y 1656 // A workaround for http://crosbug.com/6460. We should ignore very short Y
1672 // move to prevent the window from shaking up and down. 1657 // move to prevent the window from shaking up and down.
1673 const int kKeepPositionThreshold = 2; // px 1658 const int kKeepPositionThreshold = 2; // px
1674 const gfx::Rect& last_location = 1659 const gfx::Rect& last_location =
1675 candidate_window_->cursor_location(); 1660 candidate_window_->cursor_location();
1676 const int delta_y = abs(last_location.y() - y); 1661 const int delta_y = abs(last_location.y() - y);
1677 if ((last_location.x() == x) && (delta_y <= kKeepPositionThreshold)) { 1662 if ((last_location.x() == x) && (delta_y <= kKeepPositionThreshold)) {
1678 DVLOG(1) << "Ignored set_cursor_location signal to prevent window shake"; 1663 DVLOG(1) << "Ignored set_cursor_location signal to prevent window shake";
1679 return; 1664 return;
1680 } 1665 }
1681 1666
1682 // Remember the cursor location. 1667 // Remember the cursor location.
1683 candidate_window_->set_cursor_location( 1668 candidate_window_->set_cursor_location(
1684 gfx::Rect(x, y, width, height)); 1669 gfx::Rect(x, y, width, height));
1670 candidate_window_->set_composition_head_location(composition_head);
1685 // Move the window per the cursor location. 1671 // Move the window per the cursor location.
1686 candidate_window_->ResizeAndMoveParentFrame(); 1672 candidate_window_->ResizeAndMoveParentFrame();
1687 infolist_window_->ResizeAndMoveParentFrame(); 1673 infolist_window_->ResizeAndMoveParentFrame();
1688 } 1674 }
1689 1675
1690 void CandidateWindowControllerImpl::OnUpdateAuxiliaryText( 1676 void CandidateWindowControllerImpl::OnUpdateAuxiliaryText(
1691 const std::string& utf8_text, 1677 const std::string& utf8_text,
1692 bool visible) { 1678 bool visible) {
1693 // If it's not visible, hide the auxiliary text and return. 1679 // If it's not visible, hide the auxiliary text and return.
1694 if (!visible) { 1680 if (!visible) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 } 1765 }
1780 1766
1781 // static 1767 // static
1782 CandidateWindowController* 1768 CandidateWindowController*
1783 CandidateWindowController::CreateCandidateWindowController() { 1769 CandidateWindowController::CreateCandidateWindowController() {
1784 return new CandidateWindowControllerImpl; 1770 return new CandidateWindowControllerImpl;
1785 } 1771 }
1786 1772
1787 } // namespace input_method 1773 } // namespace input_method
1788 } // namespace chromeos 1774 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698