Home | History | Annotate | Download | only in bookmarks
      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/bookmarks/bookmark_bar_folder_window.h"
      6 
      7 #import "base/logging.h"
      8 #import "base/memory/scoped_nsobject.h"
      9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
     10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h"
     11 #import "chrome/browser/ui/cocoa/image_utils.h"
     12 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
     13 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
     14 
     15 using bookmarks::kBookmarkBarMenuCornerRadius;
     16 
     17 @implementation BookmarkBarFolderWindow
     18 
     19 - (id)initWithContentRect:(NSRect)contentRect
     20                 styleMask:(NSUInteger)windowStyle
     21                   backing:(NSBackingStoreType)bufferingType
     22                     defer:(BOOL)deferCreation {
     23   if ((self = [super initWithContentRect:contentRect
     24                                styleMask:NSBorderlessWindowMask // override
     25                                  backing:bufferingType
     26                                    defer:deferCreation])) {
     27     [self setBackgroundColor:[NSColor clearColor]];
     28     [self setOpaque:NO];
     29   }
     30   return self;
     31 }
     32 
     33 - (BOOL)canBecomeKeyWindow {
     34   return YES;
     35 }
     36 
     37 - (BOOL)canBecomeMainWindow {
     38   return NO;
     39 }
     40 
     41 // Override of keyDown as the NSWindow default implementation beeps.
     42 - (void)keyDown:(NSEvent *)theEvent {
     43 }
     44 
     45 @end
     46 
     47 
     48 @implementation BookmarkBarFolderWindowContentView
     49 
     50 - (void)drawRect:(NSRect)rect {
     51   // Like NSMenus, only the bottom corners are rounded.
     52   NSBezierPath* bezier =
     53       [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
     54                             topLeftCornerRadius:kBookmarkBarMenuCornerRadius
     55                            topRightCornerRadius:kBookmarkBarMenuCornerRadius
     56                          bottomLeftCornerRadius:kBookmarkBarMenuCornerRadius
     57                         bottomRightCornerRadius:kBookmarkBarMenuCornerRadius];
     58   NSColor* startColor = [NSColor colorWithCalibratedWhite:0.91 alpha:1.0];
     59   NSColor* midColor =
     60       [startColor gtm_colorAdjustedFor:GTMColorationLightMidtone faded:YES];
     61   NSColor* endColor =
     62       [startColor gtm_colorAdjustedFor:GTMColorationLightPenumbra faded:YES];
     63 
     64   scoped_nsobject<NSGradient> gradient(
     65     [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0,
     66                         midColor, 0.25,
     67                         endColor, 0.5,
     68                         midColor, 0.75,
     69                         startColor, 1.0,
     70                         nil]);
     71   [gradient drawInBezierPath:bezier angle:0.0];
     72 }
     73 
     74 @end
     75 
     76 
     77 @implementation BookmarkBarFolderWindowScrollView
     78 
     79 // We want "draw background" of the NSScrollView in the xib to be NOT
     80 // checked.  That allows us to round the bottom corners of the folder
     81 // window.  However that also allows some scrollWheel: events to leak
     82 // into the NSWindow behind it (even in a different application).
     83 // Better to plug the scroll leak than to round corners for M5.
     84 - (void)scrollWheel:(NSEvent *)theEvent {
     85   DCHECK([[[self window] windowController]
     86            respondsToSelector:@selector(scrollWheel:)]);
     87   [[[self window] windowController] scrollWheel:theEvent];
     88 }
     89 
     90 @end
     91