diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-20 23:35:24 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-20 23:35:24 +0000 |
commit | e1b58df5167ebd4374ee36ec57ee77d4f2e68595 (patch) | |
tree | ad520f91eb90596d93382ead3eb2b9d42a6aa99c | |
parent | f88f164cd5cbf64075fbfa5d95b0178c2fbb7f4c (diff) | |
download | chromium_src-e1b58df5167ebd4374ee36ec57ee77d4f2e68595.zip chromium_src-e1b58df5167ebd4374ee36ec57ee77d4f2e68595.tar.gz chromium_src-e1b58df5167ebd4374ee36ec57ee77d4f2e68595.tar.bz2 |
Infobar UI cleanup on Mac. Adds the yellow background gradient and
centers all of the buttons.
Also adds the ok/cancel buttons to the xib file. Infobars that do not
need the buttons can remove them from the view before displaying.
BUG=http://crbug.com/14462
BUG=http://crbug.com/17195
TEST=Infobars should have yellow background, look less ugly.
Review URL: http://codereview.chromium.org/155788
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21128 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/nibs/InfoBar.xib | 167 | ||||
-rw-r--r-- | chrome/browser/cocoa/infobar_controller.h | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/infobar_controller.mm | 117 | ||||
-rw-r--r-- | chrome/browser/cocoa/infobar_gradient_view.h | 16 | ||||
-rw-r--r-- | chrome/browser/cocoa/infobar_gradient_view.mm | 48 | ||||
-rw-r--r-- | chrome/browser/cocoa/infobar_gradient_view_unittest.mm | 45 | ||||
-rw-r--r-- | chrome/chrome.gyp | 3 |
7 files changed, 334 insertions, 72 deletions
diff --git a/chrome/app/nibs/InfoBar.xib b/chrome/app/nibs/InfoBar.xib index 7e1963f..1d287a4 100644 --- a/chrome/app/nibs/InfoBar.xib +++ b/chrome/app/nibs/InfoBar.xib @@ -42,13 +42,13 @@ <object class="NSTextField" id="293244832"> <reference key="NSNextResponder" ref="1005"/> <int key="NSvFlags">258</int> - <string key="NSFrame">{{53, 7}, {150, 17}}</string> + <string key="NSFrame">{{53, 7}, {198, 17}}</string> <reference key="NSSuperview" ref="1005"/> <bool key="NSEnabled">YES</bool> <object class="NSTextFieldCell" key="NSCell" id="963811960"> <int key="NSCellFlags">67239488</int> <int key="NSCellFlags2">272631808</int> - <string key="NSContents">This is not an InfoBar</string> + <string key="NSContents">InfoBar text</string> <object class="NSFont" key="NSSupport" id="3997082"> <string key="NSName">LucidaGrande</string> <double key="NSSize">1.300000e+01</double> @@ -110,21 +110,65 @@ <object class="NSButton" id="861420161"> <reference key="NSNextResponder" ref="1005"/> <int key="NSvFlags">297</int> - <string key="NSFrame">{{446, 0}, {16, 16}}</string> + <string key="NSFrame">{{444, 8}, {16, 16}}</string> <reference key="NSSuperview" ref="1005"/> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="1030694164"> <int key="NSCellFlags">67239424</int> <int key="NSCellFlags2">134217728</int> - <string key="NSContents">Button</string> + <string key="NSContents"/> <reference key="NSSupport" ref="3997082"/> <reference key="NSControlView" ref="861420161"/> - <int key="NSButtonFlags">-2042347265</int> - <int key="NSButtonFlags2">1</int> + <int key="NSButtonFlags">139215103</int> + <int key="NSButtonFlags2">6</int> <object class="NSCustomResource" key="NSNormalImage"> <string key="NSClassName">NSImage</string> - <string key="NSResourceName">NSStopProgressTemplate</string> + <string key="NSResourceName">close_bar</string> </object> + <object class="NSCustomResource" key="NSAlternateImage"> + <string key="NSClassName">NSImage</string> + <string key="NSResourceName">close_bar_p</string> + </object> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + <object class="NSButton" id="488415728"> + <reference key="NSNextResponder" ref="1005"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{346, -2}, {96, 32}}</string> + <reference key="NSSuperview" ref="1005"/> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="24619168"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134217728</int> + <string key="NSContents">Cancel</string> + <reference key="NSSupport" ref="3997082"/> + <reference key="NSControlView" ref="488415728"/> + <int key="NSButtonFlags">-2038284033</int> + <int key="NSButtonFlags2">129</int> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + <object class="NSButton" id="11488953"> + <reference key="NSNextResponder" ref="1005"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{250, -2}, {96, 32}}</string> + <reference key="NSSuperview" ref="1005"/> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="900516520"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134217728</int> + <string key="NSContents">OK</string> + <reference key="NSSupport" ref="3997082"/> + <reference key="NSControlView" ref="11488953"/> + <int key="NSButtonFlags">-2038284033</int> + <int key="NSButtonFlags2">129</int> <string key="NSAlternateContents"/> <string key="NSKeyEquivalent"/> <int key="NSPeriodicDelay">200</int> @@ -134,7 +178,7 @@ </object> <string key="NSFrameSize">{480, 30}</string> <reference key="NSSuperview"/> - <string key="NSClassName">BackgroundGradientView</string> + <string key="NSClassName">InfoBarGradientView</string> </object> </object> <object class="IBObjectContainer" key="IBDocument.Objects"> @@ -188,6 +232,38 @@ </object> <int key="connectionID">19</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">cancelButton_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="488415728"/> + </object> + <int key="connectionID">26</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">okButton_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="11488953"/> + </object> + <int key="connectionID">27</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">ok:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="11488953"/> + </object> + <int key="connectionID">28</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">cancel:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="488415728"/> + </object> + <int key="connectionID">29</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -225,6 +301,8 @@ <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="293244832"/> <reference ref="724203299"/> + <reference ref="488415728"/> + <reference ref="11488953"/> <reference ref="861420161"/> </object> <reference key="parent" ref="1002"/> @@ -258,6 +336,34 @@ <reference key="parent" ref="724203299"/> </object> <object class="IBObjectRecord"> + <int key="objectID">20</int> + <reference key="object" ref="488415728"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="24619168"/> + </object> + <reference key="parent" ref="1005"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">21</int> + <reference key="object" ref="24619168"/> + <reference key="parent" ref="488415728"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">22</int> + <reference key="object" ref="11488953"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="900516520"/> + </object> + <reference key="parent" ref="1005"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">23</int> + <reference key="object" ref="900516520"/> + <reference key="parent" ref="11488953"/> + </object> + <object class="IBObjectRecord"> <int key="objectID">15</int> <reference key="object" ref="861420161"/> <object class="NSMutableArray" key="children"> @@ -288,6 +394,10 @@ <string>16.IBPluginDependency</string> <string>2.CustomClassName</string> <string>2.IBPluginDependency</string> + <string>20.IBPluginDependency</string> + <string>21.IBPluginDependency</string> + <string>22.IBPluginDependency</string> + <string>23.IBPluginDependency</string> <string>3.IBPluginDependency</string> <string>4.IBPluginDependency</string> <string>5.IBPluginDependency</string> @@ -308,6 +418,10 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> </object> </object> <object class="NSMutableDictionary" key="unlocalizedProperties"> @@ -330,39 +444,46 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">19</int> + <int key="maxID">29</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="IBPartialClassDescription"> - <string key="className">BackgroundGradientView</string> - <string key="superclassName">NSView</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> - <string key="minorKey">browser/cocoa/background_gradient_view.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> <string key="className">InfoBarController</string> <string key="superclassName">NSViewController</string> <object class="NSMutableDictionary" key="actions"> - <string key="NS.key.0">dismiss:</string> - <string key="NS.object.0">id</string> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>cancel:</string> + <string>dismiss:</string> + <string>ok:</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>id</string> + <string>id</string> + </object> </object> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSMutableArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> + <string>cancelButton_</string> <string>closeButton_</string> <string>image_</string> <string>label_</string> + <string>okButton_</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSButton</string> + <string>NSButton</string> <string>NSImageView</string> <string>NSTextField</string> + <string>NSButton</string> </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> @@ -371,6 +492,14 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">InfoBarGradientView</string> + <string key="superclassName">NSView</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/infobar_gradient_view.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">InfoBarTextField</string> <string key="superclassName">NSTextField</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> diff --git a/chrome/browser/cocoa/infobar_controller.h b/chrome/browser/cocoa/infobar_controller.h index b8d7231..f037ddf 100644 --- a/chrome/browser/cocoa/infobar_controller.h +++ b/chrome/browser/cocoa/infobar_controller.h @@ -19,13 +19,21 @@ class InfoBarDelegate; InfoBarDelegate* delegate_; // weak IBOutlet NSImageView* image_; IBOutlet NSTextField* label_; + IBOutlet NSButton* okButton_; + IBOutlet NSButton* cancelButton_; IBOutlet NSButton* closeButton_; }; // Initializes a new InfoBarController. - (id)initWithDelegate:(InfoBarDelegate*)delegate; -// Dismisses the infobar without taking any action. +// Called when someone clicks on the ok or cancel buttons. Subclasses +// must override if they do not hide the buttons. +- (void)ok:(id)sender; +- (void)cancel:(id)sender; + +// Called when someone clicks on the close button. Dismisses the +// infobar without taking any action. - (IBAction)dismiss:(id)sender; // Subclasses can override this method to add additional controls to diff --git a/chrome/browser/cocoa/infobar_controller.mm b/chrome/browser/cocoa/infobar_controller.mm index a7c1a30..f887cf8 100644 --- a/chrome/browser/cocoa/infobar_controller.mm +++ b/chrome/browser/cocoa/infobar_controller.mm @@ -4,6 +4,7 @@ #import <Cocoa/Cocoa.h> +#include "base/logging.h" // for NOTREACHED() #include "base/mac_util.h" #include "base/sys_string_conversions.h" #include "chrome/browser/cocoa/infobar.h" @@ -47,6 +48,18 @@ [self addAdditionalControls]; } +// Called when someone clicks on the ok button. +- (void)ok:(id)sender { + // Subclasses must override this method if they do not hide the ok button. + NOTREACHED(); +} + +// Called when someone clicks on the cancel button. +- (void)cancel:(id)sender { + // Subclasses must override this method if they do not hide the cancel button. + NOTREACHED(); +} + // Called when someone clicks on the close button. - (void)dismiss:(id)sender { [self closeInfoBar]; @@ -81,6 +94,10 @@ AlertInfoBarDelegate* delegate = delegate_->AsAlertInfoBarDelegate(); [label_ setStringValue:base::SysWideToNSString( delegate->GetMessageText())]; + + // Remove the ok and cancel buttons, since they are not needed. + [okButton_ removeFromSuperview]; + [cancelButton_ removeFromSuperview]; } @end @@ -149,6 +166,10 @@ [label_ setAllowsEditingTextAttributes: YES]; [label_ setSelectable: YES]; [label_ setAttributedStringValue:infoText]; + + // Remove the ok and cancel buttons, since they are not needed. + [okButton_ removeFromSuperview]; + [cancelButton_ removeFromSuperview]; } // Called when someone clicks on the link in the infobar. This method @@ -186,75 +207,67 @@ // required and position them to the left of the close button. - (void)addAdditionalControls { ConfirmInfoBarDelegate* delegate = delegate_->AsConfirmInfoBarDelegate(); + int visibleButtons = delegate->GetButtons(); [label_ setStringValue:base::SysWideToNSString(delegate->GetMessageText())]; - int visibleButtons = delegate->GetButtons(); - NSButton *okButton = nil; - NSButton *cancelButton = nil; + // Save the margins between the buttons, so we can keep them constant. + float cancelMargin = + NSMinX([closeButton_ frame]) - NSMaxX([cancelButton_ frame]); + float okMargin = NSMinX([cancelButton_ frame]) - NSMaxX([okButton_ frame]); + float labelMargin = NSMinX([okButton_ frame]) - NSMaxX([label_ frame]); - // Create the OK button if needed. - if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK) { - okButton = [[[NSButton alloc] initWithFrame:NSZeroRect] autorelease]; - [okButton setBezelStyle:NSRoundedBezelStyle]; - [okButton setTitle:base::SysWideToNSString( - delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK))]; - [okButton sizeToFit]; - [okButton setAutoresizingMask:NSViewMinXMargin]; - [okButton setTarget:self]; - [okButton setAction:@selector(ok:)]; - } - - // Create the cancel button if needed. + // Create and position the cancel button if needed. Otherwise, hide it. if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { - cancelButton = [[[NSButton alloc] initWithFrame:NSZeroRect] autorelease]; - [cancelButton setBezelStyle:NSRoundedBezelStyle]; - [cancelButton setTitle:base::SysWideToNSString( + [cancelButton_ setTitle:base::SysWideToNSString( delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL))]; - [cancelButton sizeToFit]; - [cancelButton setAutoresizingMask:NSViewMinXMargin]; - [cancelButton setTarget:self]; - [cancelButton setAction:@selector(cancel:)]; - } + [cancelButton_ sizeToFit]; - // Position the cancel button, if it exists. - int cancelWidth = 0; - if (cancelButton) { - NSRect cancelFrame = [cancelButton frame]; - cancelWidth = cancelFrame.size.width + 10; + NSRect cancelFrame = [cancelButton_ frame]; + float cancelWidth = cancelFrame.size.width + cancelMargin; - // Position the cancel button to the left of the close button. A 10px - // margin is already built into cancelWidth. + // Position the cancel button to the left of the close button. + // The appropriate margin is already built into cancelWidth. cancelFrame.origin.x = NSMinX([closeButton_ frame]) - cancelWidth; - cancelFrame.origin.y = 0; - [cancelButton setFrame:cancelFrame]; - [[self view] addSubview:cancelButton]; + [cancelButton_ setFrame:cancelFrame]; // Resize the label box to extend all the way to the cancel button, - // minus a 10px argin. - NSRect labelFrame = [label_ frame]; - labelFrame.size.width = NSMinX(cancelFrame) - 10 - NSMinX(labelFrame); - [label_ setFrame:labelFrame]; + // minus the saved margin, but only if we're not also adding an OK button. + if (!(visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK)) { + NSRect labelFrame = [label_ frame]; + labelFrame.size.width = + NSMinX(cancelFrame) - NSMinX(labelFrame) - labelMargin; + [label_ setFrame:labelFrame]; + } + } else { + [cancelButton_ removeFromSuperview]; } - // Position the OK button, if it exists. - if (okButton) { - NSRect okFrame = [okButton frame]; - int okWidth = okFrame.size.width + 10; + // Create and position the OK button if needed. Otherwise, hide it. + if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK) { + [okButton_ setTitle:base::SysWideToNSString( + delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK))]; + [okButton_ sizeToFit]; + + NSRect okFrame = [okButton_ frame]; + int okWidth = okFrame.size.width + okMargin; + + // Position the OK button to the left of the cancel button, if + // present. Otherwise, position it relative to the close button. + float relativeX = (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) ? + NSMinX([cancelButton_ frame]) : + NSMinX([closeButton_ frame]); - // Position the OK button to the left of the close button as - // well. If a cancel button is present, |cancelWidth| will be positive. - // In either case, a 10px margin is built into okWidth. - okFrame.origin.x = - NSMinX([closeButton_ frame]) - cancelWidth - okWidth; - okFrame.origin.y = 0; - [okButton setFrame:okFrame]; - [[self view] addSubview:okButton]; + // The appropriate margin is already built into okWidth. + okFrame.origin.x = relativeX - okWidth; + [okButton_ setFrame:okFrame]; // Resize the label box to extend all the way to the OK button, - // minus a 10px argin. + // minus the saved margin. NSRect labelFrame = [label_ frame]; - labelFrame.size.width = NSMinX(okFrame) - 10 - NSMinX(labelFrame); + labelFrame.size.width = NSMinX(okFrame) - NSMinX(labelFrame) - labelMargin; [label_ setFrame:labelFrame]; + } else { + [okButton_ removeFromSuperview]; } } diff --git a/chrome/browser/cocoa/infobar_gradient_view.h b/chrome/browser/cocoa/infobar_gradient_view.h new file mode 100644 index 0000000..59d411d --- /dev/null +++ b/chrome/browser/cocoa/infobar_gradient_view.h @@ -0,0 +1,16 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_INFOBAR_GRADIENT_VIEW_H_ +#define CHROME_BROWSER_COCOA_INFOBAR_GRADIENT_VIEW_H_ + +#import <Cocoa/Cocoa.h> + +// A custom view that draws the yellow background gradient for an infobar. + +@interface InfoBarGradientView : NSView { +} +@end + +#endif // CHROME_BROWSER_COCOA_INFOBAR_GRADIENT_VIEW_H_ diff --git a/chrome/browser/cocoa/infobar_gradient_view.mm b/chrome/browser/cocoa/infobar_gradient_view.mm new file mode 100644 index 0000000..41944ff --- /dev/null +++ b/chrome/browser/cocoa/infobar_gradient_view.mm @@ -0,0 +1,48 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/cocoa/infobar_gradient_view.h" +#import "third_party/GTM/AppKit/GTMTheme.h" + +const double kBackgroundColorTop[3] = + {255.0 / 255.0, 242.0 / 255.0, 183.0 / 255.0}; +const double kBackgroundColorBottom[3] = + {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; + +@implementation InfoBarGradientView +- (NSColor*)strokeColor { + return [[self gtm_theme] strokeColorForStyle:GTMThemeStyleToolBar + state:[[self window] isKeyWindow]]; +} + +- (void)drawRect:(NSRect)rect { + NSColor* startingColor = + [NSColor colorWithCalibratedRed:kBackgroundColorTop[0] + green:kBackgroundColorTop[1] + blue:kBackgroundColorTop[2] + alpha:1.0]; + NSColor* endingColor = + [NSColor colorWithCalibratedRed:kBackgroundColorBottom[0] + green:kBackgroundColorBottom[1] + blue:kBackgroundColorBottom[2] + alpha:1.0]; + NSGradient* gradient = + [[[NSGradient alloc] initWithStartingColor:startingColor + endingColor:endingColor] autorelease]; + [gradient drawInRect:[self bounds] angle:270]; + + // Draw bottom stroke + [[self strokeColor] set]; + NSRect borderRect, contentRect; + NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); + NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); +} + +- (BOOL)mouseDownCanMoveWindow { + return NO; +} + +// This view is intentionally not opaque because it overlaps with the findbar. + +@end diff --git a/chrome/browser/cocoa/infobar_gradient_view_unittest.mm b/chrome/browser/cocoa/infobar_gradient_view_unittest.mm new file mode 100644 index 0000000..ab306ba --- /dev/null +++ b/chrome/browser/cocoa/infobar_gradient_view_unittest.mm @@ -0,0 +1,45 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> + +#include "base/scoped_nsobject.h" +#import "chrome/browser/cocoa/infobar_gradient_view.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class InfoBarGradientViewTest : public testing::Test { + public: + InfoBarGradientViewTest() { + NSRect frame = NSMakeRect(0, 0, 100, 30); + view_.reset([[InfoBarGradientView alloc] initWithFrame:frame]); + [cocoa_helper_.contentView() addSubview:view_.get()]; + } + + CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... + scoped_nsobject<InfoBarGradientView> view_; +}; + +// Test adding/removing from the view hierarchy, mostly to ensure nothing +// leaks or crashes. +TEST_F(InfoBarGradientViewTest, AddRemove) { + EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); + [view_.get() removeFromSuperview]; + EXPECT_FALSE([view_ superview]); +} + +// Test drawing, mostly to ensure nothing leaks or crashes. +TEST_F(InfoBarGradientViewTest, Display) { + [view_ display]; +} + +// Assert that the view is non-opaque, because otherwise we will end +// up with findbar painting issues. +TEST_F(InfoBarGradientViewTest, AssertViewNonOpaque) { + EXPECT_FALSE([view_ isOpaque]); +} + +} // namespace diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 29a2bc4..b97a90a 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -807,6 +807,8 @@ 'browser/cocoa/infobar_container_controller.mm', 'browser/cocoa/infobar_controller.h', 'browser/cocoa/infobar_controller.mm', + 'browser/cocoa/infobar_gradient_view.h', + 'browser/cocoa/infobar_gradient_view.mm', 'browser/cocoa/infobar_test_helper.h', 'browser/cocoa/infobar_text_field.h', 'browser/cocoa/infobar_text_field.mm', @@ -3677,6 +3679,7 @@ 'browser/cocoa/hung_renderer_controller_unittest.mm', 'browser/cocoa/infobar_container_controller_unittest.mm', 'browser/cocoa/infobar_controller_unittest.mm', + 'browser/cocoa/infobar_gradient_view_unittest.mm', 'browser/cocoa/infobar_text_field_unittest.mm', 'browser/cocoa/location_bar_view_mac_unittest.mm', 'browser/cocoa/gradient_button_cell_unittest.mm', |