| OLD | NEW |
| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Mac does (I believe their fields lose focus when the window loses | 73 // Mac does (I believe their fields lose focus when the window loses |
| 74 // focus). Rather than modifying focus outside the control's edit | 74 // focus). Rather than modifying focus outside the control's edit |
| 75 // scope, when the window resigns key the autocomplete popup is | 75 // scope, when the window resigns key the autocomplete popup is |
| 76 // closed. model() still believes it has focus, and the popup will | 76 // closed. model() still believes it has focus, and the popup will |
| 77 // be regenerated on the user's next edit. That seems to match how | 77 // be regenerated on the user's next edit. That seems to match how |
| 78 // things work on other platforms. | 78 // things work on other platforms. |
| 79 | 79 |
| 80 namespace { | 80 namespace { |
| 81 const int kOmniboxLargeFontSizeDelta = 9; | 81 const int kOmniboxLargeFontSizeDelta = 9; |
| 82 const int kOmniboxNormalFontSizeDelta = 1; | 82 const int kOmniboxNormalFontSizeDelta = 1; |
| 83 const int kOmniboxSmallFontSizeDelta = 0; | |
| 84 const int kOmniboxSmallMaterialFontSizeDelta = -1; | 83 const int kOmniboxSmallMaterialFontSizeDelta = -1; |
| 85 | 84 |
| 86 // TODO(shess): This is ugly, find a better way. Using it right now | 85 // TODO(shess): This is ugly, find a better way. Using it right now |
| 87 // so that I can crib from gtk and still be able to see that I'm using | 86 // so that I can crib from gtk and still be able to see that I'm using |
| 88 // the same values easily. | 87 // the same values easily. |
| 89 NSColor* ColorWithRGBBytes(int rr, int gg, int bb) { | 88 NSColor* ColorWithRGBBytes(int rr, int gg, int bb) { |
| 90 DCHECK_LE(rr, 255); | 89 DCHECK_LE(rr, 255); |
| 91 DCHECK_LE(bb, 255); | 90 DCHECK_LE(bb, 255); |
| 92 DCHECK_LE(gg, 255); | 91 DCHECK_LE(gg, 255); |
| 93 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0 | 92 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0 |
| 94 green:static_cast<float>(gg)/255.0 | 93 green:static_cast<float>(gg)/255.0 |
| 95 blue:static_cast<float>(bb)/255.0 | 94 blue:static_cast<float>(bb)/255.0 |
| 96 alpha:1.0]; | 95 alpha:1.0]; |
| 97 } | 96 } |
| 98 | 97 |
| 99 NSColor* HostTextColor(bool in_dark_mode) { | 98 NSColor* HostTextColor(bool in_dark_mode) { |
| 100 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 101 return [NSColor blackColor]; | |
| 102 } | |
| 103 return in_dark_mode ? [NSColor whiteColor] : [NSColor blackColor]; | 99 return in_dark_mode ? [NSColor whiteColor] : [NSColor blackColor]; |
| 104 } | 100 } |
| 105 NSColor* SecureSchemeColor(bool in_dark_mode) { | 101 NSColor* SecureSchemeColor(bool in_dark_mode) { |
| 106 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 107 return ColorWithRGBBytes(0x07, 0x95, 0x00); | |
| 108 } | |
| 109 return in_dark_mode ? skia::SkColorToSRGBNSColor(SK_ColorWHITE) | 102 return in_dark_mode ? skia::SkColorToSRGBNSColor(SK_ColorWHITE) |
| 110 : skia::SkColorToSRGBNSColor(gfx::kGoogleGreen700); | 103 : skia::SkColorToSRGBNSColor(gfx::kGoogleGreen700); |
| 111 } | 104 } |
| 112 NSColor* SecurityWarningSchemeColor(bool in_dark_mode) { | 105 NSColor* SecurityWarningSchemeColor(bool in_dark_mode) { |
| 113 return in_dark_mode | 106 return in_dark_mode |
| 114 ? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F)) | 107 ? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F)) |
| 115 : skia::SkColorToSRGBNSColor(gfx::kGoogleYellow700); | 108 : skia::SkColorToSRGBNSColor(gfx::kGoogleYellow700); |
| 116 } | 109 } |
| 117 NSColor* SecurityErrorSchemeColor(bool in_dark_mode) { | 110 NSColor* SecurityErrorSchemeColor(bool in_dark_mode) { |
| 118 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 119 return ColorWithRGBBytes(0xa2, 0x00, 0x00); | |
| 120 } | |
| 121 return in_dark_mode | 111 return in_dark_mode |
| 122 ? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F)) | 112 ? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F)) |
| 123 : skia::SkColorToSRGBNSColor(gfx::kGoogleRed700); | 113 : skia::SkColorToSRGBNSColor(gfx::kGoogleRed700); |
| 124 } | 114 } |
| 125 | 115 |
| 126 const char kOmniboxViewMacStateKey[] = "OmniboxViewMacState"; | 116 const char kOmniboxViewMacStateKey[] = "OmniboxViewMacState"; |
| 127 | 117 |
| 128 // Store's the model and view state across tab switches. | 118 // Store's the model and view state across tab switches. |
| 129 struct OmniboxViewMacState : public base::SupportsUserData::Data { | 119 struct OmniboxViewMacState : public base::SupportsUserData::Data { |
| 130 OmniboxViewMacState(const OmniboxEditModel::State model_state, | 120 OmniboxViewMacState(const OmniboxEditModel::State model_state, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 163 } |
| 174 | 164 |
| 175 //static | 165 //static |
| 176 SkColor OmniboxViewMac::BaseTextColorSkia(bool in_dark_mode) { | 166 SkColor OmniboxViewMac::BaseTextColorSkia(bool in_dark_mode) { |
| 177 return in_dark_mode ? SkColorSetA(SK_ColorWHITE, 0x7F) | 167 return in_dark_mode ? SkColorSetA(SK_ColorWHITE, 0x7F) |
| 178 : SkColorSetA(SK_ColorBLACK, 0x7F); | 168 : SkColorSetA(SK_ColorBLACK, 0x7F); |
| 179 } | 169 } |
| 180 | 170 |
| 181 // static | 171 // static |
| 182 NSColor* OmniboxViewMac::BaseTextColor(bool in_dark_mode) { | 172 NSColor* OmniboxViewMac::BaseTextColor(bool in_dark_mode) { |
| 183 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 184 return [NSColor darkGrayColor]; | |
| 185 } | |
| 186 return skia::SkColorToSRGBNSColor(BaseTextColorSkia(in_dark_mode)); | 173 return skia::SkColorToSRGBNSColor(BaseTextColorSkia(in_dark_mode)); |
| 187 } | 174 } |
| 188 | 175 |
| 189 // static | 176 // static |
| 190 NSColor* OmniboxViewMac::GetSecureTextColor( | 177 NSColor* OmniboxViewMac::GetSecureTextColor( |
| 191 security_state::SecurityStateModel::SecurityLevel security_level, | 178 security_state::SecurityStateModel::SecurityLevel security_level, |
| 192 bool in_dark_mode) { | 179 bool in_dark_mode) { |
| 193 if (security_level == security_state::SecurityStateModel::EV_SECURE || | 180 if (security_level == security_state::SecurityStateModel::EV_SECURE || |
| 194 security_level == security_state::SecurityStateModel::SECURE) { | 181 security_level == security_state::SecurityStateModel::SECURE) { |
| 195 return SecureSchemeColor(in_dark_mode); | 182 return SecureSchemeColor(in_dark_mode); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; | 565 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 579 | 566 |
| 580 ApplyTextStyle(attributedString); | 567 ApplyTextStyle(attributedString); |
| 581 | 568 |
| 582 // A kinda hacky way to add breaking at periods. This is what Safari does. | 569 // A kinda hacky way to add breaking at periods. This is what Safari does. |
| 583 // This works for IDNs too, despite the "en_US". | 570 // This works for IDNs too, despite the "en_US". |
| 584 [attributedString addAttribute:@"NSLanguage" | 571 [attributedString addAttribute:@"NSLanguage" |
| 585 value:@"en_US_POSIX" | 572 value:@"en_US_POSIX" |
| 586 range:as_entire_string]; | 573 range:as_entire_string]; |
| 587 | 574 |
| 588 if (ui::MaterialDesignController::IsModeMaterial()) { | 575 [attributedString addAttribute:NSForegroundColorAttributeName |
| 589 [attributedString addAttribute:NSForegroundColorAttributeName | 576 value:HostTextColor(in_dark_mode) |
| 590 value:HostTextColor(in_dark_mode) | 577 range:as_entire_string]; |
| 591 range:as_entire_string]; | |
| 592 } | |
| 593 | 578 |
| 594 url::Component scheme, host; | 579 url::Component scheme, host; |
| 595 AutocompleteInput::ParseForEmphasizeComponents( | 580 AutocompleteInput::ParseForEmphasizeComponents( |
| 596 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme, | 581 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme, |
| 597 &host); | 582 &host); |
| 598 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == | 583 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == |
| 599 base::UTF8ToUTF16(extensions::kExtensionScheme); | 584 base::UTF8ToUTF16(extensions::kExtensionScheme); |
| 600 if (model()->CurrentTextIsURL() && | 585 if (model()->CurrentTextIsURL() && |
| 601 (host.is_nonempty() || grey_out_url)) { | 586 (host.is_nonempty() || grey_out_url)) { |
| 602 [attributedString addAttribute:NSForegroundColorAttributeName | 587 [attributedString addAttribute:NSForegroundColorAttributeName |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 | 1078 |
| 1094 NSFont* OmniboxViewMac::GetLargeFont() { | 1079 NSFont* OmniboxViewMac::GetLargeFont() { |
| 1095 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1080 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1096 return rb | 1081 return rb |
| 1097 .GetFontWithDelta(kOmniboxLargeFontSizeDelta, gfx::Font::NORMAL, | 1082 .GetFontWithDelta(kOmniboxLargeFontSizeDelta, gfx::Font::NORMAL, |
| 1098 gfx::Font::Weight::NORMAL) | 1083 gfx::Font::Weight::NORMAL) |
| 1099 .GetNativeFont(); | 1084 .GetNativeFont(); |
| 1100 } | 1085 } |
| 1101 | 1086 |
| 1102 NSFont* OmniboxViewMac::GetSmallFont() { | 1087 NSFont* OmniboxViewMac::GetSmallFont() { |
| 1103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1088 return ui::ResourceBundle::GetSharedInstance() |
| 1104 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 1105 return rb | |
| 1106 .GetFontWithDelta(kOmniboxSmallFontSizeDelta, gfx::Font::NORMAL, | |
| 1107 gfx::Font::Weight::NORMAL) | |
| 1108 .GetNativeFont(); | |
| 1109 } | |
| 1110 | |
| 1111 return rb | |
| 1112 .GetFontWithDelta(kOmniboxSmallMaterialFontSizeDelta, gfx::Font::NORMAL, | 1089 .GetFontWithDelta(kOmniboxSmallMaterialFontSizeDelta, gfx::Font::NORMAL, |
| 1113 gfx::Font::Weight::NORMAL) | 1090 gfx::Font::Weight::NORMAL) |
| 1114 .GetNativeFont(); | 1091 .GetNativeFont(); |
| 1115 } | 1092 } |
| 1116 | 1093 |
| 1117 int OmniboxViewMac::GetOmniboxTextLength() const { | 1094 int OmniboxViewMac::GetOmniboxTextLength() const { |
| 1118 return static_cast<int>(GetTextLength()); | 1095 return static_cast<int>(GetTextLength()); |
| 1119 } | 1096 } |
| 1120 | 1097 |
| 1121 NSUInteger OmniboxViewMac::GetTextLength() const { | 1098 NSUInteger OmniboxViewMac::GetTextLength() const { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1135 display_text); | 1112 display_text); |
| 1136 NSDictionary* notification_info = @{ | 1113 NSDictionary* notification_info = @{ |
| 1137 NSAccessibilityAnnouncementKey : announcement, | 1114 NSAccessibilityAnnouncementKey : announcement, |
| 1138 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) | 1115 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) |
| 1139 }; | 1116 }; |
| 1140 NSAccessibilityPostNotificationWithUserInfo( | 1117 NSAccessibilityPostNotificationWithUserInfo( |
| 1141 [field_ window], | 1118 [field_ window], |
| 1142 NSAccessibilityAnnouncementRequestedNotification, | 1119 NSAccessibilityAnnouncementRequestedNotification, |
| 1143 notification_info); | 1120 notification_info); |
| 1144 } | 1121 } |
| OLD | NEW |