summaryrefslogtreecommitdiffstats
path: root/chrome/browser
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
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')
-rw-r--r--chrome/browser/cocoa/sad_tab_view.h22
-rw-r--r--chrome/browser/cocoa/sad_tab_view.mm74
-rw-r--r--chrome/browser/tab_contents/web_contents_view_mac.h18
-rw-r--r--chrome/browser/tab_contents/web_contents_view_mac.mm33
4 files changed, 146 insertions, 1 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
diff --git a/chrome/browser/tab_contents/web_contents_view_mac.h b/chrome/browser/tab_contents/web_contents_view_mac.h
index ec3b613..1ea5144 100644
--- a/chrome/browser/tab_contents/web_contents_view_mac.h
+++ b/chrome/browser/tab_contents/web_contents_view_mac.h
@@ -10,8 +10,10 @@
#include "base/gfx/size.h"
#include "base/scoped_cftyperef.h"
#include "chrome/browser/tab_contents/web_contents_view.h"
+#include "chrome/common/notification_registrar.h"
class FindBarMac;
+@class SadTabView;
@interface WebContentsViewCocoa : NSView {
}
@@ -20,7 +22,8 @@ class FindBarMac;
// Mac-specific implementation of the WebContentsView. It owns an NSView that
// contains all of the contents of the tab and associated child views.
-class WebContentsViewMac : public WebContentsView {
+class WebContentsViewMac : public WebContentsView,
+ public NotificationObserver {
public:
// The corresponding WebContents is passed in the constructor, and manages our
// lifetime. This doesn't need to be the case, but is this way currently
@@ -70,6 +73,12 @@ class WebContentsViewMac : public WebContentsView {
int active_match_ordinal,
bool final_update);
+ // NotificationObserver implementation ---------------------------------------
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
private:
// ---------------------------------------------------------------------------
@@ -82,6 +91,13 @@ class WebContentsViewMac : public WebContentsView {
// non-NULL, it may or may not be visible.
scoped_ptr<FindBarMac> find_bar_;
+ // Used to get notifications about renderers coming and going.
+ NotificationRegistrar registrar_;
+
+ // Used to render the sad tab. This will be non-NULL only when the sad tab is
+ // visible.
+ scoped_cftyperef<SadTabView*> sad_tab_;
+
DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac);
};
diff --git a/chrome/browser/tab_contents/web_contents_view_mac.mm b/chrome/browser/tab_contents/web_contents_view_mac.mm
index 2026b00..e59338a 100644
--- a/chrome/browser/tab_contents/web_contents_view_mac.mm
+++ b/chrome/browser/tab_contents/web_contents_view_mac.mm
@@ -5,6 +5,7 @@
#include "chrome/browser/tab_contents/web_contents_view_mac.h"
#include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
+#include "chrome/browser/cocoa/sad_tab_view.h"
#include "chrome/browser/renderer_host/render_widget_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
#include "chrome/browser/tab_contents/web_contents.h"
@@ -18,6 +19,10 @@ WebContentsView* WebContentsView::Create(WebContents* web_contents) {
WebContentsViewMac::WebContentsViewMac(WebContents* web_contents)
: web_contents_(web_contents) {
+ registrar_.Add(this, NotificationType::WEB_CONTENTS_CONNECTED,
+ Source<WebContents>(web_contents));
+ registrar_.Add(this, NotificationType::WEB_CONTENTS_DISCONNECTED,
+ Source<WebContents>(web_contents));
}
WebContentsViewMac::~WebContentsViewMac() {
@@ -232,6 +237,34 @@ void WebContentsViewMac::ShowCreatedWidgetInternal(
widget_host->Init();
}
+void WebContentsViewMac::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::WEB_CONTENTS_CONNECTED: {
+ if (sad_tab_.get()) {
+ [sad_tab_.get() removeFromSuperview];
+ sad_tab_.reset();
+ }
+ break;
+ }
+ case NotificationType::WEB_CONTENTS_DISCONNECTED: {
+ SadTabView* view = [[SadTabView alloc] initWithFrame:NSZeroRect];
+ CFRetain(view);
+ [view release];
+ sad_tab_.reset(view);
+
+ // Set as the dominant child.
+ [cocoa_view_.get() addSubview:view];
+ [view setFrame:[cocoa_view_.get() bounds]];
+ [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
+ break;
+ }
+ default:
+ NOTREACHED() << "Got a notification we didn't register for.";
+ }
+}
+
@implementation WebContentsViewCocoa
// Tons of stuff goes here, where we grab events going on in Cocoaland and send