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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 168 } |
169 | 169 |
170 // static | 170 // static |
171 NSColor* OmniboxViewMac::BaseTextColor(bool in_dark_mode) { | 171 NSColor* OmniboxViewMac::BaseTextColor(bool in_dark_mode) { |
172 if (!ui::MaterialDesignController::IsModeMaterial()) { | 172 if (!ui::MaterialDesignController::IsModeMaterial()) { |
173 return [NSColor darkGrayColor]; | 173 return [NSColor darkGrayColor]; |
174 } | 174 } |
175 return skia::SkColorToCalibratedNSColor(BaseTextColorSkia(in_dark_mode)); | 175 return skia::SkColorToCalibratedNSColor(BaseTextColorSkia(in_dark_mode)); |
176 } | 176 } |
177 | 177 |
| 178 // static |
| 179 NSColor* OmniboxViewMac::GetSecureTextColor( |
| 180 security_state::SecurityStateModel::SecurityLevel security_level, |
| 181 bool in_dark_mode) { |
| 182 if (security_level == security_state::SecurityStateModel::EV_SECURE || |
| 183 security_level == security_state::SecurityStateModel::SECURE) { |
| 184 return SecureSchemeColor(in_dark_mode); |
| 185 } |
| 186 |
| 187 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) |
| 188 return SecurityErrorSchemeColor(in_dark_mode); |
| 189 |
| 190 DCHECK_EQ(security_state::SecurityStateModel::SECURITY_WARNING, |
| 191 security_level); |
| 192 return SecurityWarningSchemeColor(in_dark_mode); |
| 193 } |
| 194 |
178 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, | 195 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, |
179 Profile* profile, | 196 Profile* profile, |
180 CommandUpdater* command_updater, | 197 CommandUpdater* command_updater, |
181 AutocompleteTextField* field) | 198 AutocompleteTextField* field) |
182 : OmniboxView( | 199 : OmniboxView( |
183 controller, | 200 controller, |
184 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), | 201 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), |
185 profile_(profile), | 202 profile_(profile), |
186 popup_view_(new OmniboxPopupViewMac(this, model(), field)), | 203 popup_view_(new OmniboxPopupViewMac(this, model(), field)), |
187 field_(field), | 204 field_(field), |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 // TODO(shess): GTK has this as a member var, figure out why. | 608 // TODO(shess): GTK has this as a member var, figure out why. |
592 // [Could it be to not change if no change? If so, I'm guessing | 609 // [Could it be to not change if no change? If so, I'm guessing |
593 // AppKit may already handle that.] | 610 // AppKit may already handle that.] |
594 const security_state::SecurityStateModel::SecurityLevel security_level = | 611 const security_state::SecurityStateModel::SecurityLevel security_level = |
595 controller()->GetToolbarModel()->GetSecurityLevel(false); | 612 controller()->GetToolbarModel()->GetSecurityLevel(false); |
596 | 613 |
597 // Emphasize the scheme for security UI display purposes (if necessary). | 614 // Emphasize the scheme for security UI display purposes (if necessary). |
598 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 615 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
599 scheme.is_nonempty() && | 616 scheme.is_nonempty() && |
600 (security_level != security_state::SecurityStateModel::NONE)) { | 617 (security_level != security_state::SecurityStateModel::NONE)) { |
601 NSColor* color; | 618 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) { |
602 if (security_level == security_state::SecurityStateModel::EV_SECURE || | |
603 security_level == security_state::SecurityStateModel::SECURE) { | |
604 color = SecureSchemeColor(in_dark_mode); | |
605 } else if (security_level == | |
606 security_state::SecurityStateModel::SECURITY_ERROR) { | |
607 color = SecurityErrorSchemeColor(in_dark_mode); | |
608 // Add a strikethrough through the scheme. | 619 // Add a strikethrough through the scheme. |
609 [attributedString addAttribute:NSStrikethroughStyleAttributeName | 620 [attributedString addAttribute:NSStrikethroughStyleAttributeName |
610 value:[NSNumber numberWithInt:NSUnderlineStyleSingle] | 621 value:[NSNumber numberWithInt:NSUnderlineStyleSingle] |
611 range:ComponentToNSRange(scheme)]; | 622 range:ComponentToNSRange(scheme)]; |
612 } else if (security_level == | |
613 security_state::SecurityStateModel::SECURITY_WARNING) { | |
614 color = SecurityWarningSchemeColor(in_dark_mode); | |
615 } else { | |
616 NOTREACHED(); | |
617 color = BaseTextColor(in_dark_mode); | |
618 } | 623 } |
619 [attributedString addAttribute:NSForegroundColorAttributeName | 624 [attributedString |
620 value:color | 625 addAttribute:NSForegroundColorAttributeName |
621 range:ComponentToNSRange(scheme)]; | 626 value:GetSecureTextColor(security_level, in_dark_mode) |
| 627 range:ComponentToNSRange(scheme)]; |
622 } | 628 } |
623 } | 629 } |
624 | 630 |
625 void OmniboxViewMac::OnTemporaryTextMaybeChanged( | 631 void OmniboxViewMac::OnTemporaryTextMaybeChanged( |
626 const base::string16& display_text, | 632 const base::string16& display_text, |
627 bool save_original_selection, | 633 bool save_original_selection, |
628 bool notify_text_changed) { | 634 bool notify_text_changed) { |
629 if (save_original_selection) | 635 if (save_original_selection) |
630 saved_temporary_selection_ = GetSelectedRange(); | 636 saved_temporary_selection_ = GetSelectedRange(); |
631 | 637 |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1139 |
1134 NSUInteger OmniboxViewMac::GetTextLength() const { | 1140 NSUInteger OmniboxViewMac::GetTextLength() const { |
1135 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1141 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
1136 [[field_ stringValue] length]; | 1142 [[field_ stringValue] length]; |
1137 } | 1143 } |
1138 | 1144 |
1139 bool OmniboxViewMac::IsCaretAtEnd() const { | 1145 bool OmniboxViewMac::IsCaretAtEnd() const { |
1140 const NSRange selection = GetSelectedRange(); | 1146 const NSRange selection = GetSelectedRange(); |
1141 return NSMaxRange(selection) == GetTextLength(); | 1147 return NSMaxRange(selection) == GetTextLength(); |
1142 } | 1148 } |
OLD | NEW |