Chromium Code Reviews| Index: ios/chrome/browser/ui/omnibox/omnibox_view_ios.mm |
| diff --git a/ios/chrome/browser/ui/omnibox/omnibox_view_ios.mm b/ios/chrome/browser/ui/omnibox/omnibox_view_ios.mm |
| index 47bf4aebde093f33a43e9ae01a3fd16b7527d748..425bb826672ef608c90c1ff2c36758c676acb96e 100644 |
| --- a/ios/chrome/browser/ui/omnibox/omnibox_view_ios.mm |
| +++ b/ios/chrome/browser/ui/omnibox/omnibox_view_ios.mm |
| @@ -50,11 +50,6 @@ UIColor* ErrorTextColor() { |
| return skia::UIColorFromSkColor(gfx::kGoogleRed700); |
| } |
| -// The color of the https when there is a warning. |
| -UIColor* WarningTextColor() { |
| - return skia::UIColorFromSkColor(gfx::kGoogleYellow700); |
| -} |
| - |
| // The color of the https when there is not an error. |
| UIColor* SecureTextColor() { |
| return skia::UIColorFromSkColor(gfx::kGoogleGreen700); |
| @@ -65,13 +60,6 @@ UIColor* IncognitoSecureTextColor() { |
| return [UIColor colorWithWhite:(255 / 255.0) alpha:1.0]; |
| } |
| -// Helper to make converting url_parse 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 |
| // Simple Obj-C object to forward UITextFieldDelegate method calls back to the |
| @@ -634,61 +622,73 @@ void OmniboxViewIOS::WillPaste() { |
| model()->OnPaste(); |
| } |
| +// static |
| +UIColor* OmniboxViewIOS::GetSecureTextColor( |
| + security_state::SecurityLevel security_level, |
| + bool in_dark_mode) { |
| + if (security_level == security_state::EV_SECURE || |
| + security_level == security_state::SECURE) { |
| + return in_dark_mode ? IncognitoSecureTextColor() : SecureTextColor(); |
| + } |
| + |
| + // Don't color strikethrough in dark mode. See https://crbug.com/635004#c6 |
| + if (security_level == security_state::DANGEROUS && !in_dark_mode) |
| + return ErrorTextColor(); |
| + |
| + return nil; |
| +} |
| + |
| +void OmniboxViewIOS::SetEmphasis(bool emphasize, gfx::Range range) { |
| + NSRange ns_range = range.IsValid() |
| + ? range.ToNSRange() |
| + : NSMakeRange(0, [attributing_display_string_ length]); |
| + |
| + [attributing_display_string_ |
| + addAttribute:NSForegroundColorAttributeName |
| + value:(emphasize) ? [field_ displayedTextColor] : BaseTextColor() |
| + range:ns_range]; |
| +} |
| + |
| +void OmniboxViewIOS::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)) |
|
Eugene But (OOO till 7-30)
2017/02/28 23:04:38
nit: Do you want to add braces, because if stateme
elawrence
2017/03/01 21:49:02
Ok. I didn't see a style guide opinion on this one
Eugene But (OOO till 7-30)
2017/03/01 22:31:19
C++ Style Guide is quite vague on this: "In genera
Peter Kasting
2017/03/01 23:18:47
Read "statement" as specifically "loop body" in th
|
| + return; |
| + |
| + DCHECK(security_level != security_state::SECURITY_WARNING); |
|
Peter Kasting
2017/03/01 02:39:11
Nit: DCHECK_NE(security_state::SECURITY_WARNING, s
elawrence
2017/03/01 21:49:02
Done.
|
| + DCHECK(security_level != security_state::SECURE_WITH_POLICY_INSTALLED_CERT); |
| + |
| + if (security_level == security_state::DANGEROUS) { |
| + // Add a strikethrough through the scheme. |
| + [attributing_display_string_ |
| + addAttribute:NSStrikethroughStyleAttributeName |
| + value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] |
| + range:range.ToNSRange()]; |
| + } |
| + |
| + UIColor* color = GetSecureTextColor(security_level, [field_ incognito]); |
| + if (color) { |
| + [attributing_display_string_ addAttribute:NSForegroundColorAttributeName |
| + value:color |
| + range:range.ToNSRange()]; |
| + } |
| +} |
| + |
| NSAttributedString* OmniboxViewIOS::ApplyTextAttributes( |
| const base::string16& text) { |
| NSMutableAttributedString* as = [[[NSMutableAttributedString alloc] |
| initWithString:base::SysUTF16ToNSString(text)] autorelease]; |
| - url::Component scheme, host; |
| - AutocompleteInput::ParseForEmphasizeComponents( |
| - text, AutocompleteSchemeClassifierImpl(), &scheme, &host); |
| - const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); |
| - if (emphasize) { |
| - [as addAttribute:NSForegroundColorAttributeName |
| - value:BaseTextColor() |
| - range:NSMakeRange(0, [as length])]; |
| - |
| - [as addAttribute:NSForegroundColorAttributeName |
| - value:[field_ displayedTextColor] |
| - range:ComponentToNSRange(host)]; |
| - |
| - if (scheme.len > 0) { |
| - UIColor* color = nil; |
| - switch (controller_->GetToolbarModel()->GetSecurityLevel(false)) { |
| - case security_state::NONE: |
| - break; |
| - case security_state::SECURITY_WARNING: |
| - // Don't color strikethrough schemes. See https://crbug.com/635004#c6 |
| - if (![field_ incognito]) |
| - color = WarningTextColor(); |
| - [as addAttribute:NSStrikethroughStyleAttributeName |
| - value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] |
| - range:ComponentToNSRange(scheme)]; |
| - break; |
| - case security_state::SECURE: |
| - case security_state::EV_SECURE: |
| - color = [field_ incognito] ? IncognitoSecureTextColor() |
| - : SecureTextColor(); |
| - break; |
| - case security_state::DANGEROUS: |
| - // Don't color strikethrough schemes. See https://crbug.com/635004#c6 |
| - if (![field_ incognito]) |
| - color = ErrorTextColor(); |
| - [as addAttribute:NSStrikethroughStyleAttributeName |
| - value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] |
| - range:ComponentToNSRange(scheme)]; |
| - break; |
| - case security_state::HTTP_SHOW_WARNING: |
| - case security_state::SECURE_WITH_POLICY_INSTALLED_CERT: |
| - NOTREACHED(); |
| - } |
| - if (color) { |
| - [as addAttribute:NSForegroundColorAttributeName |
| - value:color |
| - range:ComponentToNSRange(scheme)]; |
| - } |
| - } |
| - } |
| + // Cache a pointer to the attributed string to allow the superclass' |
| + // virtual method invocations to add attributes. |
| + attributing_display_string_ = as; |
|
Peter Kasting
2017/03/01 02:39:11
Nit: See Mac comment
elawrence
2017/03/01 21:49:02
Done.
|
| + ApplyEmphasis(text, AutocompleteSchemeClassifierImpl()); |
| + attributing_display_string_ = nullptr; |
| return as; |
| } |