Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2010 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/extensions/chevron_menu_button_cell.h"
      6 
      7 namespace {
      8 
      9 // Width of the divider.
     10 const CGFloat kDividerWidth = 1.0;
     11 
     12 // Vertical inset from edge of cell to divider start.
     13 const CGFloat kDividerInset = 3.0;
     14 
     15 // Grayscale for the center of the divider.
     16 const CGFloat kDividerGrayscale = 0.5;
     17 
     18 }  // namespace
     19 
     20 @implementation ChevronMenuButtonCell
     21 
     22 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
     23   [super drawWithFrame:cellFrame inView:controlView];
     24 
     25   if ([self isMouseInside])
     26     return;
     27 
     28   NSColor* middleColor =
     29       [NSColor colorWithCalibratedWhite:kDividerGrayscale alpha:1.0];
     30   NSColor* endPointColor = [middleColor colorWithAlphaComponent:0.0];
     31 
     32   // Blend from background to |kDividerGrayscale| and back to
     33   // background.
     34   scoped_nsobject<NSGradient> borderGradient([[NSGradient alloc]
     35       initWithColorsAndLocations:endPointColor, (CGFloat)0.0,
     36                                  middleColor, (CGFloat)0.5,
     37                                  endPointColor, (CGFloat)1.0,
     38                                  nil]);
     39 
     40   NSRect edgeRect, remainder;
     41   NSDivideRect(cellFrame, &edgeRect, &remainder, kDividerWidth, NSMaxXEdge);
     42   edgeRect = NSInsetRect(edgeRect, 0.0, kDividerInset);
     43 
     44   [borderGradient drawInRect:edgeRect angle:90.0];
     45 }
     46 
     47 @end
     48