| 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/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
| 14 #include "components/omnibox/browser/autocomplete_input.h" | 15 #include "components/omnibox/browser/autocomplete_input.h" |
| 15 #include "components/omnibox/browser/autocomplete_match.h" | 16 #include "components/omnibox/browser/autocomplete_match.h" |
| 16 #include "components/omnibox/browser/autocomplete_result.h" | 17 #include "components/omnibox/browser/autocomplete_result.h" |
| 17 #include "components/omnibox/browser/suggestion_answer.h" | 18 #include "components/omnibox/browser/suggestion_answer.h" |
| 18 #include "ios/chrome/browser/ui/animation_util.h" | 19 #include "ios/chrome/browser/ui/animation_util.h" |
| 19 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" | 20 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.h" |
| 20 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h" | 21 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_ios.h" |
| 21 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" | 22 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" |
| 22 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" | 23 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" |
| 23 #include "ios/chrome/browser/ui/rtl_geometry.h" | 24 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 24 #include "ios/chrome/browser/ui/ui_util.h" | 25 #include "ios/chrome/browser/ui/ui_util.h" |
| 25 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 26 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 26 #include "ios/chrome/grit/ios_theme_resources.h" | 27 #include "ios/chrome/grit/ios_theme_resources.h" |
| 27 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 28 #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 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 29 #include "ios/web/public/image_fetcher/image_data_fetcher.h" | |
| 30 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 const int kRowCount = 6; | 33 const int kRowCount = 6; |
| 34 const CGFloat kRowHeight = 48.0; | 34 const CGFloat kRowHeight = 48.0; |
| 35 const CGFloat kAnswerRowHeight = 64.0; | 35 const CGFloat kAnswerRowHeight = 64.0; |
| 36 const CGFloat kTopAndBottomPadding = 8.0; | 36 const CGFloat kTopAndBottomPadding = 8.0; |
| 37 // The color of the main text of a suggest cell. | 37 // The color of the main text of a suggest cell. |
| 38 UIColor* SuggestionTextColor() { | 38 UIColor* SuggestionTextColor() { |
| 39 return [UIColor colorWithWhite:(51 / 255.0) alpha:1.0]; | 39 return [UIColor colorWithWhite:(51 / 255.0) alpha:1.0]; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 base::ScopedCFTypeRef<CTFontRef> _bigFont; | 81 base::ScopedCFTypeRef<CTFontRef> _bigFont; |
| 82 base::ScopedCFTypeRef<CTFontRef> _smallBoldFont; | 82 base::ScopedCFTypeRef<CTFontRef> _smallBoldFont; |
| 83 base::ScopedCFTypeRef<CTFontRef> _bigBoldFont; | 83 base::ScopedCFTypeRef<CTFontRef> _bigBoldFont; |
| 84 | 84 |
| 85 // Alignment of omnibox text. Popup text should match this alignment. | 85 // Alignment of omnibox text. Popup text should match this alignment. |
| 86 NSTextAlignment _alignment; | 86 NSTextAlignment _alignment; |
| 87 | 87 |
| 88 OmniboxPopupViewIOS* _popupView; // weak, owns us | 88 OmniboxPopupViewIOS* _popupView; // weak, owns us |
| 89 | 89 |
| 90 // Fetcher for Answers in Suggest images. | 90 // Fetcher for Answers in Suggest images. |
| 91 std::unique_ptr<web::ImageDataFetcher> imageFetcher_; | 91 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher_; |
| 92 | 92 |
| 93 // The data source. | 93 // The data source. |
| 94 AutocompleteResult _currentResult; | 94 AutocompleteResult _currentResult; |
| 95 | 95 |
| 96 // Array containing the OmniboxPopupMaterialRow objects displayed in the view. | 96 // Array containing the OmniboxPopupMaterialRow objects displayed in the view. |
| 97 base::scoped_nsobject<NSArray> _rows; | 97 base::scoped_nsobject<NSArray> _rows; |
| 98 | 98 |
| 99 // The height of the keyboard. Used to determine the content inset for the | 99 // The height of the keyboard. Used to determine the content inset for the |
| 100 // scroll view. | 100 // scroll view. |
| 101 CGFloat keyboardHeight_; | 101 CGFloat keyboardHeight_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 @end | 104 @end |
| 105 | 105 |
| 106 @implementation OmniboxPopupMaterialViewController | 106 @implementation OmniboxPopupMaterialViewController |
| 107 | 107 |
| 108 @synthesize incognito = _incognito; | 108 @synthesize incognito = _incognito; |
| 109 | 109 |
| 110 #pragma mark - | 110 #pragma mark - |
| 111 #pragma mark Initialization | 111 #pragma mark Initialization |
| 112 | 112 |
| 113 - (instancetype)initWithPopupView:(OmniboxPopupViewIOS*)view | 113 - (instancetype) |
| 114 withFetcher: | 114 initWithPopupView:(OmniboxPopupViewIOS*)view |
| 115 (std::unique_ptr<web::ImageDataFetcher>)imageFetcher { | 115 withFetcher:(std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper>) |
| 116 imageFetcher { |
| 116 if ((self = [super init])) { | 117 if ((self = [super init])) { |
| 117 _popupView = view; | 118 _popupView = view; |
| 118 imageFetcher_ = std::move(imageFetcher); | 119 imageFetcher_ = std::move(imageFetcher); |
| 119 | 120 |
| 120 if (IsIPadIdiom()) { | 121 if (IsIPadIdiom()) { |
| 121 // The iPad keyboard can cover some of the rows of the scroll view. The | 122 // The iPad keyboard can cover some of the rows of the scroll view. The |
| 122 // scroll view's content inset may need to be updated when the keyboard is | 123 // scroll view's content inset may need to be updated when the keyboard is |
| 123 // displayed. | 124 // displayed. |
| 124 NSNotificationCenter* defaultCenter = | 125 NSNotificationCenter* defaultCenter = |
| 125 [NSNotificationCenter defaultCenter]; | 126 [NSNotificationCenter defaultCenter]; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 row.rowHeight = answerPresent ? kAnswerRowHeight : kRowHeight; | 242 row.rowHeight = answerPresent ? kAnswerRowHeight : kRowHeight; |
| 242 | 243 |
| 243 [row.detailTruncatingLabel setTextAlignment:_alignment]; | 244 [row.detailTruncatingLabel setTextAlignment:_alignment]; |
| 244 [row.textTruncatingLabel setTextAlignment:_alignment]; | 245 [row.textTruncatingLabel setTextAlignment:_alignment]; |
| 245 | 246 |
| 246 // Fetch the answer image if specified. Currently, no answer types specify an | 247 // Fetch the answer image if specified. Currently, no answer types specify an |
| 247 // image on the first line so for now we only look at the second line. | 248 // image on the first line so for now we only look at the second line. |
| 248 const BOOL answerImagePresent = | 249 const BOOL answerImagePresent = |
| 249 answerPresent && match.answer->second_line().image_url().is_valid(); | 250 answerPresent && match.answer->second_line().image_url().is_valid(); |
| 250 if (answerImagePresent) { | 251 if (answerImagePresent) { |
| 251 web::ImageFetchedCallback callback = | 252 image_fetcher::IOSImageDataFetcherCallback callback = |
| 252 ^(const GURL& original_url, int response_code, NSData* data) { | 253 ^(NSData* data, const image_fetcher::RequestMetadata& metadata) { |
| 253 if (data) { | 254 if (data) { |
| 254 UIImage* image = | 255 UIImage* image = |
| 255 [UIImage imageWithData:data scale:[UIScreen mainScreen].scale]; | 256 [UIImage imageWithData:data scale:[UIScreen mainScreen].scale]; |
| 256 if (image) { | 257 if (image) { |
| 257 row.answerImageView.image = image; | 258 row.answerImageView.image = image; |
| 258 } | 259 } |
| 259 } | 260 } |
| 260 }; | 261 }; |
| 261 imageFetcher_->StartDownload(match.answer->second_line().image_url(), | 262 imageFetcher_->FetchImageDataWebpDecoded( |
| 262 callback); | 263 match.answer->second_line().image_url(), callback); |
| 263 | 264 |
| 264 // Answers in suggest do not support RTL, left align only. | 265 // Answers in suggest do not support RTL, left align only. |
| 265 CGFloat imageLeftPadding = | 266 CGFloat imageLeftPadding = |
| 266 kTextCellLeadingPadding + kAnswerImageLeftPadding; | 267 kTextCellLeadingPadding + kAnswerImageLeftPadding; |
| 267 if (alignmentRight) { | 268 if (alignmentRight) { |
| 268 imageLeftPadding = | 269 imageLeftPadding = |
| 269 row.frame.size.width - (kAnswerImageWidth + kAppendButtonWidth); | 270 row.frame.size.width - (kAnswerImageWidth + kAppendButtonWidth); |
| 270 } | 271 } |
| 271 CGFloat imageTopPadding = | 272 CGFloat imageTopPadding = |
| 272 kDetailCellTopPadding + kAnswerRowPadding + kAnswerImageTopPadding; | 273 kDetailCellTopPadding + kAnswerRowPadding + kAnswerImageTopPadding; |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 // The delete button never disappears if you don't call this after a tap. | 783 // The delete button never disappears if you don't call this after a tap. |
| 783 // It doesn't seem to be required anywhere else. | 784 // It doesn't seem to be required anywhere else. |
| 784 [_rows[indexPath.row] prepareForReuse]; | 785 [_rows[indexPath.row] prepareForReuse]; |
| 785 const AutocompleteMatch& match = | 786 const AutocompleteMatch& match = |
| 786 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); | 787 ((const AutocompleteResult&)_currentResult).match_at(indexPath.row); |
| 787 _popupView->DeleteMatch(match); | 788 _popupView->DeleteMatch(match); |
| 788 } | 789 } |
| 789 } | 790 } |
| 790 | 791 |
| 791 @end | 792 @end |
| OLD | NEW |