OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Calculate a slightly smaller font. The ratio here is somewhat arbitrary. | 145 // Calculate a slightly smaller font. The ratio here is somewhat arbitrary. |
146 // Proportions from 5/9 to 5/7 all look pretty good. | 146 // Proportions from 5/9 to 5/7 all look pretty good. |
147 CGFloat size = [font pointSize] * 5.0 / 9.0; | 147 CGFloat size = [font pointSize] * 5.0 / 9.0; |
148 NSFontDescriptor* descriptor = [font fontDescriptor]; | 148 NSFontDescriptor* descriptor = [font fontDescriptor]; |
149 return [NSFont fontWithDescriptor:descriptor size:size]; | 149 return [NSFont fontWithDescriptor:descriptor size:size]; |
150 } | 150 } |
151 NSFont* SmallFont() { | 151 NSFont* SmallFont() { |
152 return OmniboxViewMac::GetSmallFont(); | 152 return OmniboxViewMac::GetSmallFont(); |
153 } | 153 } |
154 | 154 |
| 155 // Sets the writing direction to |direction| for a given |range| of |
| 156 // |attributedString|. |
| 157 void SetTextDirectionForRange(NSMutableAttributedString* attributedString, |
| 158 NSWritingDirection direction, |
| 159 NSRange range) { |
| 160 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( |
| 161 [[NSMutableParagraphStyle alloc] init]); |
| 162 [paragraph_style setBaseWritingDirection:direction]; |
| 163 [attributedString addAttribute:NSParagraphStyleAttributeName |
| 164 value:paragraph_style |
| 165 range:range]; |
| 166 } |
| 167 |
155 NSAttributedString* CreateAnswerStringHelper(const base::string16& text, | 168 NSAttributedString* CreateAnswerStringHelper(const base::string16& text, |
156 NSInteger style_type, | 169 NSInteger style_type, |
157 bool is_bold, | 170 bool is_bold, |
158 BOOL is_dark_theme) { | 171 BOOL is_dark_theme) { |
159 NSDictionary* answer_style = nil; | 172 NSDictionary* answer_style = nil; |
160 NSFont* answer_font = nil; | 173 NSFont* answer_font = nil; |
161 bool is_mode_material = ui::MaterialDesignController::IsModeMaterial(); | 174 bool is_mode_material = ui::MaterialDesignController::IsModeMaterial(); |
162 switch (style_type) { | 175 switch (style_type) { |
163 case SuggestionAnswer::TOP_ALIGNED: | 176 case SuggestionAnswer::TOP_ALIGNED: |
164 answer_style = @{ | 177 answer_style = @{ |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 const NSRange range = | 369 const NSRange range = |
357 NSMakeRange(location, std::min(length, match_length - location)); | 370 NSMakeRange(location, std::min(length, match_length - location)); |
358 | 371 |
359 if (0 != (i->style & ACMatchClassification::MATCH)) { | 372 if (0 != (i->style & ACMatchClassification::MATCH)) { |
360 [attributedString addAttribute:NSFontAttributeName | 373 [attributedString addAttribute:NSFontAttributeName |
361 value:BoldFieldFont() | 374 value:BoldFieldFont() |
362 range:range]; | 375 range:range]; |
363 } | 376 } |
364 | 377 |
365 if (0 != (i->style & ACMatchClassification::URL)) { | 378 if (0 != (i->style & ACMatchClassification::URL)) { |
| 379 // URLs have their text direction set to to LTR (avoids RTL characters |
| 380 // making the URL render from right to left, as per RFC 3987 Section 4.1). |
| 381 SetTextDirectionForRange(attributedString, NSWritingDirectionLeftToRight, |
| 382 range); |
366 [attributedString addAttribute:NSForegroundColorAttributeName | 383 [attributedString addAttribute:NSForegroundColorAttributeName |
367 value:URLTextColor(is_dark_theme) | 384 value:URLTextColor(is_dark_theme) |
368 range:range]; | 385 range:range]; |
369 } else if (0 != (i->style & ACMatchClassification::DIM)) { | 386 } else if (0 != (i->style & ACMatchClassification::DIM)) { |
370 [attributedString addAttribute:NSForegroundColorAttributeName | 387 [attributedString addAttribute:NSForegroundColorAttributeName |
371 value:DimTextColor(is_dark_theme) | 388 value:DimTextColor(is_dark_theme) |
372 range:range]; | 389 range:range]; |
373 } | 390 } |
374 } | 391 } |
375 | 392 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 base::string16 raw_separator = | 736 base::string16 raw_separator = |
720 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); | 737 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); |
721 return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); | 738 return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); |
722 } | 739 } |
723 | 740 |
724 + (CGFloat)getContentAreaWidth:(NSRect)cellFrame { | 741 + (CGFloat)getContentAreaWidth:(NSRect)cellFrame { |
725 return NSWidth(cellFrame) - TextStartOffset(); | 742 return NSWidth(cellFrame) - TextStartOffset(); |
726 } | 743 } |
727 | 744 |
728 @end | 745 @end |
OLD | NEW |