OLD | NEW |
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/ui/gtk/omnibox/omnibox_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 const bool selection_differs = | 717 const bool selection_differs = |
718 ((new_sel.cp_min != new_sel.cp_max) || | 718 ((new_sel.cp_min != new_sel.cp_max) || |
719 (sel_before_change_.cp_min != sel_before_change_.cp_max)) && | 719 (sel_before_change_.cp_min != sel_before_change_.cp_max)) && |
720 ((new_sel.cp_min != sel_before_change_.cp_min) || | 720 ((new_sel.cp_min != sel_before_change_.cp_min) || |
721 (new_sel.cp_max != sel_before_change_.cp_max)); | 721 (new_sel.cp_max != sel_before_change_.cp_max)); |
722 const bool at_end_of_edit = | 722 const bool at_end_of_edit = |
723 (new_sel.cp_min == length && new_sel.cp_max == length); | 723 (new_sel.cp_min == length && new_sel.cp_max == length); |
724 | 724 |
725 // See if the text or selection have changed since OnBeforePossibleChange(). | 725 // See if the text or selection have changed since OnBeforePossibleChange(). |
726 const string16 new_text(GetText()); | 726 const string16 new_text(GetText()); |
727 text_changed_ = (new_text != text_before_change_); | 727 text_changed_ = (new_text != text_before_change_) || (supports_pre_edit_ && |
728 if (supports_pre_edit_) { | 728 (pre_edit_.size() != pre_edit_size_before_change_)); |
729 text_changed_ = | |
730 text_changed_ || (pre_edit_.size() != pre_edit_size_before_change_); | |
731 } | |
732 | 729 |
733 if (text_changed_) | 730 if (text_changed_) |
734 AdjustTextJustification(); | 731 AdjustTextJustification(); |
735 | 732 |
736 // When the user has deleted text, we don't allow inline autocomplete. Make | 733 // When the user has deleted text, we don't allow inline autocomplete. Make |
737 // sure to not flag cases like selecting part of the text and then pasting | 734 // sure to not flag cases like selecting part of the text and then pasting |
738 // (or typing) the prefix of that selection. (We detect these by making | 735 // (or typing) the prefix of that selection. (We detect these by making |
739 // sure the caret, which should be after any insertion, hasn't moved | 736 // sure the caret, which should be after any insertion, hasn't moved |
740 // forward of the old selection start.) | 737 // forward of the old selection start.) |
741 const bool just_deleted_text = | 738 const bool just_deleted_text = |
742 (text_before_change_.length() > new_text.length()) && | 739 (text_before_change_.length() > new_text.length()) && |
743 (new_sel.cp_min <= std::min(sel_before_change_.cp_min, | 740 (new_sel.cp_min <= std::min(sel_before_change_.cp_min, |
744 sel_before_change_.cp_max)); | 741 sel_before_change_.cp_max)); |
745 | 742 |
746 delete_at_end_pressed_ = false; | 743 delete_at_end_pressed_ = false; |
747 | 744 |
748 const bool something_changed = model_->OnAfterPossibleChange( | 745 const bool something_changed = model_->OnAfterPossibleChange( |
749 new_text, new_sel.selection_min(), new_sel.selection_max(), | 746 text_before_change_, new_text, new_sel.selection_min(), |
750 selection_differs, text_changed_, just_deleted_text, | 747 new_sel.selection_max(), selection_differs, text_changed_, |
751 !IsImeComposing()); | 748 just_deleted_text, !IsImeComposing()); |
752 | 749 |
753 // If only selection was changed, we don't need to call |controller_|'s | 750 // If only selection was changed, we don't need to call |controller_|'s |
754 // OnChanged() method, which is called in TextChanged(). | 751 // OnChanged() method, which is called in TextChanged(). |
755 // But we still need to call EmphasizeURLComponents() to make sure the text | 752 // But we still need to call EmphasizeURLComponents() to make sure the text |
756 // attributes are updated correctly. | 753 // attributes are updated correctly. |
757 if (something_changed && text_changed_) { | 754 if (something_changed && text_changed_) { |
758 TextChanged(); | 755 TextChanged(); |
759 } else if (selection_differs) { | 756 } else if (selection_differs) { |
760 EmphasizeURLComponents(); | 757 EmphasizeURLComponents(); |
761 } else if (delete_was_pressed_ && at_end_of_edit) { | 758 } else if (delete_was_pressed_ && at_end_of_edit) { |
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 | 2424 |
2428 // Make all the children of the widget visible. NOTE: this won't display | 2425 // Make all the children of the widget visible. NOTE: this won't display |
2429 // anything, it just toggles the visible flag. | 2426 // anything, it just toggles the visible flag. |
2430 gtk_widget_show_all(omnibox_view->GetNativeView()); | 2427 gtk_widget_show_all(omnibox_view->GetNativeView()); |
2431 // Hide the widget. NativeViewHostGtk will make it visible again as necessary. | 2428 // Hide the widget. NativeViewHostGtk will make it visible again as necessary. |
2432 gtk_widget_hide(omnibox_view->GetNativeView()); | 2429 gtk_widget_hide(omnibox_view->GetNativeView()); |
2433 | 2430 |
2434 return omnibox_view; | 2431 return omnibox_view; |
2435 } | 2432 } |
2436 #endif | 2433 #endif |
OLD | NEW |