Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / confirm_bubble_controller.mm
blob128996f9959b31ddba499dfdfa435d7cd65d9040
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])) {
21     parent_ = parent;
22     origin_ = origin;
23     model_.reset(model);
24   }
25   return self;
28 - (void)loadView {
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];
38   [self autorelease];
41 // Accessors. This functions converts the C++ types retrieved from the
42 // ConfirmBubbleModel object to Objective-C types, and return them.
43 - (NSPoint)origin {
44   return NSPointFromCGPoint(origin_);
47 - (NSString*)title {
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));
69 - (BOOL)hasOkButton {
70   return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK) ? YES : NO;
73 - (BOOL)hasCancelButton {
74   return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_CANCEL) ? YES : NO;
77 - (NSImage*)icon {
78   gfx::Image* image = model_->GetIcon();
79   return !image ? nil : image->ToNSImage();
82 // Action handlers.
83 - (void)accept {
84   model_->Accept();
87 - (void)cancel {
88   model_->Cancel();
91 - (void)linkClicked {
92   model_->LinkClicked();
95 @end