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 = NSRectEdgeMaxY; |
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 = NSRectEdgeMaxY; |
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 // Draw the top highlight |
58 // Draw top stroke | |
59 NSRect borderRect, contentRect; | 43 NSRect borderRect, contentRect; |
60 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], | 44 NSDivideRect([self bounds], &borderRect, &contentRect, |
61 NSMaxYEdge); | 45 [self cr_lineWidth] * 2, NSMaxYEdge); |
Nico
2016/09/14 18:06:37
is the `* 2` here correct? from what I understand,
Sidney San Martín
2016/09/14 18:34:37
Ugh, I read that parameter as affecting position,
| |
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]; | 46 borderRect.origin.y -= [self cr_lineWidth]; |
70 if (NSIntersectsRect(borderRect, dirtyRect)) { | 47 if (NSIntersectsRect(borderRect, dirtyRect)) { |
71 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | 48 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; |
72 if (themeProvider) { | 49 if (themeProvider) { |
73 int resourceName = themeProvider->UsingSystemTheme() | 50 int resourceName = themeProvider->UsingSystemTheme() |
74 ? ThemeProperties::COLOR_TOOLBAR_BEZEL | 51 ? ThemeProperties::COLOR_TOOLBAR_BEZEL |
75 : ThemeProperties::COLOR_TOOLBAR; | 52 : ThemeProperties::COLOR_TOOLBAR; |
76 NSColor* highlightColor = themeProvider->GetNSColor(resourceName); | 53 NSColor* highlightColor = themeProvider->GetNSColor(resourceName); |
77 if (highlightColor) { | 54 if (highlightColor) { |
78 [highlightColor set]; | 55 [highlightColor set]; |
79 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), | 56 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), |
80 NSCompositeSourceOver); | 57 NSCompositeSourceOver); |
81 } | 58 } |
Nico
2016/09/14 18:06:37
this top highlight code looks pretty similar to th
Sidney San Martín
2016/09/14 18:34:37
I'm starting the MD version now :). Hopefully this
| |
82 } | 59 } |
83 } | 60 } |
84 } | 61 } |
85 | 62 |
86 // Mouse down events on the download shelf should not allow dragging the parent | 63 // Mouse down events on the download shelf should not allow dragging the parent |
87 // window around. | 64 // window around. |
88 - (BOOL)mouseDownCanMoveWindow { | 65 - (BOOL)mouseDownCanMoveWindow { |
89 return NO; | 66 return NO; |
90 } | 67 } |
91 | 68 |
92 - (ViewID)viewID { | 69 - (ViewID)viewID { |
93 return VIEW_ID_DOWNLOAD_SHELF; | 70 return VIEW_ID_DOWNLOAD_SHELF; |
94 } | 71 } |
95 | 72 |
96 - (BOOL)isOpaque { | 73 - (BOOL)isOpaque { |
97 return YES; | 74 return YES; |
98 } | 75 } |
99 | 76 |
100 @end | 77 @end |
OLD | NEW |