| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "app/mac/nsimage_cache.h" | 9 #include "app/mac/nsimage_cache.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 ApplyTextAttributes(GetText(), storage); | 525 ApplyTextAttributes(GetText(), storage); |
| 526 | 526 |
| 527 [storage endEditing]; | 527 [storage endEditing]; |
| 528 } else { | 528 } else { |
| 529 SetText(GetText()); | 529 SetText(GetText()); |
| 530 } | 530 } |
| 531 } | 531 } |
| 532 | 532 |
| 533 void OmniboxViewMac::ApplyTextAttributes(const string16& display_text, | 533 void OmniboxViewMac::ApplyTextAttributes(const string16& display_text, |
| 534 NSMutableAttributedString* as) { | 534 NSMutableAttributedString* as) { |
| 535 NSUInteger as_length = [as length]; |
| 536 NSRange as_entire_string = NSMakeRange(0, as_length); |
| 537 |
| 535 [as addAttribute:NSFontAttributeName value:GetFieldFont() | 538 [as addAttribute:NSFontAttributeName value:GetFieldFont() |
| 536 range:NSMakeRange(0, [as length])]; | 539 range:as_entire_string]; |
| 540 |
| 541 // A kinda hacky way to add breaking at periods. This is what Safari does. |
| 542 // This works for IDNs too, despite the "en_US". |
| 543 [as addAttribute:@"NSLanguage" value:@"en_US_POSIX" |
| 544 range:as_entire_string]; |
| 537 | 545 |
| 538 // Make a paragraph style locking in the standard line height as the maximum, | 546 // Make a paragraph style locking in the standard line height as the maximum, |
| 539 // otherwise the baseline may shift "downwards". | 547 // otherwise the baseline may shift "downwards". |
| 540 scoped_nsobject<NSMutableParagraphStyle> | 548 scoped_nsobject<NSMutableParagraphStyle> |
| 541 paragraph_style([[NSMutableParagraphStyle alloc] init]); | 549 paragraph_style([[NSMutableParagraphStyle alloc] init]); |
| 542 [paragraph_style setMaximumLineHeight:line_height_]; | 550 [paragraph_style setMaximumLineHeight:line_height_]; |
| 543 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style | 551 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style |
| 544 range:NSMakeRange(0, [as length])]; | 552 range:as_entire_string]; |
| 545 | 553 |
| 546 // Grey out the suggest text. | 554 // Grey out the suggest text. |
| 547 [as addAttribute:NSForegroundColorAttributeName value:SuggestTextColor() | 555 [as addAttribute:NSForegroundColorAttributeName value:SuggestTextColor() |
| 548 range:NSMakeRange([as length] - suggest_text_length_, | 556 range:NSMakeRange(as_length - suggest_text_length_, |
| 549 suggest_text_length_)]; | 557 suggest_text_length_)]; |
| 550 | 558 |
| 551 url_parse::Component scheme, host; | 559 url_parse::Component scheme, host; |
| 552 AutocompleteInput::ParseForEmphasizeComponents( | 560 AutocompleteInput::ParseForEmphasizeComponents( |
| 553 display_text, model_->GetDesiredTLD(), &scheme, &host); | 561 display_text, model_->GetDesiredTLD(), &scheme, &host); |
| 554 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); | 562 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); |
| 555 if (emphasize) { | 563 if (emphasize) { |
| 556 [as addAttribute:NSForegroundColorAttributeName value:BaseTextColor() | 564 [as addAttribute:NSForegroundColorAttributeName value:BaseTextColor() |
| 557 range:NSMakeRange(0, [as length])]; | 565 range:as_entire_string]; |
| 558 | 566 |
| 559 [as addAttribute:NSForegroundColorAttributeName value:HostTextColor() | 567 [as addAttribute:NSForegroundColorAttributeName value:HostTextColor() |
| 560 range:ComponentToNSRange(host)]; | 568 range:ComponentToNSRange(host)]; |
| 561 } | 569 } |
| 562 | 570 |
| 563 // TODO(shess): GTK has this as a member var, figure out why. | 571 // TODO(shess): GTK has this as a member var, figure out why. |
| 564 // [Could it be to not change if no change? If so, I'm guessing | 572 // [Could it be to not change if no change? If so, I'm guessing |
| 565 // AppKit may already handle that.] | 573 // AppKit may already handle that.] |
| 566 const ToolbarModel::SecurityLevel security_level = | 574 const ToolbarModel::SecurityLevel security_level = |
| 567 toolbar_model_->GetSecurityLevel(); | 575 toolbar_model_->GetSecurityLevel(); |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 | 1115 |
| 1108 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { | 1116 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { |
| 1109 DCHECK(pos <= GetTextLength()); | 1117 DCHECK(pos <= GetTextLength()); |
| 1110 SetSelectedRange(NSMakeRange(pos, pos)); | 1118 SetSelectedRange(NSMakeRange(pos, pos)); |
| 1111 } | 1119 } |
| 1112 | 1120 |
| 1113 bool OmniboxViewMac::IsCaretAtEnd() const { | 1121 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1114 const NSRange selection = GetSelectedRange(); | 1122 const NSRange selection = GetSelectedRange(); |
| 1115 return selection.length == 0 && selection.location == GetTextLength(); | 1123 return selection.length == 0 && selection.location == GetTextLength(); |
| 1116 } | 1124 } |
| OLD | NEW |