blob: 84be11ed75e340191eb5f8bdb9afdf83b9c1e807 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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.
4
5#import "chrome/browser/ui/cocoa/download/download_shelf_view.h"
6
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00007#include "chrome/browser/themes/theme_properties.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +00008#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"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010014#import "ui/base/cocoa/nsgraphics_context_additions.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000015#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
16
17@implementation DownloadShelfView
18
19// For programmatic instantiations in unit tests.
20- (id)initWithFrame:(NSRect)frameRect {
21 if ((self = [super initWithFrame:frameRect])) {
22 [self setShowsDivider:NO];
23 }
24 return self;
25}
26
27// For nib instantiations in production.
28- (id)initWithCoder:(NSCoder*)decoder {
29 if ((self = [super initWithCoder:decoder])) {
30 [self setShowsDivider:NO];
31 }
32 return self;
33}
34
35- (NSColor*)strokeColor {
36 BOOL isActive = [[self window] isMainWindow];
37 ui::ThemeProvider* themeProvider = [[self window] themeProvider];
38 return themeProvider ? themeProvider->GetNSColor(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000039 isActive ? ThemeProperties::COLOR_TOOLBAR_STROKE :
Ben Murdochbb1529c2013-08-08 10:24:53 +010040 ThemeProperties::COLOR_TOOLBAR_STROKE_INACTIVE) :
Torne (Richard Coles)58218062012-11-14 11:43:16 +000041 [NSColor blackColor];
42}
43
44- (void)drawRect:(NSRect)rect {
45 gfx::ScopedNSGraphicsContextSaveGState saveGState;
46
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]);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010052 [[NSGraphicsContext currentContext] cr_setPatternPhase:phase forView:self];
Torne (Richard Coles)58218062012-11-14 11:43:16 +000053 [self drawBackgroundWithOpaque:YES];
54
55 // Draw top stroke
56 [[self strokeColor] set];
57 NSRect borderRect, contentRect;
58 NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth],
59 NSMaxYEdge);
60 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
61
62 // Draw the top highlight
63 ThemeService* themeProvider =
64 static_cast<ThemeService*>([[self window] themeProvider]);
65 if (themeProvider) {
66 int resourceName = themeProvider->UsingDefaultTheme() ?
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000067 ThemeProperties::COLOR_TOOLBAR_BEZEL : ThemeProperties::COLOR_TOOLBAR;
Ben Murdochbb1529c2013-08-08 10:24:53 +010068 NSColor* highlightColor = themeProvider->GetNSColor(resourceName);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000069 if (highlightColor) {
70 [highlightColor set];
71 borderRect.origin.y -= [self cr_lineWidth];
72 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
73 }
74 }
75}
76
77// Mouse down events on the download shelf should not allow dragging the parent
78// window around.
79- (BOOL)mouseDownCanMoveWindow {
80 return NO;
81}
82
83- (ViewID)viewID {
84 return VIEW_ID_DOWNLOAD_SHELF;
85}
86
87- (BOOL)isOpaque {
88 return YES;
89}
90
91@end