| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.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 "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" | 11 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" |
| 12 #include "ui/base/material_design/material_design_controller.h" |
| 12 | 13 |
| 13 using bookmarks::kBookmarkBarMenuCornerRadius; | 14 using bookmarks::kBookmarkBarMenuCornerRadius; |
| 14 | 15 |
| 16 namespace { |
| 17 |
| 18 // Material Design bookmark folder window background white. |
| 19 const CGFloat kMDFolderWindowBackgroundColor = 237. / 255.; |
| 20 |
| 21 } // namespace |
| 22 |
| 15 @implementation BookmarkBarFolderWindow | 23 @implementation BookmarkBarFolderWindow |
| 16 | 24 |
| 17 - (id)initWithContentRect:(NSRect)contentRect | 25 - (id)initWithContentRect:(NSRect)contentRect |
| 18 styleMask:(NSUInteger)windowStyle | 26 styleMask:(NSUInteger)windowStyle |
| 19 backing:(NSBackingStoreType)bufferingType | 27 backing:(NSBackingStoreType)bufferingType |
| 20 defer:(BOOL)deferCreation { | 28 defer:(BOOL)deferCreation { |
| 21 if ((self = [super initWithContentRect:contentRect | 29 if ((self = [super initWithContentRect:contentRect |
| 22 styleMask:NSBorderlessWindowMask // override | 30 styleMask:NSBorderlessWindowMask // override |
| 23 backing:bufferingType | 31 backing:bufferingType |
| 24 defer:deferCreation])) { | 32 defer:deferCreation])) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 38 | 46 |
| 39 // Override of keyDown as the NSWindow default implementation beeps. | 47 // Override of keyDown as the NSWindow default implementation beeps. |
| 40 - (void)keyDown:(NSEvent *)theEvent { | 48 - (void)keyDown:(NSEvent *)theEvent { |
| 41 } | 49 } |
| 42 | 50 |
| 43 @end | 51 @end |
| 44 | 52 |
| 45 | 53 |
| 46 @implementation BookmarkBarFolderWindowContentView | 54 @implementation BookmarkBarFolderWindowContentView |
| 47 | 55 |
| 56 + (NSColor*)backgroundColor { |
| 57 DCHECK(ui::MaterialDesignController::IsModeMaterial()); |
| 58 static NSColor* backgroundColor = |
| 59 [[NSColor colorWithGenericGamma22White:kMDFolderWindowBackgroundColor |
| 60 alpha:1.0] retain]; |
| 61 return backgroundColor; |
| 62 } |
| 63 |
| 48 - (void)drawRect:(NSRect)rect { | 64 - (void)drawRect:(NSRect)rect { |
| 49 // Like NSMenus, only the bottom corners are rounded. | 65 // Like NSMenus, only the bottom corners are rounded. |
| 50 NSBezierPath* bezier = | 66 NSBezierPath* bezier = |
| 51 [NSBezierPath bezierPathWithRoundedRect:[self bounds] | 67 [NSBezierPath bezierPathWithRoundedRect:[self bounds] |
| 52 xRadius:kBookmarkBarMenuCornerRadius | 68 xRadius:kBookmarkBarMenuCornerRadius |
| 53 yRadius:kBookmarkBarMenuCornerRadius]; | 69 yRadius:kBookmarkBarMenuCornerRadius]; |
| 54 NSColor* startColor = [NSColor colorWithCalibratedWhite:0.91 alpha:1.0]; | 70 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 55 NSColor* midColor = | 71 [[BookmarkBarFolderWindowContentView backgroundColor] set]; |
| 56 [startColor gtm_colorAdjustedFor:GTMColorationLightMidtone faded:YES]; | 72 [bezier fill]; |
| 57 NSColor* endColor = | 73 } else { |
| 58 [startColor gtm_colorAdjustedFor:GTMColorationLightPenumbra faded:YES]; | 74 NSColor* startColor = [NSColor colorWithCalibratedWhite:0.91 alpha:1.0]; |
| 75 NSColor* midColor = |
| 76 [startColor gtm_colorAdjustedFor:GTMColorationLightMidtone faded:YES]; |
| 77 NSColor* endColor = |
| 78 [startColor gtm_colorAdjustedFor:GTMColorationLightPenumbra faded:YES]; |
| 59 | 79 |
| 60 base::scoped_nsobject<NSGradient> gradient( | 80 base::scoped_nsobject<NSGradient> gradient( |
| 61 [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0, | 81 [[NSGradient alloc] initWithColorsAndLocations:startColor, 0.0, |
| 62 midColor, 0.25, | 82 midColor, 0.25, |
| 63 endColor, 0.5, | 83 endColor, 0.5, |
| 64 midColor, 0.75, | 84 midColor, 0.75, |
| 65 startColor, 1.0, | 85 startColor, 1.0, |
| 66 nil]); | 86 nil]); |
| 67 [gradient drawInBezierPath:bezier angle:0.0]; | 87 [gradient drawInBezierPath:bezier angle:0.0]; |
| 88 } |
| 68 } | 89 } |
| 69 | 90 |
| 70 @end | 91 @end |
| 71 | 92 |
| 72 | 93 |
| 73 @implementation BookmarkBarFolderWindowScrollView | 94 @implementation BookmarkBarFolderWindowScrollView |
| 74 | 95 |
| 75 // We want "draw background" of the NSScrollView in the xib to be NOT | 96 // We want "draw background" of the NSScrollView in the xib to be NOT |
| 76 // checked. That allows us to round the bottom corners of the folder | 97 // checked. That allows us to round the bottom corners of the folder |
| 77 // window. However that also allows some scrollWheel: events to leak | 98 // window. However that also allows some scrollWheel: events to leak |
| 78 // into the NSWindow behind it (even in a different application). | 99 // into the NSWindow behind it (even in a different application). |
| 79 // Better to plug the scroll leak than to round corners for M5. | 100 // Better to plug the scroll leak than to round corners for M5. |
| 80 - (void)scrollWheel:(NSEvent *)theEvent { | 101 - (void)scrollWheel:(NSEvent *)theEvent { |
| 81 DCHECK([[[self window] windowController] | 102 DCHECK([[[self window] windowController] |
| 82 respondsToSelector:@selector(scrollWheel:)]); | 103 respondsToSelector:@selector(scrollWheel:)]); |
| 83 [[[self window] windowController] scrollWheel:theEvent]; | 104 [[[self window] windowController] scrollWheel:theEvent]; |
| 84 } | 105 } |
| 85 | 106 |
| 86 @end | 107 @end |
| OLD | NEW |