Commit b0871db9 authored by jianli@chromium.org's avatar jianli@chromium.org

Add icon to the panel titlebar on Mac.

Changed Panel.xib to add icon in NSView type.

BUG=none
TEST=manul test to verify it exists

Review URL: http://codereview.chromium.org/7981035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102326 0039d316-1c4b-4281-b951-d872f2087c98
parent 619864aa
This diff is collapsed.
...@@ -35,6 +35,7 @@ enum PanelDragState { ...@@ -35,6 +35,7 @@ enum PanelDragState {
@interface PanelTitlebarViewCocoa : NSView { @interface PanelTitlebarViewCocoa : NSView {
@private @private
IBOutlet PanelWindowControllerCocoa* controller_; IBOutlet PanelWindowControllerCocoa* controller_;
IBOutlet NSImageView* icon_;
IBOutlet NSTextField* title_; IBOutlet NSTextField* title_;
IBOutlet HoverImageButton* settingsButton_; IBOutlet HoverImageButton* settingsButton_;
NSButton* closeButton_; // Created explicitly, not from NIB. Weak, destroyed NSButton* closeButton_; // Created explicitly, not from NIB. Weak, destroyed
...@@ -53,9 +54,11 @@ enum PanelDragState { ...@@ -53,9 +54,11 @@ enum PanelDragState {
- (void)attach; - (void)attach;
- (void)setTitle:(NSString*)newTitle; - (void)setTitle:(NSString*)newTitle;
- (void)setIcon:(NSImage*)newIcon;
// Should be called when size of the titlebar changes. // Should be called when size of the titlebar changes.
- (void)updateCloseButtonLayout; - (void)updateCloseButtonLayout;
- (void)updateIconAndTitleLayout;
// We need to update our look when the Chrome theme changes or window focus // We need to update our look when the Chrome theme changes or window focus
// changes. // changes.
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
const int kRoundedCornerSize = 3; const int kRoundedCornerSize = 3;
const int kCloseButtonLeftPadding = 8; const int kButtonPadding = 8;
const int kIconAndTextPadding = 5;
// Used to implement TestingAPI // Used to implement TestingAPI
static NSEvent* MakeMouseEvent(NSEventType type, static NSEvent* MakeMouseEvent(NSEventType type,
...@@ -184,6 +185,7 @@ static NSEvent* MakeMouseEvent(NSEventType type, ...@@ -184,6 +185,7 @@ static NSEvent* MakeMouseEvent(NSEventType type,
// Update layout of controls in the titlebar. // Update layout of controls in the titlebar.
[self updateCloseButtonLayout]; [self updateCloseButtonLayout];
[self updateIconAndTitleLayout];
// Set autoresizing behavior: glued to edges on left, top and right. // Set autoresizing behavior: glued to edges on left, top and right.
[self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)];
...@@ -211,16 +213,16 @@ static NSEvent* MakeMouseEvent(NSEventType type, ...@@ -211,16 +213,16 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[title_ setStringValue:newTitle]; [title_ setStringValue:newTitle];
} }
- (void)setIcon:(NSImage*)newIcon {
[icon_ setImage:newIcon];
}
- (void)updateCloseButtonLayout { - (void)updateCloseButtonLayout {
NSRect buttonBounds = [closeButton_ bounds]; NSRect buttonFrame = [closeButton_ frame];
NSRect bounds = [self bounds]; NSRect bounds = [self bounds];
int x = kCloseButtonLeftPadding; buttonFrame.origin.x = kButtonPadding;
int y = (NSHeight(bounds) - NSHeight(buttonBounds)) / 2; buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2;
NSRect buttonFrame = NSMakeRect(x,
y,
NSWidth(buttonBounds),
NSHeight(buttonBounds));
[closeButton_ setFrame:buttonFrame]; [closeButton_ setFrame:buttonFrame];
DCHECK(!closeButtonTrackingArea_.get()); DCHECK(!closeButtonTrackingArea_.get());
...@@ -235,6 +237,34 @@ static NSEvent* MakeMouseEvent(NSEventType type, ...@@ -235,6 +237,34 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[self addTrackingArea:closeButtonTrackingArea_.get()]; [self addTrackingArea:closeButtonTrackingArea_.get()];
} }
- (void)updateIconAndTitleLayout {
NSRect closeButtonFrame = [closeButton_ frame];
NSRect iconFrame = [icon_ frame];
[title_ sizeToFit];
NSRect titleFrame = [title_ frame];
NSRect settingsButtonFrame = [settingsButton_ frame];
NSRect bounds = [self bounds];
// Place the icon and title at the center of the titlebar.
int iconWidthWithPadding = NSWidth(iconFrame) + kIconAndTextPadding;
int titleWidth = NSWidth(titleFrame);
int availableWidth = NSWidth(bounds) - kButtonPadding * 4 -
NSWidth(closeButtonFrame) - NSWidth(settingsButtonFrame);
if (iconWidthWithPadding + titleWidth > availableWidth)
titleWidth = availableWidth - iconWidthWithPadding;
int startX = kButtonPadding * 2 + NSWidth(closeButtonFrame) +
(availableWidth - iconWidthWithPadding - titleWidth) / 2;
iconFrame.origin.x = startX;
iconFrame.origin.y = (NSHeight(bounds) - NSHeight(iconFrame)) / 2;
[icon_ setFrame:iconFrame];
titleFrame.origin.x = startX + iconWidthWithPadding;
titleFrame.origin.y = (NSHeight(bounds) - NSHeight(titleFrame)) / 2;
titleFrame.size.width = titleWidth;
[title_ setFrame:titleFrame];
}
// PanelManager controls size/position of the window. // PanelManager controls size/position of the window.
- (BOOL)mouseDownCanMoveWindow { - (BOOL)mouseDownCanMoveWindow {
return NO; return NO;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/menu_controller.h" #import "chrome/browser/ui/cocoa/menu_controller.h"
#import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h"
#include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_browser_window_cocoa.h" #include "chrome/browser/ui/panels/panel_browser_window_cocoa.h"
#include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/panels/panel_manager.h"
...@@ -179,6 +180,12 @@ static BOOL g_reportAnimationStatus = NO; ...@@ -179,6 +180,12 @@ static BOOL g_reportAnimationStatus = NO;
withNewTitle:newTitle withNewTitle:newTitle
forWindow:[self window]]); forWindow:[self window]]);
[titlebar_view_ setTitle:newTitle]; [titlebar_view_ setTitle:newTitle];
NSImage* newIcon = mac::FaviconForTabContents(
windowShim_->browser()->GetSelectedTabContentsWrapper());
[titlebar_view_ setIcon:newIcon];
[titlebar_view_ updateIconAndTitleLayout];
} }
- (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment