diff options
-rw-r--r-- | chrome/app/nibs/Toolbar.xib | 160 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/image_button_cell.h | 8 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/image_button_cell.mm | 61 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm | 21 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h | 28 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.mm | 81 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell_unittest.mm | 38 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_nibs.gyp | 2 | ||||
-rw-r--r-- | chrome/chrome_tests_unit.gypi | 1 |
10 files changed, 207 insertions, 195 deletions
diff --git a/chrome/app/nibs/Toolbar.xib b/chrome/app/nibs/Toolbar.xib index b596477..f93f386 100644 --- a/chrome/app/nibs/Toolbar.xib +++ b/chrome/app/nibs/Toolbar.xib @@ -2,13 +2,13 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">12B19</string> - <string key="IBDocument.InterfaceBuilderVersion">2549</string> - <string key="IBDocument.AppKitVersion">1187</string> - <string key="IBDocument.HIToolboxVersion">624.00</string> + <string key="IBDocument.SystemVersion">12C3012</string> + <string key="IBDocument.InterfaceBuilderVersion">2844</string> + <string key="IBDocument.AppKitVersion">1187.34</string> + <string key="IBDocument.HIToolboxVersion">625.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="NS.object.0">2549</string> + <string key="NS.object.0">2844</string> </object> <object class="NSArray" key="IBDocument.IntegratedClassDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -50,6 +50,7 @@ <string key="NSFrame">{{572, -2}, {2, 35}}</string> <reference key="NSSuperview" ref="928520650"/> <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="602421009"/> <string key="NSClassName">BrowserActionsContainerView</string> </object> <object class="NSTextField" id="535508469"> @@ -58,12 +59,13 @@ <string key="NSFrame">{{119, 4}, {454, 27}}</string> <reference key="NSSuperview" ref="928520650"/> <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="421615633"/> <int key="NSTag">33004</int> <bool key="NSEnabled">YES</bool> <object class="NSTextFieldCell" key="NSCell" id="464583340"> <int key="NSCellFlags">-1804599231</int> <int key="NSCellFlags2">66560</int> - <string key="NSContents"></string> + <string key="NSContents"/> <object class="NSFont" key="NSSupport"> <string key="NSName">LucidaGrande</string> <double key="NSSize">13</double> @@ -98,6 +100,7 @@ <string key="NSFrame">{{87, 3}, {29, 29}}</string> <reference key="NSSuperview" ref="928520650"/> <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="535508469"/> <int key="NSTag">33003</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="760046712"> @@ -125,6 +128,7 @@ <string key="NSFrame">{{59, 3}, {29, 29}}</string> <reference key="NSSuperview" ref="928520650"/> <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="368496192"/> <int key="NSTag">33002</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="386107000"> @@ -148,6 +152,7 @@ <string key="NSFrame">{{31, 3}, {29, 29}}</string> <reference key="NSSuperview" ref="928520650"/> <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="458854861"/> <int key="NSTag">33001</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="3781855"> @@ -171,6 +176,7 @@ <string key="NSFrame">{{3, 3}, {29, 29}}</string> <reference key="NSSuperview" ref="928520650"/> <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="781044416"/> <int key="NSTag">33000</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="697431051"> @@ -214,6 +220,7 @@ <string key="NSFrameSize">{608, 34}</string> <reference key="NSSuperview"/> <reference key="NSWindow"/> + <reference key="NSNextKeyView" ref="634265909"/> <string key="NSClassName">ToolbarView</string> </object> <object class="NSCustomObject" id="1044322163"> @@ -573,7 +580,7 @@ </object> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>ClickHoldButtonCell</string> + <string>WrenchToolbarButtonCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>AutocompleteTextField</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -661,17 +668,6 @@ <object class="IBPartialClassDescription"> <string key="className">ClickHoldButtonCell</string> <string key="superclassName">ImageButtonCell</string> - <object class="NSMutableDictionary" key="outlets"> - <string key="NS.key.0">clickHoldTarget_</string> - <string key="NS.object.0">id</string> - </object> - <object class="NSMutableDictionary" key="toOneOutletInfosByName"> - <string key="NS.key.0">clickHoldTarget_</string> - <object class="IBToOneOutletInfo" key="NS.object.0"> - <string key="name">clickHoldTarget_</string> - <string key="candidateClassName">id</string> - </object> - </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">./Classes/ClickHoldButtonCell.h</string> @@ -791,22 +787,6 @@ </object> </object> <object class="IBPartialClassDescription"> - <string key="className">MenuController</string> - <string key="superclassName">NSObject</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> - <string key="minorKey">./Classes/MenuController.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> - <string key="className">MenuTrackedRootView</string> - <string key="superclassName">NSView</string> - <object class="IBClassDescriptionSource" key="sourceIdentifier"> - <string key="majorKey">IBProjectSource</string> - <string key="minorKey">./Classes/MenuTrackedRootView.h</string> - </object> - </object> - <object class="IBPartialClassDescription"> <string key="className">ReloadButton</string> <string key="superclassName">ToolbarButton</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> @@ -851,9 +831,7 @@ <string>homeButton_</string> <string>locationBar_</string> <string>reloadButton_</string> - <string>resizeDelegate_</string> <string>wrenchButton_</string> - <string>wrenchMenuController_</string> </object> <object class="NSArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -863,9 +841,7 @@ <string>ToolbarButton</string> <string>AutocompleteTextField</string> <string>ReloadButton</string> - <string>id</string> <string>MenuButton</string> - <string>WrenchMenuController</string> </object> </object> <object class="NSMutableDictionary" key="toOneOutletInfosByName"> @@ -878,9 +854,7 @@ <string>homeButton_</string> <string>locationBar_</string> <string>reloadButton_</string> - <string>resizeDelegate_</string> <string>wrenchButton_</string> - <string>wrenchMenuController_</string> </object> <object class="NSArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -909,17 +883,9 @@ <string key="candidateClassName">ReloadButton</string> </object> <object class="IBToOneOutletInfo"> - <string key="name">resizeDelegate_</string> - <string key="candidateClassName">id</string> - </object> - <object class="IBToOneOutletInfo"> <string key="name">wrenchButton_</string> <string key="candidateClassName">MenuButton</string> </object> - <object class="IBToOneOutletInfo"> - <string key="name">wrenchMenuController_</string> - <string key="candidateClassName">WrenchMenuController</string> - </object> </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> @@ -936,103 +902,11 @@ </object> </object> <object class="IBPartialClassDescription"> - <string key="className">WrenchMenuController</string> - <string key="superclassName">MenuController</string> - <object class="NSMutableDictionary" key="actions"> - <string key="NS.key.0">dispatchWrenchMenuCommand:</string> - <string key="NS.object.0">id</string> - </object> - <object class="NSMutableDictionary" key="actionInfosByName"> - <string key="NS.key.0">dispatchWrenchMenuCommand:</string> - <object class="IBActionInfo" key="NS.object.0"> - <string key="name">dispatchWrenchMenuCommand:</string> - <string key="candidateClassName">id</string> - </object> - </object> - <object class="NSMutableDictionary" key="outlets"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>editCopy_</string> - <string>editCut_</string> - <string>editItem_</string> - <string>editPaste_</string> - <string>zoomDisplay_</string> - <string>zoomFullScreen_</string> - <string>zoomItem_</string> - <string>zoomMinus_</string> - <string>zoomPlus_</string> - </object> - <object class="NSArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>NSButton</string> - <string>NSButton</string> - <string>MenuTrackedRootView</string> - <string>NSButton</string> - <string>NSButton</string> - <string>NSButton</string> - <string>MenuTrackedRootView</string> - <string>NSButton</string> - <string>NSButton</string> - </object> - </object> - <object class="NSMutableDictionary" key="toOneOutletInfosByName"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>editCopy_</string> - <string>editCut_</string> - <string>editItem_</string> - <string>editPaste_</string> - <string>zoomDisplay_</string> - <string>zoomFullScreen_</string> - <string>zoomItem_</string> - <string>zoomMinus_</string> - <string>zoomPlus_</string> - </object> - <object class="NSArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="IBToOneOutletInfo"> - <string key="name">editCopy_</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">editCut_</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">editItem_</string> - <string key="candidateClassName">MenuTrackedRootView</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">editPaste_</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">zoomDisplay_</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">zoomFullScreen_</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">zoomItem_</string> - <string key="candidateClassName">MenuTrackedRootView</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">zoomMinus_</string> - <string key="candidateClassName">NSButton</string> - </object> - <object class="IBToOneOutletInfo"> - <string key="name">zoomPlus_</string> - <string key="candidateClassName">NSButton</string> - </object> - </object> - </object> + <string key="className">WrenchToolbarButtonCell</string> + <string key="superclassName">ClickHoldButtonCell</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> - <string key="minorKey">./Classes/WrenchMenuController.h</string> + <string key="minorKey">./Classes/WrenchToolbarButtonCell.h</string> </object> </object> </object> diff --git a/chrome/browser/ui/cocoa/image_button_cell.h b/chrome/browser/ui/cocoa/image_button_cell.h index 74feb94..f591bb02 100644 --- a/chrome/browser/ui/cocoa/image_button_cell.h +++ b/chrome/browser/ui/cocoa/image_button_cell.h @@ -41,11 +41,9 @@ enum ButtonState { int imageId; scoped_nsobject<NSImage> image; } image_[image_button_cell::kButtonStateCount]; - NSInteger overlayImageID_; BOOL isMouseInside_; } -@property(assign, nonatomic) NSInteger overlayImageID; @property(assign, nonatomic) BOOL isMouseInside; // Sets the image for the given button state using an image ID. @@ -58,6 +56,12 @@ enum ButtonState { - (void)setImage:(NSImage*)image forButtonState:(image_button_cell::ButtonState)state; +// Gets the alpha to use to draw the button for the current window focus state. +- (CGFloat)imageAlphaForWindowState:(NSWindow*)window; + +// If |controlView| is a first responder then draws a blue focus ring. +- (void)drawFocusRingWithFrame:(NSRect)cellFrame inView:(NSView*)controlView; + @end #endif // CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ diff --git a/chrome/browser/ui/cocoa/image_button_cell.mm b/chrome/browser/ui/cocoa/image_button_cell.mm index 93e646a..13dc59d 100644 --- a/chrome/browser/ui/cocoa/image_button_cell.mm +++ b/chrome/browser/ui/cocoa/image_button_cell.mm @@ -13,10 +13,6 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" -// Adjust the overlay position relative to the top right of the button image. -const CGFloat kOverlayOffsetX = -3; -const CGFloat kOverlayOffsetY = 5; - // When the window doesn't have focus then we want to draw the button with a // slightly lighter color. We do this by just reducing the alpha. const CGFloat kImageNoFocusAlpha = 0.65; @@ -30,7 +26,6 @@ const CGFloat kImageNoFocusAlpha = 0.65; @implementation ImageButtonCell -@synthesize overlayImageID = overlayImageID_; @synthesize isMouseInside = isMouseInside_; // For nib instantiations @@ -68,7 +63,7 @@ const CGFloat kImageNoFocusAlpha = 0.65; image_button_cell::ButtonState state = [self currentButtonState]; BOOL windowHasFocus = [[controlView window] isMainWindow] || [[controlView window] isKeyWindow]; - CGFloat alpha = windowHasFocus ? 1.0 : kImageNoFocusAlpha; + CGFloat alpha = [self imageAlphaForWindowState:[controlView window]]; NSImage* image = [self imageForState:state view:controlView]; if (!windowHasFocus) { @@ -103,36 +98,7 @@ const CGFloat kImageNoFocusAlpha = 0.65; respectFlipped:YES hints:nil]; - if (overlayImageID_) { - NSImage* overlayImage = [self imageForID:overlayImageID_ - controlView:controlView]; - NSRect overlayRect; - overlayRect.size = [overlayImage size]; - overlayRect.origin.x = NSMaxX(imageRect) - NSWidth(overlayRect) + - kOverlayOffsetX; - overlayRect.origin.y = NSMinY(imageRect) + kOverlayOffsetY; - - [overlayImage drawInRect:overlayRect - fromRect:NSZeroRect - operation:NSCompositeSourceOver - fraction:1.0 - respectFlipped:YES - hints:nil]; - } - - // Draws the blue focus ring. - if ([self showsFirstResponder]) { - gfx::ScopedNSGraphicsContextSaveGState scoped_state; - const CGFloat lineWidth = [controlView cr_lineWidth]; - rect_path_utils::FrameRectWithInset(rect_path_utils::RoundedCornerAll, - NSInsetRect(cellFrame, 0, lineWidth), - 0.0, // insetX - 0.0, // insetY - 3.0, // outerRadius - lineWidth * 2, // lineWidth - [controlView - cr_keyboardFocusIndicatorColor]); - } + [self drawFocusRingWithFrame:cellFrame inView:controlView]; } - (void)setImageID:(NSInteger)imageID @@ -156,11 +122,24 @@ const CGFloat kImageNoFocusAlpha = 0.65; [[self controlView] setNeedsDisplay:YES]; } -- (void)setOverlayImageID:(NSInteger)imageID { - if (overlayImageID_ != imageID) { - overlayImageID_ = imageID; - [[self controlView] setNeedsDisplay:YES]; - } +- (CGFloat)imageAlphaForWindowState:(NSWindow*)window { + BOOL windowHasFocus = [window isMainWindow] || [window isKeyWindow]; + return windowHasFocus ? 1.0 : kImageNoFocusAlpha; +} + +- (void)drawFocusRingWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { + if (![self showsFirstResponder]) + return; + gfx::ScopedNSGraphicsContextSaveGState scoped_state; + const CGFloat lineWidth = [controlView cr_lineWidth]; + rect_path_utils::FrameRectWithInset(rect_path_utils::RoundedCornerAll, + NSInsetRect(cellFrame, 0, lineWidth), + 0.0, // insetX + 0.0, // insetY + 3.0, // outerRadius + lineWidth * 2, // lineWidth + [controlView + cr_keyboardFocusIndicatorColor]); } - (image_button_cell::ButtonState)currentButtonState { diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm index 00c8bda..08b7371 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm @@ -39,6 +39,7 @@ #import "chrome/browser/ui/cocoa/toolbar/reload_button.h" #import "chrome/browser/ui/cocoa/toolbar/toolbar_button.h" #import "chrome/browser/ui/cocoa/toolbar/toolbar_view.h" +#import "chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h" #import "chrome/browser/ui/cocoa/view_id_util.h" #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" #include "chrome/browser/ui/global_error/global_error_service.h" @@ -97,7 +98,7 @@ const CGFloat kWrenchMenuLeftPadding = 3.0; - (void)browserActionsContainerDragFinished:(NSNotification*)notification; - (void)browserActionsVisibilityChanged:(NSNotification*)notification; - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; -- (void)badgeWrenchMenuIfNeeded; +- (void)updateWrenchButtonSeverity; @end namespace ToolbarControllerInternal { @@ -123,7 +124,7 @@ class NotificationBridge switch (type) { case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: - [controller_ badgeWrenchMenuIfNeeded]; + [controller_ updateWrenchButtonSeverity]; break; default: NOTREACHED(); @@ -254,7 +255,7 @@ class NotificationBridge [[wrenchButton_ cell] setImageID:IDR_TOOLS_P forButtonState:image_button_cell::kPressedState]; - [self badgeWrenchMenuIfNeeded]; + [self updateWrenchButtonSeverity]; [wrenchButton_ setOpenMenuOnClick:YES]; @@ -556,22 +557,24 @@ class NotificationBridge return wrenchMenuController_; } -- (void)badgeWrenchMenuIfNeeded { +- (void)updateWrenchButtonSeverity { + WrenchToolbarButtonCell* cell = + base::mac::ObjCCastStrict<WrenchToolbarButtonCell>([wrenchButton_ cell]); if (UpgradeDetector::GetInstance()->notify_upgrade()) { - [[wrenchButton_ cell] - setOverlayImageID:UpgradeDetector::GetInstance()->GetIconResourceID( - UpgradeDetector::UPGRADE_ICON_TYPE_BADGE)]; + [cell setSeverity:WrenchIconPainter::SeverityFromUpgradeLevel( + UpgradeDetector::GetInstance()->upgrade_notification_stage())]; return; } GlobalError* error = GlobalErrorServiceFactory::GetForProfile( browser_->profile())->GetHighestSeverityGlobalErrorWithWrenchMenuItem(); if (error) { - [[wrenchButton_ cell] setOverlayImageID:IDR_UPDATE_BADGE4]; + [cell setSeverity:WrenchIconPainter::SeverityFromGlobalErrorSeverity( + error->GetSeverity())]; return; } - [[wrenchButton_ cell] setOverlayImageID:0]; + [cell setSeverity:WrenchIconPainter::SEVERITY_NONE]; } - (void)prefChanged:(const std::string&)prefName { diff --git a/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h b/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h new file mode 100644 index 0000000..24bec6d --- /dev/null +++ b/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h @@ -0,0 +1,28 @@ +// Copyright (c) 2013 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_UI_COCOA_TOOLBAR_WRENCH_TOOLBAR_BUTTON_CELL_H_ +#define CHROME_BROWSER_UI_COCOA_TOOLBAR_WRENCH_TOOLBAR_BUTTON_CELL_H_ + +#import <Cocoa/Cocoa.h> + +#include "base/memory/scoped_ptr.h" +#import "chrome/browser/ui/cocoa/clickhold_button_cell.h" +#include "chrome/browser/ui/toolbar/wrench_icon_painter.h" + +class WrenchIconPainterDelegateMac; + +// Cell for the wrench toolbar button. This is used to draw the wrench icon +// and paint severity levels. +@interface WrenchToolbarButtonCell : ClickHoldButtonCell { + @private + scoped_ptr<WrenchIconPainter> wrenchIconPainter_; + scoped_ptr<WrenchIconPainterDelegateMac> delegate_; +} + +- (void)setSeverity:(WrenchIconPainter::Severity)severity; + +@end + +#endif // CHROME_BROWSER_UI_COCOA_TOOLBAR_WRENCH_TOOLBAR_BUTTON_CELL_H_ diff --git a/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.mm b/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.mm new file mode 100644 index 0000000..7744bb4 --- /dev/null +++ b/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.mm @@ -0,0 +1,81 @@ +// Copyright (c) 2013 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 "chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h" + +#import "chrome/browser/ui/cocoa/themed_window.h" +#include "ui/gfx/canvas_skia_paint.h" +#include "ui/gfx/rect.h" + +class WrenchIconPainterDelegateMac : public WrenchIconPainter::Delegate { + public: + explicit WrenchIconPainterDelegateMac(NSCell* cell) : cell_(cell) {} + virtual ~WrenchIconPainterDelegateMac() {} + + virtual void ScheduleWrenchIconPaint() OVERRIDE { + [[cell_ controlView] setNeedsDisplay:YES]; + } + + private: + NSCell* cell_; + + DISALLOW_COPY_AND_ASSIGN(WrenchIconPainterDelegateMac); +}; + +@interface WrenchToolbarButtonCell () +- (void)commonInit; +- (WrenchIconPainter::BezelType)currentBezelType; +@end + +@implementation WrenchToolbarButtonCell + +- (id)initTextCell:(NSString*)text { + if ((self = [super initTextCell:text])) { + [self commonInit]; + } + return self; +} + +- (id)initWithCoder:(NSCoder*)decoder { + if ((self = [super initWithCoder:decoder])) { + [self commonInit]; + } + return self; +} + +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { + gfx::CanvasSkiaPaint canvas(cellFrame, false); + canvas.set_composite_alpha(true); + canvas.SaveLayerAlpha(255 * + [self imageAlphaForWindowState:[controlView window]]); + ui::ThemeProvider* themeProvider = [[controlView window] themeProvider]; + if (themeProvider) { + wrenchIconPainter_->Paint(&canvas, + [[controlView window] themeProvider], + gfx::Rect(NSRectToCGRect(cellFrame)), + [self currentBezelType]); + } + canvas.Restore(); + + [self drawFocusRingWithFrame:cellFrame inView:controlView]; +} + +- (void)setSeverity:(WrenchIconPainter::Severity)severity { + wrenchIconPainter_->SetSeverity(severity); +} + +- (void)commonInit { + delegate_.reset(new WrenchIconPainterDelegateMac(self)); + wrenchIconPainter_.reset(new WrenchIconPainter(delegate_.get())); +} + +- (WrenchIconPainter::BezelType)currentBezelType { + if ([self isHighlighted]) + return WrenchIconPainter::BEZEL_PRESSED; + if ([self isMouseInside]) + return WrenchIconPainter::BEZEL_HOVER; + return WrenchIconPainter::BEZEL_NONE; +} + +@end diff --git a/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell_unittest.mm b/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell_unittest.mm new file mode 100644 index 0000000..52226e1 --- /dev/null +++ b/chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell_unittest.mm @@ -0,0 +1,38 @@ +// Copyright (c) 2013 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 "chrome/browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h" + +#include "base/message_loop.h" +#import "chrome/browser/ui/cocoa/cocoa_test_helper.h" + +@interface TestWrenchToolbarButton : NSButton +@end + +@implementation TestWrenchToolbarButton + ++ (Class)cellClass { + return [WrenchToolbarButtonCell class]; +} + +@end + +class WrenchToolbarButtonCellTest : public CocoaTest { + protected: + WrenchToolbarButtonCellTest() { + scoped_nsobject<NSButton> button([[TestWrenchToolbarButton alloc] + initWithFrame:NSMakeRect(0, 0, 29, 29)]); + button_ = button; + [[test_window() contentView] addSubview:button_]; + } + + NSButton* button_; + scoped_nsobject<WrenchToolbarButtonCell> cell_; + MessageLoopForUI message_loop_; // Needed for ui::Animation. + + private: + DISALLOW_COPY_AND_ASSIGN(WrenchToolbarButtonCellTest); +}; + +TEST_VIEW(WrenchToolbarButtonCellTest, button_) diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 180ff8d..4fccb7d 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -812,6 +812,8 @@ 'browser/ui/cocoa/toolbar/toolbar_controller.mm', 'browser/ui/cocoa/toolbar/toolbar_view.h', 'browser/ui/cocoa/toolbar/toolbar_view.mm', + 'browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h', + 'browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.mm', 'browser/ui/cocoa/ui_localizer.h', 'browser/ui/cocoa/ui_localizer.mm', 'browser/ui/cocoa/url_drop_target.h', diff --git a/chrome/chrome_nibs.gyp b/chrome/chrome_nibs.gyp index fb52f24..d80a732 100644 --- a/chrome/chrome_nibs.gyp +++ b/chrome/chrome_nibs.gyp @@ -249,6 +249,8 @@ 'browser/ui/cocoa/toolbar/toolbar_controller.mm', 'browser/ui/cocoa/toolbar/toolbar_view.h', 'browser/ui/cocoa/toolbar/toolbar_view.mm', + 'browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.h', + 'browser/ui/cocoa/toolbar/wrench_toolbar_button_cell.mm', 'browser/ui/cocoa/ui_localizer.h', 'browser/ui/cocoa/ui_localizer.mm', 'browser/ui/cocoa/vertical_gradient_view.h', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 5b5a46e..d317d92 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1362,6 +1362,7 @@ 'browser/ui/cocoa/toolbar/toolbar_button_unittest.mm', 'browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm', 'browser/ui/cocoa/toolbar/toolbar_view_unittest.mm', + 'browser/ui/cocoa/toolbar/wrench_toolbar_button_cell_unittest.mm', 'browser/ui/cocoa/vertical_gradient_view_unittest.mm', 'browser/ui/cocoa/view_resizer_pong.h', 'browser/ui/cocoa/view_resizer_pong.mm', |