Commit 26848cb1 authored by maf@chromium.org's avatar maf@chromium.org

Mac. Build bookmark tooltips more intelligently, not showing title if same as URL.

Refactor tooltip string code to remove duplication.
R=mrossetti@chromium.org
BUG=70709
Review URL: http://codereview.chromium.org/6979021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86753 0039d316-1c4b-4281-b951-d872f2087c98
parent 8539c795
...@@ -349,7 +349,8 @@ willAnimateFromState:(bookmarks::VisualState)oldState ...@@ -349,7 +349,8 @@ willAnimateFromState:(bookmarks::VisualState)oldState
// Or from a context menu over either the bar or a button. // Or from a context menu over either the bar or a button.
- (IBAction)addPage:(id)sender; - (IBAction)addPage:(id)sender;
- (IBAction)addFolder:(id)sender; - (IBAction)addFolder:(id)sender;
// Make a relevant tooltip string for node.
- (NSString*)tooltipForNode:(const BookmarkNode*)node;
@end @end
// Redirects from BookmarkBarBridge, the C++ object which glues us to // Redirects from BookmarkBarBridge, the C++ object which glues us to
......
...@@ -1145,14 +1145,8 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -1145,14 +1145,8 @@ void RecordAppLaunch(Profile* profile, GURL url) {
[item setTarget:self]; [item setTarget:self];
[item setAction:@selector(openBookmarkMenuItem:)]; [item setAction:@selector(openBookmarkMenuItem:)];
[item setTag:[self menuTagFromNodeId:child->id()]]; [item setTag:[self menuTagFromNodeId:child->id()]];
if (child->is_url()) { if (child->is_url())
// Add a tooltip [item setToolTip:[self tooltipForNode:child]];
std::string url_string = child->GetURL().possibly_invalid_spec();
NSString* tooltip = [NSString stringWithFormat:@"%@\n%s",
base::SysUTF16ToNSString(child->GetTitle()),
url_string.c_str()];
[item setToolTip:tooltip];
}
} }
} }
...@@ -1232,6 +1226,18 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -1232,6 +1226,18 @@ void RecordAppLaunch(Profile* profile, GURL url) {
} }
} }
- (NSString*)tooltipForNode:(const BookmarkNode*)node {
NSString* title = base::SysUTF16ToNSString(node->GetTitle());
std::string url_string = node->GetURL().possibly_invalid_spec();
NSString* url = [NSString stringWithUTF8String:url_string.c_str()];
if ([title length] == 0)
return url;
else if ([url length] == 0 || [url isEqualToString:title])
return title;
else
return [NSString stringWithFormat:@"%@\n%@", title, url];
}
- (BookmarkButton*)buttonForNode:(const BookmarkNode*)node - (BookmarkButton*)buttonForNode:(const BookmarkNode*)node
xOffset:(int*)xOffset { xOffset:(int*)xOffset {
BookmarkButtonCell* cell = [self cellForBookmarkNode:node]; BookmarkButtonCell* cell = [self cellForBookmarkNode:node];
...@@ -1271,14 +1277,8 @@ void RecordAppLaunch(Profile* profile, GURL url) { ...@@ -1271,14 +1277,8 @@ void RecordAppLaunch(Profile* profile, GURL url) {
// Make the button do something // Make the button do something
[button setTarget:self]; [button setTarget:self];
[button setAction:@selector(openBookmark:)]; [button setAction:@selector(openBookmark:)];
if (node->is_url()) { if (node->is_url())
// Add a tooltip. [button setToolTip:[self tooltipForNode:node]];
NSString* title = base::SysUTF16ToNSString(node->GetTitle());
std::string url_string = node->GetURL().possibly_invalid_spec();
NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title,
url_string.c_str()];
[button setToolTip:tooltip];
}
} }
return [[button.get() retain] autorelease]; return [[button.get() retain] autorelease];
} }
......
...@@ -389,11 +389,7 @@ struct LayoutMetrics { ...@@ -389,11 +389,7 @@ struct LayoutMetrics {
[button setTarget:self]; [button setTarget:self];
[button setAction:@selector(openBookmark:)]; [button setAction:@selector(openBookmark:)];
// Add a tooltip. // Add a tooltip.
NSString* title = base::SysUTF16ToNSString(node->GetTitle()); [button setToolTip:[barController_ tooltipForNode:node]];
std::string urlString = node->GetURL().possibly_invalid_spec();
NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", title,
urlString.c_str()];
[button setToolTip:tooltip];
[button setAcceptsTrackIn:YES]; [button setAcceptsTrackIn:YES];
} }
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment