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

Unified Diff: chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm

Issue 11773025: cocoa/infobars: Split infobar_controller.* into smaller parts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add files to chrome_nibs.gyp Created 7 years, 11 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
Index: chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm
diff --git a/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..533e8a4ca574bb51fe64d350db8b056bfe51c321
--- /dev/null
+++ b/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm
@@ -0,0 +1,62 @@
+// Copyright 2012 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.
+
+#import "chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.h"
+
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+#include "chrome/browser/infobars/alternate_nav_infobar_delegate.h"
+#import "chrome/browser/ui/cocoa/hyperlink_text_view.h"
+#include "chrome/browser/ui/cocoa/event_utils.h"
+#include "chrome/browser/ui/cocoa/infobars/infobar.h"
+#include "webkit/glue/window_open_disposition.h"
+
+@implementation AlternateNavInfoBarController
+
+// Link infobars have a text message, of which part is linkified. We
+// use an NSAttributedString to display styled text, and we set a
+// NSLink attribute on the hyperlink portion of the message. Infobars
+// use a custom NSTextField subclass, which allows us to override
+// textView:clickedOnLink:atIndex: and intercept clicks.
+//
+- (void)addAdditionalControls {
+ // No buttons.
+ [self removeButtons];
+
+ AlternateNavInfoBarDelegate* delegate =
+ delegate_->AsAlternateNavInfoBarDelegate();
+ DCHECK(delegate);
+ size_t offset = string16::npos;
+ string16 message = delegate->GetMessageTextWithOffset(&offset);
+ string16 link = delegate->GetLinkText();
+ NSFont* font = [NSFont labelFontOfSize:
+ [NSFont systemFontSizeForControlSize:NSRegularControlSize]];
+ HyperlinkTextView* view = (HyperlinkTextView*)label_.get();
+ [view setMessageAndLink:base::SysUTF16ToNSString(message)
+ withLink:base::SysUTF16ToNSString(link)
+ atOffset:offset
+ font:font
+ messageColor:[NSColor blackColor]
+ linkColor:[NSColor blueColor]];
+}
+
+// Called when someone clicks on the link in the infobar. This method
+// is called by the InfobarTextField on its delegate (the
+// AlternateNavInfoBarController).
+- (void)linkClicked {
+ if (![self isOwned])
+ return;
+ WindowOpenDisposition disposition =
+ event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
+ if (delegate_->AsAlternateNavInfoBarDelegate()->LinkClicked(disposition))
+ [self removeSelf];
+}
+
+@end
+
+InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
+ AlternateNavInfoBarController* controller =
+ [[AlternateNavInfoBarController alloc] initWithDelegate:this owner:owner];
+ return new InfoBar(controller, this);
+}

Powered by Google App Engine
This is Rietveld 408576698