Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / download / download_shelf_view_cocoa.mm
blobf832a531058a559a39607765b03c4616a1e9188b
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];
19   }
20   return self;
23 // For nib instantiations in production.
24 - (id)initWithCoder:(NSCoder*)decoder {
25   if ((self = [super initWithCoder:decoder])) {
26     [self setShowsDivider:NO];
27   }
28   return self;
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) :
37       [NSColor blackColor];
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.
44   return NSMakePoint(
45       0, NSHeight([self bounds]) + [TabStripController defaultTabHeight]);
48 - (void)drawRect:(NSRect)dirtyRect {
49   [self drawBackground:dirtyRect];
51   // Draw top stroke
52   NSRect borderRect, contentRect;
53   NSDivideRect([self bounds], &borderRect, &contentRect, [self cr_lineWidth],
54                NSMaxYEdge);
55   if (NSIntersectsRect(borderRect, dirtyRect)) {
56     [[self strokeColor] set];
57     NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect),
58                              NSCompositeSourceOver);
59   }
61   // Draw the top highlight
62   borderRect.origin.y -= [self cr_lineWidth];
63   if (NSIntersectsRect(borderRect, dirtyRect)) {
64     ui::ThemeProvider* themeProvider = [[self window] themeProvider];
65     if (themeProvider) {
66       int resourceName = themeProvider->UsingSystemTheme()
67                              ? ThemeProperties::COLOR_TOOLBAR_BEZEL
68                              : ThemeProperties::COLOR_TOOLBAR;
69       NSColor* highlightColor = themeProvider->GetNSColor(resourceName);
70       if (highlightColor) {
71         [highlightColor set];
72         NSRectFillUsingOperation(NSIntersectionRect(borderRect, dirtyRect),
73                                  NSCompositeSourceOver);
74       }
75     }
76   }
79 // Mouse down events on the download shelf should not allow dragging the parent
80 // window around.
81 - (BOOL)mouseDownCanMoveWindow {
82   return NO;
85 - (ViewID)viewID {
86   return VIEW_ID_DOWNLOAD_SHELF;
89 - (BOOL)isOpaque {
90   return YES;
93 @end