From 748911bf72714626ab9d7d457df8d8025fe3b3a1 Mon Sep 17 00:00:00 2001 From: anthonyvd Date: Thu, 2 Jul 2015 11:30:28 -0700 Subject: [PATCH] Display tooltips in User Menu when the profile name is not editable. This should fix the issue where no tooltip would be shown for long supervised users' names. BUG=482440 TEST= 1. Create a supervised user with a very long name 2. Open the User Menu by clicking on the Avatar Button 3. Hover over the profile name label 4. A tooltip displaying the full profile name should be shown Note: No tooltip should be shown when the name is short enough to not be elided in the User Menu. Review URL: https://codereview.chromium.org/1210153011 Cr-Commit-Position: refs/heads/master@{#337244} --- .../ui/cocoa/profiles/profile_chooser_controller.mm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm index 9e6140c56bd0..b7d79c1d9579 100644 --- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm +++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm @@ -659,6 +659,11 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, profile_ = profile; controller_ = controller; + CGFloat availableWidth = frameRect.size.width; + NSSize textSize = [profileName sizeWithAttributes:@{ + NSFontAttributeName : [self font] + }]; + if (editingAllowed) { // Show an "edit" pencil icon when hovering over. In the default state, // we need to create an empty placeholder of the correct size, so that @@ -711,14 +716,17 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver, base::SysNSStringToUTF16(profileName)) forAttribute:NSAccessibilityTitleAttribute]; - NSSize textSize = [profileName sizeWithAttributes:@{ + // Recompute the available width for the name since the icon takes space. + availableWidth -= [hoverImage size].width * 2; + // The profileNameTextField_ might size the text differently. + textSize = [profileName sizeWithAttributes:@{ NSFontAttributeName : [profileNameTextField_ font] }]; - - if (textSize.width > frameRect.size.width - [hoverImage size].width * 2) - [self setToolTip:profileName]; } + if (textSize.width > availableWidth) + [self setToolTip:profileName]; + [[self cell] accessibilitySetOverrideValue:NSAccessibilityButtonRole forAttribute:NSAccessibilityRoleAttribute]; [[self cell] -- 2.11.4.GIT