summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-17 16:01:15 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-17 16:01:15 +0000
commitd679d4ea85aedcc22ccf7610146e77c15f9d7ac1 (patch)
treec0ddc8e569c087ccd95cdd13a2206c0e3e221509 /chrome/browser/cocoa
parentd55bf642d70dc4882644f839ec1592e9591da0ba (diff)
downloadchromium_src-d679d4ea85aedcc22ccf7610146e77c15f9d7ac1.zip
chromium_src-d679d4ea85aedcc22ccf7610146e77c15f9d7ac1.tar.gz
chromium_src-d679d4ea85aedcc22ccf7610146e77c15f9d7ac1.tar.bz2
Sad Tab view for the Mac.
Review URL: http://codereview.chromium.org/20334 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/sad_tab_view.h22
-rw-r--r--chrome/browser/cocoa/sad_tab_view.mm74
2 files changed, 96 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/sad_tab_view.h b/chrome/browser/cocoa/sad_tab_view.h
new file mode 100644
index 0000000..ffe57a5
--- /dev/null
+++ b/chrome/browser/cocoa/sad_tab_view.h
@@ -0,0 +1,22 @@
+// 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.
+
+#ifndef CHROME_BROWSER_COCOA_SAD_TAB_VIEW_H_
+#define CHROME_BROWSER_COCOA_SAD_TAB_VIEW_H_
+
+#include "chrome/browser/cocoa/event_view.h"
+
+#import <Cocoa/Cocoa.h>
+
+// A view that displays the "sad tab".
+
+@interface SadTabView : EventView {
+ @private
+}
+
+// Designated initializer is -initWithFrame: .
+
+@end
+
+#endif // CHROME_BROWSER_COCOA_SAD_TAB_VIEW_H_
diff --git a/chrome/browser/cocoa/sad_tab_view.mm b/chrome/browser/cocoa/sad_tab_view.mm
new file mode 100644
index 0000000..b862d53
--- /dev/null
+++ b/chrome/browser/cocoa/sad_tab_view.mm
@@ -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