| 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/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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 369 |
| 370 // These commands do invoke the popup. | 370 // These commands do invoke the popup. |
| 371 case IDS_APP_PASTE: | 371 case IDS_APP_PASTE: |
| 372 ExecuteEditCommand(IDS_APP_PASTE); | 372 ExecuteEditCommand(ui::TextEditCommand::PASTE); |
| 373 return; | 373 return; |
| 374 default: | 374 default: |
| 375 if (Textfield::IsCommandIdEnabled(command_id)) { | 375 if (Textfield::IsCommandIdEnabled(command_id)) { |
| 376 // The Textfield code will invoke OnBefore/AfterPossibleChange() itself | 376 // The Textfield code will invoke OnBefore/AfterPossibleChange() itself |
| 377 // as necessary. | 377 // as necessary. |
| 378 Textfield::ExecuteCommand(command_id, event_flags); | 378 Textfield::ExecuteCommand(command_id, event_flags); |
| 379 return; | 379 return; |
| 380 } | 380 } |
| 381 OnBeforePossibleChange(); | 381 OnBeforePossibleChange(); |
| 382 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 Loading... |
| 747 case ui::VKEY_ESCAPE: | 747 case ui::VKEY_ESCAPE: |
| 748 return model()->OnEscapeKeyPressed(); | 748 return model()->OnEscapeKeyPressed(); |
| 749 case ui::VKEY_CONTROL: | 749 case ui::VKEY_CONTROL: |
| 750 model()->OnControlKeyChanged(true); | 750 model()->OnControlKeyChanged(true); |
| 751 break; | 751 break; |
| 752 case ui::VKEY_DELETE: | 752 case ui::VKEY_DELETE: |
| 753 if (shift && model()->popup_model()->IsOpen()) | 753 if (shift && model()->popup_model()->IsOpen()) |
| 754 model()->popup_model()->TryDeletingCurrentItem(); | 754 model()->popup_model()->TryDeletingCurrentItem(); |
| 755 break; | 755 break; |
| 756 case ui::VKEY_UP: | 756 case ui::VKEY_UP: |
| 757 if (IsEditCommandEnabled(IDS_MOVE_UP)) { | 757 if (IsEditCommandEnabled(ui::TextEditCommand::MOVE_UP)) { |
| 758 ExecuteEditCommand(IDS_MOVE_UP); | 758 ExecuteEditCommand(ui::TextEditCommand::MOVE_UP); |
| 759 return true; | 759 return true; |
| 760 } | 760 } |
| 761 break; | 761 break; |
| 762 case ui::VKEY_DOWN: | 762 case ui::VKEY_DOWN: |
| 763 if (IsEditCommandEnabled(IDS_MOVE_DOWN)) { | 763 if (IsEditCommandEnabled(ui::TextEditCommand::MOVE_DOWN)) { |
| 764 ExecuteEditCommand(IDS_MOVE_DOWN); | 764 ExecuteEditCommand(ui::TextEditCommand::MOVE_DOWN); |
| 765 return true; | 765 return true; |
| 766 } | 766 } |
| 767 break; | 767 break; |
| 768 case ui::VKEY_PRIOR: | 768 case ui::VKEY_PRIOR: |
| 769 if (control || alt || shift) | 769 if (control || alt || shift) |
| 770 return false; | 770 return false; |
| 771 model()->OnUpOrDownKeyPressed(-1 * model()->result().size()); | 771 model()->OnUpOrDownKeyPressed(-1 * model()->result().size()); |
| 772 return true; | 772 return true; |
| 773 case ui::VKEY_NEXT: | 773 case ui::VKEY_NEXT: |
| 774 if (control || alt || shift) | 774 if (control || alt || shift) |
| 775 return false; | 775 return false; |
| 776 model()->OnUpOrDownKeyPressed(model()->result().size()); | 776 model()->OnUpOrDownKeyPressed(model()->result().size()); |
| 777 return true; | 777 return true; |
| 778 case ui::VKEY_V: | 778 case ui::VKEY_V: |
| 779 if (control && !alt && IsEditCommandEnabled(IDS_APP_PASTE)) { | 779 if (control && !alt && IsEditCommandEnabled(ui::TextEditCommand::PASTE)) { |
| 780 ExecuteEditCommand(IDS_APP_PASTE); | 780 ExecuteEditCommand(ui::TextEditCommand::PASTE); |
| 781 return true; | 781 return true; |
| 782 } | 782 } |
| 783 break; | 783 break; |
| 784 case ui::VKEY_INSERT: | 784 case ui::VKEY_INSERT: |
| 785 if (shift && !control && IsEditCommandEnabled(IDS_APP_PASTE)) { | 785 if (shift && !control && |
| 786 ExecuteEditCommand(IDS_APP_PASTE); | 786 IsEditCommandEnabled(ui::TextEditCommand::PASTE)) { |
| 787 ExecuteEditCommand(ui::TextEditCommand::PASTE); |
| 787 return true; | 788 return true; |
| 788 } | 789 } |
| 789 break; | 790 break; |
| 790 default: | 791 default: |
| 791 break; | 792 break; |
| 792 } | 793 } |
| 793 | 794 |
| 794 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event); | 795 return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event); |
| 795 } | 796 } |
| 796 | 797 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 } | 914 } |
| 914 | 915 |
| 915 void OmniboxViewViews::DoInsertChar(base::char16 ch) { | 916 void OmniboxViewViews::DoInsertChar(base::char16 ch) { |
| 916 // If |insert_char_time_| is not null, there's a pending insert char operation | 917 // If |insert_char_time_| is not null, there's a pending insert char operation |
| 917 // that hasn't been painted yet. Keep the earlier time. | 918 // that hasn't been painted yet. Keep the earlier time. |
| 918 if (insert_char_time_.is_null()) | 919 if (insert_char_time_.is_null()) |
| 919 insert_char_time_ = base::TimeTicks::Now(); | 920 insert_char_time_ = base::TimeTicks::Now(); |
| 920 Textfield::DoInsertChar(ch); | 921 Textfield::DoInsertChar(ch); |
| 921 } | 922 } |
| 922 | 923 |
| 923 bool OmniboxViewViews::IsEditCommandEnabled(int command_id) const { | 924 bool OmniboxViewViews::IsEditCommandEnabled(ui::TextEditCommand command) const { |
| 924 switch (command_id) { | 925 switch (command) { |
| 925 case IDS_MOVE_UP: | 926 case ui::TextEditCommand::MOVE_UP: |
| 926 case IDS_MOVE_DOWN: | 927 case ui::TextEditCommand::MOVE_DOWN: |
| 927 case IDS_APP_PASTE: | 928 case ui::TextEditCommand::PASTE: |
| 928 return !read_only(); | 929 return !read_only(); |
| 929 default: | 930 default: |
| 930 return Textfield::IsEditCommandEnabled(command_id); | 931 return Textfield::IsEditCommandEnabled(command); |
| 931 } | 932 } |
| 932 } | 933 } |
| 933 | 934 |
| 934 void OmniboxViewViews::ExecuteEditCommand(int command_id) { | 935 void OmniboxViewViews::ExecuteEditCommand(ui::TextEditCommand command) { |
| 935 if (!IsEditCommandEnabled(command_id)) | 936 if (!IsEditCommandEnabled(command)) |
| 936 return; | 937 return; |
| 937 | 938 |
| 938 // In the base class, touch text selection is deactivated when a command is | 939 // 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 // executed. Since we are not always calling the base class implementation |
| 940 // here, we need to deactivate touch text selection here, too. | 941 // here, we need to deactivate touch text selection here, too. |
| 941 DestroyTouchSelection(); | 942 DestroyTouchSelection(); |
| 942 | 943 |
| 943 switch (command_id) { | 944 switch (command) { |
| 944 case IDS_MOVE_UP: | 945 case ui::TextEditCommand::MOVE_UP: |
| 945 model()->OnUpOrDownKeyPressed(-1); | 946 model()->OnUpOrDownKeyPressed(-1); |
| 946 break; | 947 break; |
| 947 case IDS_MOVE_DOWN: | 948 case ui::TextEditCommand::MOVE_DOWN: |
| 948 model()->OnUpOrDownKeyPressed(1); | 949 model()->OnUpOrDownKeyPressed(1); |
| 949 break; | 950 break; |
| 950 case IDS_APP_PASTE: | 951 case ui::TextEditCommand::PASTE: |
| 951 OnPaste(); | 952 OnPaste(); |
| 952 break; | 953 break; |
| 953 default: | 954 default: |
| 954 Textfield::ExecuteEditCommand(command_id); | 955 Textfield::ExecuteEditCommand(command); |
| 955 break; | 956 break; |
| 956 } | 957 } |
| 957 } | 958 } |
| 958 | 959 |
| 959 #if defined(OS_CHROMEOS) | 960 #if defined(OS_CHROMEOS) |
| 960 void OmniboxViewViews::CandidateWindowOpened( | 961 void OmniboxViewViews::CandidateWindowOpened( |
| 961 chromeos::input_method::InputMethodManager* manager) { | 962 chromeos::input_method::InputMethodManager* manager) { |
| 962 ime_candidate_window_open_ = true; | 963 ime_candidate_window_open_ = true; |
| 963 } | 964 } |
| 964 | 965 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 menu_contents->InsertItemWithStringIdAt( | 1115 menu_contents->InsertItemWithStringIdAt( |
| 1115 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1116 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
| 1116 } | 1117 } |
| 1117 | 1118 |
| 1118 // Minor note: We use IDC_ for command id here while the underlying textfield | 1119 // Minor note: We use IDC_ for command id here while the underlying textfield |
| 1119 // is using IDS_ for all its command ids. This is because views cannot depend | 1120 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1120 // on IDC_ for now. | 1121 // on IDC_ for now. |
| 1121 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1122 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1122 IDS_EDIT_SEARCH_ENGINES); | 1123 IDS_EDIT_SEARCH_ENGINES); |
| 1123 } | 1124 } |
| OLD | NEW |