Home | History | Annotate | Download | only in cocoa
      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   [self setView:[[[ConfirmBubbleCocoa alloc] initWithParent:parent_
     30                                                  controller:self] autorelease]];
     31 }
     32 
     33 - (void)windowWillClose:(NSNotification*)notification {
     34   [self autorelease];
     35 }
     36 
     37 // Accessors. This functions converts the C++ types retrieved from the
     38 // ConfirmBubbleModel object to Objective-C types, and return them.
     39 - (NSPoint)origin {
     40   return NSPointFromCGPoint(origin_);
     41 }
     42 
     43 - (NSString*)title {
     44   return base::SysUTF16ToNSString(model_->GetTitle());
     45 }
     46 
     47 - (NSString*)messageText {
     48   return base::SysUTF16ToNSString(model_->GetMessageText());
     49 }
     50 
     51 - (NSString*)linkText {
     52   return base::SysUTF16ToNSString(model_->GetLinkText());
     53 }
     54 
     55 - (NSString*)okButtonText {
     56   return base::SysUTF16ToNSString(
     57       model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_OK));
     58 }
     59 
     60 - (NSString*)cancelButtonText {
     61   return base::SysUTF16ToNSString(
     62       model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL));
     63 }
     64 
     65 - (BOOL)hasOkButton {
     66   return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK) ? YES : NO;
     67 }
     68 
     69 - (BOOL)hasCancelButton {
     70   return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_CANCEL) ? YES : NO;
     71 }
     72 
     73 - (NSImage*)icon {
     74   gfx::Image* image = model_->GetIcon();
     75   return !image ? nil : image->ToNSImage();
     76 }
     77 
     78 // Action handlers.
     79 - (void)accept {
     80   model_->Accept();
     81 }
     82 
     83 - (void)cancel {
     84   model_->Cancel();
     85 }
     86 
     87 - (void)linkClicked {
     88   model_->LinkClicked();
     89 }
     90 
     91 @end
     92