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 void SetTextDirectionForRange(NSMutableAttributedString* attributedString, | |
tapted
2016/07/21 04:37:05
This should be something like SetURLTextDirection,
Matt Giuca
2016/07/21 04:55:37
It isn't necessarily setting the text direction fo
| |
156 NSWritingDirection direction, | |
157 NSRange range) { | |
158 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( | |
159 [[NSMutableParagraphStyle alloc] init]); | |
160 [paragraph_style setBaseWritingDirection:direction]; | |
161 [attributedString addAttribute:NSParagraphStyleAttributeName | |
162 value:paragraph_style | |
163 range:range]; | |
164 } | |
tapted
2016/07/21 04:37:05
nit: any reason to have this declared up here, rat
Matt Giuca
2016/07/21 04:55:37
Well kind of along similar lines, it isn't specifi
| |
165 | |
155 NSAttributedString* CreateAnswerStringHelper(const base::string16& text, | 166 NSAttributedString* CreateAnswerStringHelper(const base::string16& text, |
156 NSInteger style_type, | 167 NSInteger style_type, |
157 bool is_bold, | 168 bool is_bold, |
158 BOOL is_dark_theme) { | 169 BOOL is_dark_theme) { |
159 NSDictionary* answer_style = nil; | 170 NSDictionary* answer_style = nil; |
160 NSFont* answer_font = nil; | 171 NSFont* answer_font = nil; |
161 bool is_mode_material = ui::MaterialDesignController::IsModeMaterial(); | 172 bool is_mode_material = ui::MaterialDesignController::IsModeMaterial(); |
162 switch (style_type) { | 173 switch (style_type) { |
163 case SuggestionAnswer::TOP_ALIGNED: | 174 case SuggestionAnswer::TOP_ALIGNED: |
164 answer_style = @{ | 175 answer_style = @{ |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 const NSRange range = | 367 const NSRange range = |
357 NSMakeRange(location, std::min(length, match_length - location)); | 368 NSMakeRange(location, std::min(length, match_length - location)); |
358 | 369 |
359 if (0 != (i->style & ACMatchClassification::MATCH)) { | 370 if (0 != (i->style & ACMatchClassification::MATCH)) { |
360 [attributedString addAttribute:NSFontAttributeName | 371 [attributedString addAttribute:NSFontAttributeName |
361 value:BoldFieldFont() | 372 value:BoldFieldFont() |
362 range:range]; | 373 range:range]; |
363 } | 374 } |
364 | 375 |
365 if (0 != (i->style & ACMatchClassification::URL)) { | 376 if (0 != (i->style & ACMatchClassification::URL)) { |
377 // URLs have their text direction set to to LTR (avoids RTL characters | |
378 // making the URL render from right to left, as per RFC 3987 Section 4.1). | |
379 SetTextDirectionForRange(attributedString, NSWritingDirectionLeftToRight, | |
380 range); | |
366 [attributedString addAttribute:NSForegroundColorAttributeName | 381 [attributedString addAttribute:NSForegroundColorAttributeName |
367 value:URLTextColor(is_dark_theme) | 382 value:URLTextColor(is_dark_theme) |
368 range:range]; | 383 range:range]; |
369 } else if (0 != (i->style & ACMatchClassification::DIM)) { | 384 } else if (0 != (i->style & ACMatchClassification::DIM)) { |
370 [attributedString addAttribute:NSForegroundColorAttributeName | 385 [attributedString addAttribute:NSForegroundColorAttributeName |
371 value:DimTextColor(is_dark_theme) | 386 value:DimTextColor(is_dark_theme) |
372 range:range]; | 387 range:range]; |
373 } | 388 } |
374 } | 389 } |
375 | 390 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 base::string16 raw_separator = | 734 base::string16 raw_separator = |
720 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); | 735 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); |
721 return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); | 736 return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); |
722 } | 737 } |
723 | 738 |
724 + (CGFloat)getContentAreaWidth:(NSRect)cellFrame { | 739 + (CGFloat)getContentAreaWidth:(NSRect)cellFrame { |
725 return NSWidth(cellFrame) - TextStartOffset(); | 740 return NSWidth(cellFrame) - TextStartOffset(); |
726 } | 741 } |
727 | 742 |
728 @end | 743 @end |
OLD | NEW |