| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" | 5 #include "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/infobars/infobar.h" | 8 #include "chrome/browser/infobars/infobar.h" |
| 9 #import "chrome/browser/themes/theme_properties.h" | 9 #import "chrome/browser/themes/theme_properties.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 11 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 11 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 13 #import "chrome/browser/ui/cocoa/themed_window.h" | 13 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 14 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
| 15 #include "ui/base/theme_provider.h" | 15 #include "ui/base/theme_provider.h" |
| 16 | 16 |
| 17 namespace { | |
| 18 | |
| 19 const CGFloat kTipWidth = 23; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 @implementation InfoBarGradientView | 17 @implementation InfoBarGradientView |
| 24 | 18 |
| 25 @synthesize tipApex = tipApex_; | 19 @synthesize arrowHeight = arrowHeight_; |
| 20 @synthesize arrowHalfWidth = arrowHalfWidth_; |
| 21 @synthesize arrowX = arrowX_; |
| 26 @synthesize hasTip = hasTip_; | 22 @synthesize hasTip = hasTip_; |
| 27 | 23 |
| 28 - (id)initWithFrame:(NSRect)frame { | 24 - (id)initWithFrame:(NSRect)frame { |
| 29 if ((self = [super initWithFrame:frame])) { | 25 if ((self = [super initWithFrame:frame])) { |
| 30 hasTip_ = YES; | 26 hasTip_ = YES; |
| 31 } | 27 } |
| 32 return self; | 28 return self; |
| 33 } | 29 } |
| 34 | 30 |
| 35 - (id)initWithCoder:(NSCoder*)decoder { | 31 - (id)initWithCoder:(NSCoder*)decoder { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 return [NSColor blackColor]; | 50 return [NSColor blackColor]; |
| 55 | 51 |
| 56 BOOL active = [[self window] isMainWindow]; | 52 BOOL active = [[self window] isMainWindow]; |
| 57 return themeProvider->GetNSColor( | 53 return themeProvider->GetNSColor( |
| 58 active ? ThemeProperties::COLOR_TOOLBAR_STROKE : | 54 active ? ThemeProperties::COLOR_TOOLBAR_STROKE : |
| 59 ThemeProperties::COLOR_TOOLBAR_STROKE_INACTIVE); | 55 ThemeProperties::COLOR_TOOLBAR_STROKE_INACTIVE); |
| 60 } | 56 } |
| 61 | 57 |
| 62 - (void)drawRect:(NSRect)rect { | 58 - (void)drawRect:(NSRect)rect { |
| 63 NSRect bounds = [self bounds]; | 59 NSRect bounds = [self bounds]; |
| 64 bounds.size.height = infobars::kBaseHeight; | 60 bounds.size.height = InfoBar::kDefaultBarTargetHeight; |
| 65 | 61 |
| 66 const CGFloat kHalfWidth = kTipWidth / 2.0; | 62 CGFloat tipXOffset = arrowX_ - arrowHalfWidth_; |
| 67 NSPoint localApex = [self convertPoint:self.tipApex fromView:nil]; | |
| 68 CGFloat tipXOffset = localApex.x - kHalfWidth; | |
| 69 | 63 |
| 70 // Around the bounds of the infobar, continue drawing the path into which the | 64 // Around the bounds of the infobar, continue drawing the path into which the |
| 71 // gradient will be drawn. | 65 // gradient will be drawn. |
| 72 NSBezierPath* infoBarPath = [NSBezierPath bezierPath]; | 66 NSBezierPath* infoBarPath = [NSBezierPath bezierPath]; |
| 73 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; | 67 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; |
| 74 | 68 |
| 75 // Draw the tip. | 69 // Draw the tip. |
| 76 if (hasTip_) { | 70 if (hasTip_) { |
| 77 [infoBarPath lineToPoint:NSMakePoint(tipXOffset, NSMaxY(bounds))]; | 71 [infoBarPath lineToPoint:NSMakePoint(tipXOffset, NSMaxY(bounds))]; |
| 78 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth, | 72 [infoBarPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_, |
| 79 infobars::kTipHeight)]; | 73 arrowHeight_)]; |
| 80 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth, | 74 [infoBarPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_, |
| 81 -infobars::kTipHeight)]; | 75 -arrowHeight_)]; |
| 82 } | 76 } |
| 83 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; | 77 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; |
| 84 | 78 |
| 85 // Save off the top path of the infobar. | 79 // Save off the top path of the infobar. |
| 86 base::scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]); | 80 base::scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]); |
| 87 | 81 |
| 88 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; | 82 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; |
| 89 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))]; | 83 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))]; |
| 90 [infoBarPath closePath]; | 84 [infoBarPath closePath]; |
| 91 | 85 |
| 92 // Draw the gradient. | 86 // Draw the gradient. |
| 93 [[self gradient] drawInBezierPath:infoBarPath angle:270]; | 87 [[self gradient] drawInBezierPath:infoBarPath angle:270]; |
| 94 | 88 |
| 95 NSColor* strokeColor = [self strokeColor]; | 89 NSColor* strokeColor = [self strokeColor]; |
| 96 if (strokeColor) { | 90 if (strokeColor) { |
| 97 [strokeColor set]; | 91 [strokeColor set]; |
| 98 | 92 |
| 99 // Stroke the bottom of the infobar. | 93 // Stroke the bottom of the infobar. |
| 100 NSRect borderRect, contentRect; | 94 NSRect borderRect, contentRect; |
| 101 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge); | 95 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge); |
| 102 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | 96 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
| 103 | 97 |
| 104 // Re-stroke the top because the tip will have no stroke. This will draw | 98 // Re-stroke the top because the tip will have no stroke. This will draw |
| 105 // over the divider drawn by the bottom of the tabstrip. | 99 // over the divider drawn by the bottom of the tabstrip. |
| 106 [topPath stroke]; | 100 [topPath stroke]; |
| 107 } | 101 } |
| 108 | 102 |
| 109 // Add an inner stroke. | 103 // Add an inner stroke. |
| 110 const CGFloat kHighlightTipHeight = infobars::kTipHeight - 1; | 104 const CGFloat kHighlightTipHeight = arrowHeight_ - 1; |
| 111 NSBezierPath* highlightPath = [NSBezierPath bezierPath]; | 105 NSBezierPath* highlightPath = [NSBezierPath bezierPath]; |
| 112 [highlightPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds) - 1)]; | 106 [highlightPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds) - 1)]; |
| 113 if (hasTip_) { | 107 if (hasTip_) { |
| 114 [highlightPath relativeLineToPoint:NSMakePoint(tipXOffset + 1, 0)]; | 108 [highlightPath relativeLineToPoint:NSMakePoint(tipXOffset + 1, 0)]; |
| 115 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1, | 109 [highlightPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_ - 1, |
| 116 kHighlightTipHeight)]; | 110 kHighlightTipHeight)]; |
| 117 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1, | 111 [highlightPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_ - 1, |
| 118 -kHighlightTipHeight)]; | 112 -kHighlightTipHeight)]; |
| 119 } | 113 } |
| 120 [highlightPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds) - 1)]; | 114 [highlightPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds) - 1)]; |
| 121 | 115 |
| 122 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke]; | 116 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke]; |
| 123 [highlightPath stroke]; | 117 [highlightPath stroke]; |
| 124 } | 118 } |
| 125 | 119 |
| 126 - (BOOL)mouseDownCanMoveWindow { | 120 - (BOOL)mouseDownCanMoveWindow { |
| 127 return NO; | 121 return NO; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 } | 135 } |
| 142 | 136 |
| 143 - (void)setHasTip:(BOOL)hasTip { | 137 - (void)setHasTip:(BOOL)hasTip { |
| 144 if (hasTip_ == hasTip) | 138 if (hasTip_ == hasTip) |
| 145 return; | 139 return; |
| 146 hasTip_ = hasTip; | 140 hasTip_ = hasTip; |
| 147 [self setNeedsDisplay:YES]; | 141 [self setNeedsDisplay:YES]; |
| 148 } | 142 } |
| 149 | 143 |
| 150 @end | 144 @end |
| OLD | NEW |