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

Unified Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

Issue 2641003002: Show scheme in black and content in gray for data: protocol urls (Closed)
Patch Set: Update iOS Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
index cd2b95faefb8470578fb8128da5b00a47359f88f..fcec1bcf3b456d1630b6a5ea0e95fe046816f57f 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
@@ -129,13 +129,6 @@ const OmniboxViewMacState* GetStateFromTab(const WebContents* tab) {
tab->GetUserData(&kOmniboxViewMacStateKey));
}
-// Helper to make converting url ranges to NSRange easier to
-// read.
-NSRange ComponentToNSRange(const url::Component& component) {
- return NSMakeRange(static_cast<NSInteger>(component.begin),
- static_cast<NSInteger>(component.len));
-}
-
} // namespace
// static
@@ -545,6 +538,47 @@ void OmniboxViewMac::ApplyTextStyle(
range:NSMakeRange(0, [attributedString length])];
}
+void OmniboxViewMac::SetEmphasis(bool emphasize, gfx::Range range) {
+ bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme];
+
+ NSRange ns_range = range.IsValid()
+ ? range.ToNSRange()
+ : NSMakeRange(0, [attributing_display_string_ length]);
+
+ [attributing_display_string_
+ addAttribute:NSForegroundColorAttributeName
+ value:(emphasize) ? HostTextColor(in_dark_mode)
+ : BaseTextColor(in_dark_mode)
+ range:ns_range];
+}
+
+void OmniboxViewMac::UpdateSchemeEmphasis(gfx::Range range) {
+ if (!range.IsValid())
+ return;
+
+ const security_state::SecurityLevel security_level =
+ controller()->GetToolbarModel()->GetSecurityLevel(false);
+
+ if ((security_level == security_state::NONE) ||
+ (security_level == security_state::HTTP_SHOW_WARNING))
+ return;
+
+ if (security_level == security_state::DANGEROUS) {
+ // Add a strikethrough through the scheme.
+ [attributing_display_string_
+ addAttribute:NSStrikethroughStyleAttributeName
+ value:[NSNumber numberWithInt:NSUnderlineStyleSingle]
+ range:range.ToNSRange()];
+ }
+
+ bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme];
+
+ [attributing_display_string_
+ addAttribute:NSForegroundColorAttributeName
+ value:GetSecureTextColor(security_level, in_dark_mode)
+ range:range.ToNSRange()];
+}
+
void OmniboxViewMac::ApplyTextAttributes(
const base::string16& display_text,
NSMutableAttributedString* attributedString) {
Robert Sesek 2017/03/01 18:29:45 nit: Since you're here, this should be attributed_
elawrence 2017/03/01 21:49:01 Done.
@@ -552,8 +586,6 @@ void OmniboxViewMac::ApplyTextAttributes(
if (as_length == 0) {
return;
}
- NSRange as_entire_string = NSMakeRange(0, as_length);
- bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme];
ApplyTextStyle(attributedString);
@@ -561,53 +593,13 @@ void OmniboxViewMac::ApplyTextAttributes(
// This works for IDNs too, despite the "en_US".
[attributedString addAttribute:@"NSLanguage"
value:@"en_US_POSIX"
- range:as_entire_string];
+ range:NSMakeRange(0, as_length)];
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:HostTextColor(in_dark_mode)
- range:as_entire_string];
-
- url::Component scheme, host;
- AutocompleteInput::ParseForEmphasizeComponents(
- display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme,
- &host);
- bool grey_out_url = display_text.substr(scheme.begin, scheme.len) ==
- base::UTF8ToUTF16(extensions::kExtensionScheme);
- if (model()->CurrentTextIsURL() &&
- (host.is_nonempty() || grey_out_url)) {
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:BaseTextColor(in_dark_mode)
- range:as_entire_string];
-
- if (!grey_out_url) {
- [attributedString addAttribute:NSForegroundColorAttributeName
- value:HostTextColor(in_dark_mode)
- range:ComponentToNSRange(host)];
- }
- }
-
- // TODO(shess): GTK has this as a member var, figure out why.
- // [Could it be to not change if no change? If so, I'm guessing
- // AppKit may already handle that.]
- const security_state::SecurityLevel security_level =
- controller()->GetToolbarModel()->GetSecurityLevel(false);
-
- // Emphasize the scheme for security UI display purposes (if necessary).
- if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() &&
- scheme.is_nonempty() &&
- (security_level != security_state::NONE) &&
- (security_level != security_state::HTTP_SHOW_WARNING)) {
- if (security_level == security_state::DANGEROUS) {
- // Add a strikethrough through the scheme.
- [attributedString addAttribute:NSStrikethroughStyleAttributeName
- value:[NSNumber numberWithInt:NSUnderlineStyleSingle]
- range:ComponentToNSRange(scheme)];
- }
- [attributedString
- addAttribute:NSForegroundColorAttributeName
- value:GetSecureTextColor(security_level, in_dark_mode)
- range:ComponentToNSRange(scheme)];
- }
+ // Cache a pointer to the attributed string to allow the superclass'
+ // virtual method invocations to add attributes.
+ attributing_display_string_ = attributedString;
Peter Kasting 2017/03/01 02:39:10 Nit: Consider using base::AutoReset here for safet
Robert Sesek 2017/03/01 18:29:45 Perhaps DCHECK that attributing_display_string_ is
elawrence 2017/03/01 21:49:01 Done.
elawrence 2017/03/01 21:49:01 Done.
+ ApplyEmphasis(display_text, ChromeAutocompleteSchemeClassifier(profile_));
+ attributing_display_string_ = nullptr;
}
void OmniboxViewMac::OnTemporaryTextMaybeChanged(

Powered by Google App Engine
This is Rietveld 408576698