summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/confirm_bubble_controller.mm
blob: 014a5eae088150ac7d47ea0e40c2436bcaf0949b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 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/confirm_bubble_controller.h"

#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h"
#import "chrome/browser/ui/confirm_bubble_model.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/point.h"

@implementation ConfirmBubbleController

- (id)initWithParent:(NSView*)parent
              origin:(CGPoint)origin
               model:(scoped_ptr<ConfirmBubbleModel>)model {
  if ((self = [super initWithNibName:nil bundle:nil])) {
    parent_ = parent;
    origin_ = origin;
    model_ = model.Pass();
  }
  return self;
}

- (void)loadView {
  [self setView:[[[ConfirmBubbleCocoa alloc] initWithParent:parent_
                                                 controller:self] autorelease]];
}

- (void)windowWillClose:(NSNotification*)notification {
  [self autorelease];
}

// Accessors. This functions converts the C++ types retrieved from the
// ConfirmBubbleModel object to Objective-C types, and return them.
- (NSPoint)origin {
  return NSPointFromCGPoint(origin_);
}

- (NSString*)title {
  return base::SysUTF16ToNSString(model_->GetTitle());
}

- (NSString*)messageText {
  return base::SysUTF16ToNSString(model_->GetMessageText());
}

- (NSString*)linkText {
  return base::SysUTF16ToNSString(model_->GetLinkText());
}

- (NSString*)okButtonText {
  return base::SysUTF16ToNSString(
      model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_OK));
}

- (NSString*)cancelButtonText {
  return base::SysUTF16ToNSString(
      model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL));
}

- (BOOL)hasOkButton {
  return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK) ? YES : NO;
}

- (BOOL)hasCancelButton {
  return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_CANCEL) ? YES : NO;
}

- (NSImage*)icon {
  gfx::Image* image = model_->GetIcon();
  return !image ? nil : image->ToNSImage();
}

// Action handlers.
- (void)accept {
  model_->Accept();
}

- (void)cancel {
  model_->Cancel();
}

- (void)linkClicked {
  model_->LinkClicked();
}

@end