| 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; | 539 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 540 [attributedString addAttribute:NSParagraphStyleAttributeName | 540 [attributedString addAttribute:NSParagraphStyleAttributeName |
| 541 value:paragraph_style | 541 value:paragraph_style |
| 542 range:NSMakeRange(0, [attributedString length])]; | 542 range:NSMakeRange(0, [attributedString length])]; |
| 543 } | 543 } |
| 544 | 544 |
| 545 void OmniboxViewMac::ApplyTextAttributes( | 545 void OmniboxViewMac::ApplyTextAttributes( |
| 546 const base::string16& display_text, | 546 const base::string16& display_text, |
| 547 NSMutableAttributedString* attributedString) { | 547 NSMutableAttributedString* attributedString) { |
| 548 NSUInteger as_length = [attributedString length]; | 548 NSUInteger as_length = [attributedString length]; |
| 549 if (as_length == 0) { |
| 550 return; |
| 551 } |
| 549 NSRange as_entire_string = NSMakeRange(0, as_length); | 552 NSRange as_entire_string = NSMakeRange(0, as_length); |
| 550 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; | 553 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
| 551 | 554 |
| 552 ApplyTextStyle(attributedString); | 555 ApplyTextStyle(attributedString); |
| 553 | 556 |
| 554 // A kinda hacky way to add breaking at periods. This is what Safari does. | 557 // A kinda hacky way to add breaking at periods. This is what Safari does. |
| 555 // This works for IDNs too, despite the "en_US". | 558 // This works for IDNs too, despite the "en_US". |
| 556 [attributedString addAttribute:@"NSLanguage" | 559 [attributedString addAttribute:@"NSLanguage" |
| 557 value:@"en_US_POSIX" | 560 value:@"en_US_POSIX" |
| 558 range:as_entire_string]; | 561 range:as_entire_string]; |
| 559 | 562 |
| 563 // Under Material Design, force the text to be a single color white editing. |
| 564 if (ui::MaterialDesignController::IsModeMaterial() && |
| 565 [field_ currentEditor]) { |
| 566 [attributedString addAttribute:NSForegroundColorAttributeName |
| 567 value:HostTextColor(in_dark_mode) |
| 568 range:as_entire_string]; |
| 569 return; |
| 570 } |
| 571 |
| 560 url::Component scheme, host; | 572 url::Component scheme, host; |
| 561 AutocompleteInput::ParseForEmphasizeComponents( | 573 AutocompleteInput::ParseForEmphasizeComponents( |
| 562 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme, | 574 display_text, ChromeAutocompleteSchemeClassifier(profile_), &scheme, |
| 563 &host); | 575 &host); |
| 564 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == | 576 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == |
| 565 base::UTF8ToUTF16(extensions::kExtensionScheme); | 577 base::UTF8ToUTF16(extensions::kExtensionScheme); |
| 566 if (model()->CurrentTextIsURL() && | 578 if (model()->CurrentTextIsURL() && |
| 567 (host.is_nonempty() || grey_out_url)) { | 579 (host.is_nonempty() || grey_out_url)) { |
| 568 [attributedString addAttribute:NSForegroundColorAttributeName | 580 [attributedString addAttribute:NSForegroundColorAttributeName |
| 569 value:BaseTextColor(in_dark_mode) | 581 value:BaseTextColor(in_dark_mode) |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 | 1133 |
| 1122 NSUInteger OmniboxViewMac::GetTextLength() const { | 1134 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1123 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1135 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1124 [[field_ stringValue] length]; | 1136 [[field_ stringValue] length]; |
| 1125 } | 1137 } |
| 1126 | 1138 |
| 1127 bool OmniboxViewMac::IsCaretAtEnd() const { | 1139 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1128 const NSRange selection = GetSelectedRange(); | 1140 const NSRange selection = GetSelectedRange(); |
| 1129 return NSMaxRange(selection) == GetTextLength(); | 1141 return NSMaxRange(selection) == GetTextLength(); |
| 1130 } | 1142 } |
| OLD | NEW |