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

Side by Side Diff: chrome/browser/cocoa/status_bubble_mac.mm

Issue 181002: Reverting 24700. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
14 12
15 namespace { 13 namespace {
16 14
17 const int kWindowHeight = 18; 15 const int kWindowHeight = 18;
18 // The width of the bubble in relation to the width of the parent window. 16 // The width of the bubble in relation to the width of the parent window.
19 const float kWindowWidthPercent = 1.0f/3.0f; 17 const float kWindowWidthPercent = 1.0f/3.0f;
20 18
21 // How close the mouse can get to the infobubble before it starts sliding 19 // How close the mouse can get to the infobubble before it starts sliding
22 // off-screen. 20 // off-screen.
23 const int kMousePadding = 20; 21 const int kMousePadding = 20;
(...skipping 20 matching lines...) Expand all
44 enum BubbleStyle { 42 enum BubbleStyle {
45 STYLE_BOTTOM, // Hanging off the bottom of the parent window 43 STYLE_BOTTOM, // Hanging off the bottom of the parent window
46 STYLE_FLOATING, // Between BOTTOM and STANDARD 44 STYLE_FLOATING, // Between BOTTOM and STANDARD
47 STYLE_STANDARD // Nestled in the corner of the parent window 45 STYLE_STANDARD // Nestled in the corner of the parent window
48 }; 46 };
49 47
50 @interface StatusBubbleViewCocoa : NSView { 48 @interface StatusBubbleViewCocoa : NSView {
51 @private 49 @private
52 NSString* content_; 50 NSString* content_;
53 BubbleStyle style_; 51 BubbleStyle style_;
54 NSWindow* parent_;
55 } 52 }
56 53
57 - (void)setContent:(NSString*)content; 54 - (void)setContent:(NSString*)content;
58 - (void)setStyle:(BubbleStyle)style; 55 - (void)setStyle:(BubbleStyle)style;
59 - (void)setParent:(NSWindow*)parent;
60 - (NSFont*)font; 56 - (NSFont*)font;
61 @end 57 @end
62 58
63 StatusBubbleMac::StatusBubbleMac(NSWindow* parent, id delegate) 59 StatusBubbleMac::StatusBubbleMac(NSWindow* parent, id delegate)
64 : parent_(parent), 60 : parent_(parent),
65 delegate_(delegate), 61 delegate_(delegate),
66 window_(nil), 62 window_(nil),
67 status_text_(nil), 63 status_text_(nil),
68 url_text_(nil), 64 url_text_(nil),
69 is_download_shelf_visible_(false) { 65 is_download_shelf_visible_(false) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 backing:NSBackingStoreBuffered 213 backing:NSBackingStoreBuffered
218 defer:YES]; 214 defer:YES];
219 [window_ setMovableByWindowBackground:NO]; 215 [window_ setMovableByWindowBackground:NO];
220 [window_ setBackgroundColor:[NSColor clearColor]]; 216 [window_ setBackgroundColor:[NSColor clearColor]];
221 [window_ setLevel:NSNormalWindowLevel]; 217 [window_ setLevel:NSNormalWindowLevel];
222 [window_ setOpaque:NO]; 218 [window_ setOpaque:NO];
223 [window_ setHasShadow:NO]; 219 [window_ setHasShadow:NO];
224 220
225 StatusBubbleViewCocoa* view = 221 StatusBubbleViewCocoa* view =
226 [[[StatusBubbleViewCocoa alloc] initWithFrame:NSZeroRect] autorelease]; 222 [[[StatusBubbleViewCocoa alloc] initWithFrame:NSZeroRect] autorelease];
227 [view setParent:parent_];
228
229 [window_ setContentView:view]; 223 [window_ setContentView:view];
230 224
231 [parent_ addChildWindow:window_ ordered:NSWindowAbove]; 225 [parent_ addChildWindow:window_ ordered:NSWindowAbove];
232 226
233 [window_ setAlphaValue:0.0f]; 227 [window_ setAlphaValue:0.0f];
234 228
235 offset_ = 0; 229 offset_ = 0;
236 [view setStyle:STYLE_STANDARD]; 230 [view setStyle:STYLE_STANDARD];
237 MouseMoved(); 231 MouseMoved();
238 } 232 }
(...skipping 23 matching lines...) Expand all
262 [content_ autorelease]; 256 [content_ autorelease];
263 content_ = [content copy]; 257 content_ = [content copy];
264 [self setNeedsDisplay:YES]; 258 [self setNeedsDisplay:YES];
265 } 259 }
266 260
267 - (void)setStyle:(BubbleStyle)style { 261 - (void)setStyle:(BubbleStyle)style {
268 style_ = style; 262 style_ = style;
269 [self setNeedsDisplay:YES]; 263 [self setNeedsDisplay:YES];
270 } 264 }
271 265
272 - (void)setParent:(NSWindow*)parent {
273 [parent_ autorelease];
274 parent_ = [parent retain];
275 [self setNeedsDisplay:YES];
276 }
277
278 - (GTMTheme*)gtm_theme {
279 return [parent_ gtm_theme];
280 }
281
282 - (NSFont*)font { 266 - (NSFont*)font {
283 return [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; 267 return [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
284 } 268 }
285 269
286 - (void)drawRect:(NSRect)rect { 270 - (void)drawRect:(NSRect)rect {
287 float tl_radius, tr_radius, bl_radius, br_radius; 271 float tl_radius, tr_radius, bl_radius, br_radius;
288 272
289 switch (style_) { 273 switch (style_) {
290 case STYLE_BOTTOM: 274 case STYLE_BOTTOM:
291 tl_radius = 0.0f; 275 tl_radius = 0.0f;
(...skipping 17 matching lines...) Expand all
309 NOTREACHED(); 293 NOTREACHED();
310 tl_radius = 0.0f; 294 tl_radius = 0.0f;
311 tr_radius = 0.0f; 295 tr_radius = 0.0f;
312 bl_radius = 0.0f; 296 bl_radius = 0.0f;
313 br_radius = 0.0f; 297 br_radius = 0.0f;
314 } 298 }
315 299
316 // Background / Edge 300 // Background / Edge
317 301
318 NSRect bounds = [self bounds]; 302 NSRect bounds = [self bounds];
319 bounds = NSInsetRect(bounds, 0.5, 0.5);
320 NSBezierPath *border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds 303 NSBezierPath *border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds
321 topLeftCornerRadius:tl_radius 304 topLeftCornerRadius:tl_radius
322 topRightCornerRadius:tr_radius 305 topRightCornerRadius:tr_radius
323 bottomLeftCornerRadius:bl_radius 306 bottomLeftCornerRadius:bl_radius
324 bottomRightCornerRadius:br_radius]; 307 bottomRightCornerRadius:br_radius];
325 308
326 NSColor* color = 309 [[NSColor colorWithDeviceWhite:kWindowFill alpha:1.0f] set];
327 [[self gtm_theme] backgroundColorForStyle:GTMThemeStyleToolBar
328 state:GTMThemeStateActiveWindow];
329
330 // workaround for default theme
331 // TODO(alcor) next GTM update return nil for background color if not set;
332 if ([color isEqual:[NSColor colorWithCalibratedWhite:0.5 alpha:1.0]])
333 color = nil;
334 if (!color)
335 color = [NSColor colorWithCalibratedWhite:0.9 alpha:1.0];
336 [color set];
337 [border fill]; 310 [border fill];
338 311
339 border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds 312 border = [NSBezierPath gtm_bezierPathWithRoundRect:bounds
340 topLeftCornerRadius:tl_radius 313 topLeftCornerRadius:tl_radius
341 topRightCornerRadius:tr_radius 314 topRightCornerRadius:tr_radius
342 bottomLeftCornerRadius:bl_radius 315 bottomLeftCornerRadius:bl_radius
343 bottomRightCornerRadius:br_radius]; 316 bottomRightCornerRadius:br_radius];
344 317
345 [[NSColor colorWithDeviceWhite:kWindowEdge alpha:1.0f] set]; 318 [[NSColor colorWithDeviceWhite:kWindowEdge alpha:1.0f] set];
346 [border stroke]; 319 [border stroke];
347 320
348 // Text 321 // Text
349 NSColor* textColor = [color gtm_legibleTextColor]; 322
350 NSFont* textFont = [self font]; 323 NSFont* textFont = [self font];
351 NSShadow* textShadow = [[[NSShadow alloc] init] autorelease]; 324 NSShadow* textShadow = [[[NSShadow alloc] init] autorelease];
352 [textShadow setShadowBlurRadius:0.0f]; 325 [textShadow setShadowBlurRadius:1.5f];
353 [textShadow setShadowColor:[textColor gtm_legibleTextColor]]; 326 [textShadow setShadowColor:[NSColor whiteColor]];
354 [textShadow setShadowOffset:NSMakeSize(0.0f, -1.0f)]; 327 [textShadow setShadowOffset:NSMakeSize(0.0f, -1.0f)];
355 328
356 NSDictionary* textDict = [NSDictionary dictionaryWithObjectsAndKeys: 329 NSDictionary* textDict = [NSDictionary dictionaryWithObjectsAndKeys:
357 textFont, NSFontAttributeName, 330 textFont, NSFontAttributeName,
358 textShadow, NSShadowAttributeName, 331 textShadow, NSShadowAttributeName,
359 nil]; 332 nil];
360 [content_ drawAtPoint:NSMakePoint(kTextPositionX, kTextPositionY) 333 [content_ drawAtPoint:NSMakePoint(kTextPositionX, kTextPositionY)
361 withAttributes:textDict]; 334 withAttributes:textDict];
362 } 335 }
363 336
364 @end 337 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/gradient_button_cell_unittest.mm ('k') | chrome/browser/cocoa/status_bubble_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698