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

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

Issue 20334: Sad Tab view for the Mac. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/cocoa/sad_tab_view.h"
6
7 static const int kSadTabOffset = -64;
8 static const int kIconTitleSpacing = 20;
9 static const int kTitleMessageSpacing = 15;
10
11 @implementation SadTabView
12
13 - (void)drawRect:(NSRect)dirtyRect {
14 NSImage* sadTabImage = [NSImage imageNamed:@"sadtab"];
15 NSString* title = @"Aw, Snap!"; // TODO(avi):localize
16 NSString* message = @"Something went wrong while displaying this webpage. "
17 "To continue, press Reload or go to another page.";
18
19 NSColor* textColor = [NSColor whiteColor];
20 NSColor* backgroundColor = [NSColor colorWithCalibratedRed:(35.0f/255.0f)
21 green:(48.0f/255.0f)
22 blue:(64.0f/255.0f)
23 alpha:1.0];
24
25 // Layout
26 NSFont* titleFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]];
27 NSFont* messageFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
28
29 NSDictionary* titleAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
30 titleFont, NSFontAttributeName,
31 textColor, NSForegroundColorAttributeName,
32 nil];
33 NSDictionary* messageAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
34 messageFont, NSFontAttributeName,
35 textColor, NSForegroundColorAttributeName,
36 nil];
37
38 NSAttributedString* titleString =
39 [[[NSAttributedString alloc] initWithString:title
40 attributes:titleAttrs] autorelease];
41 NSAttributedString* messageString =
42 [[[NSAttributedString alloc] initWithString:message
43 attributes:messageAttrs] autorelease];
44
45 NSRect viewBounds = [self bounds];
46
47 NSSize sadTabImageSize = [sadTabImage size];
48 CGFloat iconWidth = sadTabImageSize.width;
49 CGFloat iconHeight = sadTabImageSize.height;
50 CGFloat iconX = (viewBounds.size.width - iconWidth) / 2;
51 CGFloat iconY =
52 ((viewBounds.size.height - iconHeight) / 2) - kSadTabOffset;
53
54 NSSize titleSize = [titleString size];
55 CGFloat titleX = (viewBounds.size.width - titleSize.width) / 2;
56 CGFloat titleY = iconY - kIconTitleSpacing - titleSize.height;
57
58 NSSize messageSize = [messageString size];
59 CGFloat messageX = (viewBounds.size.width - messageSize.width) / 2;
60 CGFloat messageY = titleY - kTitleMessageSpacing - messageSize.height;
61
62 // Paint
63 [backgroundColor set];
64 NSRectFill(viewBounds);
65
66 [sadTabImage drawAtPoint:NSMakePoint(iconX, iconY)
67 fromRect:NSZeroRect
68 operation:NSCompositeSourceOver
69 fraction:1.0f];
70 [titleString drawAtPoint:NSMakePoint(titleX, titleY)];
71 [messageString drawAtPoint:NSMakePoint(messageX, messageY)];
72 }
73
74 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/sad_tab_view.h ('k') | chrome/browser/tab_contents/web_contents_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698