Chromium Code Reviews| 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 commonInit]; |
| 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 commonInit]; |
| 28 } | 28 } |
| 29 return self; | 29 return self; |
| 30 } | 30 } |
| 31 | 31 |
| 32 - (NSColor*)strokeColor { | 32 - (void)commonInit { |
| 33 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | 33 self.divider = BackgroundGradientViewDivider::Top; |
| 34 if (!themeProvider) { | 34 self.showsDivider = YES; |
| 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 } | 35 } |
| 46 | 36 |
| 47 - (NSPoint)patternPhase { | 37 - (NSPoint)patternPhase { |
| 48 // We want our backgrounds for the shelf to be phased from the upper | 38 // 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 | 39 // left hand corner of the view. Offset it by tab height so that the |
| 50 // background matches the toolbar background. | 40 // background matches the toolbar background. |
| 51 return NSMakePoint( | 41 return NSMakePoint( |
| 52 0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]); | 42 0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]); |
| 53 } | 43 } |
| 54 | 44 |
| 55 - (void)drawRect:(NSRect)dirtyRect { | |
| 56 [super drawRect:dirtyRect]; | |
| 57 | |
| 58 // Draw top stroke | |
| 59 NSRect borderRect, contentRect; | |
| 60 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth], | |
| 61 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]; | |
| 70 if (NSIntersectsRect(borderRect, dirtyRect)) { | |
| 71 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | |
| 72 if (themeProvider) { | |
| 73 int resourceName = themeProvider->UsingSystemTheme() | |
| 74 ? ThemeProperties::COLOR_TOOLBAR_BEZEL | |
| 75 : ThemeProperties::COLOR_TOOLBAR; | |
| 76 NSColor* highlightColor = themeProvider->GetNSColor(resourceName); | |
| 77 if (highlightColor) { | |
| 78 [highlightColor set]; | |
| 79 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect), | |
| 80 NSCompositeSourceOver); | |
| 81 } | |
| 82 } | |
| 83 } | |
| 84 } | |
|
Nico
2016/09/12 13:45:55
Is this appearance-preserving?
Sidney San Martín
2016/09/14 17:46:59
It is now, as far as I can tell.
| |
| 85 | |
| 86 // Mouse down events on the download shelf should not allow dragging the parent | 45 // Mouse down events on the download shelf should not allow dragging the parent |
| 87 // window around. | 46 // window around. |
| 88 - (BOOL)mouseDownCanMoveWindow { | 47 - (BOOL)mouseDownCanMoveWindow { |
| 89 return NO; | 48 return NO; |
| 90 } | 49 } |
| 91 | 50 |
| 92 - (ViewID)viewID { | 51 - (ViewID)viewID { |
| 93 return VIEW_ID_DOWNLOAD_SHELF; | 52 return VIEW_ID_DOWNLOAD_SHELF; |
| 94 } | 53 } |
| 95 | 54 |
| 96 - (BOOL)isOpaque { | 55 - (BOOL)isOpaque { |
| 97 return YES; | 56 return YES; |
| 98 } | 57 } |
| 99 | 58 |
| 100 @end | 59 @end |
| OLD | NEW |