| 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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 select_all_on_mouse_release_ = false; | 690 select_all_on_mouse_release_ = false; |
| 691 | 691 |
| 692 if (HasTextBeingDragged()) | 692 if (HasTextBeingDragged()) |
| 693 CloseOmniboxPopup(); | 693 CloseOmniboxPopup(); |
| 694 | 694 |
| 695 return views::Textfield::OnMouseDragged(event); | 695 return views::Textfield::OnMouseDragged(event); |
| 696 } | 696 } |
| 697 | 697 |
| 698 void OmniboxViewViews::OnMouseReleased(const ui::MouseEvent& event) { | 698 void OmniboxViewViews::OnMouseReleased(const ui::MouseEvent& event) { |
| 699 views::Textfield::OnMouseReleased(event); | 699 views::Textfield::OnMouseReleased(event); |
| 700 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) { | 700 // When the user has clicked and released to give us focus, select all. |
| 701 // When the user has clicked and released to give us focus, select all | 701 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && |
| 702 // unless we're omitting the URL (in which case refining an existing query | 702 select_all_on_mouse_release_) { |
| 703 // is common enough that we do click-to-place-cursor). | 703 // Select all in the reverse direction so as not to scroll the caret |
| 704 if (select_all_on_mouse_release_ && | 704 // into view and shift the contents jarringly. |
| 705 !controller()->GetToolbarModel()->WouldReplaceURL()) { | 705 SelectAll(true); |
| 706 // Select all in the reverse direction so as not to scroll the caret | |
| 707 // into view and shift the contents jarringly. | |
| 708 SelectAll(true); | |
| 709 } | |
| 710 } | 706 } |
| 711 select_all_on_mouse_release_ = false; | 707 select_all_on_mouse_release_ = false; |
| 712 } | 708 } |
| 713 | 709 |
| 714 bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) { | 710 bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) { |
| 715 // Skip processing of [Alt]+<num-pad digit> Unicode alt key codes. | 711 // 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. | 712 // Otherwise, if num-lock is off, the events are handled as [Up], [Down], etc. |
| 717 if (event.IsUnicodeKeyCode()) | 713 if (event.IsUnicodeKeyCode()) |
| 718 return views::Textfield::OnKeyPressed(event); | 714 return views::Textfield::OnKeyPressed(event); |
| 719 | 715 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 // The location bar needs to repaint without a focus ring. | 873 // The location bar needs to repaint without a focus ring. |
| 878 if (ui::MaterialDesignController::IsModeMaterial()) | 874 if (ui::MaterialDesignController::IsModeMaterial()) |
| 879 location_bar_view_->SchedulePaint(); | 875 location_bar_view_->SchedulePaint(); |
| 880 } | 876 } |
| 881 | 877 |
| 882 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { | 878 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { |
| 883 if (command_id == IDS_APP_PASTE) | 879 if (command_id == IDS_APP_PASTE) |
| 884 return !read_only() && !GetClipboardText().empty(); | 880 return !read_only() && !GetClipboardText().empty(); |
| 885 if (command_id == IDS_PASTE_AND_GO) | 881 if (command_id == IDS_PASTE_AND_GO) |
| 886 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); | 882 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); |
| 883 // TODO(treib): Completely remove IDS_SHOW_URL. crbug.com/627747 |
| 887 if (command_id == IDS_SHOW_URL) | 884 if (command_id == IDS_SHOW_URL) |
| 888 return controller()->GetToolbarModel()->WouldReplaceURL(); | 885 return false; |
| 889 return Textfield::IsCommandIdEnabled(command_id) || | 886 return Textfield::IsCommandIdEnabled(command_id) || |
| 890 location_bar_view_->command_updater()->IsCommandEnabled(command_id); | 887 location_bar_view_->command_updater()->IsCommandEnabled(command_id); |
| 891 } | 888 } |
| 892 | 889 |
| 893 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { | 890 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { |
| 894 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); | 891 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); |
| 895 } | 892 } |
| 896 | 893 |
| 897 void OmniboxViewViews::DoInsertChar(base::char16 ch) { | 894 void OmniboxViewViews::DoInsertChar(base::char16 ch) { |
| 898 // If |insert_char_time_| is not null, there's a pending insert char operation | 895 // If |insert_char_time_| is not null, there's a pending insert char operation |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 1090 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
| 1094 | 1091 |
| 1095 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1092 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
| 1096 | 1093 |
| 1097 // Minor note: We use IDC_ for command id here while the underlying textfield | 1094 // 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 | 1095 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1099 // on IDC_ for now. | 1096 // on IDC_ for now. |
| 1100 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1097 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1101 IDS_EDIT_SEARCH_ENGINES); | 1098 IDS_EDIT_SEARCH_ENGINES); |
| 1102 } | 1099 } |
| OLD | NEW |