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/cocoa/bookmark_bar_folder_window.h" | 5 #import "chrome/browser/cocoa/bookmark_bar_folder_window.h" |
6 | 6 |
7 #import "base/logging.h" | 7 #import "base/logging.h" |
| 8 #include "base/nsimage_cache_mac.h" |
8 #import "base/scoped_nsobject.h" | 9 #import "base/scoped_nsobject.h" |
9 #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" | 10 #import "chrome/browser/cocoa/bookmark_bar_folder_controller.h" |
10 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 11 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
11 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 12 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
12 | 13 |
13 | 14 |
14 @implementation BookmarkBarFolderWindow | 15 @implementation BookmarkBarFolderWindow |
15 | 16 |
16 - (id)initWithContentRect:(NSRect)contentRect | 17 - (id)initWithContentRect:(NSRect)contentRect |
17 styleMask:(NSUInteger)windowStyle | 18 styleMask:(NSUInteger)windowStyle |
(...skipping 13 matching lines...) Expand all Loading... |
31 | 32 |
32 | 33 |
33 namespace { | 34 namespace { |
34 // Corner radius for our bookmark bar folder window. | 35 // Corner radius for our bookmark bar folder window. |
35 // Copied from bubble_view.mm. | 36 // Copied from bubble_view.mm. |
36 const CGFloat kViewCornerRadius = 4.0; | 37 const CGFloat kViewCornerRadius = 4.0; |
37 } | 38 } |
38 | 39 |
39 @implementation BookmarkBarFolderWindowContentView | 40 @implementation BookmarkBarFolderWindowContentView |
40 | 41 |
| 42 - (void)awakeFromNib { |
| 43 arrowUpImage_.reset([nsimage_cache::ImageNamed(@"menu_overflow_up.pdf") |
| 44 retain]); |
| 45 arrowDownImage_.reset([nsimage_cache::ImageNamed(@"menu_overflow_down.pdf") |
| 46 retain]); |
| 47 } |
| 48 |
| 49 // Draw the arrows at the top and bottom of the folder window as a |
| 50 // visual indication that scrolling is possible. We always draw the |
| 51 // scrolling arrows; when not relevant (e.g. when not scrollable), the |
| 52 // scroll view overlaps me and the arrows aren't visible. |
| 53 - (void)drawScrollArrows:(NSRect)rect { |
| 54 NSRect visibleRect = [self bounds]; |
| 55 |
| 56 // On top |
| 57 [arrowUpImage_ setFlipped:[self isFlipped]]; |
| 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 |
| 69 // On bottom |
| 70 [arrowDownImage_ setFlipped:[self isFlipped]]; |
| 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 } |
| 81 |
41 - (void)drawRect:(NSRect)rect { | 82 - (void)drawRect:(NSRect)rect { |
42 NSRect bounds = [self bounds]; | 83 NSRect bounds = [self bounds]; |
43 // Like NSMenus, only the bottom corners are rounded. | 84 // Like NSMenus, only the bottom corners are rounded. |
44 NSBezierPath* bezier = | 85 NSBezierPath* bezier = |
45 [NSBezierPath gtm_bezierPathWithRoundRect:bounds | 86 [NSBezierPath gtm_bezierPathWithRoundRect:bounds |
46 topLeftCornerRadius:0 | 87 topLeftCornerRadius:0 |
47 topRightCornerRadius:0 | 88 topRightCornerRadius:0 |
48 bottomLeftCornerRadius:kViewCornerRadius | 89 bottomLeftCornerRadius:kViewCornerRadius |
49 bottomRightCornerRadius:kViewCornerRadius]; | 90 bottomRightCornerRadius:kViewCornerRadius]; |
50 [bezier closePath]; | 91 [bezier closePath]; |
(...skipping 13 matching lines...) Expand all Loading... |
64 [base_color gtm_colorAdjustedFor:GTMColorationLightPenumbra | 105 [base_color gtm_colorAdjustedFor:GTMColorationLightPenumbra |
65 faded:YES]; | 106 faded:YES]; |
66 | 107 |
67 scoped_nsobject<NSGradient> gradient( | 108 scoped_nsobject<NSGradient> gradient( |
68 [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0, | 109 [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0, |
69 midColor, 0.25, | 110 midColor, 0.25, |
70 endColor, 0.5, | 111 endColor, 0.5, |
71 glowColor, 0.75, | 112 glowColor, 0.75, |
72 nil]); | 113 nil]); |
73 [gradient drawInBezierPath:bezier angle:0.0]; | 114 [gradient drawInBezierPath:bezier angle:0.0]; |
| 115 |
| 116 [self drawScrollArrows:rect]; |
74 } | 117 } |
75 | 118 |
76 @end | 119 @end |
77 | 120 |
78 | 121 |
79 @implementation BookmarkBarFolderWindowScrollView | 122 @implementation BookmarkBarFolderWindowScrollView |
80 | 123 |
81 // We want "draw background" of the NSScrollView in the xib to be NOT | 124 // We want "draw background" of the NSScrollView in the xib to be NOT |
82 // checked. That allows us to round the bottom corners of the folder | 125 // checked. That allows us to round the bottom corners of the folder |
83 // window. However that also allows some scrollWheel: events to leak | 126 // window. However that also allows some scrollWheel: events to leak |
84 // into the NSWindow behind it (even in a different application). | 127 // into the NSWindow behind it (even in a different application). |
85 // Better to plug the scroll leak than to round corners for M5. | 128 // Better to plug the scroll leak than to round corners for M5. |
86 - (void)scrollWheel:(NSEvent *)theEvent { | 129 - (void)scrollWheel:(NSEvent *)theEvent { |
87 DCHECK([[[self window] windowController] | 130 DCHECK([[[self window] windowController] |
88 respondsToSelector:@selector(scrollWheel:)]); | 131 respondsToSelector:@selector(scrollWheel:)]); |
89 [[[self window] windowController] scrollWheel:theEvent]; | 132 [[[self window] windowController] scrollWheel:theEvent]; |
90 } | 133 } |
91 | 134 |
92 | |
93 @end | 135 @end |
OLD | NEW |