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

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

Issue 2641003002: Show scheme in black and content in gray for data: protocol urls (Closed)
Patch Set: Update iOS Created 3 years, 9 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 13 matching lines...) Expand all
24 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
25 #include "components/omnibox/browser/autocomplete_input.h" 25 #include "components/omnibox/browser/autocomplete_input.h"
26 #include "components/omnibox/browser/autocomplete_match.h" 26 #include "components/omnibox/browser/autocomplete_match.h"
27 #include "components/omnibox/browser/omnibox_edit_controller.h" 27 #include "components/omnibox/browser/omnibox_edit_controller.h"
28 #include "components/omnibox/browser/omnibox_edit_model.h" 28 #include "components/omnibox/browser/omnibox_edit_model.h"
29 #include "components/omnibox/browser/omnibox_field_trial.h" 29 #include "components/omnibox/browser/omnibox_field_trial.h"
30 #include "components/omnibox/browser/omnibox_popup_model.h" 30 #include "components/omnibox/browser/omnibox_popup_model.h"
31 #include "components/strings/grit/components_strings.h" 31 #include "components/strings/grit/components_strings.h"
32 #include "components/toolbar/toolbar_model.h" 32 #include "components/toolbar/toolbar_model.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "extensions/common/constants.h"
35 #include "net/base/escape.h" 34 #include "net/base/escape.h"
36 #include "third_party/skia/include/core/SkColor.h" 35 #include "third_party/skia/include/core/SkColor.h"
37 #include "ui/accessibility/ax_action_data.h" 36 #include "ui/accessibility/ax_action_data.h"
38 #include "ui/accessibility/ax_node_data.h" 37 #include "ui/accessibility/ax_node_data.h"
39 #include "ui/base/clipboard/scoped_clipboard_writer.h" 38 #include "ui/base/clipboard/scoped_clipboard_writer.h"
40 #include "ui/base/dragdrop/drag_drop_types.h" 39 #include "ui/base/dragdrop/drag_drop_types.h"
41 #include "ui/base/dragdrop/os_exchange_data.h" 40 #include "ui/base/dragdrop/os_exchange_data.h"
42 #include "ui/base/ime/input_method.h" 41 #include "ui/base/ime/input_method.h"
43 #include "ui/base/ime/text_edit_commands.h" 42 #include "ui/base/ime/text_edit_commands.h"
44 #include "ui/base/ime/text_input_client.h" 43 #include "ui/base/ime/text_input_client.h"
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 556 }
558 557
559 void OmniboxViewViews::OnMatchOpened(AutocompleteMatch::Type match_type) { 558 void OmniboxViewViews::OnMatchOpened(AutocompleteMatch::Type match_type) {
560 } 559 }
561 560
562 int OmniboxViewViews::GetOmniboxTextLength() const { 561 int OmniboxViewViews::GetOmniboxTextLength() const {
563 // TODO(oshima): Support IME. 562 // TODO(oshima): Support IME.
564 return static_cast<int>(text().length()); 563 return static_cast<int>(text().length());
565 } 564 }
566 565
566 void OmniboxViewViews::SetEmphasis(bool emphasize, gfx::Range range) {
567 SkColor color = location_bar_view_->GetColor(
568 emphasize ? LocationBarView::TEXT : LocationBarView::DEEMPHASIZED_TEXT);
569 if (range.IsValid())
570 ApplyColor(color, range);
571 else
572 SetColor(color);
573 }
574
575 void OmniboxViewViews::UpdateSchemeEmphasis(gfx::Range range) {
576 SetStyle(gfx::DIAGONAL_STRIKE, false);
577 if (range.IsValid()) {
578 const SkColor security_color =
579 location_bar_view_->GetSecureTextColor(security_level_);
580 const bool strike = (security_level_ == security_state::DANGEROUS);
Peter Kasting 2017/03/01 02:39:10 Nit: () unnecessary
elawrence 2017/03/01 21:49:01 Done.
581 ApplyColor(security_color, range);
582 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, range);
583 }
584 }
585
567 void OmniboxViewViews::EmphasizeURLComponents() { 586 void OmniboxViewViews::EmphasizeURLComponents() {
568 if (!location_bar_view_) 587 if (!location_bar_view_)
569 return; 588 return;
570 589
571 // If the current contents is a URL, force left-to-right rendering at the 590 // If the current contents is a URL, force left-to-right rendering at the
572 // paragraph level. Right-to-left runs are still rendered RTL, but will not 591 // paragraph level. Right-to-left runs are still rendered RTL, but will not
573 // flip the whole URL around. For example (if "ABC" is Hebrew), this will 592 // flip the whole URL around. For example (if "ABC" is Hebrew), this will
574 // render "ABC.com" as "CBA.com", rather than "com.CBA". 593 // render "ABC.com" as "CBA.com", rather than "com.CBA".
575 bool text_is_url = model()->CurrentTextIsURL(); 594 bool text_is_url = model()->CurrentTextIsURL();
576 GetRenderText()->SetDirectionalityMode(text_is_url 595 GetRenderText()->SetDirectionalityMode(text_is_url
577 ? gfx::DIRECTIONALITY_FORCE_LTR 596 ? gfx::DIRECTIONALITY_FORCE_LTR
578 : gfx::DIRECTIONALITY_FROM_TEXT); 597 : gfx::DIRECTIONALITY_FROM_TEXT);
579 598
580 // See whether the contents are a URL with a non-empty host portion, which we 599 ApplyEmphasis(text(), ChromeAutocompleteSchemeClassifier(profile_));
581 // should emphasize. To check for a URL, rather than using the type returned
582 // by Parse(), ask the model, which will check the desired page transition for
583 // this input. This can tell us whether an UNKNOWN input string is going to
584 // be treated as a search or a navigation, and is the same method the Paste
585 // And Go system uses.
586 url::Component scheme, host;
587 AutocompleteInput::ParseForEmphasizeComponents(
588 text(), ChromeAutocompleteSchemeClassifier(profile_), &scheme, &host);
589 bool grey_out_url = text().substr(scheme.begin, scheme.len) ==
590 base::UTF8ToUTF16(extensions::kExtensionScheme);
591 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url);
592 SetColor(location_bar_view_->GetColor(
593 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
594 if (grey_base && !grey_out_url) {
595 ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT),
596 gfx::Range(host.begin, host.end()));
597 }
598
599 // Emphasize the scheme for security UI display purposes (if necessary).
600 // Note that we check CurrentTextIsURL() because if we're replacing search
601 // URLs with search terms, we may have a non-URL even when the user is not
602 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser
603 // may have incorrectly identified a qualifier as a scheme.
604 SetStyle(gfx::DIAGONAL_STRIKE, false);
605 if (!model()->user_input_in_progress() && text_is_url &&
606 scheme.is_nonempty() && (security_level_ != security_state::NONE)) {
607 SkColor security_color =
608 location_bar_view_->GetSecureTextColor(security_level_);
609 const bool strike = (security_level_ == security_state::DANGEROUS);
610 const gfx::Range scheme_range(scheme.begin, scheme.end());
611 ApplyColor(security_color, scheme_range);
612 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range);
613 }
614 } 600 }
615 601
616 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { 602 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const {
617 return command_id == IDS_PASTE_AND_GO; 603 return command_id == IDS_PASTE_AND_GO;
618 } 604 }
619 605
620 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { 606 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const {
621 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); 607 DCHECK_EQ(IDS_PASTE_AND_GO, command_id);
622 return l10n_util::GetStringUTF16( 608 return l10n_util::GetStringUTF16(
623 model()->IsPasteAndSearch(GetClipboardText()) ? 609 model()->IsPasteAndSearch(GetClipboardText()) ?
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1051 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1066 1052
1067 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1053 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1068 1054
1069 // Minor note: We use IDC_ for command id here while the underlying textfield 1055 // Minor note: We use IDC_ for command id here while the underlying textfield
1070 // is using IDS_ for all its command ids. This is because views cannot depend 1056 // is using IDS_ for all its command ids. This is because views cannot depend
1071 // on IDC_ for now. 1057 // on IDC_ for now.
1072 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1058 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1073 IDS_EDIT_SEARCH_ENGINES); 1059 IDS_EDIT_SEARCH_ENGINES);
1074 } 1060 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698