Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_folder_window.mm
blob8f71bdca2375bc1ba93e647732204bd3857a3bb1
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.
5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h"
7 #import "base/logging.h"
8 #import "base/mac/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 "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h"
12 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h"
14 using bookmarks::kBookmarkBarMenuCornerRadius;
16 @implementation BookmarkBarFolderWindow
18 - (id)initWithContentRect:(NSRect)contentRect
19                 styleMask:(NSUInteger)windowStyle
20                   backing:(NSBackingStoreType)bufferingType
21                     defer:(BOOL)deferCreation {
22   if ((self = [super initWithContentRect:contentRect
23                                styleMask:NSBorderlessWindowMask // override
24                                  backing:bufferingType
25                                    defer:deferCreation])) {
26     [self setBackgroundColor:[NSColor clearColor]];
27     [self setOpaque:NO];
28   }
29   return self;
32 - (BOOL)canBecomeKeyWindow {
33   return YES;
36 - (BOOL)canBecomeMainWindow {
37   return NO;
40 // Override of keyDown as the NSWindow default implementation beeps.
41 - (void)keyDown:(NSEvent *)theEvent {
44 @end
47 @implementation BookmarkBarFolderWindowContentView
49 - (void)drawRect:(NSRect)rect {
50   // Like NSMenus, only the bottom corners are rounded.
51   NSBezierPath* bezier =
52       [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
53                             topLeftCornerRadius:kBookmarkBarMenuCornerRadius
54                            topRightCornerRadius:kBookmarkBarMenuCornerRadius
55                          bottomLeftCornerRadius:kBookmarkBarMenuCornerRadius
56                         bottomRightCornerRadius:kBookmarkBarMenuCornerRadius];
57   NSColor* startColor = [NSColor colorWithCalibratedWhite:0.91 alpha:1.0];
58   NSColor* midColor =
59       [startColor gtm_colorAdjustedFor:GTMColorationLightMidtone faded:YES];
60   NSColor* endColor =
61       [startColor gtm_colorAdjustedFor:GTMColorationLightPenumbra faded:YES];
63   base::scoped_nsobject<NSGradient> gradient(
64       [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0,
65                                                      midColor, 0.25,
66                                                      endColor, 0.5,
67                                                      midColor, 0.75,
68                                                      startColor, 1.0,
69                                                      nil]);
70   [gradient drawInBezierPath:bezier angle:0.0];
73 @end
76 @implementation BookmarkBarFolderWindowScrollView
78 // We want "draw background" of the NSScrollView in the xib to be NOT
79 // checked.  That allows us to round the bottom corners of the folder
80 // window.  However that also allows some scrollWheel: events to leak
81 // into the NSWindow behind it (even in a different application).
82 // Better to plug the scroll leak than to round corners for M5.
83 - (void)scrollWheel:(NSEvent *)theEvent {
84   DCHECK([[[self window] windowController]
85            respondsToSelector:@selector(scrollWheel:)]);
86   [[[self window] windowController] scrollWheel:theEvent];
89 @end