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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 2273263002: MacViewsBrowser: Fix omnibox crash due to failed DCHECK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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/ui/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 SkColor security_color = 635 SkColor security_color =
636 location_bar_view_->GetSecureTextColor(security_level_); 636 location_bar_view_->GetSecureTextColor(security_level_);
637 const bool strike = 637 const bool strike =
638 (security_level_ == security_state::SecurityStateModel::SECURITY_ERROR); 638 (security_level_ == security_state::SecurityStateModel::SECURITY_ERROR);
639 const gfx::Range scheme_range(scheme.begin, scheme.end()); 639 const gfx::Range scheme_range(scheme.begin, scheme.end());
640 ApplyColor(security_color, scheme_range); 640 ApplyColor(security_color, scheme_range);
641 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); 641 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range);
642 } 642 }
643 } 643 }
644 644
645 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) {
646 // The omnibox contents may change while the control key is pressed.
647 if (event.key_code() == ui::VKEY_CONTROL)
648 model()->OnControlKeyChanged(false);
649 return views::Textfield::OnKeyReleased(event);
650 }
651
652 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { 645 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const {
653 return command_id == IDS_PASTE_AND_GO; 646 return command_id == IDS_PASTE_AND_GO;
654 } 647 }
655 648
656 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { 649 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const {
657 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); 650 DCHECK_EQ(IDS_PASTE_AND_GO, command_id);
658 return l10n_util::GetStringUTF16( 651 return l10n_util::GetStringUTF16(
659 model()->IsPasteAndSearch(GetClipboardText()) ? 652 model()->IsPasteAndSearch(GetClipboardText()) ?
660 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); 653 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
661 } 654 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 if (select_all_on_mouse_release_ && 697 if (select_all_on_mouse_release_ &&
705 !controller()->GetToolbarModel()->WouldReplaceURL()) { 698 !controller()->GetToolbarModel()->WouldReplaceURL()) {
706 // Select all in the reverse direction so as not to scroll the caret 699 // Select all in the reverse direction so as not to scroll the caret
707 // into view and shift the contents jarringly. 700 // into view and shift the contents jarringly.
708 SelectAll(true); 701 SelectAll(true);
709 } 702 }
710 } 703 }
711 select_all_on_mouse_release_ = false; 704 select_all_on_mouse_release_ = false;
712 } 705 }
713 706
714 bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
715 // Skip processing of [Alt]+<num-pad digit> Unicode alt key codes.
716 // Otherwise, if num-lock is off, the events are handled as [Up], [Down], etc.
717 if (event.IsUnicodeKeyCode())
718 return views::Textfield::OnKeyPressed(event);
719
720 const bool shift = event.IsShiftDown();
721 const bool control = event.IsControlDown();
722 const bool alt = event.IsAltDown() || event.IsAltGrDown();
723 switch (event.key_code()) {
724 case ui::VKEY_RETURN:
725 model()->AcceptInput(alt ? NEW_FOREGROUND_TAB : CURRENT_TAB, false);
726 return true;
727 case ui::VKEY_ESCAPE:
728 return model()->OnEscapeKeyPressed();
729 case ui::VKEY_CONTROL:
730 model()->OnControlKeyChanged(true);
731 break;
732 case ui::VKEY_DELETE:
733 if (shift && model()->popup_model()->IsOpen())
734 model()->popup_model()->TryDeletingCurrentItem();
735 break;
736 case ui::VKEY_UP:
737 if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_UP)) {
738 ExecuteTextEditCommand(ui::TextEditCommand::MOVE_UP);
739 return true;
740 }
741 break;
742 case ui::VKEY_DOWN:
743 if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_DOWN)) {
744 ExecuteTextEditCommand(ui::TextEditCommand::MOVE_DOWN);
745 return true;
746 }
747 break;
748 case ui::VKEY_PRIOR:
749 if (control || alt || shift)
750 return false;
751 model()->OnUpOrDownKeyPressed(-1 * model()->result().size());
752 return true;
753 case ui::VKEY_NEXT:
754 if (control || alt || shift)
755 return false;
756 model()->OnUpOrDownKeyPressed(model()->result().size());
757 return true;
758 case ui::VKEY_V:
759 if (control && !alt &&
760 IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
761 ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
762 return true;
763 }
764 break;
765 case ui::VKEY_INSERT:
766 if (shift && !control &&
767 IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
768 ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
769 return true;
770 }
771 break;
772 default:
773 break;
774 }
775
776 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event);
karandeepb 2016/08/25 10:03:53 Any reason why this wasn't HandleEarlyTabActions(
777 }
778
779 void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) { 707 void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {
780 if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) { 708 if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) {
781 select_all_on_gesture_tap_ = true; 709 select_all_on_gesture_tap_ = true;
782 710
783 // If we're trying to select all on tap, invalidate any saved selection lest 711 // If we're trying to select all on tap, invalidate any saved selection lest
784 // restoring it fights with the "select all" action. 712 // restoring it fights with the "select all" action.
785 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); 713 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
786 } 714 }
787 715
788 views::Textfield::OnGestureEvent(event); 716 views::Textfield::OnGestureEvent(event);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 ime_candidate_window_open_ = false; 879 ime_candidate_window_open_ = false;
952 } 880 }
953 #endif 881 #endif
954 882
955 void OmniboxViewViews::ContentsChanged(views::Textfield* sender, 883 void OmniboxViewViews::ContentsChanged(views::Textfield* sender,
956 const base::string16& new_contents) { 884 const base::string16& new_contents) {
957 } 885 }
958 886
959 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, 887 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
960 const ui::KeyEvent& event) { 888 const ui::KeyEvent& event) {
961 if (event.type() != ui::ET_KEY_PRESSED) 889 if (event.type() == ui::ET_KEY_RELEASED) {
890 // The omnibox contents may change while the control key is pressed.
891 if (event.key_code() == ui::VKEY_CONTROL)
892 model()->OnControlKeyChanged(false);
893
962 return false; 894 return false;
895 }
963 896
964 delete_at_end_pressed_ = false; 897 delete_at_end_pressed_ = false;
karandeepb 2016/08/25 10:03:53 Can't seem to find any callers for OmniboxView::De
965 898
966 if (event.key_code() == ui::VKEY_BACK) { 899 // Skip processing of [Alt]+<num-pad digit> Unicode alt key codes.
967 // No extra handling is needed in keyword search mode, if there is a 900 // Otherwise, if num-lock is off, the events are handled as [Up], [Down], etc.
968 // non-empty selection, or if the cursor is not leading the text. 901 if (event.IsUnicodeKeyCode())
969 if (model()->is_keyword_hint() || model()->keyword().empty() || 902 return views::Textfield::OnKeyPressed(event);
970 HasSelection() || GetCursorPosition() != 0) 903
971 return false; 904 const bool shift = event.IsShiftDown();
972 model()->ClearKeyword(); 905 const bool control = event.IsControlDown();
973 return true; 906 const bool alt = event.IsAltDown() || event.IsAltGrDown();
907 switch (event.key_code()) {
908 case ui::VKEY_RETURN:
909 model()->AcceptInput(alt ? NEW_FOREGROUND_TAB : CURRENT_TAB, false);
910 return true;
911 case ui::VKEY_ESCAPE:
912 return model()->OnEscapeKeyPressed();
913 case ui::VKEY_CONTROL:
914 model()->OnControlKeyChanged(true);
915 break;
916 case ui::VKEY_DELETE:
917 if (shift && model()->popup_model()->IsOpen())
918 model()->popup_model()->TryDeletingCurrentItem();
919
920 delete_at_end_pressed_ = (!event.IsAltDown() && !HasSelection() &&
921 GetCursorPosition() == text().length());
922 break;
923 case ui::VKEY_UP:
924 if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_UP)) {
925 ExecuteTextEditCommand(ui::TextEditCommand::MOVE_UP);
926 return true;
927 }
928 break;
929 case ui::VKEY_DOWN:
930 if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_DOWN)) {
931 ExecuteTextEditCommand(ui::TextEditCommand::MOVE_DOWN);
932 return true;
933 }
934 break;
935 case ui::VKEY_PRIOR:
936 if (control || alt || shift)
937 return false;
938 model()->OnUpOrDownKeyPressed(-1 * model()->result().size());
939 return true;
940 case ui::VKEY_NEXT:
941 if (control || alt || shift)
942 return false;
943 model()->OnUpOrDownKeyPressed(model()->result().size());
944 return true;
945 case ui::VKEY_V:
946 if (control && !alt &&
947 IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
948 ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
949 return true;
950 }
951 break;
952 case ui::VKEY_INSERT:
953 if (shift && !control &&
954 IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
955 ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
956 return true;
957 }
958 break;
959 case ui::VKEY_BACK:
960 // No extra handling is needed in keyword search mode, if there is a
961 // non-empty selection, or if the cursor is not leading the text.
962 if (model()->is_keyword_hint() || model()->keyword().empty() ||
963 HasSelection() || GetCursorPosition() != 0)
964 return false;
965 model()->ClearKeyword();
966 return true;
967
968 // Handle the right-arrow key for LTR text and the left-arrow key for RTL
969 // text
970 // if there is gray text that needs to be committed.
971 case ui::VKEY_RIGHT:
972 if (GetCursorPosition() == text().length() &&
973 GetTextDirection() == base::i18n::LEFT_TO_RIGHT)
974 return model()->CommitSuggestedText();
975 break;
976 case ui::VKEY_LEFT:
977 if (GetCursorPosition() == text().length() &&
978 GetTextDirection() == base::i18n::RIGHT_TO_LEFT)
979 return model()->CommitSuggestedText();
980 break;
981 default:
982 break;
974 } 983 }
975 984
976 if (event.key_code() == ui::VKEY_DELETE && !event.IsAltDown()) { 985 return HandleEarlyTabActions(event);
977 delete_at_end_pressed_ =
978 (!HasSelection() && GetCursorPosition() == text().length());
979 }
980
981 // Handle the right-arrow key for LTR text and the left-arrow key for RTL text
982 // if there is gray text that needs to be committed.
983 if (GetCursorPosition() == text().length()) {
984 base::i18n::TextDirection direction = GetTextDirection();
985 if ((direction == base::i18n::LEFT_TO_RIGHT &&
986 event.key_code() == ui::VKEY_RIGHT) ||
987 (direction == base::i18n::RIGHT_TO_LEFT &&
988 event.key_code() == ui::VKEY_LEFT)) {
989 return model()->CommitSuggestedText();
990 }
991 }
992
993 return false;
994 } 986 }
995 987
996 void OmniboxViewViews::OnBeforeUserAction(views::Textfield* sender) { 988 void OmniboxViewViews::OnBeforeUserAction(views::Textfield* sender) {
997 OnBeforePossibleChange(); 989 OnBeforePossibleChange();
998 } 990 }
999 991
1000 void OmniboxViewViews::OnAfterUserAction(views::Textfield* sender) { 992 void OmniboxViewViews::OnAfterUserAction(views::Textfield* sender) {
1001 OnAfterPossibleChange(true); 993 OnAfterPossibleChange(true);
1002 } 994 }
1003 995
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1085 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1094 1086
1095 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1087 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1096 1088
1097 // Minor note: We use IDC_ for command id here while the underlying textfield 1089 // Minor note: We use IDC_ for command id here while the underlying textfield
1098 // is using IDS_ for all its command ids. This is because views cannot depend 1090 // is using IDS_ for all its command ids. This is because views cannot depend
1099 // on IDC_ for now. 1091 // on IDC_ for now.
1100 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1092 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1101 IDS_EDIT_SEARCH_ENGINES); 1093 IDS_EDIT_SEARCH_ENGINES);
1102 } 1094 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | ui/views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698