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

Side by Side 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: Hoist deemphasis logic 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/cocoa/omnibox/omnibox_view_mac.h" 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
6 6
7 #include <Carbon/Carbon.h> // kVK_Return 7 #include <Carbon/Carbon.h> // kVK_Return
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; 556 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme];
557 557
558 ApplyTextStyle(attributedString); 558 ApplyTextStyle(attributedString);
559 559
560 // A kinda hacky way to add breaking at periods. This is what Safari does. 560 // A kinda hacky way to add breaking at periods. This is what Safari does.
561 // This works for IDNs too, despite the "en_US". 561 // This works for IDNs too, despite the "en_US".
562 [attributedString addAttribute:@"NSLanguage" 562 [attributedString addAttribute:@"NSLanguage"
563 value:@"en_US_POSIX" 563 value:@"en_US_POSIX"
564 range:as_entire_string]; 564 range:as_entire_string];
565 565
566 [attributedString addAttribute:NSForegroundColorAttributeName
567 value:HostTextColor(in_dark_mode)
568 range:as_entire_string];
569
570 url::Component scheme, host; 566 url::Component scheme, host;
571 AutocompleteInput::ParseForEmphasizeComponents( 567 AutocompleteInput::ParseForEmphasizeComponents(
572 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme, 568 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme,
573 &host); 569 &host);
574 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == 570
575 base::UTF8ToUTF16(extensions::kExtensionScheme); 571 const base::string16 url_scheme =
576 if (model()->CurrentTextIsURL() && 572 display_text.substr(scheme.begin, scheme.len);
577 (host.is_nonempty() || grey_out_url)) { 573
574 // Determine if any url components should be visually deemphasized.
575 DEEMPHASIZE_COMPONENTS deemphasize =
576 GetDeemphasis(url_scheme, host.is_nonempty());
577
578 [attributedString
579 addAttribute:NSForegroundColorAttributeName
580 value:(deemphasize == NOTHING) ? HostTextColor(in_dark_mode)
581 : BaseTextColor(in_dark_mode)
582 range:as_entire_string];
583
584 if (deemphasize == ALL_BUT_SCHEME) {
578 [attributedString addAttribute:NSForegroundColorAttributeName 585 [attributedString addAttribute:NSForegroundColorAttributeName
579 value:BaseTextColor(in_dark_mode) 586 value:HostTextColor(in_dark_mode)
580 range:as_entire_string]; 587 range:ComponentToNSRange(scheme)];
581 588 } else if (deemphasize == ALL_BUT_HOST) {
582 if (!grey_out_url) { 589 [attributedString addAttribute:NSForegroundColorAttributeName
583 [attributedString addAttribute:NSForegroundColorAttributeName 590 value:HostTextColor(in_dark_mode)
584 value:HostTextColor(in_dark_mode) 591 range:ComponentToNSRange(host)];
585 range:ComponentToNSRange(host)];
586 }
587 } 592 }
588 593
589 // TODO(shess): GTK has this as a member var, figure out why. 594 // TODO(shess): GTK has this as a member var, figure out why.
590 // [Could it be to not change if no change? If so, I'm guessing 595 // [Could it be to not change if no change? If so, I'm guessing
591 // AppKit may already handle that.] 596 // AppKit may already handle that.]
592 const security_state::SecurityLevel security_level = 597 const security_state::SecurityLevel security_level =
593 controller()->GetToolbarModel()->GetSecurityLevel(false); 598 controller()->GetToolbarModel()->GetSecurityLevel(false);
594 599
595 // Emphasize the scheme for security UI display purposes (if necessary). 600 // Emphasize the scheme for security UI display purposes (if necessary).
596 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && 601 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() &&
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 display_text); 1093 display_text);
1089 NSDictionary* notification_info = @{ 1094 NSDictionary* notification_info = @{
1090 NSAccessibilityAnnouncementKey : announcement, 1095 NSAccessibilityAnnouncementKey : announcement,
1091 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) 1096 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)
1092 }; 1097 };
1093 NSAccessibilityPostNotificationWithUserInfo( 1098 NSAccessibilityPostNotificationWithUserInfo(
1094 [field_ window], 1099 [field_ window],
1095 NSAccessibilityAnnouncementRequestedNotification, 1100 NSAccessibilityAnnouncementRequestedNotification,
1096 notification_info); 1101 notification_info);
1097 } 1102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698