| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/cocoa/status_bubble_mac.h" | 5 #include "chrome/browser/cocoa/status_bubble_mac.h" |
| 6 | 6 |
| 7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 11 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
| 12 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
| 13 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 const int kWindowHeight = 18; | 17 const int kWindowHeight = 18; |
| 16 // The width of the bubble in relation to the width of the parent window. | 18 // The width of the bubble in relation to the width of the parent window. |
| 17 const float kWindowWidthPercent = 1.0f/3.0f; | 19 const float kWindowWidthPercent = 1.0f/3.0f; |
| 18 | 20 |
| 19 // How close the mouse can get to the infobubble before it starts sliding | 21 // How close the mouse can get to the infobubble before it starts sliding |
| 20 // off-screen. | 22 // off-screen. |
| 21 const int kMousePadding = 20; | 23 const int kMousePadding = 20; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 enum BubbleStyle { | 44 enum BubbleStyle { |
| 43 STYLE_BOTTOM, // Hanging off the bottom of the parent window | 45 STYLE_BOTTOM, // Hanging off the bottom of the parent window |
| 44 STYLE_FLOATING, // Between BOTTOM and STANDARD | 46 STYLE_FLOATING, // Between BOTTOM and STANDARD |
| 45 STYLE_STANDARD // Nestled in the corner of the parent window | 47 STYLE_STANDARD // Nestled in the corner of the parent window |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 @interface StatusBubbleViewCocoa : NSView { | 50 @interface StatusBubbleViewCocoa : NSView { |
| 49 @private | 51 @private |
| 50 NSString* content_; | 52 NSString* content_; |
| 51 BubbleStyle style_; | 53 BubbleStyle style_; |
| 54 NSWindow* parent_; |
| 52 } | 55 } |
| 53 | 56 |
| 54 - (void)setContent:(NSString*)content; | 57 - (void)setContent:(NSString*)content; |
| 55 - (void)setStyle:(BubbleStyle)style; | 58 - (void)setStyle:(BubbleStyle)style; |
| 59 - (void)setParent:(NSWindow*)parent; |
| 56 - (NSFont*)font; | 60 - (NSFont*)font; |
| 57 @end | 61 @end |
| 58 | 62 |
| 59 StatusBubbleMac::StatusBubbleMac(NSWindow* parent, id delegate) | 63 StatusBubbleMac::StatusBubbleMac(NSWindow* parent, id delegate) |
| 60 : parent_(parent), | 64 : parent_(parent), |
| 61 delegate_(delegate), | 65 delegate_(delegate), |
| 62 window_(nil), | 66 window_(nil), |
| 63 status_text_(nil), | 67 status_text_(nil), |
| 64 url_text_(nil), | 68 url_text_(nil), |
| 65 is_download_shelf_visible_(false) { | 69 is_download_shelf_visible_(false) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 backing:NSBackingStoreBuffered | 217 backing:NSBackingStoreBuffered |
| 214 defer:YES]; | 218 defer:YES]; |
| 215 [window_ setMovableByWindowBackground:NO]; | 219 [window_ setMovableByWindowBackground:NO]; |
| 216 [window_ setBackgroundColor:[NSColor clearColor]]; | 220 [window_ setBackgroundColor:[NSColor clearColor]]; |
| 217 [window_ setLevel:NSNormalWindowLevel]; | 221 [window_ setLevel:NSNormalWindowLevel]; |
| 218 [window_ setOpaque:NO]; | 222 [window_ setOpaque:NO]; |
| 219 [window_ setHasShadow:NO]; | 223 [window_ setHasShadow:NO]; |
| 220 | 224 |
| 221 StatusBubbleViewCocoa* view = | 225 StatusBubbleViewCocoa* view = |
| 222 [[[StatusBubbleViewCocoa alloc] initWithFrame:NSZeroRect] autorelease]; | 226 [[[StatusBubbleViewCocoa alloc] initWithFrame:NSZeroRect] autorelease]; |
| 227 [view setParent:parent_]; |
| 228 |
| 223 [window_ setContentView:view]; | 229 [window_ setContentView:view]; |
| 224 | 230 |
| 225 [parent_ addChildWindow:window_ ordered:NSWindowAbove]; | 231 [parent_ addChildWindow:window_ ordered:NSWindowAbove]; |
| 226 | 232 |
| 227 [window_ setAlphaValue:0.0f]; | 233 [window_ setAlphaValue:0.0f]; |
| 228 | 234 |
| 229 offset_ = 0; | 235 offset_ = 0; |
| 230 [view setStyle:STYLE_STANDARD]; | 236 [view setStyle:STYLE_STANDARD]; |
| 231 MouseMoved(); | 237 MouseMoved(); |
| 232 } | 238 } |
| 233 | 239 |
| 234 void StatusBubbleMac::FadeIn() { | 240 void StatusBubbleMac::FadeIn() { |
| 235 [NSAnimationContext beginGrouping]; | 241 [NSAnimationContext beginGrouping]; |
| 236 [[NSAnimationContext currentContext] setDuration:kShowFadeDuration]; | 242 [[NSAnimationContext currentContext] setDuration:kShowFadeDuration]; |
| 237 [[window_ animator] setAlphaValue:1.0f]; | 243 [[window_ animator] setAlphaValue:1.0f]; |
| 238 [NSAnimationContext endGrouping]; | 244 [NSAnimationContext endGrouping]; |
| 239 } | 245 } |
| 240 | 246 |
| 241 void StatusBubbleMac::FadeOut() { | 247 void StatusBubbleMac::FadeOut() { |
| 242 [NSAnimationContext beginGrouping]; | 248 [NSAnimationContext beginGrouping]; |
| 243 [[NSAnimationContext currentContext] setDuration:kHideFadeDuration]; | 249 [[NSAnimationContext currentContext] setDuration:kHideFadeDuration]; |
| 244 [[window_ animator] setAlphaValue:0.0f]; | 250 [[window_ animator] setAlphaValue:0.0f]; |
| 245 [NSAnimationContext endGrouping]; | 251 [NSAnimationContext endGrouping]; |
| 246 } | 252 } |
| 247 | 253 |
| 248 @implementation StatusBubbleViewCocoa | 254 @implementation StatusBubbleViewCocoa |
| 249 | 255 |
| 250 - (void)dealloc { | 256 - (void)dealloc { |
| 257 [parent_ release]; |
| 251 [content_ release]; | 258 [content_ release]; |
| 252 [super dealloc]; | 259 [super dealloc]; |
| 253 } | 260 } |
| 254 | 261 |
| 255 - (void)setContent:(NSString*)content { | 262 - (void)setContent:(NSString*)content { |
| 256 [content_ autorelease]; | 263 [content_ autorelease]; |
| 257 content_ = [content copy]; | 264 content_ = [content copy]; |
| 258 [self setNeedsDisplay:YES]; | 265 [self setNeedsDisplay:YES]; |
| 259 } | 266 } |
| 260 | 267 |
| 261 - (void)setStyle:(BubbleStyle)style { | 268 - (void)setStyle:(BubbleStyle)style { |
| 262 style_ = style; | 269 style_ = style; |
| 263 [self setNeedsDisplay:YES]; | 270 [self setNeedsDisplay:YES]; |
| 264 } | 271 } |
| 265 | 272 |
| 273 - (void)setParent:(NSWindow*)parent { |
| 274 [parent_ autorelease]; |
| 275 parent_ = [parent retain]; |
| 276 [self setNeedsDisplay:YES]; |
| 277 } |
| 278 |
| 279 - (GTMTheme*)gtm_theme { |
| 280 return [parent_ gtm_theme]; |
| 281 } |
| 282 |
| 266 - (NSFont*)font { | 283 - (NSFont*)font { |
| 267 return [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 284 return [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
| 268 } | 285 } |
| 269 | 286 |
| 270 - (void)drawRect:(NSRect)rect { | 287 - (void)drawRect:(NSRect)rect { |
| 271 float tl_radius, tr_radius, bl_radius, br_radius; | 288 float tl_radius, tr_radius, bl_radius, br_radius; |
| 272 | 289 |
| 273 switch (style_) { | 290 switch (style_) { |
| 274 case STYLE_BOTTOM: | 291 case STYLE_BOTTOM: |
| 275 tl_radius = 0.0f; | 292 tl_radius = 0.0f; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 293 NOTREACHED(); | 310 NOTREACHED(); |
| 294 tl_radius = 0.0f; | 311 tl_radius = 0.0f; |
| 295 tr_radius = 0.0f; | 312 tr_radius = 0.0f; |
| 296 bl_radius = 0.0f; | 313 bl_radius = 0.0f; |
| 297 br_radius = 0.0f; | 314 br_radius = 0.0f; |
| 298 } | 315 } |
| 299 | 316 |
| 300 // Background / Edge | 317 // Background / Edge |
| 301 | 318 |
| 302 NSRect bounds = [self bounds]; | 319 NSRect bounds = [self bounds]; |
| 320 bounds = NSInsetRect(bounds, 0.5, 0.5); |
| 303 NSBezierPath *border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds | 321 NSBezierPath *border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds |
| 304 topLeftCornerRadius:tl_radius | 322 topLeftCornerRadius:tl_radius |
| 305 topRightCornerRadius:tr_radius | 323 topRightCornerRadius:tr_radius |
| 306 bottomLeftCornerRadius:bl_radius | 324 bottomLeftCornerRadius:bl_radius |
| 307 bottomRightCornerRadius:br_radius]; | 325 bottomRightCornerRadius:br_radius]; |
| 308 | 326 |
| 309 [[NSColor colorWithDeviceWhite:kWindowFill alpha:1.0f] set]; | 327 NSColor* color = |
| 328 [[self gtm_theme] backgroundColorForStyle:GTMThemeStyleToolBar |
| 329 state:GTMThemeStateActiveWindow]; |
| 330 |
| 331 // workaround for default theme |
| 332 // TODO(alcor) next GTM update return nil for background color if not set; |
| 333 if ([color isEqual:[NSColor colorWithCalibratedWhite:0.5 alpha:1.0]]) |
| 334 color = nil; |
| 335 if (!color) |
| 336 color = [NSColor colorWithCalibratedWhite:0.9 alpha:1.0]; |
| 337 [color set]; |
| 310 [border fill]; | 338 [border fill]; |
| 311 | 339 |
| 312 border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds | 340 border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds |
| 313 topLeftCornerRadius:tl_radius | 341 topLeftCornerRadius:tl_radius |
| 314 topRightCornerRadius:tr_radius | 342 topRightCornerRadius:tr_radius |
| 315 bottomLeftCornerRadius:bl_radius | 343 bottomLeftCornerRadius:bl_radius |
| 316 bottomRightCornerRadius:br_radius]; | 344 bottomRightCornerRadius:br_radius]; |
| 317 | 345 |
| 318 [[NSColor colorWithDeviceWhite:kWindowEdge alpha:1.0f] set]; | 346 [[NSColor colorWithDeviceWhite:kWindowEdge alpha:1.0f] set]; |
| 319 [border stroke]; | 347 [border stroke]; |
| 320 | 348 |
| 321 // Text | 349 // Text |
| 322 | 350 NSColor* textColor = [color gtm_legibleTextColor]; |
| 323 NSFont* textFont = [self font]; | 351 NSFont* textFont = [self font]; |
| 324 NSShadow* textShadow = [[[NSShadow alloc] init] autorelease]; | 352 NSShadow* textShadow = [[[NSShadow alloc] init] autorelease]; |
| 325 [textShadow setShadowBlurRadius:1.5f]; | 353 [textShadow setShadowBlurRadius:0.0f]; |
| 326 [textShadow setShadowColor:[NSColor whiteColor]]; | 354 [textShadow setShadowColor:[textColor gtm_legibleTextColor]]; |
| 327 [textShadow setShadowOffset:NSMakeSize(0.0f, -1.0f)]; | 355 [textShadow setShadowOffset:NSMakeSize(0.0f, -1.0f)]; |
| 328 | 356 |
| 329 NSDictionary* textDict = [NSDictionary dictionaryWithObjectsAndKeys: | 357 NSDictionary* textDict = [NSDictionary dictionaryWithObjectsAndKeys: |
| 330 textFont, NSFontAttributeName, | 358 textFont, NSFontAttributeName, |
| 331 textShadow, NSShadowAttributeName, | 359 textShadow, NSShadowAttributeName, |
| 332 nil]; | 360 nil]; |
| 333 [content_ drawAtPoint:NSMakePoint(kTextPositionX, kTextPositionY) | 361 [content_ drawAtPoint:NSMakePoint(kTextPositionX, kTextPositionY) |
| 334 withAttributes:textDict]; | 362 withAttributes:textDict]; |
| 335 } | 363 } |
| 336 | 364 |
| 337 @end | 365 @end |
| OLD | NEW |