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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/download/download_shelf_view_cocoa.h"
7 #include "chrome/browser/themes/theme_properties.h"
8 #include "chrome/browser/themes/theme_service.h"
9 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
10 #import "chrome/browser/ui/cocoa/view_id_util.h"
11 #import "ui/base/cocoa/nsview_additions.h"
13 @implementation DownloadShelfView
15 // For programmatic instantiations in unit tests.
16 - (id)initWithFrame:(NSRect)frameRect {
17 if ((self = [super initWithFrame:frameRect])) {
18 [self setShowsDivider:NO];
23 // For nib instantiations in production.
24 - (id)initWithCoder:(NSCoder*)decoder {
25 if ((self = [super initWithCoder:decoder])) {
26 [self setShowsDivider:NO];
31 - (NSColor*)strokeColor {
32 BOOL isActive = [[self window] isMainWindow];
33 ui::ThemeProvider* themeProvider = [[self window] themeProvider];
34 return themeProvider ? themeProvider->GetNSColor(
35 isActive ? ThemeProperties::COLOR_TOOLBAR_STROKE :
36 ThemeProperties::COLOR_TOOLBAR_STROKE_INACTIVE) :
40 - (NSPoint)patternPhase {
41 // We want our backgrounds for the shelf to be phased from the upper
42 // left hand corner of the view. Offset it by tab height so that the
43 // background matches the toolbar background.
45 0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]);
48 - (void)drawRect:(NSRect)dirtyRect {
49 [self drawBackground:dirtyRect];
52 NSRect borderRect, contentRect;
53 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth],
55 if (NSIntersectsRect(borderRect, dirtyRect)) {
56 [[self strokeColor] set];
57 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect),
58 NSCompositeSourceOver);
61 // Draw the top highlight
62 borderRect.origin.y -= [self cr_lineWidth];
63 if (NSIntersectsRect(borderRect, dirtyRect)) {
64 ui::ThemeProvider* themeProvider = [[self window] themeProvider];
66 int resourceName = themeProvider->UsingSystemTheme()
67 ? ThemeProperties::COLOR_TOOLBAR_BEZEL
68 : ThemeProperties::COLOR_TOOLBAR;
69 NSColor* highlightColor = themeProvider->GetNSColor(resourceName);
72 NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect),
73 NSCompositeSourceOver);
79 // Mouse down events on the download shelf should not allow dragging the parent
81 - (BOOL)mouseDownCanMoveWindow {
86 return VIEW_ID_DOWNLOAD_SHELF;