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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (end == base::string16::npos) | 261 if (end == base::string16::npos) |
262 break; | 262 break; |
263 [result appendAttributedString:CreateAnswerStringHelper( | 263 [result appendAttributedString:CreateAnswerStringHelper( |
264 text.substr(begin, end - begin), | 264 text.substr(begin, end - begin), |
265 style_type, true, is_dark_theme)]; | 265 style_type, true, is_dark_theme)]; |
266 begin = end + end_tag.length(); | 266 begin = end + end_tag.length(); |
267 } | 267 } |
268 return result.autorelease(); | 268 return result.autorelease(); |
269 } | 269 } |
270 | 270 |
271 int ParseNumLines(const SuggestionAnswer::TextFields& text_fields) { | |
272 for (const SuggestionAnswer::TextField& text_field : text_fields) { | |
273 if (text_field.has_num_lines() && text_field.num_lines() > 1) | |
274 return text_field.num_lines(); | |
275 } | |
276 return 1; | |
277 } | |
278 | |
279 NSAttributedString* CreateAnswerLine(const SuggestionAnswer::ImageLine& line, | 271 NSAttributedString* CreateAnswerLine(const SuggestionAnswer::ImageLine& line, |
280 BOOL is_dark_theme) { | 272 BOOL is_dark_theme) { |
281 base::scoped_nsobject<NSMutableAttributedString> answer_string( | 273 base::scoped_nsobject<NSMutableAttributedString> answer_string( |
282 [[NSMutableAttributedString alloc] init]); | 274 [[NSMutableAttributedString alloc] init]); |
283 DCHECK(!line.text_fields().empty()); | 275 DCHECK(!line.text_fields().empty()); |
284 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) { | 276 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) { |
285 [answer_string appendAttributedString:CreateAnswerString(text_field.text(), | 277 [answer_string appendAttributedString:CreateAnswerString(text_field.text(), |
286 text_field.type(), | 278 text_field.type(), |
287 is_dark_theme)]; | 279 is_dark_theme)]; |
288 } | 280 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 base::UTF8ToUTF16( | 429 base::UTF8ToUTF16( |
438 match.GetAdditionalInfo(kACMatchPropertyContentsPrefix)), | 430 match.GetAdditionalInfo(kACMatchPropertyContentsPrefix)), |
439 ContentTextColor(isDarkTheme), textAlignment) retain]; | 431 ContentTextColor(isDarkTheme), textAlignment) retain]; |
440 | 432 |
441 isAnswer_ = !!match.answer; | 433 isAnswer_ = !!match.answer; |
442 if (isAnswer_) { | 434 if (isAnswer_) { |
443 contents_ = | 435 contents_ = |
444 [CreateAnswerLine(match.answer->first_line(), isDarkTheme) retain]; | 436 [CreateAnswerLine(match.answer->first_line(), isDarkTheme) retain]; |
445 description_ = | 437 description_ = |
446 [CreateAnswerLine(match.answer->second_line(), isDarkTheme) retain]; | 438 [CreateAnswerLine(match.answer->second_line(), isDarkTheme) retain]; |
447 max_lines_ = ParseNumLines(match.answer->second_line().text_fields()); | 439 max_lines_ = match.answer->second_line().num_text_lines(); |
448 } else { | 440 } else { |
449 contents_ = [CreateClassifiedAttributedString( | 441 contents_ = [CreateClassifiedAttributedString( |
450 match.contents, ContentTextColor(isDarkTheme), match.contents_class, | 442 match.contents, ContentTextColor(isDarkTheme), match.contents_class, |
451 isDarkTheme) retain]; | 443 isDarkTheme) retain]; |
452 if (!match.description.empty()) { | 444 if (!match.description.empty()) { |
453 description_ = [CreateClassifiedAttributedString( | 445 description_ = [CreateClassifiedAttributedString( |
454 match.description, DimTextColor(isDarkTheme), | 446 match.description, DimTextColor(isDarkTheme), |
455 match.description_class, isDarkTheme) retain]; | 447 match.description_class, isDarkTheme) retain]; |
456 } | 448 } |
457 max_lines_ = 1; | 449 max_lines_ = 1; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 base::string16 raw_separator = | 719 base::string16 raw_separator = |
728 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); | 720 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); |
729 return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); | 721 return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); |
730 } | 722 } |
731 | 723 |
732 + (CGFloat)getContentAreaWidth:(NSRect)cellFrame { | 724 + (CGFloat)getContentAreaWidth:(NSRect)cellFrame { |
733 return NSWidth(cellFrame) - TextStartOffset(); | 725 return NSWidth(cellFrame) - TextStartOffset(); |
734 } | 726 } |
735 | 727 |
736 @end | 728 @end |
OLD | NEW |