| 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" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" | 13 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
| 14 #include "components/omnibox/browser/autocomplete_input.h" | 14 #include "components/omnibox/browser/autocomplete_input.h" |
| 15 #include "components/omnibox/browser/autocomplete_match.h" | 15 #include "components/omnibox/browser/autocomplete_match.h" |
| 16 #include "components/omnibox/browser/autocomplete_result.h" | 16 #include "components/omnibox/browser/autocomplete_result.h" |
| 17 #include "components/omnibox/browser/suggestion_answer.h" | 17 #include "components/omnibox/browser/suggestion_answer.h" |
| 18 #include "ios/chrome/browser/ui/animation_util.h" | 18 #include "ios/chrome/browser/ui/animation_util.h" |
| 19 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" | 19 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" |
| 20 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h" | 20 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h" |
| 21 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" | 21 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" |
| 22 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" | 22 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" |
| 23 #include "ios/chrome/browser/ui/rtl_geometry.h" | 23 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 24 #include "ios/chrome/browser/ui/ui_util.h" | 24 #include "ios/chrome/browser/ui/ui_util.h" |
| 25 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 25 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 26 #include "ios/chrome/grit/ios_theme_resources.h" | 26 #include "ios/chrome/grit/ios_theme_resources.h" |
| 27 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 27 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 28 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | |
| 29 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 30 | 29 |
| 31 #if !defined(__has_feature) || !__has_feature(objc_arc) | 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 32 #error "This file requires ARC support." | 31 #error "This file requires ARC support." |
| 33 #endif | 32 #endif |
| 34 | 33 |
| 35 namespace { | 34 namespace { |
| 36 const int kRowCount = 6; | 35 const int kRowCount = 6; |
| 37 const CGFloat kRowHeight = 48.0; | 36 const CGFloat kRowHeight = 48.0; |
| 38 const CGFloat kAnswerRowHeight = 64.0; | 37 const CGFloat kAnswerRowHeight = 64.0; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 NSDictionary* attributes = nil; | 464 NSDictionary* attributes = nil; |
| 466 | 465 |
| 467 const id font = (id)NSFontAttributeName; | 466 const id font = (id)NSFontAttributeName; |
| 468 NSString* foregroundColor = (NSString*)NSForegroundColorAttributeName; | 467 NSString* foregroundColor = (NSString*)NSForegroundColorAttributeName; |
| 469 const id baselineOffset = (id)NSBaselineOffsetAttributeName; | 468 const id baselineOffset = (id)NSBaselineOffsetAttributeName; |
| 470 | 469 |
| 471 // Answer types, sizes and colors specified at http://goto.google.com/ais_api. | 470 // Answer types, sizes and colors specified at http://goto.google.com/ais_api. |
| 472 switch (type) { | 471 switch (type) { |
| 473 case SuggestionAnswer::TOP_ALIGNED: | 472 case SuggestionAnswer::TOP_ALIGNED: |
| 474 attributes = @{ | 473 attributes = @{ |
| 475 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:12], | 474 font : [[MDCTypography fontLoader] regularFontOfSize:12], |
| 476 baselineOffset : @10.0f, | 475 baselineOffset : @10.0f, |
| 477 foregroundColor : [UIColor grayColor], | 476 foregroundColor : [UIColor grayColor], |
| 478 }; | 477 }; |
| 479 break; | 478 break; |
| 480 case SuggestionAnswer::DESCRIPTION_POSITIVE: | 479 case SuggestionAnswer::DESCRIPTION_POSITIVE: |
| 481 attributes = @{ | 480 attributes = @{ |
| 482 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16], | 481 font : [[MDCTypography fontLoader] regularFontOfSize:16], |
| 483 foregroundColor : [UIColor colorWithRed:11 / 255.0 | 482 foregroundColor : [UIColor colorWithRed:11 / 255.0 |
| 484 green:128 / 255.0 | 483 green:128 / 255.0 |
| 485 blue:67 / 255.0 | 484 blue:67 / 255.0 |
| 486 alpha:1.0], | 485 alpha:1.0], |
| 487 }; | 486 }; |
| 488 break; | 487 break; |
| 489 case SuggestionAnswer::DESCRIPTION_NEGATIVE: | 488 case SuggestionAnswer::DESCRIPTION_NEGATIVE: |
| 490 attributes = @{ | 489 attributes = @{ |
| 491 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16], | 490 font : [[MDCTypography fontLoader] regularFontOfSize:16], |
| 492 foregroundColor : [UIColor colorWithRed:197 / 255.0 | 491 foregroundColor : [UIColor colorWithRed:197 / 255.0 |
| 493 green:57 / 255.0 | 492 green:57 / 255.0 |
| 494 blue:41 / 255.0 | 493 blue:41 / 255.0 |
| 495 alpha:1.0], | 494 alpha:1.0], |
| 496 }; | 495 }; |
| 497 break; | 496 break; |
| 498 case SuggestionAnswer::PERSONALIZED_SUGGESTION: | 497 case SuggestionAnswer::PERSONALIZED_SUGGESTION: |
| 499 attributes = @{ | 498 attributes = @{ |
| 500 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16], | 499 font : [[MDCTypography fontLoader] regularFontOfSize:16], |
| 501 }; | 500 }; |
| 502 break; | 501 break; |
| 503 case SuggestionAnswer::ANSWER_TEXT_MEDIUM: | 502 case SuggestionAnswer::ANSWER_TEXT_MEDIUM: |
| 504 attributes = @{ | 503 attributes = @{ |
| 505 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:20], | 504 font : [[MDCTypography fontLoader] regularFontOfSize:20], |
| 506 foregroundColor : [UIColor grayColor], | 505 foregroundColor : [UIColor grayColor], |
| 507 }; | 506 }; |
| 508 break; | 507 break; |
| 509 case SuggestionAnswer::ANSWER_TEXT_LARGE: | 508 case SuggestionAnswer::ANSWER_TEXT_LARGE: |
| 510 attributes = @{ | 509 attributes = @{ |
| 511 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:24], | 510 font : [[MDCTypography fontLoader] regularFontOfSize:24], |
| 512 foregroundColor : [UIColor grayColor], | 511 foregroundColor : [UIColor grayColor], |
| 513 }; | 512 }; |
| 514 break; | 513 break; |
| 515 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: | 514 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: |
| 516 attributes = @{ | 515 attributes = @{ |
| 517 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:12], | 516 font : [[MDCTypography fontLoader] regularFontOfSize:12], |
| 518 foregroundColor : [UIColor grayColor], | 517 foregroundColor : [UIColor grayColor], |
| 519 }; | 518 }; |
| 520 break; | 519 break; |
| 521 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM: | 520 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM: |
| 522 attributes = @{ | 521 attributes = @{ |
| 523 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14], | 522 font : [[MDCTypography fontLoader] regularFontOfSize:14], |
| 524 foregroundColor : [UIColor grayColor], | 523 foregroundColor : [UIColor grayColor], |
| 525 }; | 524 }; |
| 526 break; | 525 break; |
| 527 case SuggestionAnswer::SUGGESTION: | 526 case SuggestionAnswer::SUGGESTION: |
| 528 // Fall through. | 527 // Fall through. |
| 529 default: | 528 default: |
| 530 attributes = @{ | 529 attributes = @{ |
| 531 font : [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16], | 530 font : [[MDCTypography fontLoader] regularFontOfSize:16], |
| 532 }; | 531 }; |
| 533 } | 532 } |
| 534 | 533 |
| 535 NSString* unescapedString = | 534 NSString* unescapedString = |
| 536 base::SysUTF16ToNSString(net::UnescapeForHTML(string)); | 535 base::SysUTF16ToNSString(net::UnescapeForHTML(string)); |
| 537 // TODO(jdonnelly): Remove this tag stripping once the JSON parsing class | 536 // TODO(jdonnelly): Remove this tag stripping once the JSON parsing class |
| 538 // handles HTML tags. | 537 // handles HTML tags. |
| 539 unescapedString = [unescapedString stringByReplacingOccurrencesOfString:@"<b>" | 538 unescapedString = [unescapedString stringByReplacingOccurrencesOfString:@"<b>" |
| 540 withString:@""]; | 539 withString:@""]; |
| 541 unescapedString = | 540 unescapedString = |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 [[NSMutableAttributedString alloc] initWithString:text]; | 689 [[NSMutableAttributedString alloc] initWithString:text]; |
| 691 | 690 |
| 692 // Set the base attributes to the default font and color. | 691 // Set the base attributes to the default font and color. |
| 693 NSDictionary* dict = @{ | 692 NSDictionary* dict = @{ |
| 694 NSFontAttributeName : fontRef, | 693 NSFontAttributeName : fontRef, |
| 695 NSForegroundColorAttributeName : defaultColor, | 694 NSForegroundColorAttributeName : defaultColor, |
| 696 }; | 695 }; |
| 697 [as addAttributes:dict range:NSMakeRange(0, [text length])]; | 696 [as addAttributes:dict range:NSMakeRange(0, [text length])]; |
| 698 | 697 |
| 699 if (classifications != NULL) { | 698 if (classifications != NULL) { |
| 700 UIFont* boldFontRef = [[MDFRobotoFontLoader sharedInstance] | 699 UIFont* boldFontRef = |
| 701 mediumFontOfSize:fontRef.pointSize]; | 700 [[MDCTypography fontLoader] mediumFontOfSize:fontRef.pointSize]; |
| 702 | 701 |
| 703 for (ACMatchClassifications::const_iterator i = classifications->begin(); | 702 for (ACMatchClassifications::const_iterator i = classifications->begin(); |
| 704 i != classifications->end(); ++i) { | 703 i != classifications->end(); ++i) { |
| 705 const BOOL isLast = (i + 1) == classifications->end(); | 704 const BOOL isLast = (i + 1) == classifications->end(); |
| 706 const size_t nextOffset = (isLast ? [text length] : (i + 1)->offset); | 705 const size_t nextOffset = (isLast ? [text length] : (i + 1)->offset); |
| 707 const NSInteger location = static_cast<NSInteger>(i->offset); | 706 const NSInteger location = static_cast<NSInteger>(i->offset); |
| 708 const NSInteger length = static_cast<NSInteger>(nextOffset - i->offset); | 707 const NSInteger length = static_cast<NSInteger>(nextOffset - i->offset); |
| 709 // Guard against bad, off-the-end classification ranges due to | 708 // Guard against bad, off-the-end classification ranges due to |
| 710 // crbug.com/121703 and crbug.com/131370. | 709 // crbug.com/121703 and crbug.com/131370. |
| 711 if (i->offset + length > [text length] || length <= 0) | 710 if (i->offset + length > [text length] || length <= 0) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // The delete button never disappears if you don't call this after a tap. | 786 // The delete button never disappears if you don't call this after a tap. |
| 788 // It doesn't seem to be required anywhere else. | 787 // It doesn't seem to be required anywhere else. |
| 789 [_rows[indexPath.row] prepareForReuse]; | 788 [_rows[indexPath.row] prepareForReuse]; |
| 790 const AutocompleteMatch& match = | 789 const AutocompleteMatch& match = |
| 791 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); | 790 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); |
| 792 _popupView->DeleteMatch(match); | 791 _popupView->DeleteMatch(match); |
| 793 } | 792 } |
| 794 } | 793 } |
| 795 | 794 |
| 796 @end | 795 @end |
| OLD | NEW |