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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 [as addAttribute:NSFontAttributeName value:GetFieldFont() | 535 [as addAttribute:NSFontAttributeName value:GetFieldFont() |
536 range:NSMakeRange(0, [as length])]; | 536 range:NSMakeRange(0, [as length])]; |
537 | 537 |
538 // A kinda hacky way to add breaking at periods. This is what Safari does. | |
539 // This works for IDNs too, despite the "en_US". | |
540 [as addAttribute:@"NSLanguage" value:@"en_US_POSIX" | |
541 range:NSMakeRange(0, [as length])]; | |
Mark Mentovai
2011/06/09 14:23:05
Optional: consider computing NSMakeRange(0, [as le
| |
542 | |
538 // Make a paragraph style locking in the standard line height as the maximum, | 543 // Make a paragraph style locking in the standard line height as the maximum, |
539 // otherwise the baseline may shift "downwards". | 544 // otherwise the baseline may shift "downwards". |
540 scoped_nsobject<NSMutableParagraphStyle> | 545 scoped_nsobject<NSMutableParagraphStyle> |
541 paragraph_style([[NSMutableParagraphStyle alloc] init]); | 546 paragraph_style([[NSMutableParagraphStyle alloc] init]); |
542 [paragraph_style setMaximumLineHeight:line_height_]; | 547 [paragraph_style setMaximumLineHeight:line_height_]; |
543 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style | 548 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style |
544 range:NSMakeRange(0, [as length])]; | 549 range:NSMakeRange(0, [as length])]; |
545 | 550 |
546 // Grey out the suggest text. | 551 // Grey out the suggest text. |
547 [as addAttribute:NSForegroundColorAttributeName value:SuggestTextColor() | 552 [as addAttribute:NSForegroundColorAttributeName value:SuggestTextColor() |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 | 1112 |
1108 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { | 1113 void OmniboxViewMac::PlaceCaretAt(NSUInteger pos) { |
1109 DCHECK(pos <= GetTextLength()); | 1114 DCHECK(pos <= GetTextLength()); |
1110 SetSelectedRange(NSMakeRange(pos, pos)); | 1115 SetSelectedRange(NSMakeRange(pos, pos)); |
1111 } | 1116 } |
1112 | 1117 |
1113 bool OmniboxViewMac::IsCaretAtEnd() const { | 1118 bool OmniboxViewMac::IsCaretAtEnd() const { |
1114 const NSRange selection = GetSelectedRange(); | 1119 const NSRange selection = GetSelectedRange(); |
1115 return selection.length == 0 && selection.location == GetTextLength(); | 1120 return selection.length == 0 && selection.location == GetTextLength(); |
1116 } | 1121 } |
OLD | NEW |