1 // Copyright (c) 2012 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.
5 #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
7 #include "base/mac/mac_util.h"
8 #include "base/strings/sys_string_conversions.h"
9 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
10 #import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h"
11 #import "chrome/browser/ui/confirm_bubble_model.h"
12 #include "ui/gfx/image/image.h"
13 #include "ui/gfx/point.h"
15 @implementation ConfirmBubbleController
17 - (id)initWithParent:(NSView*)parent
18 origin:(CGPoint)origin
19 model:(ConfirmBubbleModel*)model {
20 if ((self = [super initWithNibName:nil bundle:nil])) {
29 [[BrowserWindowController
30 browserWindowControllerForView:parent_] onOverlappedViewShown];
31 [self setView:[[[ConfirmBubbleCocoa alloc] initWithParent:parent_
32 controller:self] autorelease]];
35 - (void)windowWillClose:(NSNotification*)notification {
36 [[BrowserWindowController
37 browserWindowControllerForView:parent_] onOverlappedViewHidden];
41 // Accessors. This functions converts the C++ types retrieved from the
42 // ConfirmBubbleModel object to Objective-C types, and return them.
44 return NSPointFromCGPoint(origin_);
48 return base::SysUTF16ToNSString(model_->GetTitle());
51 - (NSString*)messageText {
52 return base::SysUTF16ToNSString(model_->GetMessageText());
55 - (NSString*)linkText {
56 return base::SysUTF16ToNSString(model_->GetLinkText());
59 - (NSString*)okButtonText {
60 return base::SysUTF16ToNSString(
61 model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_OK));
64 - (NSString*)cancelButtonText {
65 return base::SysUTF16ToNSString(
66 model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL));
70 return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK) ? YES : NO;
73 - (BOOL)hasCancelButton {
74 return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_CANCEL) ? YES : NO;
78 gfx::Image* image = model_->GetIcon();
79 return !image ? nil : image->ToNSImage();
92 model_->LinkClicked();