Commit 890dcc45 authored by shrike's avatar shrike Committed by Commit bot

Fix darkly-drawn Show All button in Downloads Shelf.

When the download shelf appears the Show All button at the far right is
very dark, almost as if its been drawn several times on top of itself
(see the original bug report for a screenshot of the problem).

The problem is that the Show All button is layer backed (because the
shelf is), so it caches its contents. The Show All button also declares
itself to be opaque but wants the shelf background texture to show
through. It accomplishes this by simulating a lock focus onto the shelf
from within its drawRect:, and calling the shelf's drawRect:.

Unfortunately, when the button first draws (into its layer) the shelf
is hidden and so the shelf's height is 0.0. The shelf's drawing routines
restrict themselves to the shelf's bounds rect - that works most of the
time because if the shelf has 0 height there should be no drawing to be
done. This optimization doesn't work for the Show All button when it
uses the zero-height shelf to draw its background.

The proposed fix is to detect the zero-height shelf from within
drawRect:, and to use a frame-changed notification from the shelf as
the signal to request a redraw.

BUG=485782

Review URL: https://codereview.chromium.org/1125363005

Cr-Commit-Position: refs/heads/master@{#330120}
parent 8b2f729d
...@@ -44,7 +44,18 @@ ...@@ -44,7 +44,18 @@
- (void)drawRect:(NSRect)rect { - (void)drawRect:(NSRect)rect {
NSView* downloadShelfView = [self ancestorWithViewID:VIEW_ID_DOWNLOAD_SHELF]; NSView* downloadShelfView = [self ancestorWithViewID:VIEW_ID_DOWNLOAD_SHELF];
[self cr_drawUsingAncestor:downloadShelfView inRect:rect]; // Previously the show all button used 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 call a variant of that method which
// does restrict drawing to the ancestor view's bounds.
[self cr_drawUsingAncestor:downloadShelfView
inRect:rect
clippedToAncestorBounds:NO];
[super drawRect:rect]; [super drawRect:rect];
} }
......
...@@ -37,7 +37,12 @@ ...@@ -37,7 +37,12 @@
// Draw using ancestorView's drawRect function into this view's rect. Do any // Draw using ancestorView's drawRect function into this view's rect. Do any
// required translating or flipping to transform between the two coordinate // required translating or flipping to transform between the two coordinate
// systems. // systems, and optionally clip to the ancestor view's bounds.
- (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)dirtyRect
clippedToAncestorBounds:(BOOL)clipToAncestorBounds;
// Same as cr_drawUsingAncestor:inRect:clippedToAncestorBounds: except always
// clips to the ancestor view's bounds.
- (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)dirtyRect; - (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)dirtyRect;
// Used by ancestorView in the above draw call, to look up the child view that // Used by ancestorView in the above draw call, to look up the child view that
......
...@@ -75,7 +75,8 @@ ...@@ -75,7 +75,8 @@
static NSView* g_ancestorBeingDrawnFrom = nil; static NSView* g_ancestorBeingDrawnFrom = nil;
static NSView* g_childBeingDrawnTo = nil; static NSView* g_childBeingDrawnTo = nil;
- (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)dirtyRect { - (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)dirtyRect
clippedToAncestorBounds:(BOOL)clipToAncestorBounds {
gfx::ScopedNSGraphicsContextSaveGState scopedGSState; gfx::ScopedNSGraphicsContextSaveGState scopedGSState;
NSRect frame = [self convertRect:[self bounds] toView:ancestorView]; NSRect frame = [self convertRect:[self bounds] toView:ancestorView];
NSAffineTransform* transform = [NSAffineTransform transform]; NSAffineTransform* transform = [NSAffineTransform transform];
...@@ -91,13 +92,21 @@ static NSView* g_childBeingDrawnTo = nil; ...@@ -91,13 +92,21 @@ static NSView* g_childBeingDrawnTo = nil;
DCHECK(!g_ancestorBeingDrawnFrom && !g_childBeingDrawnTo); DCHECK(!g_ancestorBeingDrawnFrom && !g_childBeingDrawnTo);
g_ancestorBeingDrawnFrom = ancestorView; g_ancestorBeingDrawnFrom = ancestorView;
g_childBeingDrawnTo = self; g_childBeingDrawnTo = self;
[ancestorView drawRect:NSIntersectionRect( NSRect drawRect = [self convertRect:dirtyRect toView:ancestorView];
[ancestorView bounds], if (clipToAncestorBounds) {
[self convertRect:dirtyRect toView:ancestorView])]; drawRect = NSIntersectionRect([ancestorView bounds], drawRect);
}
[ancestorView drawRect:drawRect];
g_childBeingDrawnTo = nil; g_childBeingDrawnTo = nil;
g_ancestorBeingDrawnFrom = nil; g_ancestorBeingDrawnFrom = nil;
} }
- (void)cr_drawUsingAncestor:(NSView*)ancestorView inRect:(NSRect)dirtyRect {
[self cr_drawUsingAncestor:ancestorView
inRect:dirtyRect
clippedToAncestorBounds:YES];
}
- (NSView*)cr_viewBeingDrawnTo { - (NSView*)cr_viewBeingDrawnTo {
if (!g_ancestorBeingDrawnFrom) if (!g_ancestorBeingDrawnFrom)
return self; return self;
......
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