| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.h" | 5 #include "chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 9 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 10 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 10 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
| 11 #include "chrome/browser/ui/cocoa/infobars/infobar.h" | 11 #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" |
| 12 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 12 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 13 #import "ui/base/cocoa/cocoa_event_utils.h" | 13 #import "ui/base/cocoa/cocoa_event_utils.h" |
| 14 #include "ui/base/window_open_disposition.h" | 14 #include "ui/base/window_open_disposition.h" |
| 15 | 15 |
| 16 @implementation ConfirmInfoBarController | 16 @implementation ConfirmInfoBarController |
| 17 | 17 |
| 18 // Called when someone clicks on the "OK" button. | 18 // Called when someone clicks on the "OK" button. |
| 19 - (IBAction)ok:(id)sender { | 19 - (IBAction)ok:(id)sender { |
| 20 if (![self isOwned]) | 20 if (![self isOwned]) |
| 21 return; | 21 return; |
| 22 if (delegate_->AsConfirmInfoBarDelegate()->Accept()) | 22 if ([self delegate]->AsConfirmInfoBarDelegate()->Accept()) |
| 23 [self removeSelf]; | 23 [self removeSelf]; |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Called when someone clicks on the "Cancel" button. | 26 // Called when someone clicks on the "Cancel" button. |
| 27 - (IBAction)cancel:(id)sender { | 27 - (IBAction)cancel:(id)sender { |
| 28 if (![self isOwned]) | 28 if (![self isOwned]) |
| 29 return; | 29 return; |
| 30 if (delegate_->AsConfirmInfoBarDelegate()->Cancel()) | 30 if ([self delegate]->AsConfirmInfoBarDelegate()->Cancel()) |
| 31 [self removeSelf]; | 31 [self removeSelf]; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Confirm infobars can have OK and/or cancel buttons, depending on | 34 // Confirm infobars can have OK and/or cancel buttons, depending on |
| 35 // the return value of GetButtons(). We create each button if | 35 // the return value of GetButtons(). We create each button if |
| 36 // required and position them to the left of the close button. | 36 // required and position them to the left of the close button. |
| 37 - (void)addAdditionalControls { | 37 - (void)addAdditionalControls { |
| 38 ConfirmInfoBarDelegate* delegate = delegate_->AsConfirmInfoBarDelegate(); | 38 ConfirmInfoBarDelegate* delegate = |
| 39 [self delegate]->AsConfirmInfoBarDelegate(); |
| 39 DCHECK(delegate); | 40 DCHECK(delegate); |
| 40 int visibleButtons = delegate->GetButtons(); | 41 int visibleButtons = delegate->GetButtons(); |
| 41 | 42 |
| 42 NSRect okButtonFrame = [okButton_ frame]; | 43 NSRect okButtonFrame = [okButton_ frame]; |
| 43 NSRect cancelButtonFrame = [cancelButton_ frame]; | 44 NSRect cancelButtonFrame = [cancelButton_ frame]; |
| 44 | 45 |
| 45 DCHECK(NSMaxX(cancelButtonFrame) < NSMinX(okButtonFrame)) | 46 DCHECK(NSMaxX(cancelButtonFrame) < NSMinX(okButtonFrame)) |
| 46 << "Ok button expected to be on the right of the Cancel button in nib"; | 47 << "Ok button expected to be on the right of the Cancel button in nib"; |
| 47 | 48 |
| 48 CGFloat rightEdge = NSMaxX(okButtonFrame); | 49 CGFloat rightEdge = NSMaxX(okButtonFrame); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 124 } |
| 124 | 125 |
| 125 // Called when someone clicks on the link in the infobar. This method | 126 // Called when someone clicks on the link in the infobar. This method |
| 126 // is called by the InfobarTextField on its delegate (the | 127 // is called by the InfobarTextField on its delegate (the |
| 127 // AlternateNavInfoBarController). | 128 // AlternateNavInfoBarController). |
| 128 - (void)linkClicked { | 129 - (void)linkClicked { |
| 129 if (![self isOwned]) | 130 if (![self isOwned]) |
| 130 return; | 131 return; |
| 131 WindowOpenDisposition disposition = | 132 WindowOpenDisposition disposition = |
| 132 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 133 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 133 if (delegate_->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) | 134 if ([self delegate]->AsConfirmInfoBarDelegate()->LinkClicked(disposition)) |
| 134 [self removeSelf]; | 135 [self removeSelf]; |
| 135 } | 136 } |
| 136 | 137 |
| 137 @end | 138 @end |
| 138 | 139 |
| 139 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 140 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { |
| 140 ConfirmInfoBarController* controller = | 141 scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); |
| 141 [[ConfirmInfoBarController alloc] initWithDelegate:this owner:owner]; | 142 base::scoped_nsobject<ConfirmInfoBarController> controller( |
| 142 return new InfoBar(controller, this); | 143 [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); |
| 144 infobar->set_controller(controller); |
| 145 return infobar.release(); |
| 143 } | 146 } |
| OLD | NEW |