| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/settings/search_engine_settings_collection_view_c
ontroller.h" | 5 #import "ios/chrome/browser/ui/settings/search_engine_settings_collection_view_c
ontroller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #import "base/mac/scoped_nsobject.h" | 11 #import "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "components/search_engines/template_url_service.h" | 13 #include "components/search_engines/template_url_service.h" |
| 14 #include "components/search_engines/template_url_service_observer.h" | 14 #include "components/search_engines/template_url_service_observer.h" |
| 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 16 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | 16 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h
" |
| 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 19 #include "ios/chrome/grit/ios_strings.h" | 20 #include "ios/chrome/grit/ios_strings.h" |
| 20 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 21 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
| 22 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 23 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 21 #include "ui/base/l10n/l10n_util_mac.h" | 24 #include "ui/base/l10n/l10n_util_mac.h" |
| 22 | 25 |
| 23 @interface SearchEngineSettingsCollectionViewController () | 26 @interface SearchEngineSettingsCollectionViewController () |
| 24 - (void)onChange; | 27 - (void)onChange; |
| 25 @end | 28 @end |
| 26 | 29 |
| 27 namespace { | 30 namespace { |
| 28 | 31 |
| 29 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 32 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 30 SectionIdentifierSearchEngines = kSectionIdentifierEnumZero, | 33 SectionIdentifierSearchEngines = kSectionIdentifierEnumZero, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 initWithType:ItemTypeSearchEnginesEngine]); | 115 initWithType:ItemTypeSearchEnginesEngine]); |
| 113 [engine setText:value]; | 116 [engine setText:value]; |
| 114 if (checked) { | 117 if (checked) { |
| 115 [engine setAccessoryType:MDCCollectionViewCellAccessoryCheckmark]; | 118 [engine setAccessoryType:MDCCollectionViewCellAccessoryCheckmark]; |
| 116 } | 119 } |
| 117 [model addItem:engine | 120 [model addItem:engine |
| 118 toSectionWithIdentifier:SectionIdentifierSearchEngines]; | 121 toSectionWithIdentifier:SectionIdentifierSearchEngines]; |
| 119 } | 122 } |
| 120 } | 123 } |
| 121 | 124 |
| 125 #pragma mark - UICollectionViewDataSource |
| 126 |
| 127 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 128 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 129 UICollectionViewCell* cell = |
| 130 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 131 |
| 132 NSInteger itemType = |
| 133 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 134 switch (itemType) { |
| 135 case ItemTypeSearchEnginesEngine: { |
| 136 CollectionViewTextCell* textCell = |
| 137 base::mac::ObjCCastStrict<CollectionViewTextCell>(cell); |
| 138 textCell.textLabel.font = [MDCTypography body2Font]; |
| 139 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 140 textCell.detailTextLabel.font = [MDCTypography body1Font]; |
| 141 textCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 142 break; |
| 143 } |
| 144 default: |
| 145 break; |
| 146 } |
| 147 return cell; |
| 148 } |
| 149 |
| 122 #pragma mark UICollectionViewDelegate | 150 #pragma mark UICollectionViewDelegate |
| 123 | 151 |
| 124 - (void)collectionView:(UICollectionView*)collectionView | 152 - (void)collectionView:(UICollectionView*)collectionView |
| 125 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 153 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 126 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 154 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
| 127 CollectionViewModel* model = self.collectionViewModel; | 155 CollectionViewModel* model = self.collectionViewModel; |
| 128 | 156 |
| 129 // Only handle taps on search engine items. | 157 // Only handle taps on search engine items. |
| 130 CollectionViewItem* selectedItem = [model itemAtIndexPath:indexPath]; | 158 CollectionViewItem* selectedItem = [model itemAtIndexPath:indexPath]; |
| 131 if (selectedItem.type != ItemTypeSearchEnginesEngine) { | 159 if (selectedItem.type != ItemTypeSearchEnginesEngine) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 templateURLService_->SetUserSelectedDefaultSearchProvider(urls[index]); | 223 templateURLService_->SetUserSelectedDefaultSearchProvider(urls[index]); |
| 196 updatingBackend_ = NO; | 224 updatingBackend_ = NO; |
| 197 } | 225 } |
| 198 | 226 |
| 199 - (void)onChange { | 227 - (void)onChange { |
| 200 if (!updatingBackend_) | 228 if (!updatingBackend_) |
| 201 [self reloadData]; | 229 [self reloadData]; |
| 202 } | 230 } |
| 203 | 231 |
| 204 @end | 232 @end |
| OLD | NEW |