| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/omnibox/omnibox_popup_separator_view.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_separator_view.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" |
| 7 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
| 8 #import "ui/base/cocoa/nsview_additions.h" | 9 #import "ui/base/cocoa/nsview_additions.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 10 | 11 |
| 11 @implementation OmniboxPopupTopSeparatorView | 12 @implementation OmniboxPopupTopSeparatorView |
| 12 | 13 |
| 13 + (CGFloat)preferredHeight { | 14 + (CGFloat)preferredHeight { |
| 14 return 1; | 15 return 1; |
| 15 } | 16 } |
| 16 | 17 |
| 17 - (void)drawRect:(NSRect)rect { | 18 - (void)drawRect:(NSRect)rect { |
| 18 NSRect separatorRect = [self bounds]; | 19 NSRect separatorRect = [self bounds]; |
| 19 separatorRect.size.height = [self cr_lineWidth]; | 20 separatorRect.size.height = [self cr_lineWidth]; |
| 20 [[self strokeColor] set]; | 21 [[self strokeColor] set]; |
| 21 NSRectFillUsingOperation(separatorRect, NSCompositeSourceOver); | 22 NSRectFillUsingOperation(separatorRect, NSCompositeSourceOver); |
| 22 } | 23 } |
| 23 | 24 |
| 24 @end | 25 @end |
| 25 | 26 |
| 26 @implementation OmniboxPopupBottomSeparatorView | 27 @implementation OmniboxPopupBottomSeparatorView |
| 27 | 28 |
| 28 + (CGFloat)preferredHeight { | 29 + (CGFloat)preferredHeight { |
| 29 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 30 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 30 NSImage* shadowImage = | 31 NSImage* shadowImage = |
| 31 rb.GetNativeImageNamed(IDR_OVERLAY_DROP_SHADOW).ToNSImage(); | 32 rb.GetNativeImageNamed(IDR_OVERLAY_DROP_SHADOW).ToNSImage(); |
| 32 return [shadowImage size].height; | 33 return [shadowImage size].height; |
| 33 } | 34 } |
| 34 | 35 |
| 36 - (instancetype)initWithFrame:(NSRect)frame forDarkTheme:(BOOL)isDarkTheme { |
| 37 if ((self = [self initWithFrame:frame])) { |
| 38 isDarkTheme_ = isDarkTheme; |
| 39 // For dark themes the OmniboxPopupBottomSeparatorView will render a shadow |
| 40 // rather than blit a bitmap. Shadows are expensive to draw so use a layer |
| 41 // to cache the result. |
| 42 if (isDarkTheme_) { |
| 43 [self setWantsLayer:YES]; |
| 44 } |
| 45 } |
| 46 return self; |
| 47 } |
| 48 |
| 35 - (void)drawRect:(NSRect)rect { | 49 - (void)drawRect:(NSRect)rect { |
| 36 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 37 NSRect bounds = [self bounds]; | 50 NSRect bounds = [self bounds]; |
| 38 | 51 |
| 52 if (isDarkTheme_) { |
| 53 // There's an image for the shadow the Omnibox casts, but this shadow is |
| 54 // an opaque mix of white and black, which makes it look strange against a |
| 55 // dark NTP page. For dark mode, draw the shadow in code instead so that |
| 56 // it has some transparency. |
| 57 base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); |
| 58 [shadow setShadowBlurRadius:8]; |
| 59 [shadow setShadowColor:[NSColor blackColor]]; |
| 60 [shadow set]; |
| 61 |
| 62 // Fill a rect that's out of view to get just the shadow it casts. |
| 63 [[NSColor blackColor] set]; |
| 64 NSRectFill(NSMakeRect(-3, NSMaxY(bounds), NSWidth(bounds) + 6, 5)); |
| 65 return; |
| 66 } |
| 67 |
| 39 // Draw the shadow. | 68 // Draw the shadow. |
| 69 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 40 NSImage* shadowImage = | 70 NSImage* shadowImage = |
| 41 rb.GetNativeImageNamed(IDR_OVERLAY_DROP_SHADOW).ToNSImage(); | 71 rb.GetNativeImageNamed(IDR_OVERLAY_DROP_SHADOW).ToNSImage(); |
| 42 [shadowImage drawInRect:bounds | 72 [shadowImage drawInRect:bounds |
| 43 fromRect:NSZeroRect | 73 fromRect:NSZeroRect |
| 44 operation:NSCompositeSourceOver | 74 operation:NSCompositeSourceOver |
| 45 fraction:1.0]; | 75 fraction:1.0]; |
| 46 } | 76 } |
| 47 | 77 |
| 48 @end | 78 @end |
| OLD | NEW |