OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "ios/chrome/browser/ui/omnibox/omnibox_popup_material_view_controller.h" | 5 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_view_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 LayoutRect detailTextLabelLayout = | 278 LayoutRect detailTextLabelLayout = |
279 LayoutRectMake(leadingPadding, CGRectGetWidth(self.view.bounds), | 279 LayoutRectMake(leadingPadding, CGRectGetWidth(self.view.bounds), |
280 kDetailCellTopPadding, labelWidth, labelHeight); | 280 kDetailCellTopPadding, labelWidth, labelHeight); |
281 detailTextLabel.frame = LayoutRectGetRect(detailTextLabelLayout); | 281 detailTextLabel.frame = LayoutRectGetRect(detailTextLabelLayout); |
282 | 282 |
283 // The detail text should be the URL (|match.contents|) for non-search | 283 // The detail text should be the URL (|match.contents|) for non-search |
284 // suggestions and the entity type (|match.description|) for search entity | 284 // suggestions and the entity type (|match.description|) for search entity |
285 // suggestions. For all other search suggestions, |match.description| is the | 285 // suggestions. For all other search suggestions, |match.description| is the |
286 // name of the currently selected search engine, which for mobile we suppress. | 286 // name of the currently selected search engine, which for mobile we suppress. |
287 NSString* detailText = nil; | 287 NSString* detailText = nil; |
288 if (![self isSearchMatch:match.type]) | 288 if (!AutocompleteMatch::IsSearchType(match.type)) |
289 detailText = base::SysUTF16ToNSString(match.contents); | 289 detailText = base::SysUTF16ToNSString(match.contents); |
290 else if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY) | 290 else if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY) |
291 detailText = base::SysUTF16ToNSString(match.description); | 291 detailText = base::SysUTF16ToNSString(match.description); |
292 | 292 |
293 if (answerPresent) { | 293 if (answerPresent) { |
294 detailTextLabel.attributedText = | 294 detailTextLabel.attributedText = |
295 [self attributedStringWithAnswerLine:match.answer->second_line()]; | 295 [self attributedStringWithAnswerLine:match.answer->second_line()]; |
296 | 296 |
297 // Answers specify their own limit on the number of lines to show but we | 297 // Answers specify their own limit on the number of lines to show but we |
298 // additionally cap this at 3 to guard against unreasonable values. | 298 // additionally cap this at 3 to guard against unreasonable values. |
299 const SuggestionAnswer::TextField& first_text_field = | 299 const SuggestionAnswer::TextField& first_text_field = |
300 match.answer->second_line().text_fields()[0]; | 300 match.answer->second_line().text_fields()[0]; |
301 if (first_text_field.has_num_lines() && first_text_field.num_lines() > 1) | 301 if (first_text_field.has_num_lines() && first_text_field.num_lines() > 1) |
302 detailTextLabel.numberOfLines = MIN(3, first_text_field.num_lines()); | 302 detailTextLabel.numberOfLines = MIN(3, first_text_field.num_lines()); |
303 else | 303 else |
304 detailTextLabel.numberOfLines = 1; | 304 detailTextLabel.numberOfLines = 1; |
305 } else { | 305 } else { |
306 const ACMatchClassifications* classifications = | 306 const ACMatchClassifications* classifications = |
307 ![self isSearchMatch:match.type] ? &match.contents_class : nil; | 307 !AutocompleteMatch::IsSearchType(match.type) ? &match.contents_class |
| 308 : nil; |
308 // The suggestion detail color should match the main text color for entity | 309 // The suggestion detail color should match the main text color for entity |
309 // suggestions. For non-search suggestions (URLs), a highlight color is used | 310 // suggestions. For non-search suggestions (URLs), a highlight color is used |
310 // instead. | 311 // instead. |
311 UIColor* suggestionDetailTextColor = nil; | 312 UIColor* suggestionDetailTextColor = nil; |
312 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY) { | 313 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY) { |
313 suggestionDetailTextColor = | 314 suggestionDetailTextColor = |
314 _incognito ? SuggestionTextColorIncognito() : SuggestionTextColor(); | 315 _incognito ? SuggestionTextColorIncognito() : SuggestionTextColor(); |
315 } else { | 316 } else { |
316 suggestionDetailTextColor = SuggestionDetailTextColor(); | 317 suggestionDetailTextColor = SuggestionDetailTextColor(); |
317 } | 318 } |
318 DCHECK(suggestionDetailTextColor); | 319 DCHECK(suggestionDetailTextColor); |
319 detailTextLabel.attributedText = | 320 detailTextLabel.attributedText = |
320 [self attributedStringWithString:detailText | 321 [self attributedStringWithString:detailText |
321 classifications:classifications | 322 classifications:classifications |
322 smallFont:YES | 323 smallFont:YES |
323 color:suggestionDetailTextColor | 324 color:suggestionDetailTextColor |
324 dimColor:DimColor()]; | 325 dimColor:DimColor()]; |
325 } | 326 } |
326 [detailTextLabel setNeedsDisplay]; | 327 [detailTextLabel setNeedsDisplay]; |
327 | 328 |
328 OmniboxPopupTruncatingLabel* textLabel = row.textTruncatingLabel; | 329 OmniboxPopupTruncatingLabel* textLabel = row.textTruncatingLabel; |
329 [textLabel setTextAlignment:_alignment]; | 330 [textLabel setTextAlignment:_alignment]; |
330 LayoutRect textLabelLayout = | 331 LayoutRect textLabelLayout = |
331 LayoutRectMake(kTextCellLeadingPadding, CGRectGetWidth(self.view.bounds), | 332 LayoutRectMake(kTextCellLeadingPadding, CGRectGetWidth(self.view.bounds), |
332 0, labelWidth, kTextLabelHeight); | 333 0, labelWidth, kTextLabelHeight); |
333 textLabel.frame = LayoutRectGetRect(textLabelLayout); | 334 textLabel.frame = LayoutRectGetRect(textLabelLayout); |
334 | 335 |
335 // The text should be search term (|match.contents|) for searches, otherwise | 336 // The text should be search term (|match.contents|) for searches, otherwise |
336 // page title (|match.description|). | 337 // page title (|match.description|). |
337 base::string16 textString = | 338 base::string16 textString = AutocompleteMatch::IsSearchType(match.type) |
338 [self isSearchMatch:match.type] ? match.contents : match.description; | 339 ? match.contents |
| 340 : match.description; |
339 NSString* text = base::SysUTF16ToNSString(textString); | 341 NSString* text = base::SysUTF16ToNSString(textString); |
340 const ACMatchClassifications* textClassifications = | 342 const ACMatchClassifications* textClassifications = |
341 [self isSearchMatch:match.type] ? &match.contents_class | 343 AutocompleteMatch::IsSearchType(match.type) ? &match.contents_class |
342 : &match.description_class; | 344 : &match.description_class; |
343 | 345 |
344 // If for some reason the title is empty, copy the detailText. | 346 // If for some reason the title is empty, copy the detailText. |
345 if ([text length] == 0 && [detailText length] != 0) { | 347 if ([text length] == 0 && [detailText length] != 0) { |
346 text = detailText; | 348 text = detailText; |
347 } | 349 } |
348 // Center the textLabel if detailLabel is empty. | 350 // Center the textLabel if detailLabel is empty. |
349 if (!answerPresent && [detailText length] == 0) { | 351 if (!answerPresent && [detailText length] == 0) { |
350 textLabel.center = CGPointMake(textLabel.center.x, floor(kRowHeight / 2)); | 352 textLabel.center = CGPointMake(textLabel.center.x, floor(kRowHeight / 2)); |
351 textLabel.frame = AlignRectToPixel(textLabel.frame); | 353 textLabel.frame = AlignRectToPixel(textLabel.frame); |
352 } else { | 354 } else { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 for (OmniboxPopupMaterialRow* row in _rows) { | 664 for (OmniboxPopupMaterialRow* row in _rows) { |
663 row.highlighted = NO; | 665 row.highlighted = NO; |
664 } | 666 } |
665 } | 667 } |
666 | 668 |
667 // Set text alignment for popup cells. | 669 // Set text alignment for popup cells. |
668 - (void)setTextAlignment:(NSTextAlignment)alignment { | 670 - (void)setTextAlignment:(NSTextAlignment)alignment { |
669 _alignment = alignment; | 671 _alignment = alignment; |
670 } | 672 } |
671 | 673 |
672 - (BOOL)isSearchMatch:(const AutocompleteMatch::Type&)type { | |
673 return (type == AutocompleteMatchType::NAVSUGGEST || | |
674 type == AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED || | |
675 type == AutocompleteMatchType::SEARCH_HISTORY || | |
676 type == AutocompleteMatchType::SEARCH_SUGGEST || | |
677 type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY || | |
678 type == AutocompleteMatchType::SEARCH_OTHER_ENGINE); | |
679 } | |
680 | |
681 - (NSMutableAttributedString*) | 674 - (NSMutableAttributedString*) |
682 attributedStringWithString:(NSString*)text | 675 attributedStringWithString:(NSString*)text |
683 classifications:(const ACMatchClassifications*)classifications | 676 classifications:(const ACMatchClassifications*)classifications |
684 smallFont:(BOOL)smallFont | 677 smallFont:(BOOL)smallFont |
685 color:(UIColor*)defaultColor | 678 color:(UIColor*)defaultColor |
686 dimColor:(UIColor*)dimColor { | 679 dimColor:(UIColor*)dimColor { |
687 if (text == nil) | 680 if (text == nil) |
688 return nil; | 681 return nil; |
689 | 682 |
690 UIFont* fontRef = | 683 UIFont* fontRef = |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 // The delete button never disappears if you don't call this after a tap. | 784 // The delete button never disappears if you don't call this after a tap. |
792 // It doesn't seem to be required anywhere else. | 785 // It doesn't seem to be required anywhere else. |
793 [_rows[indexPath.row] prepareForReuse]; | 786 [_rows[indexPath.row] prepareForReuse]; |
794 const AutocompleteMatch& match = | 787 const AutocompleteMatch& match = |
795 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); | 788 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); |
796 _popupView->DeleteMatch(match); | 789 _popupView->DeleteMatch(match); |
797 } | 790 } |
798 } | 791 } |
799 | 792 |
800 @end | 793 @end |
OLD | NEW |