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 #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/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
8 #include "chrome/browser/tab_contents/infobar.h" | 8 #include "chrome/browser/tab_contents/infobar.h" |
9 #import "chrome/browser/themes/theme_service.h" | 9 #import "chrome/browser/themes/theme_service.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
10 #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" |
11 #import "chrome/browser/ui/cocoa/themed_window.h" | 13 #import "chrome/browser/ui/cocoa/themed_window.h" |
12 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
13 | 15 |
| 16 namespace { |
| 17 |
| 18 const CGFloat kTipWidth = 23; |
| 19 |
| 20 } // namespace |
| 21 |
14 @implementation InfoBarGradientView | 22 @implementation InfoBarGradientView |
15 | 23 |
| 24 @synthesize tipApex = tipApex_; |
| 25 |
16 - (void)setInfobarType:(InfoBarDelegate::Type)infobarType { | 26 - (void)setInfobarType:(InfoBarDelegate::Type)infobarType { |
17 SkColor topColor = GetInfoBarTopColor(infobarType); | 27 SkColor topColor = GetInfoBarTopColor(infobarType); |
18 SkColor bottomColor = GetInfoBarBottomColor(infobarType); | 28 SkColor bottomColor = GetInfoBarBottomColor(infobarType); |
19 scoped_nsobject<NSGradient> gradient([[NSGradient alloc] | 29 scoped_nsobject<NSGradient> gradient([[NSGradient alloc] |
20 initWithStartingColor:gfx::SkColorToCalibratedNSColor(topColor) | 30 initWithStartingColor:gfx::SkColorToCalibratedNSColor(topColor) |
21 endingColor:gfx::SkColorToCalibratedNSColor(bottomColor)]); | 31 endingColor:gfx::SkColorToCalibratedNSColor(bottomColor)]); |
22 [self setGradient:gradient]; | 32 [self setGradient:gradient]; |
23 } | 33 } |
24 | 34 |
25 - (NSColor*)strokeColor { | 35 - (NSColor*)strokeColor { |
26 ui::ThemeProvider* themeProvider = [[self window] themeProvider]; | 36 ui::ThemeProvider* themeProvider = [[self window] themeProvider]; |
27 if (!themeProvider) | 37 if (!themeProvider) |
28 return [NSColor blackColor]; | 38 return [NSColor blackColor]; |
29 | 39 |
30 BOOL active = [[self window] isMainWindow]; | 40 BOOL active = [[self window] isMainWindow]; |
31 return themeProvider->GetNSColor( | 41 return themeProvider->GetNSColor( |
32 active ? ThemeService::COLOR_TOOLBAR_STROKE : | 42 active ? ThemeService::COLOR_TOOLBAR_STROKE : |
33 ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE, | 43 ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE, |
34 true); | 44 true); |
35 } | 45 } |
36 | 46 |
37 - (void)drawRect:(NSRect)rect { | 47 - (void)drawRect:(NSRect)rect { |
38 NSRect bounds = [self bounds]; | 48 NSRect bounds = [self bounds]; |
39 bounds.size.height = infobars::kBaseHeight; | 49 bounds.size.height = infobars::kBaseHeight; |
40 | 50 |
| 51 const CGFloat kHalfWidth = kTipWidth / 2.0; |
| 52 const CGFloat kTipXOffset = self.tipApex.x - kHalfWidth; |
| 53 |
41 // Around the bounds of the infobar, continue drawing the path into which the | 54 // Around the bounds of the infobar, continue drawing the path into which the |
42 // gradient will be drawn. | 55 // gradient will be drawn. |
43 NSBezierPath* infoBarPath = [NSBezierPath bezierPath]; | 56 NSBezierPath* infoBarPath = [NSBezierPath bezierPath]; |
44 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; | 57 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; |
| 58 |
| 59 // Draw the tip. |
| 60 [infoBarPath lineToPoint:NSMakePoint(kTipXOffset, NSMaxY(bounds))]; |
| 61 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth, |
| 62 infobars::kTipHeight)]; |
| 63 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth, |
| 64 -infobars::kTipHeight)]; |
45 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; | 65 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; |
| 66 |
| 67 // Save off the top path of the infobar. |
46 scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]); | 68 scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]); |
47 | 69 |
48 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; | 70 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; |
49 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))]; | 71 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))]; |
50 [infoBarPath closePath]; | 72 [infoBarPath closePath]; |
51 | 73 |
52 // Draw the gradient. | 74 // Draw the gradient. |
53 [[self gradient] drawInBezierPath:infoBarPath angle:270]; | 75 [[self gradient] drawInBezierPath:infoBarPath angle:270]; |
54 | 76 |
55 // Stroke the bottom. | |
56 NSColor* strokeColor = [self strokeColor]; | 77 NSColor* strokeColor = [self strokeColor]; |
57 if (strokeColor) { | 78 if (strokeColor) { |
58 [strokeColor set]; | 79 [strokeColor set]; |
| 80 |
| 81 // Stroke the bottom of the infobar. |
59 NSRect borderRect, contentRect; | 82 NSRect borderRect, contentRect; |
60 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge); | 83 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge); |
61 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); | 84 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); |
| 85 |
| 86 // Re-stroke the top because the tip will have no stroke. This will draw |
| 87 // over the divider drawn by the bottom of the tabstrip. |
| 88 [topPath stroke]; |
62 } | 89 } |
63 | 90 |
64 // Add an inner stroke. | 91 // Add an inner stroke. |
| 92 const CGFloat kHighlightTipHeight = infobars::kTipHeight - 1; |
| 93 NSBezierPath* highlightPath = [NSBezierPath bezierPath]; |
| 94 [highlightPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds) - 1)]; |
| 95 [highlightPath relativeLineToPoint:NSMakePoint(kTipXOffset + 1, 0)]; |
| 96 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1, |
| 97 kHighlightTipHeight)]; |
| 98 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1, |
| 99 -kHighlightTipHeight)]; |
| 100 [highlightPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds) - 1)]; |
| 101 |
65 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke]; | 102 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke]; |
66 NSAffineTransform* transform = [NSAffineTransform transform]; | 103 [highlightPath stroke]; |
67 [transform translateXBy:0.0 yBy:-1.0]; | |
68 [topPath transformUsingAffineTransform:transform]; | |
69 [topPath stroke]; | |
70 } | 104 } |
71 | 105 |
72 - (BOOL)mouseDownCanMoveWindow { | 106 - (BOOL)mouseDownCanMoveWindow { |
73 return NO; | 107 return NO; |
74 } | 108 } |
75 | 109 |
76 // This view is intentionally not opaque because it overlaps with the findbar. | 110 // This view is intentionally not opaque because it overlaps with the findbar. |
77 | 111 |
78 - (BOOL)accessibilityIsIgnored { | 112 - (BOOL)accessibilityIsIgnored { |
79 return NO; | 113 return NO; |
80 } | 114 } |
81 | 115 |
82 - (id)accessibilityAttributeValue:(NSString*)attribute { | 116 - (id)accessibilityAttributeValue:(NSString*)attribute { |
83 if ([attribute isEqual:NSAccessibilityRoleAttribute]) | 117 if ([attribute isEqual:NSAccessibilityRoleAttribute]) |
84 return NSAccessibilityGroupRole; | 118 return NSAccessibilityGroupRole; |
85 | 119 |
86 return [super accessibilityAttributeValue:attribute]; | 120 return [super accessibilityAttributeValue:attribute]; |
87 } | 121 } |
88 | 122 |
89 @end | 123 @end |
OLD | NEW |