• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5#import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
6
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"
14
15@implementation ConfirmBubbleController
16
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;
26}
27
28- (void)loadView {
29  [[BrowserWindowController
30      browserWindowControllerForView:parent_] onOverlappedViewShown];
31  [self setView:[[[ConfirmBubbleCocoa alloc] initWithParent:parent_
32                                                 controller:self] autorelease]];
33}
34
35- (void)windowWillClose:(NSNotification*)notification {
36  [[BrowserWindowController
37      browserWindowControllerForView:parent_] onOverlappedViewHidden];
38  [self autorelease];
39}
40
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_);
45}
46
47- (NSString*)title {
48  return base::SysUTF16ToNSString(model_->GetTitle());
49}
50
51- (NSString*)messageText {
52  return base::SysUTF16ToNSString(model_->GetMessageText());
53}
54
55- (NSString*)linkText {
56  return base::SysUTF16ToNSString(model_->GetLinkText());
57}
58
59- (NSString*)okButtonText {
60  return base::SysUTF16ToNSString(
61      model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_OK));
62}
63
64- (NSString*)cancelButtonText {
65  return base::SysUTF16ToNSString(
66      model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL));
67}
68
69- (BOOL)hasOkButton {
70  return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK) ? YES : NO;
71}
72
73- (BOOL)hasCancelButton {
74  return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_CANCEL) ? YES : NO;
75}
76
77- (NSImage*)icon {
78  gfx::Image* image = model_->GetIcon();
79  return !image ? nil : image->ToNSImage();
80}
81
82// Action handlers.
83- (void)accept {
84  model_->Accept();
85}
86
87- (void)cancel {
88  model_->Cancel();
89}
90
91- (void)linkClicked {
92  model_->LinkClicked();
93}
94
95@end
96