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

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

Issue 2029733003: Views: Replace resource ids with ui::TextEditCommand enum for text editing commands in Textfield. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 24 matching lines...) Expand all
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "extensions/common/constants.h" 36 #include "extensions/common/constants.h"
37 #include "grit/components_strings.h" 37 #include "grit/components_strings.h"
38 #include "net/base/escape.h" 38 #include "net/base/escape.h"
39 #include "third_party/skia/include/core/SkColor.h" 39 #include "third_party/skia/include/core/SkColor.h"
40 #include "ui/accessibility/ax_view_state.h" 40 #include "ui/accessibility/ax_view_state.h"
41 #include "ui/base/clipboard/scoped_clipboard_writer.h" 41 #include "ui/base/clipboard/scoped_clipboard_writer.h"
42 #include "ui/base/dragdrop/drag_drop_types.h" 42 #include "ui/base/dragdrop/drag_drop_types.h"
43 #include "ui/base/dragdrop/os_exchange_data.h" 43 #include "ui/base/dragdrop/os_exchange_data.h"
44 #include "ui/base/ime/input_method.h" 44 #include "ui/base/ime/input_method.h"
45 #include "ui/base/ime/text_edit_commands.h"
45 #include "ui/base/ime/text_input_client.h" 46 #include "ui/base/ime/text_input_client.h"
46 #include "ui/base/ime/text_input_type.h" 47 #include "ui/base/ime/text_input_type.h"
47 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/base/material_design/material_design_controller.h" 49 #include "ui/base/material_design/material_design_controller.h"
49 #include "ui/base/models/simple_menu_model.h" 50 #include "ui/base/models/simple_menu_model.h"
50 #include "ui/compositor/layer.h" 51 #include "ui/compositor/layer.h"
51 #include "ui/events/event.h" 52 #include "ui/events/event.h"
52 #include "ui/gfx/canvas.h" 53 #include "ui/gfx/canvas.h"
53 #include "ui/gfx/font_list.h" 54 #include "ui/gfx/font_list.h"
54 #include "ui/gfx/selection_model.h" 55 #include "ui/gfx/selection_model.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). 359 // These commands don't invoke the popup via OnBefore/AfterPossibleChange().
359 case IDS_PASTE_AND_GO: 360 case IDS_PASTE_AND_GO:
360 model()->PasteAndGo(GetClipboardText()); 361 model()->PasteAndGo(GetClipboardText());
361 return; 362 return;
362 case IDS_SHOW_URL: 363 case IDS_SHOW_URL:
363 controller()->ShowURL(); 364 controller()->ShowURL();
364 return; 365 return;
365 case IDC_EDIT_SEARCH_ENGINES: 366 case IDC_EDIT_SEARCH_ENGINES:
366 location_bar_view_->command_updater()->ExecuteCommand(command_id); 367 location_bar_view_->command_updater()->ExecuteCommand(command_id);
367 return; 368 return;
368 case IDS_MOVE_DOWN:
369 case IDS_MOVE_UP:
370 model()->OnUpOrDownKeyPressed(command_id == IDS_MOVE_DOWN ? 1 : -1);
371 return;
372 369
373 // These commands do invoke the popup. 370 // These commands do invoke the popup.
374 case IDS_APP_PASTE: 371 case IDS_APP_PASTE:
375 OnPaste(); 372 ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
376 return; 373 return;
377 default: 374 default:
378 if (Textfield::IsCommandIdEnabled(command_id)) { 375 if (Textfield::IsCommandIdEnabled(command_id)) {
379 // The Textfield code will invoke OnBefore/AfterPossibleChange() itself 376 // The Textfield code will invoke OnBefore/AfterPossibleChange() itself
380 // as necessary. 377 // as necessary.
381 Textfield::ExecuteCommand(command_id, event_flags); 378 Textfield::ExecuteCommand(command_id, event_flags);
382 return; 379 return;
383 } 380 }
384 OnBeforePossibleChange(); 381 OnBeforePossibleChange();
385 location_bar_view_->command_updater()->ExecuteCommand(command_id); 382 location_bar_view_->command_updater()->ExecuteCommand(command_id);
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 case ui::VKEY_ESCAPE: 737 case ui::VKEY_ESCAPE:
741 return model()->OnEscapeKeyPressed(); 738 return model()->OnEscapeKeyPressed();
742 case ui::VKEY_CONTROL: 739 case ui::VKEY_CONTROL:
743 model()->OnControlKeyChanged(true); 740 model()->OnControlKeyChanged(true);
744 break; 741 break;
745 case ui::VKEY_DELETE: 742 case ui::VKEY_DELETE:
746 if (shift && model()->popup_model()->IsOpen()) 743 if (shift && model()->popup_model()->IsOpen())
747 model()->popup_model()->TryDeletingCurrentItem(); 744 model()->popup_model()->TryDeletingCurrentItem();
748 break; 745 break;
749 case ui::VKEY_UP: 746 case ui::VKEY_UP:
750 if (!read_only()) { 747 if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_UP)) {
751 model()->OnUpOrDownKeyPressed(-1); 748 ExecuteTextEditCommand(ui::TextEditCommand::MOVE_UP);
752 return true; 749 return true;
753 } 750 }
754 break; 751 break;
755 case ui::VKEY_DOWN: 752 case ui::VKEY_DOWN:
756 if (!read_only()) { 753 if (IsTextEditCommandEnabled(ui::TextEditCommand::MOVE_DOWN)) {
757 model()->OnUpOrDownKeyPressed(1); 754 ExecuteTextEditCommand(ui::TextEditCommand::MOVE_DOWN);
758 return true; 755 return true;
759 } 756 }
760 break; 757 break;
761 case ui::VKEY_PRIOR: 758 case ui::VKEY_PRIOR:
762 if (control || alt || shift) 759 if (control || alt || shift)
763 return false; 760 return false;
764 model()->OnUpOrDownKeyPressed(-1 * model()->result().size()); 761 model()->OnUpOrDownKeyPressed(-1 * model()->result().size());
765 return true; 762 return true;
766 case ui::VKEY_NEXT: 763 case ui::VKEY_NEXT:
767 if (control || alt || shift) 764 if (control || alt || shift)
768 return false; 765 return false;
769 model()->OnUpOrDownKeyPressed(model()->result().size()); 766 model()->OnUpOrDownKeyPressed(model()->result().size());
770 return true; 767 return true;
771 case ui::VKEY_V: 768 case ui::VKEY_V:
772 if (control && !alt && !read_only()) { 769 if (control && !alt &&
773 ExecuteCommand(IDS_APP_PASTE, 0); 770 IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
771 ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
774 return true; 772 return true;
775 } 773 }
776 break; 774 break;
777 case ui::VKEY_INSERT: 775 case ui::VKEY_INSERT:
778 if (shift && !control && !read_only()) { 776 if (shift && !control &&
779 ExecuteCommand(IDS_APP_PASTE, 0); 777 IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)) {
778 ExecuteTextEditCommand(ui::TextEditCommand::PASTE);
780 return true; 779 return true;
781 } 780 }
782 break; 781 break;
783 default: 782 default:
784 break; 783 break;
785 } 784 }
786 785
787 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event); 786 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event);
788 } 787 }
789 788
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 location_bar_view_->SchedulePaint(); 889 location_bar_view_->SchedulePaint();
891 } 890 }
892 891
893 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { 892 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
894 if (command_id == IDS_APP_PASTE) 893 if (command_id == IDS_APP_PASTE)
895 return !read_only() && !GetClipboardText().empty(); 894 return !read_only() && !GetClipboardText().empty();
896 if (command_id == IDS_PASTE_AND_GO) 895 if (command_id == IDS_PASTE_AND_GO)
897 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); 896 return !read_only() && model()->CanPasteAndGo(GetClipboardText());
898 if (command_id == IDS_SHOW_URL) 897 if (command_id == IDS_SHOW_URL)
899 return controller()->GetToolbarModel()->WouldReplaceURL(); 898 return controller()->GetToolbarModel()->WouldReplaceURL();
900 return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP || 899 return Textfield::IsCommandIdEnabled(command_id) ||
901 Textfield::IsCommandIdEnabled(command_id) ||
902 location_bar_view_->command_updater()->IsCommandEnabled(command_id); 900 location_bar_view_->command_updater()->IsCommandEnabled(command_id);
903 } 901 }
904 902
905 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { 903 base::string16 OmniboxViewViews::GetSelectionClipboardText() const {
906 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); 904 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText());
907 } 905 }
908 906
909 void OmniboxViewViews::DoInsertChar(base::char16 ch) { 907 void OmniboxViewViews::DoInsertChar(base::char16 ch) {
910 // If |insert_char_time_| is not null, there's a pending insert char operation 908 // If |insert_char_time_| is not null, there's a pending insert char operation
911 // that hasn't been painted yet. Keep the earlier time. 909 // that hasn't been painted yet. Keep the earlier time.
912 if (insert_char_time_.is_null()) 910 if (insert_char_time_.is_null())
913 insert_char_time_ = base::TimeTicks::Now(); 911 insert_char_time_ = base::TimeTicks::Now();
914 Textfield::DoInsertChar(ch); 912 Textfield::DoInsertChar(ch);
915 } 913 }
916 914
915 bool OmniboxViewViews::IsTextEditCommandEnabled(
916 ui::TextEditCommand command) const {
917 switch (command) {
918 case ui::TextEditCommand::MOVE_UP:
919 case ui::TextEditCommand::MOVE_DOWN:
920 return !read_only();
921 case ui::TextEditCommand::PASTE:
922 return !read_only() && !GetClipboardText().empty();
923 default:
924 return Textfield::IsTextEditCommandEnabled(command);
925 }
926 }
927
928 void OmniboxViewViews::ExecuteTextEditCommand(ui::TextEditCommand command) {
929 // In the base class, touch text selection is deactivated when a command is
930 // executed. Since we are not always calling the base class implementation
931 // here, we need to deactivate touch text selection here, too.
932 DestroyTouchSelection();
933
934 if (!IsTextEditCommandEnabled(command))
935 return;
936
937 switch (command) {
938 case ui::TextEditCommand::MOVE_UP:
939 model()->OnUpOrDownKeyPressed(-1);
940 break;
941 case ui::TextEditCommand::MOVE_DOWN:
942 model()->OnUpOrDownKeyPressed(1);
943 break;
944 case ui::TextEditCommand::PASTE:
945 OnPaste();
946 break;
947 default:
948 Textfield::ExecuteTextEditCommand(command);
949 break;
950 }
951 }
952
917 #if defined(OS_CHROMEOS) 953 #if defined(OS_CHROMEOS)
918 void OmniboxViewViews::CandidateWindowOpened( 954 void OmniboxViewViews::CandidateWindowOpened(
919 chromeos::input_method::InputMethodManager* manager) { 955 chromeos::input_method::InputMethodManager* manager) {
920 ime_candidate_window_open_ = true; 956 ime_candidate_window_open_ = true;
921 } 957 }
922 958
923 void OmniboxViewViews::CandidateWindowClosed( 959 void OmniboxViewViews::CandidateWindowClosed(
924 chromeos::input_method::InputMethodManager* manager) { 960 chromeos::input_method::InputMethodManager* manager) {
925 ime_candidate_window_open_ = false; 961 ime_candidate_window_open_ = false;
926 } 962 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 menu_contents->InsertItemWithStringIdAt( 1108 menu_contents->InsertItemWithStringIdAt(
1073 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); 1109 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL);
1074 } 1110 }
1075 1111
1076 // Minor note: We use IDC_ for command id here while the underlying textfield 1112 // Minor note: We use IDC_ for command id here while the underlying textfield
1077 // is using IDS_ for all its command ids. This is because views cannot depend 1113 // is using IDS_ for all its command ids. This is because views cannot depend
1078 // on IDC_ for now. 1114 // on IDC_ for now.
1079 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1115 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1080 IDS_EDIT_SEARCH_ENGINES); 1116 IDS_EDIT_SEARCH_ENGINES);
1081 } 1117 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | components/arc/ime/arc_ime_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698