1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/download/download_show_all_button.h"
7 #include "base/logging.h"
8 #import "chrome/browser/ui/cocoa/download/download_show_all_cell.h"
9 #import "chrome/browser/ui/cocoa/view_id_util.h"
10 #include "grit/theme_resources.h"
11 #import "ui/base/cocoa/nsview_additions.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/image/image.h"
15 @implementation DownloadShowAllButton
17 - (void)awakeFromNib {
18 DCHECK([[self cell] isKindOfClass:[DownloadShowAllCell class]]);
19 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
20 NSImage* favicon = rb.GetNativeImageNamed(IDR_DOWNLOADS_FAVICON).ToNSImage();
21 [self setImage:favicon];
24 // GTM's layout tweaker calls sizeToFit to receive the desired width of views.
25 // By default, buttons will be only 14px high, but the Show All button needs to
28 NSRect oldRect = [self frame];
30 NSRect newRect = [self frame];
33 newRect.origin.y = oldRect.origin.y;
34 newRect.size.height = oldRect.size.height;
36 [self setFrame:newRect];
40 // Make this control opaque so that sub-pixel anti-aliasing works when
41 // CoreAnimation is enabled.
45 - (void)drawRect:(NSRect)rect {
46 NSView* downloadShelfView = [self ancestorWithViewID:VIEW_ID_DOWNLOAD_SHELF];
47 // Previously the show all button used cr_drawUsingAncestor:inRect: to use
48 // the download shelf to draw its background. However when the download
49 // shelf has zero height, the shelf's drawing methods don't work as expected
50 // because they constrain their drawing to the shelf's bounds rect. This
51 // situation occurs sometimes when the shelf is about to become visible,
52 // and the result is a very dark show all button
54 // To work around this problem, we'll call a variant of that method which
55 // does restrict drawing to the ancestor view's bounds.
56 [self cr_drawUsingAncestor:downloadShelfView
58 clippedToAncestorBounds:NO];
59 [super drawRect:rect];
62 // ThemedWindowDrawing implementation.
64 - (void)windowDidChangeTheme {
65 [self setNeedsDisplay:YES];
68 - (void)windowDidChangeActive {
69 [self setNeedsDisplay:YES];