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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_touch_bar.mm

Issue 2796303007: [Mac] Added Accessibility Labels to the Default Touch Bar (Closed)
Patch Set: Nit 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/ui/cocoa/browser_window_touch_bar.h" 5 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 #import "base/mac/sdk_forward_declarations.h" 11 #import "base/mac/sdk_forward_declarations.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/app/vector_icons/vector_icons.h" 15 #include "chrome/app/vector_icons/vector_icons.h"
16 #include "chrome/browser/command_updater.h" 16 #include "chrome/browser/command_updater.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_command_controller.h" 20 #include "chrome/browser/ui/browser_command_controller.h"
21 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 21 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
22 #include "chrome/common/chrome_features.h" 22 #include "chrome/common/chrome_features.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
25 #include "components/omnibox/browser/vector_icons.h" 25 #include "components/omnibox/browser/vector_icons.h"
26 #include "components/prefs/pref_member.h" 26 #include "components/prefs/pref_member.h"
27 #include "components/search_engines/util.h" 27 #include "components/search_engines/util.h"
28 #include "components/strings/grit/components_strings.h"
28 #include "components/toolbar/vector_icons.h" 29 #include "components/toolbar/vector_icons.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/l10n/l10n_util_mac.h"
30 #include "ui/gfx/color_palette.h" 32 #include "ui/gfx/color_palette.h"
31 #include "ui/gfx/color_utils.h" 33 #include "ui/gfx/color_utils.h"
32 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
33 #include "ui/gfx/image/image_skia_util_mac.h" 35 #include "ui/gfx/image/image_skia_util_mac.h"
34 #include "ui/gfx/paint_vector_icon.h" 36 #include "ui/gfx/paint_vector_icon.h"
35 #include "ui/vector_icons/vector_icons.h" 37 #include "ui/vector_icons/vector_icons.h"
36 38
37 namespace { 39 namespace {
38 40
39 // The touch bar actions that are being recorded in a histogram. These values 41 // The touch bar actions that are being recorded in a histogram. These values
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 SkColor color = kTouchBarDefaultIconColor) { 84 SkColor color = kTouchBarDefaultIconColor) {
83 return NSImageFromImageSkiaWithColorSpace( 85 return NSImageFromImageSkiaWithColorSpace(
84 gfx::CreateVectorIcon(icon, kTouchBarIconSize, color), 86 gfx::CreateVectorIcon(icon, kTouchBarIconSize, color),
85 base::mac::GetSRGBColorSpace()); 87 base::mac::GetSRGBColorSpace());
86 } 88 }
87 89
88 // Creates a NSButton for the touch bar. 90 // Creates a NSButton for the touch bar.
89 NSButton* CreateTouchBarButton(const gfx::VectorIcon& icon, 91 NSButton* CreateTouchBarButton(const gfx::VectorIcon& icon,
90 BrowserWindowTouchBar* owner, 92 BrowserWindowTouchBar* owner,
91 int command, 93 int command,
94 int tooltip_id,
92 SkColor color = kTouchBarDefaultIconColor) { 95 SkColor color = kTouchBarDefaultIconColor) {
93 NSButton* button = 96 NSButton* button =
94 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) 97 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color)
95 target:owner 98 target:owner
96 action:@selector(executeCommand:)]; 99 action:@selector(executeCommand:)];
97 button.tag = command; 100 button.tag = command;
101 [button setAccessibilityLabel:l10n_util::GetNSString(tooltip_id)];
98 return button; 102 return button;
99 } 103 }
100 104
101 TouchBarAction TouchBarActionFromCommand(int command) { 105 TouchBarAction TouchBarActionFromCommand(int command) {
102 switch (command) { 106 switch (command) {
103 case IDC_BACK: 107 case IDC_BACK:
104 return TouchBarAction::BACK; 108 return TouchBarAction::BACK;
105 case IDC_FORWARD: 109 case IDC_FORWARD:
106 return TouchBarAction::FORWARD; 110 return TouchBarAction::FORWARD;
107 case IDC_STOP: 111 case IDC_STOP:
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (!touchBar) 231 if (!touchBar)
228 return nil; 232 return nil;
229 233
230 base::scoped_nsobject<NSCustomTouchBarItem> touchBarItem([[NSClassFromString( 234 base::scoped_nsobject<NSCustomTouchBarItem> touchBarItem([[NSClassFromString(
231 @"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]); 235 @"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]);
232 if ([identifier isEqualTo:kBackForwardTouchId]) { 236 if ([identifier isEqualTo:kBackForwardTouchId]) {
233 [touchBarItem setView:[self backOrForwardTouchBarView]]; 237 [touchBarItem setView:[self backOrForwardTouchBarView]];
234 } else if ([identifier isEqualTo:kReloadOrStopTouchId]) { 238 } else if ([identifier isEqualTo:kReloadOrStopTouchId]) {
235 const gfx::VectorIcon& icon = 239 const gfx::VectorIcon& icon =
236 isPageLoading_ ? kNavigateStopIcon : kNavigateReloadIcon; 240 isPageLoading_ ? kNavigateStopIcon : kNavigateReloadIcon;
237 int command_id = isPageLoading_ ? IDC_STOP : IDC_RELOAD; 241 int commandId = isPageLoading_ ? IDC_STOP : IDC_RELOAD;
238 [touchBarItem setView:CreateTouchBarButton(icon, self, command_id)]; 242 int tooltipId = isPageLoading_ ? IDS_TOOLTIP_STOP : IDS_TOOLTIP_RELOAD;
243 [touchBarItem
244 setView:CreateTouchBarButton(icon, self, commandId, tooltipId)];
239 } else if ([identifier isEqualTo:kHomeTouchId]) { 245 } else if ([identifier isEqualTo:kHomeTouchId]) {
246 [touchBarItem setView:CreateTouchBarButton(kNavigateHomeIcon, self,
247 IDC_HOME, IDS_TOOLTIP_HOME)];
248 } else if ([identifier isEqualTo:kNewTabTouchId]) {
240 [touchBarItem 249 [touchBarItem
241 setView:CreateTouchBarButton(kNavigateHomeIcon, self, IDC_HOME)]; 250 setView:CreateTouchBarButton(kNewTabMacTouchbarIcon, self, IDC_NEW_TAB,
242 } else if ([identifier isEqualTo:kNewTabTouchId]) { 251 IDS_TOOLTIP_NEW_TAB)];
243 [touchBarItem setView:CreateTouchBarButton(kNewTabMacTouchbarIcon, self,
244 IDC_NEW_TAB)];
245 } else if ([identifier isEqualTo:kStarTouchId]) { 252 } else if ([identifier isEqualTo:kStarTouchId]) {
246 const gfx::VectorIcon& icon = 253 const gfx::VectorIcon& icon =
247 isStarred_ ? toolbar::kStarActiveIcon : toolbar::kStarIcon; 254 isStarred_ ? toolbar::kStarActiveIcon : toolbar::kStarIcon;
248 SkColor iconColor = 255 SkColor iconColor =
249 isStarred_ ? kTouchBarStarActiveColor : kTouchBarDefaultIconColor; 256 isStarred_ ? kTouchBarStarActiveColor : kTouchBarDefaultIconColor;
250 [touchBarItem 257 int tooltipId = isStarred_ ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR;
251 setView:CreateTouchBarButton(icon, self, IDC_BOOKMARK_PAGE, iconColor)]; 258 [touchBarItem setView:CreateTouchBarButton(icon, self, IDC_BOOKMARK_PAGE,
259 tooltipId, iconColor)];
252 } else if ([identifier isEqualTo:kSearchTouchId]) { 260 } else if ([identifier isEqualTo:kSearchTouchId]) {
253 [touchBarItem setView:[self searchTouchBarView]]; 261 [touchBarItem setView:[self searchTouchBarView]];
254 } 262 }
255 263
256 return touchBarItem.autorelease(); 264 return touchBarItem.autorelease();
257 } 265 }
258 266
259 - (NSView*)backOrForwardTouchBarView { 267 - (NSView*)backOrForwardTouchBarView {
260 NSArray* images = @[ 268 NSArray* images = @[
261 CreateNSImageFromIcon(ui::kBackArrowIcon), 269 CreateNSImageFromIcon(ui::kBackArrowIcon),
262 CreateNSImageFromIcon(ui::kForwardArrowIcon) 270 CreateNSImageFromIcon(ui::kForwardArrowIcon)
263 ]; 271 ];
264 272
265 NSSegmentedControl* control = [NSSegmentedControl 273 NSSegmentedControl* control = [NSSegmentedControl
266 segmentedControlWithImages:images 274 segmentedControlWithImages:images
267 trackingMode:NSSegmentSwitchTrackingMomentary 275 trackingMode:NSSegmentSwitchTrackingMomentary
268 target:self 276 target:self
269 action:@selector(backOrForward:)]; 277 action:@selector(backOrForward:)];
270 control.segmentStyle = NSSegmentStyleSeparated; 278 control.segmentStyle = NSSegmentStyleSeparated;
271 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_BACK) 279 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_BACK)
272 forSegment:kBackSegmentIndex]; 280 forSegment:kBackSegmentIndex];
273 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_FORWARD) 281 [control setEnabled:commandUpdater_->IsCommandEnabled(IDC_FORWARD)
274 forSegment:kForwardSegmentIndex]; 282 forSegment:kForwardSegmentIndex];
283
284 // Use the accessibility protocol to get the children.
285 // Use NSAccessibilityUnignoredDescendant to be sure we start with the correct
286 // object.
287 id segmentElement = NSAccessibilityUnignoredDescendant(control);
288 NSArray* segments = [segmentElement
289 accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
290 NSEnumerator* e = [segments objectEnumerator];
291 [[e nextObject] accessibilitySetOverrideValue:l10n_util::GetNSString(
292 IDS_TOOLTIP_TOUCH_BAR_BACK)
293 forAttribute:NSAccessibilityTitleAttribute];
294 [[e nextObject]
295 accessibilitySetOverrideValue:l10n_util::GetNSString(
296 IDS_TOOLTIP_TOUCH_BAR_FORWARD)
297 forAttribute:NSAccessibilityTitleAttribute];
275 return control; 298 return control;
276 } 299 }
277 300
278 - (NSView*)searchTouchBarView { 301 - (NSView*)searchTouchBarView {
279 TemplateURLService* templateUrlService = 302 TemplateURLService* templateUrlService =
280 TemplateURLServiceFactory::GetForProfile(browser_->profile()); 303 TemplateURLServiceFactory::GetForProfile(browser_->profile());
281 const TemplateURL* defaultProvider = 304 const TemplateURL* defaultProvider =
282 templateUrlService->GetDefaultSearchProvider(); 305 templateUrlService->GetDefaultSearchProvider();
283 BOOL isGoogle = 306 BOOL isGoogle =
284 defaultProvider->GetEngineType(templateUrlService->search_terms_data()) == 307 defaultProvider->GetEngineType(templateUrlService->search_terms_data()) ==
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 commandUpdater_->ExecuteCommand(command); 343 commandUpdater_->ExecuteCommand(command);
321 } 344 }
322 345
323 - (void)executeCommand:(id)sender { 346 - (void)executeCommand:(id)sender {
324 int command = [sender tag]; 347 int command = [sender tag];
325 LogTouchBarUMA(command); 348 LogTouchBarUMA(command);
326 commandUpdater_->ExecuteCommand(command); 349 commandUpdater_->ExecuteCommand(command);
327 } 350 }
328 351
329 @end 352 @end
OLDNEW
« chrome/app/generated_resources.grd ('K') | « chrome/app/generated_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698