Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2708)

Unified Diff: chrome/browser/ui/cocoa/download/download_show_all_button.mm

Issue 1125363005: Fix darkly-drawn Show All button in Downloads Shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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];
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698