Chromium Code Reviews| 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 SkColor OmniboxViewMac::GetSecureTextColorSkia( | |
| 180 security_state::SecurityStateModel::SecurityLevel security_level, | |
| 181 bool in_dark_mode) { | |
| 182 return skia::NSDeviceColorToSkColor( | |
| 183 GetSecureTextColor(security_level, in_dark_mode)); | |
| 184 } | |
| 185 | |
| 186 // static | |
| 187 NSColor* OmniboxViewMac::GetSecureTextColor( | |
| 188 security_state::SecurityStateModel::SecurityLevel security_level, | |
| 189 bool in_dark_mode) { | |
| 190 NSColor* color; | |
| 191 if (security_level == security_state::SecurityStateModel::EV_SECURE || | |
| 192 security_level == security_state::SecurityStateModel::SECURE) { | |
| 193 color = SecureSchemeColor(in_dark_mode); | |
| 194 } else if (security_level == | |
| 195 security_state::SecurityStateModel::SECURITY_ERROR) { | |
| 196 color = SecurityErrorSchemeColor(in_dark_mode); | |
| 197 } else if (security_level == | |
| 198 security_state::SecurityStateModel::SECURITY_WARNING) { | |
| 199 color = SecurityWarningSchemeColor(in_dark_mode); | |
| 200 } else { | |
| 201 NOTREACHED(); | |
| 202 color = BaseTextColor(in_dark_mode); | |
|
Evan Stade
2016/05/19 17:58:49
I'm often told not to handle NOTREACHED
Peter Kasting
2016/05/19 18:36:19
Yeah. And in general looking at this makes it cle
palmer
2016/05/19 18:40:40
This is borrowed from the pre-existing code (compa
Peter Kasting
2016/05/19 18:43:21
Please do fix, here and/or there, as possible.
palmer
2016/05/19 19:55:44
Fixed here in Cocoa.
The Views code by estade/est
| |
| 203 } | |
| 204 return color; | |
| 205 } | |
| 206 | |
| 178 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, | 207 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, |
| 179 Profile* profile, | 208 Profile* profile, |
| 180 CommandUpdater* command_updater, | 209 CommandUpdater* command_updater, |
| 181 AutocompleteTextField* field) | 210 AutocompleteTextField* field) |
| 182 : OmniboxView( | 211 : OmniboxView( |
| 183 controller, | 212 controller, |
| 184 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), | 213 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), |
| 185 profile_(profile), | 214 profile_(profile), |
| 186 popup_view_(new OmniboxPopupViewMac(this, model(), field)), | 215 popup_view_(new OmniboxPopupViewMac(this, model(), field)), |
| 187 field_(field), | 216 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. | 620 // 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 | 621 // [Could it be to not change if no change? If so, I'm guessing |
| 593 // AppKit may already handle that.] | 622 // AppKit may already handle that.] |
| 594 const security_state::SecurityStateModel::SecurityLevel security_level = | 623 const security_state::SecurityStateModel::SecurityLevel security_level = |
| 595 controller()->GetToolbarModel()->GetSecurityLevel(false); | 624 controller()->GetToolbarModel()->GetSecurityLevel(false); |
| 596 | 625 |
| 597 // Emphasize the scheme for security UI display purposes (if necessary). | 626 // Emphasize the scheme for security UI display purposes (if necessary). |
| 598 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 627 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
| 599 scheme.is_nonempty() && | 628 scheme.is_nonempty() && |
| 600 (security_level != security_state::SecurityStateModel::NONE)) { | 629 (security_level != security_state::SecurityStateModel::NONE)) { |
| 601 NSColor* color; | 630 NSColor* color = GetSecureTextColor(security_level, in_dark_mode); |
|
Evan Stade
2016/05/19 17:58:49
no need for this local var
palmer
2016/05/19 18:40:40
Done.
| |
| 602 if (security_level == security_state::SecurityStateModel::EV_SECURE || | 631 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) { |
| 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. | 632 // Add a strikethrough through the scheme. |
| 609 [attributedString addAttribute:NSStrikethroughStyleAttributeName | 633 [attributedString addAttribute:NSStrikethroughStyleAttributeName |
| 610 value:[NSNumber numberWithInt:NSUnderlineStyleSingle] | 634 value:[NSNumber numberWithInt:NSUnderlineStyleSingle] |
| 611 range:ComponentToNSRange(scheme)]; | 635 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 } | 636 } |
| 619 [attributedString addAttribute:NSForegroundColorAttributeName | 637 [attributedString addAttribute:NSForegroundColorAttributeName |
| 620 value:color | 638 value:color |
| 621 range:ComponentToNSRange(scheme)]; | 639 range:ComponentToNSRange(scheme)]; |
| 622 } | 640 } |
| 623 } | 641 } |
| 624 | 642 |
| 625 void OmniboxViewMac::OnTemporaryTextMaybeChanged( | 643 void OmniboxViewMac::OnTemporaryTextMaybeChanged( |
| 626 const base::string16& display_text, | 644 const base::string16& display_text, |
| 627 bool save_original_selection, | 645 bool save_original_selection, |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 | 1151 |
| 1134 NSUInteger OmniboxViewMac::GetTextLength() const { | 1152 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1135 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1153 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1136 [[field_ stringValue] length]; | 1154 [[field_ stringValue] length]; |
| 1137 } | 1155 } |
| 1138 | 1156 |
| 1139 bool OmniboxViewMac::IsCaretAtEnd() const { | 1157 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1140 const NSRange selection = GetSelectedRange(); | 1158 const NSRange selection = GetSelectedRange(); |
| 1141 return NSMaxRange(selection) == GetTextLength(); | 1159 return NSMaxRange(selection) == GetTextLength(); |
| 1142 } | 1160 } |
| OLD | NEW |