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.h"
7 #include "chrome/browser/themes/theme_properties.h"
8 #include "chrome/browser/themes/theme_service.h"
9 #import "chrome/browser/ui/cocoa/nsview_additions.h"
10 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
11 #import "chrome/browser/ui/cocoa/themed_window.h"
12 #import "chrome/browser/ui/cocoa/view_id_util.h"
13 #include "grit/theme_resources.h"
14 #import "ui/base/cocoa/nsgraphics_context_additions.h"
15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
17 @implementation DownloadShelfView
19 // For programmatic instantiations in unit tests.
20 - (id)initWithFrame:(NSRect)frameRect {
21 if ((self = [super initWithFrame:frameRect])) {
22 [self setShowsDivider:NO];
27 // For nib instantiations in production.
28 - (id)initWithCoder:(NSCoder*)decoder {
29 if ((self = [super initWithCoder:decoder])) {
30 [self setShowsDivider:NO];
35 - (NSColor*)strokeColor {
36 BOOL isActive = [[self window] isMainWindow];
37 ui::ThemeProvider* themeProvider = [[self window] themeProvider];
38 return themeProvider ? themeProvider->GetNSColor(
39 isActive ? ThemeProperties::COLOR_TOOLBAR_STROKE :
40 ThemeProperties::COLOR_TOOLBAR_STROKE_INACTIVE) :
44 - (void)drawRect:(NSRect)rect {
45 gfx::ScopedNSGraphicsContextSaveGState saveGState;
47 // We want our backgrounds for the shelf to be phased from the upper
48 // left hand corner of the view. Offset it by tab height so that the
49 // background matches the toolbar background.
50 NSPoint phase = NSMakePoint(
51 0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]);
52 [[NSGraphicsContext currentContext]
53 cr_setPatternPhase:phase forView:[self cr_viewBeingDrawnTo]];
54 [self drawBackgroundWithOpaque:YES];
57 [[self strokeColor] set];
58 NSRect borderRect, contentRect;
59 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth],
61 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
63 // Draw the top highlight
64 ThemeService* themeProvider =
65 static_cast<ThemeService*>([[self window] themeProvider]);
67 int resourceName = themeProvider->UsingDefaultTheme() ?
68 ThemeProperties::COLOR_TOOLBAR_BEZEL : ThemeProperties::COLOR_TOOLBAR;
69 NSColor* highlightColor = themeProvider->GetNSColor(resourceName);
72 borderRect.origin.y -= [self cr_lineWidth];
73 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
78 // Mouse down events on the download shelf should not allow dragging the parent
80 - (BOOL)mouseDownCanMoveWindow {
85 return VIEW_ID_DOWNLOAD_SHELF;