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