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

Side by Side Diff: ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item.mm

Issue 2625423003: [ios] Fix settings switch accessibility value and hint (Closed)
Patch Set: Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/collection_view/cells/collection_view_switch_item .h" 5 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h"
6 6
7 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 7 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
8 #include "ios/chrome/grit/ios_strings.h"
8 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 9 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
9 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 10 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
11 #include "ui/base/l10n/l10n_util_mac.h"
10 12
11 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support." 14 #error "This file requires ARC support."
13 #endif 15 #endif
14 16
15 namespace { 17 namespace {
16 // Padding used on the leading and trailing edges of the cell. 18 // Padding used on the leading and trailing edges of the cell.
17 const CGFloat kHorizontalPadding = 16; 19 const CGFloat kHorizontalPadding = 16;
18 20
19 // Padding used on the top and bottom edges of the cell. 21 // Padding used on the top and bottom edges of the cell.
20 const CGFloat kVerticalPadding = 16; 22 const CGFloat kVerticalPadding = 16;
21 } // namespace 23 } // namespace
22 24
23 @implementation CollectionViewSwitchItem 25 @implementation CollectionViewSwitchItem
24 26
25 @synthesize text = _text; 27 @synthesize text = _text;
26 @synthesize on = _on; 28 @synthesize on = _on;
27 @synthesize enabled = _enabled; 29 @synthesize enabled = _enabled;
28 30
29 - (instancetype)initWithType:(NSInteger)type { 31 - (instancetype)initWithType:(NSInteger)type {
30 self = [super initWithType:type]; 32 self = [super initWithType:type];
31 if (self) { 33 if (self) {
32 self.cellClass = [CollectionViewSwitchCell class]; 34 self.cellClass = [CollectionViewSwitchCell class];
33 self.enabled = YES; 35 self.enabled = YES;
34 self.accessibilityTraits |= UIAccessibilityTraitButton;
lpromero 2017/01/13 10:01:33 No action needed: Agreed. Being as similar to iOS
35 } 36 }
36 return self; 37 return self;
37 } 38 }
38 39
39 #pragma mark CollectionViewItem 40 #pragma mark CollectionViewItem
40 41
41 - (void)configureCell:(CollectionViewSwitchCell*)cell { 42 - (void)configureCell:(CollectionViewSwitchCell*)cell {
42 [super configureCell:cell]; 43 [super configureCell:cell];
43 cell.textLabel.text = self.text; 44 cell.textLabel.text = self.text;
44 cell.switchView.enabled = self.isEnabled; 45 cell.switchView.enabled = self.isEnabled;
(...skipping 22 matching lines...) Expand all
67 [self.contentView addSubview:_textLabel]; 68 [self.contentView addSubview:_textLabel];
68 69
69 _textLabel.font = 70 _textLabel.font =
70 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14]; 71 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14];
71 _textLabel.textColor = [[MDCPalette greyPalette] tint900]; 72 _textLabel.textColor = [[MDCPalette greyPalette] tint900];
72 _textLabel.numberOfLines = 0; 73 _textLabel.numberOfLines = 0;
73 74
74 _switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; 75 _switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
75 _switchView.translatesAutoresizingMaskIntoConstraints = NO; 76 _switchView.translatesAutoresizingMaskIntoConstraints = NO;
76 _switchView.onTintColor = [[MDCPalette cr_bluePalette] tint500]; 77 _switchView.onTintColor = [[MDCPalette cr_bluePalette] tint500];
78 _switchView.accessibilityHint = l10n_util::GetNSString(
79 IDS_IOS_TOGGLE_SETTING_SWITCH_ACCESSIBILITY_HINT);
77 [self.contentView addSubview:_switchView]; 80 [self.contentView addSubview:_switchView];
78 81
79 // Set up the constraints. 82 // Set up the constraints.
80 [NSLayoutConstraint activateConstraints:@[ 83 [NSLayoutConstraint activateConstraints:@[
81 [_textLabel.leadingAnchor 84 [_textLabel.leadingAnchor
82 constraintEqualToAnchor:self.contentView.leadingAnchor 85 constraintEqualToAnchor:self.contentView.leadingAnchor
83 constant:kHorizontalPadding], 86 constant:kHorizontalPadding],
84 [_switchView.trailingAnchor 87 [_switchView.trailingAnchor
85 constraintEqualToAnchor:self.contentView.trailingAnchor 88 constraintEqualToAnchor:self.contentView.trailingAnchor
86 constant:-kHorizontalPadding], 89 constant:-kHorizontalPadding],
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 134
132 - (CGPoint)accessibilityActivationPoint { 135 - (CGPoint)accessibilityActivationPoint {
133 // Center the activation point over the switch, so that double-tapping toggles 136 // Center the activation point over the switch, so that double-tapping toggles
134 // the switch. 137 // the switch.
135 CGRect switchFrame = 138 CGRect switchFrame =
136 UIAccessibilityConvertFrameToScreenCoordinates(_switchView.frame, self); 139 UIAccessibilityConvertFrameToScreenCoordinates(_switchView.frame, self);
137 return CGPointMake(CGRectGetMidX(switchFrame), CGRectGetMidY(switchFrame)); 140 return CGPointMake(CGRectGetMidX(switchFrame), CGRectGetMidY(switchFrame));
138 } 141 }
139 142
140 - (NSString*)accessibilityHint { 143 - (NSString*)accessibilityHint {
141 return _switchView.accessibilityHint; 144 if (_switchView.isEnabled) {
145 return _switchView.accessibilityHint;
146 } else {
147 return @"";
148 }
142 } 149 }
143 150
144 - (NSString*)accessibilityLabel { 151 - (NSString*)accessibilityLabel {
145 return _textLabel.text; 152 return _textLabel.text;
146 } 153 }
147 154
148 - (NSString*)accessibilityValue { 155 - (NSString*)accessibilityValue {
149 return _switchView.accessibilityValue; 156 if (_switchView.on) {
157 return l10n_util::GetNSString(IDS_IOS_SETTING_ON);
158 } else {
159 return l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
160 }
150 } 161 }
151 162
152 @end 163 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698