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

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

Issue 2817953002: CollectionViewTextItem no longer styles CollectionViewTextCell (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 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/block_popups_collection_view_controller. h" 5 #import "ios/chrome/browser/ui/settings/block_popups_collection_view_controller. h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/foundation_util.h" 8 #import "base/mac/foundation_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "components/content_settings/core/browser/host_content_settings_map.h" 11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 #include "components/content_settings/core/common/content_settings_pattern.h" 12 #include "components/content_settings/core/common/content_settings_pattern.h"
13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
14 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h" 14 #include "ios/chrome/browser/content_settings/host_content_settings_map_factory. h"
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h"
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h "
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
18 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" 19 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
19 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h" 20 #import "ios/chrome/browser/ui/settings/utils/content_setting_backed_boolean.h"
20 #include "ios/chrome/grit/ios_strings.h" 21 #include "ios/chrome/grit/ios_strings.h"
21 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.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"
22 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/l10n/l10n_util_mac.h" 25 #include "ui/base/l10n/l10n_util_mac.h"
24 26
25 #if !defined(__has_feature) || !__has_feature(objc_arc) 27 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support." 28 #error "This file requires ARC support."
27 #endif 29 #endif
28 30
29 namespace { 31 namespace {
30 32
31 typedef NS_ENUM(NSInteger, SectionIdentifier) { 33 typedef NS_ENUM(NSInteger, SectionIdentifier) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return YES; 130 return YES;
129 } 131 }
130 132
131 #pragma mark - UICollectionViewDataSource 133 #pragma mark - UICollectionViewDataSource
132 134
133 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView 135 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
134 cellForItemAtIndexPath:(NSIndexPath*)indexPath { 136 cellForItemAtIndexPath:(NSIndexPath*)indexPath {
135 UICollectionViewCell* cell = 137 UICollectionViewCell* cell =
136 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; 138 [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
137 139
138 if ([self.collectionViewModel itemTypeForIndexPath:indexPath] == 140 NSInteger itemType =
139 ItemTypeMainSwitch) { 141 [self.collectionViewModel itemTypeForIndexPath:indexPath];
142 if (itemType == ItemTypeMainSwitch) {
140 CollectionViewSwitchCell* switchCell = 143 CollectionViewSwitchCell* switchCell =
141 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell); 144 base::mac::ObjCCastStrict<CollectionViewSwitchCell>(cell);
142 [switchCell.switchView addTarget:self 145 [switchCell.switchView addTarget:self
143 action:@selector(blockPopupsSwitchChanged:) 146 action:@selector(blockPopupsSwitchChanged:)
144 forControlEvents:UIControlEventValueChanged]; 147 forControlEvents:UIControlEventValueChanged];
148 } else if (itemType == ItemTypeHeader || itemType == ItemTypeException) {
149 CollectionViewTextCell* textCell =
150 base::mac::ObjCCastStrict<CollectionViewTextCell>(cell);
151 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500];
145 } 152 }
146 return cell; 153 return cell;
147 } 154 }
148 155
149 #pragma mark - MDCCollectionViewEditingDelegate 156 #pragma mark - MDCCollectionViewEditingDelegate
150 157
151 - (BOOL)collectionView:(UICollectionView*)collectionView 158 - (BOOL)collectionView:(UICollectionView*)collectionView
152 canEditItemAtIndexPath:(NSIndexPath*)indexPath { 159 canEditItemAtIndexPath:(NSIndexPath*)indexPath {
153 // Any item in SectionIdentifierExceptions is editable. 160 // Any item in SectionIdentifierExceptions is editable.
154 return [self.collectionViewModel 161 return [self.collectionViewModel
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 296 }
290 } 297 }
291 298
292 - (void)populateExceptionsItems { 299 - (void)populateExceptionsItems {
293 CollectionViewModel* model = self.collectionViewModel; 300 CollectionViewModel* model = self.collectionViewModel;
294 [model addSectionWithIdentifier:SectionIdentifierExceptions]; 301 [model addSectionWithIdentifier:SectionIdentifierExceptions];
295 302
296 CollectionViewTextItem* header = 303 CollectionViewTextItem* header =
297 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; 304 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
298 header.text = l10n_util::GetNSString(IDS_IOS_POPUPS_ALLOWED); 305 header.text = l10n_util::GetNSString(IDS_IOS_POPUPS_ALLOWED);
299 header.textColor = [[MDCPalette greyPalette] tint500];
300 [model setHeader:header forSectionWithIdentifier:SectionIdentifierExceptions]; 306 [model setHeader:header forSectionWithIdentifier:SectionIdentifierExceptions];
301 307
302 for (size_t i = 0; i < _exceptions.GetSize(); ++i) { 308 for (size_t i = 0; i < _exceptions.GetSize(); ++i) {
303 std::string allowed_url; 309 std::string allowed_url;
304 _exceptions.GetString(i, &allowed_url); 310 _exceptions.GetString(i, &allowed_url);
305 CollectionViewTextItem* item = 311 CollectionViewTextItem* item =
306 [[CollectionViewTextItem alloc] initWithType:ItemTypeException]; 312 [[CollectionViewTextItem alloc] initWithType:ItemTypeException];
307 item.text = base::SysUTF8ToNSString(allowed_url); 313 item.text = base::SysUTF8ToNSString(allowed_url);
308 [model addItem:item toSectionWithIdentifier:SectionIdentifierExceptions]; 314 [model addItem:item toSectionWithIdentifier:SectionIdentifierExceptions];
309 } 315 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 [[strongSelf collectionViewModel] 347 [[strongSelf collectionViewModel]
342 removeSectionWithIdentifier:SectionIdentifierExceptions]; 348 removeSectionWithIdentifier:SectionIdentifierExceptions];
343 [[strongSelf collectionView] 349 [[strongSelf collectionView]
344 deleteSections:[NSIndexSet indexSetWithIndex:index]]; 350 deleteSections:[NSIndexSet indexSetWithIndex:index]];
345 } 351 }
346 completion:nil]; 352 completion:nil];
347 } 353 }
348 } 354 }
349 355
350 @end 356 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698