Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: ios/chrome/browser/ui/omnibox/omnibox_popup_material_view_controller.mm

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

Powered by Google App Engine
This is Rietveld 408576698