• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#include "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h"
6
7#include "base/memory/scoped_nsobject.h"
8#import "chrome/browser/themes/theme_service.h"
9#import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
10#import "chrome/browser/ui/cocoa/themed_window.h"
11
12namespace {
13
14const double kBackgroundColorTop[3] =
15    {255.0 / 255.0, 242.0 / 255.0, 183.0 / 255.0};
16const double kBackgroundColorBottom[3] =
17    {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0};
18}
19
20@implementation InfoBarGradientView
21
22- (id)initWithFrame:(NSRect)frameRect {
23  if ((self = [super initWithFrame:frameRect])) {
24    NSColor* startingColor =
25        [NSColor colorWithCalibratedRed:kBackgroundColorTop[0]
26                                  green:kBackgroundColorTop[1]
27                                   blue:kBackgroundColorTop[2]
28                                  alpha:1.0];
29    NSColor* endingColor =
30        [NSColor colorWithCalibratedRed:kBackgroundColorBottom[0]
31                                  green:kBackgroundColorBottom[1]
32                                   blue:kBackgroundColorBottom[2]
33                                  alpha:1.0];
34    scoped_nsobject<NSGradient> gradient(
35        [[NSGradient alloc] initWithStartingColor:startingColor
36                                       endingColor:endingColor]);
37    [self setGradient:gradient];
38  }
39  return self;
40}
41
42- (NSColor*)strokeColor {
43  ui::ThemeProvider* themeProvider = [[self window] themeProvider];
44  if (!themeProvider)
45    return [NSColor blackColor];
46
47  BOOL active = [[self window] isMainWindow];
48  return themeProvider->GetNSColor(
49      active ? ThemeService::COLOR_TOOLBAR_STROKE :
50               ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE,
51      true);
52}
53
54- (void)drawRect:(NSRect)rect {
55  NSRect bounds = [self bounds];
56  bounds.size.height = infobars::kBaseHeight;
57
58  // Around the bounds of the infobar, continue drawing the path into which the
59  // gradient will be drawn.
60  NSBezierPath* infoBarPath = [NSBezierPath bezierPath];
61  [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))];
62  [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))];
63  scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]);
64
65  [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))];
66  [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))];
67  [infoBarPath closePath];
68
69  // Draw the gradient.
70  [[self gradient] drawInBezierPath:infoBarPath angle:270];
71
72  // Stroke the bottom.
73  NSColor* strokeColor = [self strokeColor];
74  if (strokeColor) {
75    [strokeColor set];
76    NSRect borderRect, contentRect;
77    NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge);
78    NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
79  }
80
81  // Add an inner stroke.
82  [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke];
83  NSAffineTransform* transform = [NSAffineTransform transform];
84  [transform translateXBy:0.0 yBy:-1.0];
85  [topPath transformUsingAffineTransform:transform];
86  [topPath stroke];
87}
88
89- (BOOL)mouseDownCanMoveWindow {
90  return NO;
91}
92
93// This view is intentionally not opaque because it overlaps with the findbar.
94
95- (BOOL)accessibilityIsIgnored {
96  return NO;
97}
98
99- (id)accessibilityAttributeValue:(NSString*)attribute {
100  if ([attribute isEqual:NSAccessibilityRoleAttribute])
101    return NSAccessibilityGroupRole;
102
103  return [super accessibilityAttributeValue:attribute];
104}
105
106@end
107