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

Side by Side Diff: ios/chrome/browser/ui/settings/content_settings_collection_view_controller.mm

Issue 2814813003: [ObjC ARC] Converts ios/chrome/browser/ui/settings:settings_arc_transition to ARC. (Closed)
Patch Set: rebase Created 3 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/content_settings_collection_view_control ler.h" 5 #import "ios/chrome/browser/ui/settings/content_settings_collection_view_control ler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/scoped_nsobject.h"
9 #include "components/content_settings/core/browser/host_content_settings_map.h" 8 #include "components/content_settings/core/browser/host_content_settings_map.h"
10 #include "components/content_settings/core/common/content_settings.h" 9 #include "components/content_settings/core/common/content_settings.h"
11 #include "components/content_settings/core/common/content_settings_types.h" 10 #include "components/content_settings/core/common/content_settings_types.h"
12 #include "components/prefs/pref_change_registrar.h" 11 #include "components/prefs/pref_change_registrar.h"
13 #include "components/prefs/pref_service.h" 12 #include "components/prefs/pref_service.h"
14 #include "components/strings/grit/components_strings.h" 13 #include "components/strings/grit/components_strings.h"
15 #include "components/translate/core/common/translate_pref_names.h" 14 #include "components/translate/core/common/translate_pref_names.h"
16 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
17 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h" 16 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h"
18 #import "ios/chrome/browser/prefs/pref_observer_bridge.h" 17 #import "ios/chrome/browser/prefs/pref_observer_bridge.h"
19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
20 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
21 #import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller. h" 20 #import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller. h"
22 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" 21 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
23 #import "ios/chrome/browser/ui/settings/translate_collection_view_controller.h" 22 #import "ios/chrome/browser/ui/settings/translate_collection_view_controller.h"
24 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h" 23 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h"
25 #include "ios/chrome/grit/ios_strings.h" 24 #include "ios/chrome/grit/ios_strings.h"
26 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 25 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
27 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 26 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
28 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/l10n/l10n_util_mac.h" 28 #include "ui/base/l10n/l10n_util_mac.h"
30 29
30 #if !defined(__has_feature) || !__has_feature(objc_arc)
31 #error "This file requires ARC support."
32 #endif
33
31 namespace { 34 namespace {
32 35
33 typedef NS_ENUM(NSInteger, SectionIdentifier) { 36 typedef NS_ENUM(NSInteger, SectionIdentifier) {
34 SectionIdentifierSettings = kSectionIdentifierEnumZero, 37 SectionIdentifierSettings = kSectionIdentifierEnumZero,
35 }; 38 };
36 39
37 typedef NS_ENUM(NSInteger, ItemType) { 40 typedef NS_ENUM(NSInteger, ItemType) {
38 ItemTypeSettingsBlockPopups = kItemTypeEnumZero, 41 ItemTypeSettingsBlockPopups = kItemTypeEnumZero,
39 ItemTypeSettingsTranslate, 42 ItemTypeSettingsTranslate,
40 }; 43 };
41 44
42 } // namespace 45 } // namespace
43 46
44 @interface ContentSettingsCollectionViewController ()<PrefObserverDelegate, 47 @interface ContentSettingsCollectionViewController ()<PrefObserverDelegate,
45 BooleanObserver> { 48 BooleanObserver> {
46 // Pref observer to track changes to prefs. 49 // Pref observer to track changes to prefs.
47 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; 50 std::unique_ptr<PrefObserverBridge> _prefObserverBridge;
48 // Registrar for pref changes notifications. 51 // Registrar for pref changes notifications.
49 PrefChangeRegistrar _prefChangeRegistrar; 52 PrefChangeRegistrar _prefChangeRegistrar;
50 53
51 // The observable boolean that binds to the "Disable Popups" setting state. 54 // The observable boolean that binds to the "Disable Popups" setting state.
52 base::scoped_nsobject<ContentSettingBackedBoolean> _disablePopupsSetting; 55 ContentSettingBackedBoolean* _disablePopupsSetting;
53 56
54 // Updatable Items 57 // Updatable Items
55 base::scoped_nsobject<CollectionViewDetailItem> _blockPopupsDetailItem; 58 CollectionViewDetailItem* _blockPopupsDetailItem;
56 base::scoped_nsobject<CollectionViewDetailItem> _translateDetailItem; 59 CollectionViewDetailItem* _translateDetailItem;
57 } 60 }
58 61
59 // Returns the value for the default setting with ID |settingID|. 62 // Returns the value for the default setting with ID |settingID|.
60 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID; 63 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID;
61 64
62 // Helpers to create collection view items. 65 // Helpers to create collection view items.
63 - (id)blockPopupsItem; 66 - (id)blockPopupsItem;
64 - (id)translateItem; 67 - (id)translateItem;
65 68
66 @end 69 @end
(...skipping 11 matching lines...) Expand all
78 81
79 _prefChangeRegistrar.Init(browserState->GetPrefs()); 82 _prefChangeRegistrar.Init(browserState->GetPrefs());
80 _prefObserverBridge.reset(new PrefObserverBridge(self)); 83 _prefObserverBridge.reset(new PrefObserverBridge(self));
81 // Register to observe any changes on Perf backed values displayed by the 84 // Register to observe any changes on Perf backed values displayed by the
82 // screen. 85 // screen.
83 _prefObserverBridge->ObserveChangesForPreference(prefs::kEnableTranslate, 86 _prefObserverBridge->ObserveChangesForPreference(prefs::kEnableTranslate,
84 &_prefChangeRegistrar); 87 &_prefChangeRegistrar);
85 88
86 HostContentSettingsMap* settingsMap = 89 HostContentSettingsMap* settingsMap =
87 ios::HostContentSettingsMapFactory::GetForBrowserState(browserState); 90 ios::HostContentSettingsMapFactory::GetForBrowserState(browserState);
88 _disablePopupsSetting.reset([[ContentSettingBackedBoolean alloc] 91 _disablePopupsSetting = [[ContentSettingBackedBoolean alloc]
89 initWithHostContentSettingsMap:settingsMap 92 initWithHostContentSettingsMap:settingsMap
90 settingID:CONTENT_SETTINGS_TYPE_POPUPS 93 settingID:CONTENT_SETTINGS_TYPE_POPUPS
91 inverted:YES]); 94 inverted:YES];
92 [_disablePopupsSetting setObserver:self]; 95 [_disablePopupsSetting setObserver:self];
93 96
94 [self loadModel]; 97 [self loadModel];
95 } 98 }
96 return self; 99 return self;
97 } 100 }
98 101
99 - (void)dealloc { 102 - (void)dealloc {
100 [_disablePopupsSetting setObserver:nil]; 103 [_disablePopupsSetting setObserver:nil];
101 [super dealloc];
102 } 104 }
103 105
104 - (instancetype)init { 106 - (instancetype)init {
105 NOTREACHED(); 107 NOTREACHED();
106 return nil; 108 return nil;
107 } 109 }
108 110
109 - (void)loadModel { 111 - (void)loadModel {
110 [super loadModel]; 112 [super loadModel];
111 113
112 CollectionViewModel* model = self.collectionViewModel; 114 CollectionViewModel* model = self.collectionViewModel;
113 [model addSectionWithIdentifier:SectionIdentifierSettings]; 115 [model addSectionWithIdentifier:SectionIdentifierSettings];
114 [model addItem:[self blockPopupsItem] 116 [model addItem:[self blockPopupsItem]
115 toSectionWithIdentifier:SectionIdentifierSettings]; 117 toSectionWithIdentifier:SectionIdentifierSettings];
116 [model addItem:[self translateItem] 118 [model addItem:[self translateItem]
117 toSectionWithIdentifier:SectionIdentifierSettings]; 119 toSectionWithIdentifier:SectionIdentifierSettings];
118 } 120 }
119 121
120 - (CollectionViewItem*)blockPopupsItem { 122 - (CollectionViewItem*)blockPopupsItem {
121 _blockPopupsDetailItem.reset([[CollectionViewDetailItem alloc] 123 _blockPopupsDetailItem = [[CollectionViewDetailItem alloc]
122 initWithType:ItemTypeSettingsBlockPopups]); 124 initWithType:ItemTypeSettingsBlockPopups];
123 NSString* subtitle = [_disablePopupsSetting value] 125 NSString* subtitle = [_disablePopupsSetting value]
124 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 126 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
125 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 127 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
126 _blockPopupsDetailItem.get().text = 128 _blockPopupsDetailItem.text = l10n_util::GetNSString(IDS_IOS_BLOCK_POPUPS);
127 l10n_util::GetNSString(IDS_IOS_BLOCK_POPUPS); 129 _blockPopupsDetailItem.detailText = subtitle;
128 _blockPopupsDetailItem.get().detailText = subtitle; 130 _blockPopupsDetailItem.accessoryType =
129 _blockPopupsDetailItem.get().accessoryType =
130 MDCCollectionViewCellAccessoryDisclosureIndicator; 131 MDCCollectionViewCellAccessoryDisclosureIndicator;
131 _blockPopupsDetailItem.get().accessibilityTraits |= 132 _blockPopupsDetailItem.accessibilityTraits |= UIAccessibilityTraitButton;
132 UIAccessibilityTraitButton;
133 return _blockPopupsDetailItem; 133 return _blockPopupsDetailItem;
134 } 134 }
135 135
136 - (CollectionViewItem*)translateItem { 136 - (CollectionViewItem*)translateItem {
137 _translateDetailItem.reset([[CollectionViewDetailItem alloc] 137 _translateDetailItem =
138 initWithType:ItemTypeSettingsTranslate]); 138 [[CollectionViewDetailItem alloc] initWithType:ItemTypeSettingsTranslate];
139 BOOL enabled = browserState_->GetPrefs()->GetBoolean(prefs::kEnableTranslate); 139 BOOL enabled = browserState_->GetPrefs()->GetBoolean(prefs::kEnableTranslate);
140 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 140 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
141 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 141 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
142 _translateDetailItem.get().text = 142 _translateDetailItem.text = l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING);
143 l10n_util::GetNSString(IDS_IOS_TRANSLATE_SETTING); 143 _translateDetailItem.detailText = subtitle;
144 _translateDetailItem.get().detailText = subtitle; 144 _translateDetailItem.accessoryType =
145 _translateDetailItem.get().accessoryType =
146 MDCCollectionViewCellAccessoryDisclosureIndicator; 145 MDCCollectionViewCellAccessoryDisclosureIndicator;
147 _translateDetailItem.get().accessibilityTraits |= UIAccessibilityTraitButton; 146 _translateDetailItem.accessibilityTraits |= UIAccessibilityTraitButton;
148 return _translateDetailItem; 147 return _translateDetailItem;
149 } 148 }
150 149
151 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID { 150 - (ContentSetting)getContentSetting:(ContentSettingsType)settingID {
152 return ios::HostContentSettingsMapFactory::GetForBrowserState(browserState_) 151 return ios::HostContentSettingsMapFactory::GetForBrowserState(browserState_)
153 ->GetDefaultContentSetting(settingID, NULL); 152 ->GetDefaultContentSetting(settingID, NULL);
154 } 153 }
155 154
156 #pragma mark - UICollectionViewDelegate 155 #pragma mark - UICollectionViewDelegate
157 156
158 - (void)collectionView:(UICollectionView*)collectionView 157 - (void)collectionView:(UICollectionView*)collectionView
159 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 158 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
160 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 159 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
161 160
162 NSInteger itemType = 161 NSInteger itemType =
163 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 162 [self.collectionViewModel itemTypeForIndexPath:indexPath];
164 switch (itemType) { 163 switch (itemType) {
165 case ItemTypeSettingsBlockPopups: { 164 case ItemTypeSettingsBlockPopups: {
166 base::scoped_nsobject<UIViewController> controller( 165 UIViewController* controller =
167 [[BlockPopupsCollectionViewController alloc] 166 [[BlockPopupsCollectionViewController alloc]
168 initWithBrowserState:browserState_]); 167 initWithBrowserState:browserState_];
169 [self.navigationController pushViewController:controller animated:YES]; 168 [self.navigationController pushViewController:controller animated:YES];
170 break; 169 break;
171 } 170 }
172 case ItemTypeSettingsTranslate: { 171 case ItemTypeSettingsTranslate: {
173 base::scoped_nsobject<UIViewController> controller( 172 UIViewController* controller = [[TranslateCollectionViewController alloc]
174 [[TranslateCollectionViewController alloc] 173 initWithPrefs:browserState_->GetPrefs()];
175 initWithPrefs:browserState_->GetPrefs()]);
176 [self.navigationController pushViewController:controller animated:YES]; 174 [self.navigationController pushViewController:controller animated:YES];
177 break; 175 break;
178 } 176 }
179 } 177 }
180 } 178 }
181 179
182 #pragma mark - PrefObserverDelegate 180 #pragma mark - PrefObserverDelegate
183 181
184 - (void)onPreferenceChanged:(const std::string&)preferenceName { 182 - (void)onPreferenceChanged:(const std::string&)preferenceName {
185 if (preferenceName == prefs::kEnableTranslate) { 183 if (preferenceName == prefs::kEnableTranslate) {
186 BOOL enabled = browserState_->GetPrefs()->GetBoolean(preferenceName); 184 BOOL enabled = browserState_->GetPrefs()->GetBoolean(preferenceName);
187 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 185 NSString* subtitle = enabled ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
188 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 186 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
189 _translateDetailItem.get().detailText = subtitle; 187 _translateDetailItem.detailText = subtitle;
190 [self reconfigureCellsForItems:@[ _translateDetailItem ] 188 [self reconfigureCellsForItems:@[ _translateDetailItem ]
191 inSectionWithIdentifier:SectionIdentifierSettings]; 189 inSectionWithIdentifier:SectionIdentifierSettings];
192 } 190 }
193 } 191 }
194 192
195 #pragma mark - BooleanObserver 193 #pragma mark - BooleanObserver
196 194
197 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean { 195 - (void)booleanDidChange:(id<ObservableBoolean>)observableBoolean {
198 DCHECK_EQ(observableBoolean, _disablePopupsSetting.get()); 196 DCHECK_EQ(observableBoolean, _disablePopupsSetting);
199 197
200 NSString* subtitle = [_disablePopupsSetting value] 198 NSString* subtitle = [_disablePopupsSetting value]
201 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON) 199 ? l10n_util::GetNSString(IDS_IOS_SETTING_ON)
202 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF); 200 : l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
203 // Update the item. 201 // Update the item.
204 _blockPopupsDetailItem.get().detailText = subtitle; 202 _blockPopupsDetailItem.detailText = subtitle;
205 203
206 // Update the cell. 204 // Update the cell.
207 [self reconfigureCellsForItems:@[ _blockPopupsDetailItem ] 205 [self reconfigureCellsForItems:@[ _blockPopupsDetailItem ]
208 inSectionWithIdentifier:SectionIdentifierSettings]; 206 inSectionWithIdentifier:SectionIdentifierSettings];
209 } 207 }
210 208
211 @end 209 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698