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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 // that happens, |storage| and |field_| will not be synced automatically any | 542 // that happens, |storage| and |field_| will not be synced automatically any |
543 // more. Calling -stringValue ensures that |field_| reflects the changes to | 543 // more. Calling -stringValue ensures that |field_| reflects the changes to |
544 // |storage|. | 544 // |storage|. |
545 [field_ stringValue]; | 545 [field_ stringValue]; |
546 } else { | 546 } else { |
547 SetText(GetText()); | 547 SetText(GetText()); |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 void OmniboxViewMac::ApplyTextStyle( | 551 void OmniboxViewMac::ApplyTextStyle( |
552 bool force_ltr, | |
552 NSMutableAttributedString* attributedString) { | 553 NSMutableAttributedString* attributedString) { |
553 [attributedString addAttribute:NSFontAttributeName | 554 [attributedString addAttribute:NSFontAttributeName |
554 value:GetNormalFieldFont() | 555 value:GetNormalFieldFont() |
555 range:NSMakeRange(0, [attributedString length])]; | 556 range:NSMakeRange(0, [attributedString length])]; |
556 | 557 |
557 // Make a paragraph style locking in the standard line height as the maximum, | 558 // Make a paragraph style locking in the standard line height as the maximum, |
558 // otherwise the baseline may shift "downwards". | 559 // otherwise the baseline may shift "downwards". |
559 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( | 560 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( |
560 [[NSMutableParagraphStyle alloc] init]); | 561 [[NSMutableParagraphStyle alloc] init]); |
561 CGFloat line_height = [[field_ cell] lineHeight]; | 562 CGFloat line_height = [[field_ cell] lineHeight]; |
562 [paragraph_style setMaximumLineHeight:line_height]; | 563 [paragraph_style setMaximumLineHeight:line_height]; |
563 [paragraph_style setMinimumLineHeight:line_height]; | 564 [paragraph_style setMinimumLineHeight:line_height]; |
564 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; | 565 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; |
566 if (force_ltr) | |
tapted
2016/07/21 04:37:05
optional: I'd probably just use model()->CurrentTe
Matt Giuca
2016/07/21 04:55:37
Done.
| |
567 [paragraph_style setBaseWritingDirection:NSWritingDirectionLeftToRight]; | |
565 [attributedString addAttribute:NSParagraphStyleAttributeName | 568 [attributedString addAttribute:NSParagraphStyleAttributeName |
566 value:paragraph_style | 569 value:paragraph_style |
567 range:NSMakeRange(0, [attributedString length])]; | 570 range:NSMakeRange(0, [attributedString length])]; |
568 } | 571 } |
569 | 572 |
570 void OmniboxViewMac::ApplyTextAttributes( | 573 void OmniboxViewMac::ApplyTextAttributes( |
571 const base::string16& display_text, | 574 const base::string16& display_text, |
572 NSMutableAttributedString* attributedString) { | 575 NSMutableAttributedString* attributedString) { |
573 NSUInteger as_length = [attributedString length]; | 576 NSUInteger as_length = [attributedString length]; |
574 if (as_length == 0) { | 577 if (as_length == 0) { |
575 return; | 578 return; |
576 } | 579 } |
577 NSRange as_entire_string = NSMakeRange(0, as_length); | 580 NSRange as_entire_string = NSMakeRange(0, as_length); |
578 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; | 581 bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme]; |
582 // If this is a URL, set the top-level paragraph direction to LTR (avoids RTL | |
583 // characters from making the URL render from right to left, as per RFC 3987 | |
584 // Section 4.1). | |
585 bool force_ltr = model()->CurrentTextIsURL(); | |
579 | 586 |
580 ApplyTextStyle(attributedString); | 587 ApplyTextStyle(force_ltr, attributedString); |
581 | 588 |
582 // A kinda hacky way to add breaking at periods. This is what Safari does. | 589 // A kinda hacky way to add breaking at periods. This is what Safari does. |
583 // This works for IDNs too, despite the "en_US". | 590 // This works for IDNs too, despite the "en_US". |
584 [attributedString addAttribute:@"NSLanguage" | 591 [attributedString addAttribute:@"NSLanguage" |
585 value:@"en_US_POSIX" | 592 value:@"en_US_POSIX" |
586 range:as_entire_string]; | 593 range:as_entire_string]; |
587 | 594 |
588 if (ui::MaterialDesignController::IsModeMaterial()) { | 595 if (ui::MaterialDesignController::IsModeMaterial()) { |
589 [attributedString addAttribute:NSForegroundColorAttributeName | 596 [attributedString addAttribute:NSForegroundColorAttributeName |
590 value:HostTextColor(in_dark_mode) | 597 value:HostTextColor(in_dark_mode) |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1157 display_text); | 1164 display_text); |
1158 NSDictionary* notification_info = @{ | 1165 NSDictionary* notification_info = @{ |
1159 NSAccessibilityAnnouncementKey : announcement, | 1166 NSAccessibilityAnnouncementKey : announcement, |
1160 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) | 1167 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) |
1161 }; | 1168 }; |
1162 NSAccessibilityPostNotificationWithUserInfo( | 1169 NSAccessibilityPostNotificationWithUserInfo( |
1163 [field_ window], | 1170 [field_ window], |
1164 NSAccessibilityAnnouncementRequestedNotification, | 1171 NSAccessibilityAnnouncementRequestedNotification, |
1165 notification_info); | 1172 notification_info); |
1166 } | 1173 } |
OLD | NEW |