1// Copyright (c) 2011 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 7#include "base/memory/scoped_nsobject.h" 8#include "chrome/browser/themes/theme_service.h" 9#import "chrome/browser/ui/cocoa/themed_window.h" 10#import "chrome/browser/ui/cocoa/view_id_util.h" 11#include "grit/theme_resources.h" 12 13@implementation DownloadShelfView 14 15- (NSColor*)strokeColor { 16 BOOL isKey = [[self window] isKeyWindow]; 17 ui::ThemeProvider* themeProvider = [[self window] themeProvider]; 18 return themeProvider ? themeProvider->GetNSColor( 19 isKey ? ThemeService::COLOR_TOOLBAR_STROKE : 20 ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE, true) : 21 [NSColor blackColor]; 22} 23 24- (void)drawRect:(NSRect)rect { 25 BOOL isKey = [[self window] isKeyWindow]; 26 ui::ThemeProvider* themeProvider = [[self window] themeProvider]; 27 if (!themeProvider) 28 return; 29 30 NSColor* backgroundImageColor = 31 themeProvider->GetNSImageColorNamed(IDR_THEME_TOOLBAR, false); 32 if (backgroundImageColor) { 33 // We want our backgrounds for the shelf to be phased from the upper 34 // left hand corner of the view. 35 NSPoint phase = NSMakePoint(0, NSHeight([self bounds])); 36 [[NSGraphicsContext currentContext] setPatternPhase:phase]; 37 [backgroundImageColor set]; 38 NSRectFill([self bounds]); 39 } else { 40 NSGradient* gradient = themeProvider->GetNSGradient( 41 isKey ? ThemeService::GRADIENT_TOOLBAR : 42 ThemeService::GRADIENT_TOOLBAR_INACTIVE); 43 NSPoint startPoint = [self convertPoint:NSMakePoint(0, 0) fromView:nil]; 44 NSPoint endPoint = 45 [self convertPoint:NSMakePoint(0, [self frame].size.height) 46 fromView:nil]; 47 48 [gradient drawFromPoint:startPoint 49 toPoint:endPoint 50 options:NSGradientDrawsBeforeStartingLocation | 51 NSGradientDrawsAfterEndingLocation]; 52 } 53 54 // Draw top stroke 55 [[self strokeColor] set]; 56 NSRect borderRect, contentRect; 57 NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMaxYEdge); 58 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); 59} 60 61// Mouse down events on the download shelf should not allow dragging the parent 62// window around. 63- (BOOL)mouseDownCanMoveWindow { 64 return NO; 65} 66 67- (ViewID)viewID { 68 return VIEW_ID_DOWNLOAD_SHELF; 69} 70 71@end 72