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

Unified Diff: chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm

Issue 7981035: Add icon to the panel titlebar on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
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..7eaca372a4cf7a96c0a7a0ac6ec04c3be333269b 100644
--- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
@@ -17,11 +17,13 @@
#import "chrome/browser/ui/panels/panel_window_controller_cocoa.h"
#include "grit/theme_resources_standard.h"
#import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/mac/nsimage_cache.h"
#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 +184,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)];
@@ -207,13 +210,18 @@ static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) {
- (void)setTitle:(NSString*)newTitle {
[title_ setStringValue:newTitle];
+
Avi (use Gerrit) 2011/09/21 21:04:25 remove extra line
jianli 2011/09/21 23:15:25 Done.
+}
+
+- (void)setIcon:(NSImage*)newIcon {
+ [icon_ setImage:newIcon];
}
- (void)updateCloseButtonLayout {
NSRect buttonBounds = [closeButton_ bounds];
NSRect bounds = [self bounds];
- int x = kCloseButtonLeftPadding;
+ int x = kButtonPadding;
int y = (NSHeight(bounds) - NSHeight(buttonBounds)) / 2;
NSRect buttonFrame = NSMakeRect(x,
y,
@@ -233,6 +241,43 @@ static NSEvent* MakeMouseEvent(NSEventType type, NSPoint point) {
[self addTrackingArea:closeButtonTrackingArea_.get()];
}
+- (void)updateIconAndTitleLayout {
+ NSRect closeButtonBounds = [closeButton_ bounds];
Dmitry Titov 2011/09/21 21:32:11 We should call those 'frame' ratehr then 'bounds'
jennb 2011/09/21 22:10:38 Is updateCloseButtonLayout also using bounds incor
jianli 2011/09/21 23:15:25 Changed to call sizeToFit before querying its boun
jianli 2011/09/21 23:15:25 Done.
jianli 2011/09/21 23:15:25 Done.
+ NSRect iconBounds = [icon_ bounds];
+ NSRect titleBounds = [title_ bounds];
+ NSRect settingsButtonBounds = [settingsButton_ bounds];
+ NSRect bounds = [self bounds];
+
+ // Compute the size of the title text.
+ NSDictionary* attributes =
+ [NSDictionary dictionaryWithObjectsAndKeys:[NSFont userFontOfSize:12],
Avi (use Gerrit) 2011/09/21 21:04:25 Don't make assumptions. You should be able to use
jianli 2011/09/21 23:15:25 Removed since it is not needed.
+ NSFontAttributeName,
+ nil];
+ NSAttributedString* text =
+ [[NSAttributedString alloc] initWithString:[title_ stringValue]
+ attributes:attributes];
Avi (use Gerrit) 2011/09/21 21:04:25 Alternatively, does [title_ attributedStringValue]
Dmitry Titov 2011/09/21 21:32:11 'test' should be autoreleased in the same statemen
jianli 2011/09/21 23:15:25 Removed since it is not needed.
+ NSSize titleSize = [text size];
+ int titleWidth = titleSize.width;
+
+ // Place the icon and title at the center of the titlebar.
+ int iconWidthWithPadding = NSWidth(iconBounds) + kIconAndTextPadding;
+ int availableWidth = NSWidth(bounds) - kButtonPadding * 4 -
+ NSWidth(closeButtonBounds) - NSWidth(settingsButtonBounds);
+ if (iconWidthWithPadding + titleWidth > availableWidth)
+ titleWidth = availableWidth - iconWidthWithPadding;
+ int startX = kButtonPadding * 2 + NSWidth(closeButtonBounds) +
+ (availableWidth - iconWidthWithPadding - titleWidth) / 2;
+
+ iconBounds.origin.x = startX;
+ iconBounds.origin.y = (NSHeight(bounds) - NSHeight(iconBounds)) / 2;
+ [icon_ setFrame:iconBounds];
+
+ titleBounds.origin.x = startX + iconWidthWithPadding;
+ titleBounds.origin.y = (NSHeight(bounds) - NSHeight(titleBounds)) / 2;
+ titleBounds.size.width = titleWidth;
+ [title_ setFrame:titleBounds];
+}
+
// PanelManager controls size/position of the window.
- (BOOL)mouseDownCanMoveWindow {
return NO;
« no previous file with comments | « chrome/browser/ui/panels/panel_titlebar_view_cocoa.h ('k') | chrome/browser/ui/panels/panel_window_controller_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698