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

Side by Side Diff: ios/chrome/browser/ui/settings/cells/sync_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/settings/cells/sync_switch_item.h" 5 #import "ios/chrome/browser/ui/settings/cells/sync_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.
(...skipping 11 matching lines...) Expand all
31 @synthesize detailText = _detailText; 33 @synthesize detailText = _detailText;
32 @synthesize on = _on; 34 @synthesize on = _on;
33 @synthesize enabled = _enabled; 35 @synthesize enabled = _enabled;
34 @synthesize dataType = _dataType; 36 @synthesize dataType = _dataType;
35 37
36 - (instancetype)initWithType:(NSInteger)type { 38 - (instancetype)initWithType:(NSInteger)type {
37 self = [super initWithType:type]; 39 self = [super initWithType:type];
38 if (self) { 40 if (self) {
39 self.cellClass = [SyncSwitchCell class]; 41 self.cellClass = [SyncSwitchCell class];
40 self.enabled = YES; 42 self.enabled = YES;
41 self.accessibilityTraits |= UIAccessibilityTraitButton;
42 } 43 }
43 return self; 44 return self;
44 } 45 }
45 46
46 - (void)configureCell:(SyncSwitchCell*)cell { 47 - (void)configureCell:(SyncSwitchCell*)cell {
47 [super configureCell:cell]; 48 [super configureCell:cell];
48 cell.textLabel.text = self.text; 49 cell.textLabel.text = self.text;
49 cell.detailTextLabel.text = self.detailText; 50 cell.detailTextLabel.text = self.detailText;
50 cell.switchView.enabled = self.isEnabled; 51 cell.switchView.enabled = self.isEnabled;
51 cell.switchView.on = self.isOn; 52 cell.switchView.on = self.isOn;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 [self.contentView addSubview:_detailTextLabel]; 90 [self.contentView addSubview:_detailTextLabel];
90 91
91 _detailTextLabel.font = 92 _detailTextLabel.font =
92 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14]; 93 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14];
93 _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; 94 _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500];
94 _detailTextLabel.numberOfLines = 0; 95 _detailTextLabel.numberOfLines = 0;
95 96
96 _switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; 97 _switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
97 _switchView.translatesAutoresizingMaskIntoConstraints = NO; 98 _switchView.translatesAutoresizingMaskIntoConstraints = NO;
98 _switchView.onTintColor = [[MDCPalette cr_bluePalette] tint500]; 99 _switchView.onTintColor = [[MDCPalette cr_bluePalette] tint500];
100 _switchView.accessibilityHint = l10n_util::GetNSString(
101 IDS_IOS_TOGGLE_SETTING_SWITCH_ACCESSIBILITY_HINT);
99 [self.contentView addSubview:_switchView]; 102 [self.contentView addSubview:_switchView];
100 103
101 [self setConstraints]; 104 [self setConstraints];
102 } 105 }
103 106
104 return self; 107 return self;
105 } 108 }
106 109
107 - (void)setConstraints { 110 - (void)setConstraints {
108 UIView* contentView = self.contentView; 111 UIView* contentView = self.contentView;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 175
173 - (CGPoint)accessibilityActivationPoint { 176 - (CGPoint)accessibilityActivationPoint {
174 // Center the activation point over the switch, so that double-tapping toggles 177 // Center the activation point over the switch, so that double-tapping toggles
175 // the switch. 178 // the switch.
176 CGRect switchFrame = 179 CGRect switchFrame =
177 UIAccessibilityConvertFrameToScreenCoordinates(_switchView.frame, self); 180 UIAccessibilityConvertFrameToScreenCoordinates(_switchView.frame, self);
178 return CGPointMake(CGRectGetMidX(switchFrame), CGRectGetMidY(switchFrame)); 181 return CGPointMake(CGRectGetMidX(switchFrame), CGRectGetMidY(switchFrame));
179 } 182 }
180 183
181 - (NSString*)accessibilityHint { 184 - (NSString*)accessibilityHint {
182 return _switchView.accessibilityHint; 185 if (_switchView.isEnabled) {
186 return _switchView.accessibilityHint;
edchin 2017/01/12 22:13:45 Should both the row and the switch have the same h
sczs 2017/01/12 22:26:17 Yes, we are aiming to imitate iOS settings switche
edchin 2017/01/12 22:37:54 Why not set the hint only on the row if it is the
lpromero 2017/01/13 10:01:33 No action needed: If in the future we need to have
187 } else {
188 return @"";
189 }
183 } 190 }
184 191
185 - (NSString*)accessibilityLabel { 192 - (NSString*)accessibilityLabel {
186 if (_detailTextLabel.text) { 193 if (_detailTextLabel.text) {
187 return [NSString 194 return [NSString
188 stringWithFormat:@"%@, %@", _textLabel.text, _detailTextLabel.text]; 195 stringWithFormat:@"%@, %@", _textLabel.text, _detailTextLabel.text];
189 } 196 }
190 return _textLabel.text; 197 return _textLabel.text;
191 } 198 }
192 199
193 - (NSString*)accessibilityValue { 200 - (NSString*)accessibilityValue {
194 return _switchView.accessibilityValue; 201 if (_switchView.on) {
202 return l10n_util::GetNSString(IDS_IOS_SETTING_ON);
203 } else {
204 return l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
205 }
195 } 206 }
196 207
197 @end 208 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698