Index: chrome/browser/ui/cocoa/download/download_show_all_button.mm |
diff --git a/chrome/browser/ui/cocoa/download/download_show_all_button.mm b/chrome/browser/ui/cocoa/download/download_show_all_button.mm |
index 6a915433865bcc19b141c6fc23acfb0d18decdb5..fef7dc4163b33b4f3f156e668dfd92b70fc34024 100644 |
--- a/chrome/browser/ui/cocoa/download/download_show_all_button.mm |
+++ b/chrome/browser/ui/cocoa/download/download_show_all_button.mm |
@@ -21,6 +21,12 @@ |
[self setImage:favicon]; |
} |
+- (void)dealloc { |
+ [[NSNotificationCenter defaultCenter] removeObserver:self]; |
+ |
+ [super dealloc]; |
+} |
+ |
// GTM's layout tweaker calls sizeToFit to receive the desired width of views. |
// By default, buttons will be only 14px high, but the Show All button needs to |
// be higher. |
@@ -42,9 +48,39 @@ |
return YES; |
} |
+- (void)downloadShelfFrameDidChange:(NSNotification*)aNotification { |
+ [[NSNotificationCenter defaultCenter] |
+ removeObserver:self |
+ name:NSViewFrameDidChangeNotification |
+ object:[self ancestorWithViewID:VIEW_ID_DOWNLOAD_SHELF]]; |
+ |
+ [self setNeedsDisplay:YES]; |
+} |
+ |
- (void)drawRect:(NSRect)rect { |
NSView* downloadShelfView = [self ancestorWithViewID:VIEW_ID_DOWNLOAD_SHELF]; |
- [self cr_drawUsingAncestor:downloadShelfView inRect:rect]; |
+ if ([downloadShelfView bounds].size.height < [self bounds].size.height) { |
+ // Ordinarily the show all button uses cr_drawUsingAncestor:inRect: to use |
+ // the download shelf to draw its background. However when the download |
+ // shelf has zero height, the shelf's drawing methods don't work as expected |
+ // because they constrain their drawing to the shelf's bounds rect. This |
+ // situation occurs sometimes when the shelf is about to become visible, |
+ // and the result is a very dark show all button. |
+ // |
+ // To work around this problem, we'll draw a color that roughly matches |
+ // the shelf's background gradient, and then wait for the shelf to change |
+ // its frame, at which point we'll schedule a redraw (which will work |
+ // correctly because the shelf will have a non-zero height). |
+ [[NSColor colorWithCalibratedWhite:0.8 alpha:1.0] set]; |
asanka
2015/05/08 17:49:39
Is there a way to determine this at runtime withou
shrike
2015/05/08 18:27:48
Not cleanly. The code that we need lives in [Backg
asanka
2015/05/12 00:20:51
The only thing I'm worried about is whether this w
|
+ NSRectFill(rect); |
+ NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
+ [defaultCenter addObserver:self |
+ selector:@selector(downloadShelfFrameDidChange:) |
+ name:NSViewFrameDidChangeNotification |
+ object:downloadShelfView]; |
+ } else { |
asanka
2015/05/08 17:48:36
Do we need the observer if there was a successful
shrike
2015/05/08 18:27:48
No, we should not. Are you asking because you see
asanka
2015/05/12 00:20:51
Right. Misread.
|
+ [self cr_drawUsingAncestor:downloadShelfView inRect:rect]; |
+ } |
[super drawRect:rect]; |
} |