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

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

Issue 2031433002: Views::Textfield: Decouple handling of menu and text editing commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor2_virtual_calls
Patch Set: Created 4 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/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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). 359 // These commands don't invoke the popup via OnBefore/AfterPossibleChange().
360 case IDS_PASTE_AND_GO: 360 case IDS_PASTE_AND_GO:
361 model()->PasteAndGo(GetClipboardText()); 361 model()->PasteAndGo(GetClipboardText());
362 return; 362 return;
363 case IDS_SHOW_URL: 363 case IDS_SHOW_URL:
364 controller()->ShowURL(); 364 controller()->ShowURL();
365 return; 365 return;
366 case IDC_EDIT_SEARCH_ENGINES: 366 case IDC_EDIT_SEARCH_ENGINES:
367 location_bar_view_->command_updater()->ExecuteCommand(command_id); 367 location_bar_view_->command_updater()->ExecuteCommand(command_id);
368 return; 368 return;
369 case IDS_MOVE_DOWN:
370 case IDS_MOVE_UP:
371 model()->OnUpOrDownKeyPressed(command_id == IDS_MOVE_DOWN ? 1 : -1);
372 return;
373 369
374 // These commands do invoke the popup. 370 // These commands do invoke the popup.
375 case IDS_APP_PASTE: 371 case IDS_APP_PASTE:
376 OnPaste(); 372 ExecuteEditCommand(IDS_APP_PASTE);
377 return; 373 return;
378 default: 374 default:
379 if (Textfield::IsCommandIdEnabled(command_id)) { 375 if (Textfield::IsCommandIdEnabled(command_id)) {
380 // The Textfield code will invoke OnBefore/AfterPossibleChange() itself 376 // The Textfield code will invoke OnBefore/AfterPossibleChange() itself
381 // as necessary. 377 // as necessary.
382 Textfield::ExecuteCommand(command_id, event_flags); 378 Textfield::ExecuteCommand(command_id, event_flags);
383 return; 379 return;
384 } 380 }
385 OnBeforePossibleChange(); 381 OnBeforePossibleChange();
386 location_bar_view_->command_updater()->ExecuteCommand(command_id); 382 location_bar_view_->command_updater()->ExecuteCommand(command_id);
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 case ui::VKEY_ESCAPE: 747 case ui::VKEY_ESCAPE:
752 return model()->OnEscapeKeyPressed(); 748 return model()->OnEscapeKeyPressed();
753 case ui::VKEY_CONTROL: 749 case ui::VKEY_CONTROL:
754 model()->OnControlKeyChanged(true); 750 model()->OnControlKeyChanged(true);
755 break; 751 break;
756 case ui::VKEY_DELETE: 752 case ui::VKEY_DELETE:
757 if (shift && model()->popup_model()->IsOpen()) 753 if (shift && model()->popup_model()->IsOpen())
758 model()->popup_model()->TryDeletingCurrentItem(); 754 model()->popup_model()->TryDeletingCurrentItem();
759 break; 755 break;
760 case ui::VKEY_UP: 756 case ui::VKEY_UP:
761 if (!read_only()) { 757 if (IsEditCommandEnabled(IDS_MOVE_UP)) {
762 model()->OnUpOrDownKeyPressed(-1); 758 ExecuteEditCommand(IDS_MOVE_UP);
763 return true; 759 return true;
764 } 760 }
765 break; 761 break;
766 case ui::VKEY_DOWN: 762 case ui::VKEY_DOWN:
767 if (!read_only()) { 763 if (IsEditCommandEnabled(IDS_MOVE_DOWN)) {
768 model()->OnUpOrDownKeyPressed(1); 764 ExecuteEditCommand(IDS_MOVE_DOWN);
769 return true; 765 return true;
770 } 766 }
771 break; 767 break;
772 case ui::VKEY_PRIOR: 768 case ui::VKEY_PRIOR:
773 if (control || alt || shift) 769 if (control || alt || shift)
774 return false; 770 return false;
775 model()->OnUpOrDownKeyPressed(-1 * model()->result().size()); 771 model()->OnUpOrDownKeyPressed(-1 * model()->result().size());
776 return true; 772 return true;
777 case ui::VKEY_NEXT: 773 case ui::VKEY_NEXT:
778 if (control || alt || shift) 774 if (control || alt || shift)
779 return false; 775 return false;
780 model()->OnUpOrDownKeyPressed(model()->result().size()); 776 model()->OnUpOrDownKeyPressed(model()->result().size());
781 return true; 777 return true;
782 case ui::VKEY_V: 778 case ui::VKEY_V:
783 if (control && !alt && !read_only()) { 779 if (control && !alt && IsEditCommandEnabled(IDS_APP_PASTE)) {
784 ExecuteCommand(IDS_APP_PASTE, 0); 780 ExecuteEditCommand(IDS_APP_PASTE);
785 return true; 781 return true;
786 } 782 }
787 break; 783 break;
788 case ui::VKEY_INSERT: 784 case ui::VKEY_INSERT:
789 if (shift && !control && !read_only()) { 785 if (shift && !control && IsEditCommandEnabled(IDS_APP_PASTE)) {
790 ExecuteCommand(IDS_APP_PASTE, 0); 786 ExecuteEditCommand(IDS_APP_PASTE);
791 return true; 787 return true;
792 } 788 }
793 break; 789 break;
794 default: 790 default:
795 break; 791 break;
796 } 792 }
797 793
798 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event); 794 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event);
799 } 795 }
800 796
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 location_bar_view_->SchedulePaint(); 897 location_bar_view_->SchedulePaint();
902 } 898 }
903 899
904 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { 900 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
905 if (command_id == IDS_APP_PASTE) 901 if (command_id == IDS_APP_PASTE)
906 return !read_only() && !GetClipboardText().empty(); 902 return !read_only() && !GetClipboardText().empty();
907 if (command_id == IDS_PASTE_AND_GO) 903 if (command_id == IDS_PASTE_AND_GO)
908 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); 904 return !read_only() && model()->CanPasteAndGo(GetClipboardText());
909 if (command_id == IDS_SHOW_URL) 905 if (command_id == IDS_SHOW_URL)
910 return controller()->GetToolbarModel()->WouldReplaceURL(); 906 return controller()->GetToolbarModel()->WouldReplaceURL();
911 return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP || 907 return Textfield::IsCommandIdEnabled(command_id) ||
912 Textfield::IsCommandIdEnabled(command_id) ||
913 location_bar_view_->command_updater()->IsCommandEnabled(command_id); 908 location_bar_view_->command_updater()->IsCommandEnabled(command_id);
914 } 909 }
915 910
916 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { 911 base::string16 OmniboxViewViews::GetSelectionClipboardText() const {
917 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); 912 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText());
918 } 913 }
919 914
920 void OmniboxViewViews::DoInsertChar(base::char16 ch) { 915 void OmniboxViewViews::DoInsertChar(base::char16 ch) {
921 // If |insert_char_time_| is not null, there's a pending insert char operation 916 // If |insert_char_time_| is not null, there's a pending insert char operation
922 // that hasn't been painted yet. Keep the earlier time. 917 // that hasn't been painted yet. Keep the earlier time.
923 if (insert_char_time_.is_null()) 918 if (insert_char_time_.is_null())
924 insert_char_time_ = base::TimeTicks::Now(); 919 insert_char_time_ = base::TimeTicks::Now();
925 Textfield::DoInsertChar(ch); 920 Textfield::DoInsertChar(ch);
926 } 921 }
927 922
923 bool OmniboxViewViews::IsEditCommandEnabled(int command_id) const {
924 switch (command_id) {
925 case IDS_MOVE_UP:
926 case IDS_MOVE_DOWN:
927 case IDS_APP_PASTE:
tapted 2016/06/06 07:42:27 Is Paste not handled by Textfield::IsCommandIdEnab
karandeepb 2016/06/08 03:06:57 Added the clipboard condition. Yeah it is. But Omn
928 return !read_only();
929 default:
930 return Textfield::IsEditCommandEnabled(command_id);
931 }
932 }
933
934 void OmniboxViewViews::ExecuteEditCommand(int command_id) {
935 if (!IsEditCommandEnabled(command_id))
tapted 2016/06/06 07:42:27 could this DCHECK? (if we can't we should probably
karandeepb 2016/06/08 03:06:57 A normal if condition looks safer to me. Why does
936 return;
937
938 // In the base class, touch text selection is deactivated when a command is
939 // executed. Since we are not always calling the base class implementation
940 // here, we need to deactivate touch text selection here, too.
941 DestroyTouchSelection();
942
943 switch (command_id) {
944 case IDS_MOVE_UP:
945 model()->OnUpOrDownKeyPressed(-1);
946 break;
947 case IDS_MOVE_DOWN:
948 model()->OnUpOrDownKeyPressed(1);
949 break;
950 case IDS_APP_PASTE:
951 OnPaste();
952 break;
953 default:
954 Textfield::ExecuteEditCommand(command_id);
955 break;
956 }
957 }
958
928 #if defined(OS_CHROMEOS) 959 #if defined(OS_CHROMEOS)
929 void OmniboxViewViews::CandidateWindowOpened( 960 void OmniboxViewViews::CandidateWindowOpened(
930 chromeos::input_method::InputMethodManager* manager) { 961 chromeos::input_method::InputMethodManager* manager) {
931 ime_candidate_window_open_ = true; 962 ime_candidate_window_open_ = true;
932 } 963 }
933 964
934 void OmniboxViewViews::CandidateWindowClosed( 965 void OmniboxViewViews::CandidateWindowClosed(
935 chromeos::input_method::InputMethodManager* manager) { 966 chromeos::input_method::InputMethodManager* manager) {
936 ime_candidate_window_open_ = false; 967 ime_candidate_window_open_ = false;
937 } 968 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 menu_contents->InsertItemWithStringIdAt( 1114 menu_contents->InsertItemWithStringIdAt(
1084 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); 1115 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL);
1085 } 1116 }
1086 1117
1087 // Minor note: We use IDC_ for command id here while the underlying textfield 1118 // Minor note: We use IDC_ for command id here while the underlying textfield
1088 // is using IDS_ for all its command ids. This is because views cannot depend 1119 // is using IDS_ for all its command ids. This is because views cannot depend
1089 // on IDC_ for now. 1120 // on IDC_ for now.
1090 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1121 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1091 IDS_EDIT_SEARCH_ENGINES); 1122 IDS_EDIT_SEARCH_ENGINES);
1092 } 1123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698