Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm |
| diff --git a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm |
| index 08fdc1b840f598d19a66aa4f3cfea5f3407fbad2..a518dc824bc2fa41d1b57f0045f2159ffd931303 100644 |
| --- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm |
| +++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm |
| @@ -21,7 +21,8 @@ |
| #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| const int kRoundedCornerSize = 3; |
| -const int kCloseButtonLeftPadding = 8; |
| +const int kButtonPadding = 8; |
| +const int kIconAndTextPadding = 5; |
| // Used to implement TestingAPI |
| static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) { |
| @@ -182,6 +183,7 @@ static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) { |
| // Update layout of controls in the titlebar. |
| [self updateCloseButtonLayout]; |
| + [self updateIconAndTitleLayout]; |
| // Set autoresizing behavior: glued to edges on left, top and right. |
| [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; |
| @@ -209,16 +211,16 @@ static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) { |
| [title_ setStringValue:newTitle]; |
| } |
| +- (void)setIcon:(NSImage*)newIcon { |
| + [icon_ setImage:newIcon]; |
| +} |
| + |
| - (void)updateCloseButtonLayout { |
| - NSRect buttonBounds = [closeButton_ bounds]; |
| - NSRect bounds = [self bounds]; |
| - |
| - int x = kCloseButtonLeftPadding; |
| - int y = (NSHeight(bounds) - NSHeight(buttonBounds)) / 2; |
| - NSRect buttonFrame = NSMakeRect(x, |
| - y, |
| - NSWidth(buttonBounds), |
| - NSHeight(buttonBounds)); |
| + NSRect buttonFrame = [closeButton_ frame]; |
| + NSRect frame = [self frame]; |
| + |
| + buttonFrame.origin.x = kButtonPadding; |
| + buttonFrame.origin.y = (NSHeight(frame) - NSHeight(buttonFrame)) / 2; |
| [closeButton_ setFrame:buttonFrame]; |
| DCHECK(!closeButtonTrackingArea_.get()); |
| @@ -233,6 +235,34 @@ static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) { |
| [self addTrackingArea:closeButtonTrackingArea_.get()]; |
| } |
| +- (void)updateIconAndTitleLayout { |
| + NSRect closeButtonFrame = [closeButton_ frame]; |
| + NSRect iconFrame = [icon_ frame]; |
| + [title_ sizeToFit]; |
|
Dmitry Titov
2011/09/21 23:30:23
Magic :-)
|
| + NSRect titleFrame = [title_ frame]; |
| + NSRect settingsButtonFrame = [settingsButton_ frame]; |
| + NSRect frame = [self frame]; |
|
Dmitry Titov
2011/09/21 23:31:42
Discussed offline: This one should still be 'bound
|
| + |
| + // Place the icon and title at the center of the titlebar. |
| + int iconWidthWithPadding = NSWidth(iconFrame) + kIconAndTextPadding; |
| + int titleWidth = NSWidth(titleFrame); |
| + int availableWidth = NSWidth(frame) - 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(frame) - NSHeight(iconFrame)) / 2; |
| + [icon_ setFrame:iconFrame]; |
| + |
| + titleFrame.origin.x = startX + iconWidthWithPadding; |
| + titleFrame.origin.y = (NSHeight(frame) - NSHeight(titleFrame)) / 2; |
| + titleFrame.size.width = titleWidth; |
| + [title_ setFrame:titleFrame]; |
| +} |
| + |
| // PanelManager controls size/position of the window. |
| - (BOOL)mouseDownCanMoveWindow { |
| return NO; |