Home | History | Annotate | Download | only in location_bar
      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 <algorithm>
      6 
      7 #import "chrome/browser/ui/cocoa/location_bar/instant_opt_in_view.h"
      8 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
      9 
     10 namespace {
     11 // How to round off the popup's corners.  Goal is to match star and go
     12 // buttons.
     13 const CGFloat kPopupRoundingRadius = 3.5;
     14 
     15 // How far from the top of the view to place the horizontal line.
     16 const CGFloat kHorizontalLineTopOffset = 2;
     17 
     18 // How far from the sides to inset the horizontal line.
     19 const CGFloat kHorizontalLineInset = 2;
     20 }
     21 
     22 @implementation InstantOptInView
     23 
     24 - (void)drawRect:(NSRect)rect {
     25   // Round off the bottom corners only.
     26   NSBezierPath* path =
     27      [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
     28                            topLeftCornerRadius:0
     29                           topRightCornerRadius:0
     30                         bottomLeftCornerRadius:kPopupRoundingRadius
     31                        bottomRightCornerRadius:kPopupRoundingRadius];
     32 
     33   [NSGraphicsContext saveGraphicsState];
     34   [path addClip];
     35 
     36   // Background is white.
     37   [[NSColor whiteColor] set];
     38   NSRectFill(rect);
     39 
     40   // Draw a horizontal line 2 px down from the top of the view, inset at the
     41   // sides by 2 px.
     42   CGFloat lineY = NSMaxY([self bounds]) - kHorizontalLineTopOffset;
     43   CGFloat minX = std::min(NSMinX([self bounds]) + kHorizontalLineInset,
     44                           NSMaxX([self bounds]));
     45   CGFloat maxX = std::max(NSMaxX([self bounds]) - kHorizontalLineInset,
     46                           NSMinX([self bounds]));
     47 
     48   [[NSColor lightGrayColor] set];
     49   NSRectFill(NSMakeRect(minX, lineY, maxX - minX, 1));
     50 
     51   [NSGraphicsContext restoreGraphicsState];
     52 }
     53 
     54 @end
     55