blob: 147ae046d841024fe73c7e9b05e308aeee19c68a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/cocoa/bookmark_button_cell.h"
#import "chrome/browser/cocoa/bookmark_menu.h"
#import "third_party/GTM/AppKit/GTMTheme.h"
@implementation BookmarkButtonCell
- (id)initTextCell:(NSString *)string {
if ((self = [super initTextCell:string])) {
[self setButtonType:NSMomentaryPushInButton];
[self setBezelStyle:NSShadowlessSquareBezelStyle];
[self setShowsBorderOnlyWhileMouseInside:YES];
[self setControlSize:NSSmallControlSize];
[self setAlignment:NSLeftTextAlignment];
[self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[self setWraps:NO];
// NSLineBreakByTruncatingMiddle seems more common on OSX but let's
// try to match Windows for a bit to see what happens.
[self setLineBreakMode:NSLineBreakByTruncatingTail];
// Theming doesn't work for bookmark buttons yet (text chucked).
[super setShouldTheme:NO];
}
return self;
}
- (NSSize)cellSizeForBounds:(NSRect)aRect {
NSSize size = [super cellSizeForBounds:aRect];
size.width += 2;
size.height += 4;
return size;
}
- (void)setBookmarkCellText:(NSString*)title
image:(NSImage*)image {
title = [title stringByReplacingOccurrencesOfString:@"\n"
withString:@" "];
title = [title stringByReplacingOccurrencesOfString:@"\r"
withString:@" "];
if (image) {
[self setImage:image];
if ([title length] < 1) {
[self setImagePosition:NSImageOnly];
} else {
[self setImagePosition:NSImageLeft];
}
}
[self setTitle:title];
}
// We share the context menu among all bookmark buttons. To allow us
// to disambiguate when needed (e.g. "open bookmark"), we set the
// menu's associated node to be our represented object.
- (NSMenu*)menu {
BookmarkMenu* menu = (BookmarkMenu*)[super menu];
[menu setRepresentedObject:[self representedObject]];
return menu;
}
@end
|