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

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

Issue 23338005: Mac InfoBar: Use cross platform infobar classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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) 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
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;
65 60
66 const CGFloat kHalfWidth = kTipWidth / 2.0; 61 /*
67 NSPoint localApex = [self convertPoint:self.tipApex fromView:nil]; 62 [[NSColor redColor] set];
68 CGFloat tipXOffset = localApex.x - kHalfWidth; 63 NSRectFill(bounds);
64 [[NSColor blueColor] set];
65 NSRect arect = bounds;
66 arect.size.height = arrowHeight_;
67 arect.origin.y = NSMaxY(bounds) - arect.size.height;
68 NSRectFill(arect);
69 return;
70 */
71
72 bounds.size.height = InfoBar::kDefaultBarTargetHeight;
73
74 CGFloat tipXOffset = arrowX_ - arrowHalfWidth_;
69 75
70 // Around the bounds of the infobar, continue drawing the path into which the 76 // Around the bounds of the infobar, continue drawing the path into which the
71 // gradient will be drawn. 77 // gradient will be drawn.
72 NSBezierPath* infoBarPath = [NSBezierPath bezierPath]; 78 NSBezierPath* infoBarPath = [NSBezierPath bezierPath];
73 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; 79 [infoBarPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))];
74 80
75 // Draw the tip. 81 // Draw the tip.
76 if (hasTip_) { 82 if (hasTip_) {
77 [infoBarPath lineToPoint:NSMakePoint(tipXOffset, NSMaxY(bounds))]; 83 [infoBarPath lineToPoint:NSMakePoint(tipXOffset, NSMaxY(bounds))];
78 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth, 84 [infoBarPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_,
79 infobars::kTipHeight)]; 85 arrowHeight_)];
80 [infoBarPath relativeLineToPoint:NSMakePoint(kHalfWidth, 86 [infoBarPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_,
81 -infobars::kTipHeight)]; 87 -arrowHeight_)];
82 } 88 }
83 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; 89 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))];
84 90
85 // Save off the top path of the infobar. 91 // Save off the top path of the infobar.
86 base::scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]); 92 base::scoped_nsobject<NSBezierPath> topPath([infoBarPath copy]);
87 93
88 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; 94 [infoBarPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))];
89 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))]; 95 [infoBarPath lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))];
90 [infoBarPath closePath]; 96 [infoBarPath closePath];
91 97
92 // Draw the gradient. 98 // Draw the gradient.
93 [[self gradient] drawInBezierPath:infoBarPath angle:270]; 99 [[self gradient] drawInBezierPath:infoBarPath angle:270];
94 100
95 NSColor* strokeColor = [self strokeColor]; 101 NSColor* strokeColor = [self strokeColor];
96 if (strokeColor) { 102 if (strokeColor) {
97 [strokeColor set]; 103 [strokeColor set];
98 104
99 // Stroke the bottom of the infobar. 105 // Stroke the bottom of the infobar.
100 NSRect borderRect, contentRect; 106 NSRect borderRect, contentRect;
101 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge); 107 NSDivideRect(bounds, &borderRect, &contentRect, 1, NSMinYEdge);
102 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); 108 NSRectFillUsingOperation(borderRect, NSCompositeSourceOver);
103 109
104 // Re-stroke the top because the tip will have no stroke. This will draw 110 // 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. 111 // over the divider drawn by the bottom of the tabstrip.
106 [topPath stroke]; 112 [topPath stroke];
107 } 113 }
108 114
109 // Add an inner stroke. 115 // Add an inner stroke.
110 const CGFloat kHighlightTipHeight = infobars::kTipHeight - 1; 116 const CGFloat kHighlightTipHeight = arrowHeight_ - 1;
111 NSBezierPath* highlightPath = [NSBezierPath bezierPath]; 117 NSBezierPath* highlightPath = [NSBezierPath bezierPath];
112 [highlightPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds) - 1)]; 118 [highlightPath moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds) - 1)];
113 if (hasTip_) { 119 if (hasTip_) {
114 [highlightPath relativeLineToPoint:NSMakePoint(tipXOffset + 1, 0)]; 120 [highlightPath relativeLineToPoint:NSMakePoint(tipXOffset + 1, 0)];
115 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1, 121 [highlightPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_ - 1,
116 kHighlightTipHeight)]; 122 kHighlightTipHeight)];
117 [highlightPath relativeLineToPoint:NSMakePoint(kHalfWidth - 1, 123 [highlightPath relativeLineToPoint:NSMakePoint(arrowHalfWidth_ - 1,
118 -kHighlightTipHeight)]; 124 -kHighlightTipHeight)];
119 } 125 }
120 [highlightPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds) - 1)]; 126 [highlightPath lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds) - 1)];
121 127
122 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke]; 128 [[NSColor colorWithDeviceWhite:1.0 alpha:1.0] setStroke];
123 [highlightPath stroke]; 129 [highlightPath stroke];
124 } 130 }
125 131
126 - (BOOL)mouseDownCanMoveWindow { 132 - (BOOL)mouseDownCanMoveWindow {
127 return NO; 133 return NO;
(...skipping 13 matching lines...) Expand all
141 } 147 }
142 148
143 - (void)setHasTip:(BOOL)hasTip { 149 - (void)setHasTip:(BOOL)hasTip {
144 if (hasTip_ == hasTip) 150 if (hasTip_ == hasTip)
145 return; 151 return;
146 hasTip_ = hasTip; 152 hasTip_ = hasTip;
147 [self setNeedsDisplay:YES]; 153 [self setNeedsDisplay:YES];
148 } 154 }
149 155
150 @end 156 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698