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 |
17 @synthesize divider = divider_; | |
22 @synthesize showsDivider = showsDivider_; | 18 @synthesize showsDivider = showsDivider_; |
23 | 19 |
24 - (id)initWithFrame:(NSRect)frameRect { | 20 - (void)setDivider:(BackgroundGradientViewDivider)divider { |
25 if ((self = [super initWithFrame:frameRect])) { | 21 if (divider_ == divider) |
26 [self commonInit]; | 22 return; |
27 } | 23 divider_ = divider; |
28 return self; | 24 [self setNeedsDisplay:YES]; |
29 } | |
30 | |
31 - (id)initWithCoder:(NSCoder*)decoder { | |
32 if ((self = [super initWithCoder:decoder])) { | |
33 [self commonInit]; | |
34 } | |
35 return self; | |
36 } | |
37 | |
38 - (void)commonInit { | |
39 showsDivider_ = YES; | |
Nico
2016/09/12 13:45:55
This used to default to divider-on, now it default
Sidney San Martín
2016/09/14 17:46:59
Fixed, thanks.
| |
40 } | 25 } |
41 | 26 |
42 - (void)setShowsDivider:(BOOL)show { | 27 - (void)setShowsDivider:(BOOL)show { |
43 if (showsDivider_ == show) | 28 if (showsDivider_ == show) |
44 return; | 29 return; |
45 showsDivider_ = show; | 30 showsDivider_ = show; |
46 [self setNeedsDisplay:YES]; | 31 [self setNeedsDisplay:YES]; |
47 } | 32 } |
48 | 33 |
49 - (NSPoint)patternPhase { | 34 - (NSPoint)patternPhase { |
(...skipping 11 matching lines...) Expand all Loading... | |
61 // If the background image is semi transparent then we need something | 46 // 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. | 47 // to blend against. Using 20% black gives us a color similar to Windows. |
63 [[NSColor colorWithCalibratedWhite:0.2 alpha:1.0] set]; | 48 [[NSColor colorWithCalibratedWhite:0.2 alpha:1.0] set]; |
64 NSRectFill(dirtyRect); | 49 NSRectFill(dirtyRect); |
65 } | 50 } |
66 | 51 |
67 [[self backgroundImageColor] set]; | 52 [[self backgroundImageColor] set]; |
68 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); | 53 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); |
69 | 54 |
70 if (showsDivider_) { | 55 if (showsDivider_) { |
71 // Draw bottom stroke | 56 CGFloat lineWidth = [self cr_lineWidth]; |
72 NSRect borderRect, contentRect; | 57 NSRect borderRect = NSMakeRect(0, 0, self.bounds.size.width, lineWidth); |
73 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], | 58 |
74 NSMinYEdge); | 59 switch (divider_) { |
60 case BackgroundGradientViewDivider::Bottom: | |
61 break; | |
62 case BackgroundGradientViewDivider::Top: | |
63 borderRect.origin.y = self.bounds.size.height - lineWidth; | |
64 break; | |
65 } | |
Nico
2016/09/12 13:45:55
These 7 lines are shorter as
if (divider_ == Ba
Sidney San Martín
2016/09/14 17:46:59
I think I had an incomplete understanding of NSDiv
| |
75 if (NSIntersectsRect(borderRect, dirtyRect)) { | 66 if (NSIntersectsRect(borderRect, dirtyRect)) { |
76 [[self strokeColor] set]; | 67 [[self strokeColor] set]; |
77 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), | 68 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), |
78 NSCompositeSourceOver); | 69 NSCompositeSourceOver); |
79 } | 70 } |
80 } | 71 } |
81 } | 72 } |
82 | 73 |
83 - (NSColor*)strokeColor { | 74 - (NSColor*)strokeColor { |
84 NSWindow* window = [self window]; | 75 NSWindow* window = [self window]; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 166 |
176 - (void)windowDidChangeTheme { | 167 - (void)windowDidChangeTheme { |
177 [self setNeedsDisplay:YES]; | 168 [self setNeedsDisplay:YES]; |
178 } | 169 } |
179 | 170 |
180 - (void)windowDidChangeActive { | 171 - (void)windowDidChangeActive { |
181 [self setNeedsDisplay:YES]; | 172 [self setNeedsDisplay:YES]; |
182 } | 173 } |
183 | 174 |
184 @end | 175 @end |
OLD | NEW |