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

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

Issue 731423002: Remove OriginChip code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gyp file and bad merge Created 5 years, 10 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
« no previous file with comments | « chrome/browser/ui/views/location_bar/origin_chip_view.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 15 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
16 #include "chrome/browser/command_updater.h" 16 #include "chrome/browser/command_updater.h"
17 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
18 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" 18 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
19 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" 19 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
20 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 20 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
21 #include "chrome/browser/ui/view_ids.h" 21 #include "chrome/browser/ui/view_ids.h"
22 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 22 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
23 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" 23 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
24 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h" 24 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h"
25 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h "
26 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
27 #include "components/bookmarks/browser/bookmark_node_data.h" 26 #include "components/bookmarks/browser/bookmark_node_data.h"
28 #include "components/omnibox/autocomplete_input.h" 27 #include "components/omnibox/autocomplete_input.h"
29 #include "components/omnibox/autocomplete_match.h" 28 #include "components/omnibox/autocomplete_match.h"
30 #include "components/omnibox/omnibox_field_trial.h" 29 #include "components/omnibox/omnibox_field_trial.h"
31 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
32 #include "extensions/common/constants.h" 31 #include "extensions/common/constants.h"
33 #include "net/base/escape.h" 32 #include "net/base/escape.h"
34 #include "third_party/skia/include/core/SkColor.h" 33 #include "third_party/skia/include/core/SkColor.h"
35 #include "ui/accessibility/ax_view_state.h" 34 #include "ui/accessibility/ax_view_state.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 221 }
223 222
224 void OmniboxViewViews::Update() { 223 void OmniboxViewViews::Update() {
225 UpdatePlaceholderText(); 224 UpdatePlaceholderText();
226 225
227 const ToolbarModel::SecurityLevel old_security_level = security_level_; 226 const ToolbarModel::SecurityLevel old_security_level = security_level_;
228 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false); 227 security_level_ = controller()->GetToolbarModel()->GetSecurityLevel(false);
229 if (model()->UpdatePermanentText()) { 228 if (model()->UpdatePermanentText()) {
230 // Something visibly changed. Re-enable URL replacement. 229 // Something visibly changed. Re-enable URL replacement.
231 controller()->GetToolbarModel()->set_url_replacement_enabled(true); 230 controller()->GetToolbarModel()->set_url_replacement_enabled(true);
232 controller()->GetToolbarModel()->set_origin_chip_enabled(true);
233 model()->UpdatePermanentText(); 231 model()->UpdatePermanentText();
234 232
235 // Select all the new text if the user had all the old text selected, or if 233 // Select all the new text if the user had all the old text selected, or if
236 // there was no previous text (for new tab page URL replacement extensions). 234 // there was no previous text (for new tab page URL replacement extensions).
237 // This makes one particular case better: the user clicks in the box to 235 // This makes one particular case better: the user clicks in the box to
238 // change it right before the permanent URL is changed. Since the new URL 236 // change it right before the permanent URL is changed. Since the new URL
239 // is still fully selected, the user's typing will replace the edit contents 237 // is still fully selected, the user's typing will replace the edit contents
240 // as they'd intended. 238 // as they'd intended.
241 const bool was_select_all = IsSelectAll(); 239 const bool was_select_all = IsSelectAll();
242 const bool was_reversed = GetSelectedRange().is_reversed(); 240 const bool was_reversed = GetSelectedRange().is_reversed();
243 241
244 RevertAll(); 242 RevertAll();
245 243
246 // Only select all when we have focus. If we don't have focus, selecting 244 // Only select all when we have focus. If we don't have focus, selecting
247 // all is unnecessary since the selection will change on regaining focus, 245 // all is unnecessary since the selection will change on regaining focus,
248 // and can in fact cause artifacts, e.g. if the user is on the NTP and 246 // and can in fact cause artifacts, e.g. if the user is on the NTP and
249 // clicks a link to navigate, causing |was_select_all| to be vacuously true 247 // clicks a link to navigate, causing |was_select_all| to be vacuously true
250 // for the empty omnibox, and we then select all here, leading to the 248 // for the empty omnibox, and we then select all here, leading to the
251 // trailing portion of a long URL being scrolled into view. We could try 249 // trailing portion of a long URL being scrolled into view. We could try
252 // and address cases like this, but it seems better to just not muck with 250 // and address cases like this, but it seems better to just not muck with
253 // things when the omnibox isn't focused to begin with. 251 // things when the omnibox isn't focused to begin with.
254 if (was_select_all && model()->has_focus()) 252 if (was_select_all && model()->has_focus())
255 SelectAll(was_reversed); 253 SelectAll(was_reversed);
256 } else if (old_security_level != security_level_) { 254 } else if (old_security_level != security_level_) {
257 EmphasizeURLComponents(); 255 EmphasizeURLComponents();
258 } 256 }
259 } 257 }
260 258
261 void OmniboxViewViews::UpdatePlaceholderText() { 259 void OmniboxViewViews::UpdatePlaceholderText() {
262 if (chrome::ShouldDisplayOriginChip() || 260 if (OmniboxFieldTrial::DisplayHintTextWhenPossible())
263 OmniboxFieldTrial::DisplayHintTextWhenPossible())
264 set_placeholder_text(GetHintText()); 261 set_placeholder_text(GetHintText());
265 } 262 }
266 263
267 base::string16 OmniboxViewViews::GetText() const { 264 base::string16 OmniboxViewViews::GetText() const {
268 // TODO(oshima): IME support 265 // TODO(oshima): IME support
269 return text(); 266 return text();
270 } 267 }
271 268
272 void OmniboxViewViews::SetUserText(const base::string16& text, 269 void OmniboxViewViews::SetUserText(const base::string16& text,
273 const base::string16& display_text, 270 const base::string16& display_text,
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) { 682 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) {
686 // When the user has clicked and released to give us focus, select all 683 // When the user has clicked and released to give us focus, select all
687 // unless we're omitting the URL (in which case refining an existing query 684 // unless we're omitting the URL (in which case refining an existing query
688 // is common enough that we do click-to-place-cursor). 685 // is common enough that we do click-to-place-cursor).
689 if (select_all_on_mouse_release_ && 686 if (select_all_on_mouse_release_ &&
690 !controller()->GetToolbarModel()->WouldReplaceURL()) { 687 !controller()->GetToolbarModel()->WouldReplaceURL()) {
691 // Select all in the reverse direction so as not to scroll the caret 688 // Select all in the reverse direction so as not to scroll the caret
692 // into view and shift the contents jarringly. 689 // into view and shift the contents jarringly.
693 SelectAll(true); 690 SelectAll(true);
694 } 691 }
695
696 HandleOriginChipMouseRelease();
697 } 692 }
698 select_all_on_mouse_release_ = false; 693 select_all_on_mouse_release_ = false;
699 } 694 }
700 695
701 bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) { 696 bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
702 // Skip processing of [Alt]+<num-pad digit> Unicode alt key codes. 697 // Skip processing of [Alt]+<num-pad digit> Unicode alt key codes.
703 // Otherwise, if num-lock is off, the events are handled as [Up], [Down], etc. 698 // Otherwise, if num-lock is off, the events are handled as [Up], [Down], etc.
704 if (event.IsUnicodeKeyCode()) 699 if (event.IsUnicodeKeyCode())
705 return views::Textfield::OnKeyPressed(event); 700 return views::Textfield::OnKeyPressed(event);
706 701
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 event->type() == ui::ET_GESTURE_SCROLL_BEGIN || 776 event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
782 event->type() == ui::ET_GESTURE_PINCH_BEGIN || 777 event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
783 event->type() == ui::ET_GESTURE_LONG_PRESS || 778 event->type() == ui::ET_GESTURE_LONG_PRESS ||
784 event->type() == ui::ET_GESTURE_LONG_TAP) { 779 event->type() == ui::ET_GESTURE_LONG_TAP) {
785 select_all_on_gesture_tap_ = false; 780 select_all_on_gesture_tap_ = false;
786 } 781 }
787 } 782 }
788 783
789 void OmniboxViewViews::AboutToRequestFocusFromTabTraversal(bool reverse) { 784 void OmniboxViewViews::AboutToRequestFocusFromTabTraversal(bool reverse) {
790 views::Textfield::AboutToRequestFocusFromTabTraversal(reverse); 785 views::Textfield::AboutToRequestFocusFromTabTraversal(reverse);
791 // Tabbing into the omnibox should affect the origin chip in the same way
792 // clicking it should.
793 HandleOriginChipMouseRelease();
794 } 786 }
795 787
796 bool OmniboxViewViews::SkipDefaultKeyEventProcessing( 788 bool OmniboxViewViews::SkipDefaultKeyEventProcessing(
797 const ui::KeyEvent& event) { 789 const ui::KeyEvent& event) {
798 if (views::FocusManager::IsTabTraversalKeyEvent(event) && 790 if (views::FocusManager::IsTabTraversalKeyEvent(event) &&
799 ((model()->is_keyword_hint() && !event.IsShiftDown()) || 791 ((model()->is_keyword_hint() && !event.IsShiftDown()) ||
800 model()->popup_model()->IsOpen())) { 792 model()->popup_model()->IsOpen())) {
801 return true; 793 return true;
802 } 794 }
803 return Textfield::SkipDefaultKeyEventProcessing(event); 795 return Textfield::SkipDefaultKeyEventProcessing(event);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 // Save the user's existing selection to restore it later. 832 // Save the user's existing selection to restore it later.
841 saved_selection_for_focus_change_ = GetSelectedRange(); 833 saved_selection_for_focus_change_ = GetSelectedRange();
842 834
843 views::Textfield::OnBlur(); 835 views::Textfield::OnBlur();
844 model()->OnWillKillFocus(); 836 model()->OnWillKillFocus();
845 CloseOmniboxPopup(); 837 CloseOmniboxPopup();
846 838
847 // Tell the model to reset itself. 839 // Tell the model to reset itself.
848 model()->OnKillFocus(); 840 model()->OnKillFocus();
849 841
850 // Ignore loss of focus if we lost focus because the website settings popup
851 // is open. When the popup is destroyed, focus will return to the Omnibox.
852 if (!WebsiteSettingsPopupView::IsPopupShowing())
853 OnDidKillFocus();
854
855 // Make sure the beginning of the text is visible. 842 // Make sure the beginning of the text is visible.
856 SelectRange(gfx::Range(0)); 843 SelectRange(gfx::Range(0));
857 } 844 }
858 845
859 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { 846 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
860 if (command_id == IDS_APP_PASTE) 847 if (command_id == IDS_APP_PASTE)
861 return !read_only() && !GetClipboardText().empty(); 848 return !read_only() && !GetClipboardText().empty();
862 if (command_id == IDS_PASTE_AND_GO) 849 if (command_id == IDS_PASTE_AND_GO)
863 return !read_only() && model()->CanPasteAndGo(GetClipboardText()); 850 return !read_only() && model()->CanPasteAndGo(GetClipboardText());
864 if (command_id == IDS_SHOW_URL) 851 if (command_id == IDS_SHOW_URL)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1003 }
1017 1004
1018 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { 1005 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) {
1019 int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); 1006 int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE);
1020 DCHECK_GE(paste_position, 0); 1007 DCHECK_GE(paste_position, 0);
1021 menu_contents->InsertItemWithStringIdAt( 1008 menu_contents->InsertItemWithStringIdAt(
1022 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1009 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1023 1010
1024 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1011 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1025 1012
1026 if (chrome::IsQueryExtractionEnabled() || chrome::ShouldDisplayOriginChip()) { 1013 if (chrome::IsQueryExtractionEnabled()) {
1027 int select_all_position = menu_contents->GetIndexOfCommandId( 1014 int select_all_position = menu_contents->GetIndexOfCommandId(
1028 IDS_APP_SELECT_ALL); 1015 IDS_APP_SELECT_ALL);
1029 DCHECK_GE(select_all_position, 0); 1016 DCHECK_GE(select_all_position, 0);
1030 menu_contents->InsertItemWithStringIdAt( 1017 menu_contents->InsertItemWithStringIdAt(
1031 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); 1018 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL);
1032 } 1019 }
1033 1020
1034 // Minor note: We use IDC_ for command id here while the underlying textfield 1021 // Minor note: We use IDC_ for command id here while the underlying textfield
1035 // is using IDS_ for all its command ids. This is because views cannot depend 1022 // is using IDS_ for all its command ids. This is because views cannot depend
1036 // on IDC_ for now. 1023 // on IDC_ for now.
1037 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1024 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1038 IDS_EDIT_SEARCH_ENGINES); 1025 IDS_EDIT_SEARCH_ENGINES);
1039 } 1026 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/origin_chip_view.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698