OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
6 | 6 |
7 #import "base/logging.h" | 7 #import "base/logging.h" |
8 #include "app/mac/nsimage_cache.h" | |
9 #import "base/scoped_nsobject.h" | 8 #import "base/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" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
11 #import "chrome/browser/ui/cocoa/image_utils.h" | 11 #import "chrome/browser/ui/cocoa/image_utils.h" |
12 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 12 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
13 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 13 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
14 | 14 |
15 using bookmarks::kBookmarkBarMenuCornerRadius; | |
15 | 16 |
16 @implementation BookmarkBarFolderWindow | 17 @implementation BookmarkBarFolderWindow |
17 | 18 |
18 - (id)initWithContentRect:(NSRect)contentRect | 19 - (id)initWithContentRect:(NSRect)contentRect |
19 styleMask:(NSUInteger)windowStyle | 20 styleMask:(NSUInteger)windowStyle |
20 backing:(NSBackingStoreType)bufferingType | 21 backing:(NSBackingStoreType)bufferingType |
21 defer:(BOOL)deferCreation { | 22 defer:(BOOL)deferCreation { |
22 if ((self = [super initWithContentRect:contentRect | 23 if ((self = [super initWithContentRect:contentRect |
23 styleMask:NSBorderlessWindowMask // override | 24 styleMask:NSBorderlessWindowMask // override |
24 backing:bufferingType | 25 backing:bufferingType |
25 defer:deferCreation])) { | 26 defer:deferCreation])) { |
26 [self setBackgroundColor:[NSColor clearColor]]; | 27 [self setBackgroundColor:[NSColor clearColor]]; |
27 [self setOpaque:NO]; | 28 [self setOpaque:NO]; |
28 } | 29 } |
29 return self; | 30 return self; |
30 } | 31 } |
31 | 32 |
32 @end | 33 @end |
33 | 34 |
34 | 35 |
35 namespace { | |
36 // Corner radius for our bookmark bar folder window. | |
37 // Copied from bubble_view.mm. | |
38 const CGFloat kViewCornerRadius = 4.0; | |
39 } | |
40 | |
41 @implementation BookmarkBarFolderWindowContentView | 36 @implementation BookmarkBarFolderWindowContentView |
42 | 37 |
43 - (void)awakeFromNib { | |
44 arrowUpImage_.reset( | |
45 [app::mac::GetCachedImageWithName(@"menu_overflow_up.pdf") retain]); | |
46 arrowDownImage_.reset( | |
47 [app::mac::GetCachedImageWithName(@"menu_overflow_down.pdf") retain]); | |
48 } | |
49 | |
50 // Draw the arrows at the top and bottom of the folder window as a | |
51 // visual indication that scrolling is possible. We always draw the | |
52 // scrolling arrows; when not relevant (e.g. when not scrollable), the | |
53 // scroll view overlaps the window and the arrows aren't visible. | |
54 - (void)drawScrollArrows:(NSRect)rect { | |
John Grabowski
2011/01/06 23:30:18
I like how you moved this out of window
| |
55 NSRect visibleRect = [self bounds]; | |
56 | |
57 // On top | |
58 NSRect imageRect = NSZeroRect; | |
59 imageRect.size = [arrowUpImage_ size]; | |
60 NSRect drawRect = NSOffsetRect( | |
61 imageRect, | |
62 (NSWidth(visibleRect) - NSWidth(imageRect)) / 2, | |
63 NSHeight(visibleRect) - NSHeight(imageRect)); | |
64 [arrowUpImage_ drawInRect:drawRect | |
65 fromRect:imageRect | |
66 operation:NSCompositeSourceOver | |
67 fraction:1.0 | |
68 neverFlipped:YES]; | |
69 | |
70 // On bottom | |
71 imageRect = NSZeroRect; | |
72 imageRect.size = [arrowDownImage_ size]; | |
73 drawRect = NSOffsetRect(imageRect, | |
74 (NSWidth(visibleRect) - NSWidth(imageRect)) / 2, | |
75 0); | |
76 [arrowDownImage_ drawInRect:drawRect | |
77 fromRect:imageRect | |
78 operation:NSCompositeSourceOver | |
79 fraction:1.0 | |
80 neverFlipped:YES]; | |
81 } | |
82 | |
83 - (void)drawRect:(NSRect)rect { | 38 - (void)drawRect:(NSRect)rect { |
84 NSRect bounds = [self bounds]; | |
85 // Like NSMenus, only the bottom corners are rounded. | 39 // Like NSMenus, only the bottom corners are rounded. |
86 NSBezierPath* bezier = | 40 NSBezierPath* bezier = |
87 [NSBezierPath gtm_bezierPathWithRoundRect:bounds | 41 [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds] |
88 topLeftCornerRadius:0 | 42 topLeftCornerRadius:kBookmarkBarMenuCornerRadius |
89 topRightCornerRadius:0 | 43 topRightCornerRadius:kBookmarkBarMenuCornerRadius |
90 bottomLeftCornerRadius:kViewCornerRadius | 44 bottomLeftCornerRadius:kBookmarkBarMenuCornerRadius |
91 bottomRightCornerRadius:kViewCornerRadius]; | 45 bottomRightCornerRadius:kBookmarkBarMenuCornerRadius]; |
92 [bezier closePath]; | 46 NSColor* startColor = [NSColor colorWithCalibratedWhite:0.91 alpha:1.0]; |
93 | |
94 // TODO(jrg): share code with info_bubble_view.mm? Or bubble_view.mm? | |
95 NSColor* base_color = [NSColor colorWithCalibratedWhite:0.5 alpha:1.0]; | |
96 NSColor* startColor = | |
97 [base_color gtm_colorAdjustedFor:GTMColorationLightHighlight | |
98 faded:YES]; | |
99 NSColor* midColor = | 47 NSColor* midColor = |
100 [base_color gtm_colorAdjustedFor:GTMColorationLightMidtone | 48 [startColor gtm_colorAdjustedFor:GTMColorationLightMidtone faded:YES]; |
101 faded:YES]; | |
102 NSColor* endColor = | 49 NSColor* endColor = |
103 [base_color gtm_colorAdjustedFor:GTMColorationLightShadow | 50 [startColor gtm_colorAdjustedFor:GTMColorationLightPenumbra faded:YES]; |
104 faded:YES]; | |
105 NSColor* glowColor = | |
106 [base_color gtm_colorAdjustedFor:GTMColorationLightPenumbra | |
107 faded:YES]; | |
108 | 51 |
109 scoped_nsobject<NSGradient> gradient( | 52 scoped_nsobject<NSGradient> gradient( |
110 [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0, | 53 [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0, |
111 midColor, 0.25, | 54 midColor, 0.25, |
112 endColor, 0.5, | 55 endColor, 0.5, |
113 glowColor, 0.75, | 56 midColor, 0.75, |
57 startColor, 1.0, | |
114 nil]); | 58 nil]); |
115 [gradient drawInBezierPath:bezier angle:0.0]; | 59 [gradient drawInBezierPath:bezier angle:0.0]; |
116 | |
117 [self drawScrollArrows:rect]; | |
118 } | 60 } |
119 | 61 |
120 @end | 62 @end |
121 | 63 |
122 | 64 |
123 @implementation BookmarkBarFolderWindowScrollView | 65 @implementation BookmarkBarFolderWindowScrollView |
124 | 66 |
125 // We want "draw background" of the NSScrollView in the xib to be NOT | 67 // We want "draw background" of the NSScrollView in the xib to be NOT |
126 // checked. That allows us to round the bottom corners of the folder | 68 // checked. That allows us to round the bottom corners of the folder |
127 // window. However that also allows some scrollWheel: events to leak | 69 // window. However that also allows some scrollWheel: events to leak |
128 // into the NSWindow behind it (even in a different application). | 70 // into the NSWindow behind it (even in a different application). |
129 // Better to plug the scroll leak than to round corners for M5. | 71 // Better to plug the scroll leak than to round corners for M5. |
130 - (void)scrollWheel:(NSEvent *)theEvent { | 72 - (void)scrollWheel:(NSEvent *)theEvent { |
131 DCHECK([[[self window] windowController] | 73 DCHECK([[[self window] windowController] |
132 respondsToSelector:@selector(scrollWheel:)]); | 74 respondsToSelector:@selector(scrollWheel:)]); |
133 [[[self window] windowController] scrollWheel:theEvent]; | 75 [[[self window] windowController] scrollWheel:theEvent]; |
134 } | 76 } |
135 | 77 |
136 @end | 78 @end |
OLD | NEW |