Commit 02a48496 authored by sdy's avatar sdy Committed by Commit bot

Revert of BackgroundGradientView: -drawBackground: → -drawRect: (patchset #2...

Revert of BackgroundGradientView: -drawBackground: → -drawRect: (patchset #2 id:40001 of https://codereview.chromium.org/2336453002/ )

Reason for revert:
AnimatableView inherits from BackgroundGradientView, so a number of
other views which *don't* want backgrounds end up inheriting from
BackgroundGradientView. This widened the scope of the change beyond what
I intended.

Original issue's description:
> BackgroundGradientView: -drawBackground: → -drawRect:
>
> BackgroundGradientView had a -drawBackground: method that its clients
> were expected to call. This change moves background drawing to
> -drawRect: so that the it happens by default.
>
> Subclasses that did custom drawing already override -drawRect:, but this
> removes a couple of overrides that just forwarded to -drawBackground:.
>
> BUG=589943
>
> Committed: https://crrev.com/6b1939a26d2839136aeeba2aa0e359fce0c20281
> Cr-Commit-Position: refs/heads/master@{#418358}

TBR=thakis@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=647018

Review-Url: https://codereview.chromium.org/2339143003
Cr-Commit-Position: refs/heads/master@{#418714}
parent 9e0e8b2b
......@@ -22,12 +22,15 @@
// The color used for the bottom stroke. Public so subclasses can use.
- (NSColor*)strokeColor;
// The pattern phase that will be used by -drawRect:.
// The pattern phase that will be used by -drawBackground:.
// Defaults to align the top of the theme image with the top of the tabs.
// Views that draw at the bottom of the window (download bar) can override to
// change the pattern phase.
- (NSPoint)patternPhase;
// Draws the background image into the current NSGraphicsContext.
- (void)drawBackground:(NSRect)dirtyRect;
@end
#endif // CHROME_BROWSER_UI_COCOA_BACKGROUND_GRADIENT_VIEW_H_
......@@ -55,7 +55,7 @@
themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
}
- (void)drawRect:(NSRect)dirtyRect {
- (void)drawBackground:(NSRect)dirtyRect {
[[NSGraphicsContext currentContext]
cr_setPatternPhase:[self patternPhase]
forView:[self cr_viewBeingDrawnTo]];
......
......@@ -10,19 +10,32 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
// Since BackgroundGradientView doesn't do any drawing by default, we
// create a subclass to call its draw method for us.
@interface BackgroundGradientSubClassTest : BackgroundGradientView
@end
@implementation BackgroundGradientSubClassTest
- (void)drawRect:(NSRect)dirtyRect {
[self drawBackground:dirtyRect];
}
@end
namespace {
class BackgroundGradientViewTest : public CocoaTest {
public:
BackgroundGradientViewTest() {
NSRect frame = NSMakeRect(0, 0, 100, 30);
base::scoped_nsobject<BackgroundGradientView> view(
[[BackgroundGradientView alloc] initWithFrame:frame]);
base::scoped_nsobject<BackgroundGradientSubClassTest> view(
[[BackgroundGradientSubClassTest alloc] initWithFrame:frame]);
view_ = view.get();
[[test_window() contentView] addSubview:view_];
}
BackgroundGradientView* view_;
BackgroundGradientSubClassTest* view_;
};
TEST_VIEW(BackgroundGradientViewTest, view_)
......
......@@ -24,8 +24,8 @@
@implementation BookmarkBarToolbarView
- (BOOL)isOpaque {
// -drawRect: calls -drawAsDetachedBubble: or -[super drawRect:], both of
// which fill the dirty rect with an opaque color.
// -drawRect: calls -drawAsDetachedBubble: or -drawBackground:, both of which
// fill the dirty rect with an opaque color.
return YES;
}
......@@ -41,7 +41,7 @@
[controller_ isAnimatingFromState:BookmarkBar::DETACHED]) {
[self drawAsDetachedBubble:dirtyRect];
} else {
[super drawRect:dirtyRect];
[self drawBackground:dirtyRect];
}
}
......@@ -70,7 +70,7 @@
CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]);
CGContextSetAlpha(cgContext, 1 - morph);
CGContextBeginTransparencyLayer(cgContext, NULL);
[super drawRect:dirtyRect];
[self drawBackground:dirtyRect];
CGContextEndTransparencyLayer(cgContext);
}
......
......@@ -38,7 +38,7 @@
}
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
[self drawBackground:dirtyRect];
// Draw the top highlight
NSRect borderRect, contentRect;
......
......@@ -75,7 +75,7 @@ CGFloat kCurveSize = 8;
{
gfx::ScopedNSGraphicsContextSaveGState scopedGState;
[path addClip];
[super drawRect:dirtyRect];
[self drawBackground:dirtyRect];
}
[[self strokeColor] set];
......
......@@ -66,7 +66,7 @@
NSRect backgroundRect = [self bounds];
backgroundRect.size.height = 2 * [self cr_lineWidth];
if (NSIntersectsRect(backgroundRect, dirtyRect))
[super drawRect:backgroundRect];
[self drawBackground:backgroundRect];
// Draw the border bitmap, which is partially transparent.
NSImage* image = themeProvider->GetNSImageNamed(IDR_TOOLBAR_SHADE_TOP);
......@@ -90,7 +90,7 @@
NSRect backgroundRect = [self bounds];
backgroundRect.size.height = [self cr_lineWidth];
if (NSIntersectsRect(backgroundRect, dirtyRect)) {
[super drawRect:backgroundRect];
[self drawBackground:backgroundRect];
}
// Pre-MD the IDR_TOOLBAR_SHADE_TOP image would lay down a light highlight
......
......@@ -17,6 +17,10 @@
return NO;
}
- (void)drawRect:(NSRect)dirtyRect {
[self drawBackground:dirtyRect];
}
// Override of |-[BackgroundGradientView strokeColor]|; make it respect opacity.
- (NSColor*)strokeColor {
// Only return a transparent color if not Material Design.
......
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