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

Side by Side Diff: chrome/browser/ui/cocoa/constrained_window/constrained_window_button.mm

Issue 11348343: Use bold for default constrained window button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
6 6
7 #include "base/memory/scoped_nsobject.h" 7 #include "base/memory/scoped_nsobject.h"
8 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
8 #include "skia/ext/skia_utils_mac.h" 9 #include "skia/ext/skia_utils_mac.h"
9 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h" 10 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h"
10 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 11 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
11 12
12 namespace { 13 namespace {
13 14
14 enum ButtonState { 15 enum ButtonState {
15 BUTTON_NORMAL, 16 BUTTON_NORMAL,
16 BUTTON_HOVER, 17 BUTTON_HOVER,
17 BUTTON_PRESSED, 18 BUTTON_PRESSED,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return shadow; 73 return shadow;
73 } 74 }
74 75
75 NSColor* GetButtonBorderColor(ButtonState button_state) { 76 NSColor* GetButtonBorderColor(ButtonState button_state) {
76 const SkColor color[] = {0x40000000, 0x4D000000, 0x4D000000, 0x1F000000}; 77 const SkColor color[] = {0x40000000, 0x4D000000, 0x4D000000, 0x1F000000};
77 78
78 return gfx::SkColorToCalibratedNSColor(color[button_state]); 79 return gfx::SkColorToCalibratedNSColor(color[button_state]);
79 } 80 }
80 81
81 NSAttributedString* GetButtonAttributedString(NSString* title, 82 NSAttributedString* GetButtonAttributedString(NSString* title,
83 NSString* key_equivalent,
82 ButtonState button_state) { 84 ButtonState button_state) {
83 const SkColor text_color[] = {0xFF333333, 0XFF000000, 0xFF000000, 0xFFAAAAAA}; 85 const SkColor text_color[] = {0xFF333333, 0XFF000000, 0xFF000000, 0xFFAAAAAA};
84 // The shadow color should be 0xFFF0F0F0 but that doesn't show up so use 86 // The shadow color should be 0xFFF0F0F0 but that doesn't show up so use
85 // pure white instead. 87 // pure white instead.
86 const SkColor shadow_color[] = 88 const SkColor shadow_color[] =
87 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF}; 89 {0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF};
88 90
89 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); 91 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]);
90 [shadow setShadowColor: 92 [shadow setShadowColor:
91 gfx::SkColorToCalibratedNSColor(shadow_color[button_state])]; 93 gfx::SkColorToCalibratedNSColor(shadow_color[button_state])];
92 [shadow setShadowOffset:NSMakeSize(0, -1)]; 94 [shadow setShadowOffset:NSMakeSize(0, -1)];
93 [shadow setShadowBlurRadius:0]; 95 [shadow setShadowBlurRadius:0];
94 96
95 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 97 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
96 [[NSMutableParagraphStyle alloc] init]); 98 [[NSMutableParagraphStyle alloc] init]);
97 [paragraphStyle setAlignment:NSCenterTextAlignment]; 99 [paragraphStyle setAlignment:NSCenterTextAlignment];
98 100
101 NSFont* font = nil;
102 if ([key_equivalent isEqualToString:kKeyEquivalentReturn])
103 font = [NSFont boldSystemFontOfSize:12];
104 else
105 font = [NSFont systemFontOfSize:12];
106
99 NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: 107 NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
100 [NSFont systemFontOfSize:12], NSFontAttributeName, 108 font, NSFontAttributeName,
101 gfx::SkColorToCalibratedNSColor(text_color[button_state]), 109 gfx::SkColorToCalibratedNSColor(text_color[button_state]),
102 NSForegroundColorAttributeName, 110 NSForegroundColorAttributeName,
103 shadow.get(), NSShadowAttributeName, 111 shadow.get(), NSShadowAttributeName,
104 paragraphStyle.get(), NSParagraphStyleAttributeName, 112 paragraphStyle.get(), NSParagraphStyleAttributeName,
105 nil]; 113 nil];
106 return [[[NSAttributedString alloc] initWithString:title 114 return [[[NSAttributedString alloc] initWithString:title
107 attributes:attributes] autorelease]; 115 attributes:attributes] autorelease];
108 } 116 }
109 117
110 } // namespace 118 } // namespace
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Border 213 // Border
206 path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 0.5, 0.5) 214 path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 0.5, 0.5)
207 xRadius:2 215 xRadius:2
208 yRadius:2]; 216 yRadius:2];
209 if ([[[controlView window] firstResponder] isEqual:controlView]) 217 if ([[[controlView window] firstResponder] isEqual:controlView])
210 [[NSColor colorWithCalibratedRed:0.30 green:0.57 blue:1.0 alpha:1.0] set]; 218 [[NSColor colorWithCalibratedRed:0.30 green:0.57 blue:1.0 alpha:1.0] set];
211 else 219 else
212 [GetButtonBorderColor(buttonState) set]; 220 [GetButtonBorderColor(buttonState) set];
213 [path stroke]; 221 [path stroke];
214 222
215 [self drawTitle:GetButtonAttributedString([self title], buttonState) 223 NSAttributedString* title = GetButtonAttributedString(
216 withFrame:frame 224 [self title], [self keyEquivalent], buttonState);
217 inView:controlView]; 225 [self drawTitle:title withFrame:frame inView:controlView];
218 } 226 }
219 227
220 - (NSSize)cellSize { 228 - (NSSize)cellSize {
221 NSAttributedString* attributedString = 229 NSAttributedString* title = GetButtonAttributedString(
222 GetButtonAttributedString([self title], BUTTON_NORMAL); 230 [self title], [self keyEquivalent], [self buttonState]);
223 NSSize size = [attributedString size]; 231 NSSize size = [title size];
224 size.height = std::max(size.height, kButtonHeight); 232 size.height = std::max(size.height, kButtonHeight);
225 size.width += kButtonPaddingX * 2; 233 size.width += kButtonPaddingX * 2;
226 return size; 234 return size;
227 } 235 }
228 236
229 - (ButtonState)buttonState { 237 - (ButtonState)buttonState {
230 if (![self isEnabled]) 238 if (![self isEnabled])
231 return BUTTON_DISABLED; 239 return BUTTON_DISABLED;
232 if ([self isHighlighted]) 240 if ([self isHighlighted])
233 return BUTTON_PRESSED; 241 return BUTTON_PRESSED;
234 if (isMouseInside_) 242 if (isMouseInside_)
235 return BUTTON_HOVER; 243 return BUTTON_HOVER;
236 return BUTTON_NORMAL; 244 return BUTTON_NORMAL;
237 } 245 }
238 246
239 @end 247 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698