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
25 defer:deferCreation])) {
26 [self setBackgroundColor:[NSColor clearColor]];
32 - (BOOL)canBecomeKeyWindow {
36 - (BOOL)canBecomeMainWindow {
40 // Override of keyDown as the NSWindow default implementation beeps.
41 - (void)keyDown:(NSEvent *)theEvent {
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];
59 [startColor gtm_colorAdjustedFor:GTMColorationLightMidtone faded:YES];
61 [startColor gtm_colorAdjustedFor:GTMColorationLightPenumbra faded:YES];
63 base::scoped_nsobject<NSGradient> gradient(
64 [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0,
70 [gradient drawInBezierPath:bezier angle:0.0];
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];