Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/ui/cocoa/infobars/infobar_gradient_view.mm

Issue 7461134: [Mac] Unspoofable infobars v3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Rohit Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 const CGFloat kTipWidth = 23;
rohitrao (ping after 24h) 2011/08/05 14:24:12 Might as well put this in a namespace.
Robert Sesek 2011/08/05 15:10:40 Done.
17
18 @interface InfoBarGradientView (Private)
19 - (NSPoint)pointForTipApex;
rohitrao (ping after 24h) 2011/08/05 14:24:12 Add a comment for this method. Mention what coord
Robert Sesek 2011/08/05 15:10:40 Done.
20 @end
21
14 @implementation InfoBarGradientView 22 @implementation InfoBarGradientView
15 23
16 - (void)setInfobarType:(InfoBarDelegate::Type)infobarType { 24 - (void)setInfobarType:(InfoBarDelegate::Type)infobarType {
17 SkColor topColor = GetInfoBarTopColor(infobarType); 25 SkColor topColor = GetInfoBarTopColor(infobarType);
18 SkColor bottomColor = GetInfoBarBottomColor(infobarType); 26 SkColor bottomColor = GetInfoBarBottomColor(infobarType);
19 scoped_nsobject<NSGradient> gradient([[NSGradient alloc] 27 scoped_nsobject<NSGradient> gradient([[NSGradient alloc]
20 initWithStartingColor:gfx::SkColorToCalibratedNSColor(topColor) 28 initWithStartingColor:gfx::SkColorToCalibratedNSColor(topColor)
21 endingColor:gfx::SkColorToCalibratedNSColor(bottomColor)]); 29 endingColor:gfx::SkColorToCalibratedNSColor(bottomColor)]);
22 [self setGradient:gradient]; 30 [self setGradient:gradient];
23 } 31 }
24 32
25 - (NSColor*)strokeColor { 33 - (NSColor*)strokeColor {
26 ui::ThemeProvider* themeProvider = [[self window] themeProvider]; 34 ui::ThemeProvider* themeProvider = [[self window] themeProvider];
27 if (!themeProvider) 35 if (!themeProvider)
28 return [NSColor blackColor]; 36 return [NSColor blackColor];
29 37
30 BOOL active = [[self window] isMainWindow]; 38 BOOL active = [[self window] isMainWindow];
31 return themeProvider->GetNSColor( 39 return themeProvider->GetNSColor(
32 active ? ThemeService::COLOR_TOOLBAR_STROKE : 40 active ? ThemeService::COLOR_TOOLBAR_STROKE :
33 ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE, 41 ThemeService::COLOR_TOOLBAR_STROKE_INACTIVE,
34 true); 42 true);
35 } 43 }
36 44
37 - (void)drawRect:(NSRect)rect { 45 - (void)drawRect:(NSRect)rect {
38 NSRect bounds = [self bounds]; 46 NSRect bounds = [self bounds];
39 bounds.size.height = infobars::kBaseHeight; 47 bounds.size.height = infobars::kBaseHeight;
40 48
49 const CGFloat kHalfWidth = kTipWidth / 2.0;
50 const CGFloat kTipXOffset = [self pointForTipApex].x - kHalfWidth;
51
41 // Around the bounds of the infobar, continue drawing the path into which the 52 // Around the bounds of the infobar, continue drawing the path into which the
42 // gradient will be drawn. 53 // gradient will be drawn.
43 NSBezierPath* infoBarPath = [NSBezierPath bezierPath]; 54 NSBezierPath* infoBarPath = [NSBezierPath bezierPath];
44 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; 55 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))];
56
57 // Draw the tip.
58 [infoBarPath lineToPoint:NSMakePoint(kTipXOffset, NSMaxY(bounds))];
59 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth,
60 infobars::kTipHeight)];
61 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth,
62 -infobars::kTipHeight)];
45 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; 63 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))];
64
65 // Save off the top path of the infobar.
46 scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]); 66 scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]);
47 67
48 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; 68 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))];
49 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))]; 69 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))];
50 [infoBarPath closePath]; 70 [infoBarPath closePath];
51 71
52 // Draw the gradient. 72 // Draw the gradient.
53 [[self gradient] drawInBezierPath:infoBarPath angle:270]; 73 [[self gradient] drawInBezierPath:infoBarPath angle:270];
54 74
55 // Stroke the bottom.
56 NSColor* strokeColor = [self strokeColor]; 75 NSColor* strokeColor = [self strokeColor];
57 if (strokeColor) { 76 if (strokeColor) {
58 [strokeColor set]; 77 [strokeColor set];
78
79 // Stroke the bottom of the infobar.
59 NSRect borderRect, contentRect; 80 NSRect borderRect, contentRect;
60 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge); 81 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge);
61 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); 82 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
83
84 // Re-stroke the top because the tip will have no stroke. This will draw
85 // over the divider drawn by the bottom of the tabstrip.
86 [topPath stroke];
62 } 87 }
63 88
64 // Add an inner stroke. 89 // Add an inner stroke.
90 const CGFloat kHighlightTipHeight = infobars::kTipHeight - 1;
91 NSBezierPath* highlightPath = [NSBezierPath bezierPath];
92 [highlightPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds) - 1)];
93 [highlightPath relativeLineToPoint:NSMakePoint(kTipXOffset + 1, 0)];
94 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1,
95 kHighlightTipHeight)];
96 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1,
97 -kHighlightTipHeight)];
98 [highlightPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds) - 1)];
99
65 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke]; 100 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke];
66 NSAffineTransform* transform = [NSAffineTransform transform]; 101 [highlightPath stroke];
67 [transform translateXBy:0.0 yBy:-1.0];
68 [topPath transformUsingAffineTransform:transform];
69 [topPath stroke];
70 } 102 }
71 103
72 - (BOOL)mouseDownCanMoveWindow { 104 - (BOOL)mouseDownCanMoveWindow {
73 return NO; 105 return NO;
74 } 106 }
75 107
76 // This view is intentionally not opaque because it overlaps with the findbar. 108 // This view is intentionally not opaque because it overlaps with the findbar.
77 109
78 - (BOOL)accessibilityIsIgnored { 110 - (BOOL)accessibilityIsIgnored {
79 return NO; 111 return NO;
80 } 112 }
81 113
82 - (id)accessibilityAttributeValue:(NSString*)attribute { 114 - (id)accessibilityAttributeValue:(NSString*)attribute {
83 if ([attribute isEqual:NSAccessibilityRoleAttribute]) 115 if ([attribute isEqual:NSAccessibilityRoleAttribute])
84 return NSAccessibilityGroupRole; 116 return NSAccessibilityGroupRole;
85 117
86 return [super accessibilityAttributeValue:attribute]; 118 return [super accessibilityAttributeValue:attribute];
87 } 119 }
88 120
121 // Private /////////////////////////////////////////////////////////////////////
122
123 // Returns the point, in local coordinates, at which the apex of the infobar tip
124 // should be drawn.
125 - (NSPoint)pointForTipApex {
126 id controller = [[self window] windowController];
rohitrao (ping after 24h) 2011/08/05 14:24:12 Can we do this through a delegate interface instea
Robert Sesek 2011/08/05 15:10:40 Routed through protocols. Done.
127 if (![controller isKindOfClass:[BrowserWindowController class]]) {
128 NOTREACHED();
129 return NSZeroPoint;
130 }
131
132 BrowserWindowController* windowController =
133 static_cast<BrowserWindowController*>(controller);
134 LocationBarViewMac* locationBar = [windowController locationBarBridge];
135 NSPoint point = locationBar->GetPageInfoBubblePoint();
136 point = [self convertPoint:point fromView:nil];
137 return point;
138 }
139
89 @end 140 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698