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