OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/cocoa/background_gradient_view.h" | 5 #include "chrome/browser/ui/cocoa/background_gradient_view.h" |
6 | 6 |
7 #import "chrome/browser/themes/theme_properties.h" | 7 #import "chrome/browser/themes/theme_properties.h" |
8 #import "chrome/browser/themes/theme_service.h" | 8 #import "chrome/browser/themes/theme_service.h" |
9 #import "chrome/browser/ui/cocoa/themed_window.h" | 9 #import "chrome/browser/ui/cocoa/themed_window.h" |
10 #include "chrome/grit/theme_resources.h" | 10 #include "chrome/grit/theme_resources.h" |
11 #import "ui/base/cocoa/nsgraphics_context_additions.h" | 11 #import "ui/base/cocoa/nsgraphics_context_additions.h" |
12 #import "ui/base/cocoa/nsview_additions.h" | 12 #import "ui/base/cocoa/nsview_additions.h" |
13 #include "ui/base/material_design/material_design_controller.h" | 13 #include "ui/base/material_design/material_design_controller.h" |
14 | 14 |
15 @interface BackgroundGradientView (Private) | |
16 - (void)commonInit; | |
17 - (NSColor*)backgroundImageColor; | |
18 @end | |
19 | |
20 @implementation BackgroundGradientView | 15 @implementation BackgroundGradientView |
21 | 16 |
22 @synthesize showsDivider = showsDivider_; | 17 @synthesize showsDivider = showsDivider_; |
| 18 @synthesize dividerEdge = dividerEdge_; |
23 | 19 |
24 - (id)initWithFrame:(NSRect)frameRect { | 20 - (id)initWithFrame:(NSRect)frameRect { |
25 if ((self = [super initWithFrame:frameRect])) { | 21 if ((self = [super initWithFrame:frameRect])) { |
26 [self commonInit]; | 22 [self commonInit]; |
27 } | 23 } |
28 return self; | 24 return self; |
29 } | 25 } |
30 | 26 |
31 - (id)initWithCoder:(NSCoder*)decoder { | 27 - (id)initWithCoder:(NSCoder*)decoder { |
32 if ((self = [super initWithCoder:decoder])) { | 28 if ((self = [super initWithCoder:decoder])) { |
33 [self commonInit]; | 29 [self commonInit]; |
34 } | 30 } |
35 return self; | 31 return self; |
36 } | 32 } |
37 | 33 |
38 - (void)commonInit { | 34 - (void)commonInit { |
39 showsDivider_ = YES; | 35 showsDivider_ = YES; |
| 36 dividerEdge_ = NSMinYEdge; |
40 } | 37 } |
41 | 38 |
42 - (void)setShowsDivider:(BOOL)show { | 39 - (void)setShowsDivider:(BOOL)show { |
43 if (showsDivider_ == show) | 40 if (showsDivider_ == show) |
44 return; | 41 return; |
45 showsDivider_ = show; | 42 showsDivider_ = show; |
46 [self setNeedsDisplay:YES]; | 43 [self setNeedsDisplay:YES]; |
47 } | 44 } |
48 | 45 |
| 46 - (void)setDividerEdge:(NSRectEdge)dividerEdge { |
| 47 if (dividerEdge_ == dividerEdge) |
| 48 return; |
| 49 dividerEdge_ = dividerEdge; |
| 50 [self setNeedsDisplay:YES]; |
| 51 } |
| 52 |
49 - (NSPoint)patternPhase { | 53 - (NSPoint)patternPhase { |
50 return [[self window] | 54 return [[self window] |
51 themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP]; | 55 themeImagePositionForAlignment:THEME_IMAGE_ALIGN_WITH_TAB_STRIP]; |
52 } | 56 } |
53 | 57 |
54 - (void)drawRect:(NSRect)dirtyRect { | 58 - (void)drawRect:(NSRect)dirtyRect { |
55 [[NSGraphicsContext currentContext] | 59 [[NSGraphicsContext currentContext] |
56 cr_setPatternPhase:[self patternPhase] | 60 cr_setPatternPhase:[self patternPhase] |
57 forView:[self cr_viewBeingDrawnTo]]; | 61 forView:[self cr_viewBeingDrawnTo]]; |
58 | 62 |
59 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | 63 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; |
60 if (themeProvider && !themeProvider->UsingSystemTheme()) { | 64 if (themeProvider && !themeProvider->UsingSystemTheme()) { |
61 // If the background image is semi transparent then we need something | 65 // If the background image is semi transparent then we need something |
62 // to blend against. Using 20% black gives us a color similar to Windows. | 66 // to blend against. Using 20% black gives us a color similar to Windows. |
63 [[NSColor colorWithCalibratedWhite:0.2 alpha:1.0] set]; | 67 [[NSColor colorWithCalibratedWhite:0.2 alpha:1.0] set]; |
64 NSRectFill(dirtyRect); | 68 NSRectFill(dirtyRect); |
65 } | 69 } |
66 | 70 |
67 [[self backgroundImageColor] set]; | 71 [[self backgroundImageColor] set]; |
68 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); | 72 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); |
69 | 73 |
70 if (showsDivider_) { | 74 if (showsDivider_) { |
71 // Draw bottom stroke | 75 // Draw stroke |
72 NSRect borderRect, contentRect; | 76 NSRect borderRect, contentRect; |
73 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], | 77 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], |
74 NSMinYEdge); | 78 dividerEdge_); |
75 if (NSIntersectsRect(borderRect, dirtyRect)) { | 79 if (NSIntersectsRect(borderRect, dirtyRect)) { |
76 [[self strokeColor] set]; | 80 [[self strokeColor] set]; |
77 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), | 81 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), |
78 NSCompositeSourceOver); | 82 NSCompositeSourceOver); |
79 } | 83 } |
80 } | 84 } |
81 } | 85 } |
82 | 86 |
83 - (NSColor*)strokeColor { | 87 - (NSColor*)strokeColor { |
84 NSWindow* window = [self window]; | 88 NSWindow* window = [self window]; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 179 |
176 - (void)windowDidChangeTheme { | 180 - (void)windowDidChangeTheme { |
177 [self setNeedsDisplay:YES]; | 181 [self setNeedsDisplay:YES]; |
178 } | 182 } |
179 | 183 |
180 - (void)windowDidChangeActive { | 184 - (void)windowDidChangeActive { |
181 [self setNeedsDisplay:YES]; | 185 [self setNeedsDisplay:YES]; |
182 } | 186 } |
183 | 187 |
184 @end | 188 @end |
OLD | NEW |