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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/sad_tab_view.mm
===================================================================
--- chrome/browser/cocoa/sad_tab_view.mm (revision 0)
+++ chrome/browser/cocoa/sad_tab_view.mm (revision 0)
@@ -0,0 +1,74 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/cocoa/sad_tab_view.h"
+
+static const int kSadTabOffset = -64;
+static const int kIconTitleSpacing = 20;
+static const int kTitleMessageSpacing = 15;
+
+@implementation SadTabView
+
+- (void)drawRect:(NSRect)dirtyRect {
+ NSImage* sadTabImage = [NSImage imageNamed:@"sadtab"];
+ NSString* title = @"Aw, Snap!"; // TODO(avi):localize
+ NSString* message = @"Something went wrong while displaying this webpage. "
+ "To continue, press Reload or go to another page.";
+
+ NSColor* textColor = [NSColor whiteColor];
+ NSColor* backgroundColor = [NSColor colorWithCalibratedRed:(35.0f/255.0f)
+ green:(48.0f/255.0f)
+ blue:(64.0f/255.0f)
+ alpha:1.0];
+
+ // Layout
+ NSFont* titleFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]];
+ NSFont* messageFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+
+ NSDictionary* titleAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
+ titleFont, NSFontAttributeName,
+ textColor, NSForegroundColorAttributeName,
+ nil];
+ NSDictionary* messageAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
+ messageFont, NSFontAttributeName,
+ textColor, NSForegroundColorAttributeName,
+ nil];
+
+ NSAttributedString* titleString =
+ [[[NSAttributedString alloc] initWithString:title
+ attributes:titleAttrs] autorelease];
+ NSAttributedString* messageString =
+ [[[NSAttributedString alloc] initWithString:message
+ attributes:messageAttrs] autorelease];
+
+ NSRect viewBounds = [self bounds];
+
+ NSSize sadTabImageSize = [sadTabImage size];
+ CGFloat iconWidth = sadTabImageSize.width;
+ CGFloat iconHeight = sadTabImageSize.height;
+ CGFloat iconX = (viewBounds.size.width - iconWidth) / 2;
+ CGFloat iconY =
+ ((viewBounds.size.height - iconHeight) / 2) - kSadTabOffset;
+
+ NSSize titleSize = [titleString size];
+ CGFloat titleX = (viewBounds.size.width - titleSize.width) / 2;
+ CGFloat titleY = iconY - kIconTitleSpacing - titleSize.height;
+
+ NSSize messageSize = [messageString size];
+ CGFloat messageX = (viewBounds.size.width - messageSize.width) / 2;
+ CGFloat messageY = titleY - kTitleMessageSpacing - messageSize.height;
+
+ // Paint
+ [backgroundColor set];
+ NSRectFill(viewBounds);
+
+ [sadTabImage drawAtPoint:NSMakePoint(iconX, iconY)
+ fromRect:NSZeroRect
+ operation:NSCompositeSourceOver
+ fraction:1.0f];
+ [titleString drawAtPoint:NSMakePoint(titleX, titleY)];
+ [messageString drawAtPoint:NSMakePoint(messageX, messageY)];
+}
+
+@end
Property changes on: chrome/browser/cocoa/sad_tab_view.mm
___________________________________________________________________
Name: svn:eol-style
+ LF
« 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