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 #import "chrome/browser/ui/cocoa/download/download_shelf_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/download/download_shelf_view_cocoa.h" |
6 | 6 |
7 #include "chrome/browser/themes/theme_properties.h" | 7 #include "chrome/browser/themes/theme_properties.h" |
8 #include "chrome/browser/themes/theme_service.h" | 8 #include "chrome/browser/themes/theme_service.h" |
9 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 9 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
10 #import "chrome/browser/ui/cocoa/view_id_util.h" | 10 #import "chrome/browser/ui/cocoa/view_id_util.h" |
11 #import "ui/base/cocoa/nsview_additions.h" | 11 #import "ui/base/cocoa/nsview_additions.h" |
12 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
13 | 13 |
14 @implementation DownloadShelfView | 14 @implementation DownloadShelfView |
15 | 15 |
16 // For programmatic instantiations in unit tests. | 16 // For programmatic instantiations in unit tests. |
17 - (id)initWithFrame:(NSRect)frameRect { | 17 - (id)initWithFrame:(NSRect)frameRect { |
18 if ((self = [super initWithFrame:frameRect])) { | 18 if ((self = [super initWithFrame:frameRect])) { |
19 [self setShowsDivider:NO]; | 19 self.dividerEdge = NSMaxYEdge; |
20 } | 20 } |
21 return self; | 21 return self; |
22 } | 22 } |
23 | 23 |
24 // For nib instantiations in production. | 24 // For nib instantiations in production. |
25 - (id)initWithCoder:(NSCoder*)decoder { | 25 - (id)initWithCoder:(NSCoder*)decoder { |
26 if ((self = [super initWithCoder:decoder])) { | 26 if ((self = [super initWithCoder:decoder])) { |
27 [self setShowsDivider:NO]; | 27 self.dividerEdge = NSMaxYEdge; |
28 } | 28 } |
29 return self; | 29 return self; |
30 } | 30 } |
31 | 31 |
32 - (NSColor*)strokeColor { | |
33 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | |
34 if (!themeProvider) { | |
35 return [NSColor blackColor]; | |
36 } | |
37 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
38 BOOL isActive = [[self window] isMainWindow]; | |
39 return themeProvider->GetNSColor( | |
40 isActive ? ThemeProperties::COLOR_TOOLBAR_STROKE : | |
41 ThemeProperties::COLOR_TOOLBAR_STROKE_INACTIVE); | |
42 } | |
43 return themeProvider->GetNSColor( | |
44 ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR); | |
45 } | |
46 | |
47 - (NSPoint)patternPhase { | 32 - (NSPoint)patternPhase { |
48 // We want our backgrounds for the shelf to be phased from the upper | 33 // We want our backgrounds for the shelf to be phased from the upper |
49 // left hand corner of the view. Offset it by tab height so that the | 34 // left hand corner of the view. Offset it by tab height so that the |
50 // background matches the toolbar background. | 35 // background matches the toolbar background. |
51 return NSMakePoint( | 36 return NSMakePoint( |
52 0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]); | 37 0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]); |
53 } | 38 } |
54 | 39 |
55 - (void)drawRect:(NSRect)dirtyRect { | 40 - (void)drawRect:(NSRect)dirtyRect { |
56 [super drawRect:dirtyRect]; | 41 [super drawRect:dirtyRect]; |
57 | 42 |
58 // Draw top stroke | 43 // Draw the top highlight |
59 NSRect borderRect, contentRect; | 44 NSRect borderRect, contentRect; |
60 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], | 45 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], |
61 NSMaxYEdge); | 46 NSMaxYEdge); |
62 if (NSIntersectsRect(borderRect, dirtyRect)) { | |
63 [[self strokeColor] set]; | |
64 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), | |
65 NSCompositeSourceOver); | |
66 } | |
67 | |
68 // Draw the top highlight | |
69 borderRect.origin.y -= [self cr_lineWidth]; | 47 borderRect.origin.y -= [self cr_lineWidth]; |
70 if (NSIntersectsRect(borderRect, dirtyRect)) { | 48 if (NSIntersectsRect(borderRect, dirtyRect)) { |
71 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | 49 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; |
72 if (themeProvider) { | 50 if (themeProvider) { |
73 int resourceName = themeProvider->UsingSystemTheme() | 51 int resourceName = themeProvider->UsingSystemTheme() |
74 ? ThemeProperties::COLOR_TOOLBAR_BEZEL | 52 ? ThemeProperties::COLOR_TOOLBAR_BEZEL |
75 : ThemeProperties::COLOR_TOOLBAR; | 53 : ThemeProperties::COLOR_TOOLBAR; |
76 NSColor* highlightColor = themeProvider->GetNSColor(resourceName); | 54 NSColor* highlightColor = themeProvider->GetNSColor(resourceName); |
77 if (highlightColor) { | 55 if (highlightColor) { |
78 [highlightColor set]; | 56 [highlightColor set]; |
(...skipping 12 matching lines...) Expand all Loading... |
91 | 69 |
92 - (ViewID)viewID { | 70 - (ViewID)viewID { |
93 return VIEW_ID_DOWNLOAD_SHELF; | 71 return VIEW_ID_DOWNLOAD_SHELF; |
94 } | 72 } |
95 | 73 |
96 - (BOOL)isOpaque { | 74 - (BOOL)isOpaque { |
97 return YES; | 75 return YES; |
98 } | 76 } |
99 | 77 |
100 @end | 78 @end |
OLD | NEW |