Commit 1e6e9e83 authored by sdy's avatar sdy Committed by Commit bot

Make the edge where BackgroundGradientView draws a divider selectable.

…and remove the duplicate divider drawing in DownloadShelfView.

BUG=589943

Review-Url: https://codereview.chromium.org/2336463002
Cr-Commit-Position: refs/heads/master@{#418641}
parent 19adc908
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
// A custom view that draws a 'standard' background gradient. // A custom view that draws a 'standard' background gradient.
// Base class for other Chromium views. // Base class for other Chromium views.
@interface BackgroundGradientView : NSView<ThemedWindowDrawing> { @interface BackgroundGradientView : NSView<ThemedWindowDrawing>
@private
BOOL showsDivider_;
}
// Controls whether the bar draws a dividing line at the bottom. // Controls whether the bar draws a dividing line.
@property(nonatomic, assign) BOOL showsDivider; @property(nonatomic, assign) BOOL showsDivider;
// Controls where the bar draws a dividing line.
@property(nonatomic, assign) NSRectEdge dividerEdge;
// 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;
......
...@@ -12,14 +12,10 @@ ...@@ -12,14 +12,10 @@
#import "ui/base/cocoa/nsview_additions.h" #import "ui/base/cocoa/nsview_additions.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
@interface BackgroundGradientView (Private)
- (void)commonInit;
- (NSColor*)backgroundImageColor;
@end
@implementation BackgroundGradientView @implementation BackgroundGradientView
@synthesize showsDivider = showsDivider_; @synthesize showsDivider = showsDivider_;
@synthesize dividerEdge = dividerEdge_;
- (id)initWithFrame:(NSRect)frameRect { - (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) { if ((self = [super initWithFrame:frameRect])) {
...@@ -37,6 +33,7 @@ ...@@ -37,6 +33,7 @@
- (void)commonInit { - (void)commonInit {
showsDivider_ = YES; showsDivider_ = YES;
dividerEdge_ = NSMinYEdge;
} }
- (void)setShowsDivider:(BOOL)show { - (void)setShowsDivider:(BOOL)show {
...@@ -46,6 +43,13 @@ ...@@ -46,6 +43,13 @@
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }
- (void)setDividerEdge:(NSRectEdge)dividerEdge {
if (dividerEdge_ == dividerEdge)
return;
dividerEdge_ = dividerEdge;
[self setNeedsDisplay:YES];
}
- (NSPoint)patternPhase { - (NSPoint)patternPhase {
return [[self window] return [[self window]
themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP]; themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP];
...@@ -68,10 +72,10 @@ ...@@ -68,10 +72,10 @@
NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
if (showsDivider_) { if (showsDivider_) {
// Draw bottom stroke // Draw stroke
NSRect borderRect, contentRect; NSRect borderRect, contentRect;
NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth],
NSMinYEdge); dividerEdge_);
if (NSIntersectsRect(borderRect, dirtyRect)) { if (NSIntersectsRect(borderRect, dirtyRect)) {
[[self strokeColor] set]; [[self strokeColor] set];
NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect),
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// For programmatic instantiations in unit tests. // For programmatic instantiations in unit tests.
- (id)initWithFrame:(NSRect)frameRect { - (id)initWithFrame:(NSRect)frameRect {
if ((self = [super initWithFrame:frameRect])) { if ((self = [super initWithFrame:frameRect])) {
[self setShowsDivider:NO]; self.dividerEdge = NSMaxYEdge;
} }
return self; return self;
} }
...@@ -24,26 +24,11 @@ ...@@ -24,26 +24,11 @@
// For nib instantiations in production. // For nib instantiations in production.
- (id)initWithCoder:(NSCoder*)decoder { - (id)initWithCoder:(NSCoder*)decoder {
if ((self = [super initWithCoder:decoder])) { if ((self = [super initWithCoder:decoder])) {
[self setShowsDivider:NO]; self.dividerEdge = NSMaxYEdge;
} }
return self; return self;
} }
- (NSColor*)strokeColor {
const ui::ThemeProvider* themeProvider = [[self window] themeProvider];
if (!themeProvider) {
return [NSColor blackColor];
}
if (!ui::MaterialDesignController::IsModeMaterial()) {
BOOL isActive = [[self window] isMainWindow];
return themeProvider->GetNSColor(
isActive ? ThemeProperties::COLOR_TOOLBAR_STROKE :
ThemeProperties::COLOR_TOOLBAR_STROKE_INACTIVE);
}
return themeProvider->GetNSColor(
ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR);
}
- (NSPoint)patternPhase { - (NSPoint)patternPhase {
// We want our backgrounds for the shelf to be phased from the upper // We want our backgrounds for the shelf to be phased from the upper
// left hand corner of the view. Offset it by tab height so that the // left hand corner of the view. Offset it by tab height so that the
...@@ -55,17 +40,10 @@ ...@@ -55,17 +40,10 @@
- (void)drawRect:(NSRect)dirtyRect { - (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect]; [super drawRect:dirtyRect];
// Draw top stroke // Draw the top highlight
NSRect borderRect, contentRect; NSRect borderRect, contentRect;
NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth],
NSMaxYEdge); NSMaxYEdge);
if (NSIntersectsRect(borderRect, dirtyRect)) {
[[self strokeColor] set];
NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect),
NSCompositeSourceOver);
}
// Draw the top highlight
borderRect.origin.y -= [self cr_lineWidth]; borderRect.origin.y -= [self cr_lineWidth];
if (NSIntersectsRect(borderRect, dirtyRect)) { if (NSIntersectsRect(borderRect, dirtyRect)) {
const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; const ui::ThemeProvider* themeProvider = [[self window] themeProvider];
......
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