Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: ios/chrome/browser/infobars/confirm_infobar_controller.mm

Issue 1161243002: Fixit: Cleanup of InfoBarController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding mising forward declaration. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ios/chrome/browser/infobars/infobar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ios/chrome/browser/infobars/confirm_infobar_controller.h" 5 #include "ios/chrome/browser/infobars/confirm_infobar_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "components/infobars/core/confirm_infobar_delegate.h" 9 #include "components/infobars/core/confirm_infobar_delegate.h"
10 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 10 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
(...skipping 30 matching lines...) Expand all
41 - (void)infoBarButtonDidPress:(id)sender; 41 - (void)infoBarButtonDidPress:(id)sender;
42 42
43 @end 43 @end
44 44
45 @implementation ConfirmInfoBarController { 45 @implementation ConfirmInfoBarController {
46 } 46 }
47 47
48 #pragma mark - 48 #pragma mark -
49 #pragma mark InfoBarController 49 #pragma mark InfoBarController
50 50
51 - (void)layoutForDelegate:(infobars::InfoBarDelegate*)delegate 51 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>)
52 frame:(CGRect)frame { 52 viewForDelegate:(infobars::InfoBarDelegate*)delegate
53 frame:(CGRect)frame {
54 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView;
53 ConfirmInfoBarDelegate* infoBarModel = delegate->AsConfirmInfoBarDelegate(); 55 ConfirmInfoBarDelegate* infoBarModel = delegate->AsConfirmInfoBarDelegate();
54 DCHECK(!infoBarView_); 56 infoBarView.reset(
55 infoBarView_.reset([ios::GetChromeBrowserProvider()->CreateInfoBarView() 57 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate));
56 initWithFrame:frame
57 delegate:delegate_]);
58
59 // Model data. 58 // Model data.
60 NSString* modelMsg = nil; 59 NSString* modelMsg = nil;
61 if (infoBarModel->GetMessageText().length()) 60 if (infoBarModel->GetMessageText().length())
62 modelMsg = base::SysUTF16ToNSString(infoBarModel->GetMessageText()); 61 modelMsg = base::SysUTF16ToNSString(infoBarModel->GetMessageText());
63 gfx::Image modelIcon = infoBarModel->GetIcon(); 62 gfx::Image modelIcon = infoBarModel->GetIcon();
64 int buttons = infoBarModel->GetButtons(); 63 int buttons = infoBarModel->GetButtons();
65 NSString* buttonOK = nil; 64 NSString* buttonOK = nil;
66 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { 65 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) {
67 buttonOK = base::SysUTF16ToNSString( 66 buttonOK = base::SysUTF16ToNSString(
68 infoBarModel->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); 67 infoBarModel->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
69 } 68 }
70 NSString* buttonCancel = nil; 69 NSString* buttonCancel = nil;
71 if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL) { 70 if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
72 buttonCancel = base::SysUTF16ToNSString( 71 buttonCancel = base::SysUTF16ToNSString(
73 infoBarModel->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); 72 infoBarModel->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
74 } 73 }
75 74
76 [infoBarView_ addCloseButtonWithTag:ConfirmInfoBarUITags::CLOSE 75 [infoBarView addCloseButtonWithTag:ConfirmInfoBarUITags::CLOSE
77 target:self 76 target:self
78 action:@selector(infoBarButtonDidPress:)]; 77 action:@selector(infoBarButtonDidPress:)];
79 78
80 // Optional left icon. 79 // Optional left icon.
81 if (!modelIcon.IsEmpty()) 80 if (!modelIcon.IsEmpty())
82 [infoBarView_ addLeftIcon:modelIcon.ToUIImage()]; 81 [infoBarView addLeftIcon:modelIcon.ToUIImage()];
83 82
84 // Optional message. 83 // Optional message.
85 if (modelMsg) 84 if (modelMsg)
86 [infoBarView_ addLabel:modelMsg]; 85 [infoBarView addLabel:modelMsg];
87 86
88 if (buttonOK && buttonCancel) { 87 if (buttonOK && buttonCancel) {
89 [infoBarView_ addButton1:buttonOK 88 [infoBarView addButton1:buttonOK
90 tag1:ConfirmInfoBarUITags::OK 89 tag1:ConfirmInfoBarUITags::OK
91 button2:buttonCancel 90 button2:buttonCancel
92 tag2:ConfirmInfoBarUITags::CANCEL 91 tag2:ConfirmInfoBarUITags::CANCEL
93 target:self
94 action:@selector(infoBarButtonDidPress:)];
95 } else if (buttonOK) {
96 [infoBarView_ addButton:buttonOK
97 tag:ConfirmInfoBarUITags::OK
98 target:self 92 target:self
99 action:@selector(infoBarButtonDidPress:)]; 93 action:@selector(infoBarButtonDidPress:)];
94 } else if (buttonOK) {
95 [infoBarView addButton:buttonOK
96 tag:ConfirmInfoBarUITags::OK
97 target:self
98 action:@selector(infoBarButtonDidPress:)];
100 } else { 99 } else {
101 // No buttons, only message. 100 // No buttons, only message.
102 DCHECK(modelMsg && !buttonCancel); 101 DCHECK(modelMsg && !buttonCancel);
103 } 102 }
103 return infoBarView;
104 } 104 }
105 105
106 #pragma mark - Handling of User Events 106 #pragma mark - Handling of User Events
107 107
108 - (void)infoBarButtonDidPress:(id)sender { 108 - (void)infoBarButtonDidPress:(id)sender {
109 // This press might have occurred after the user has already pressed a button, 109 // This press might have occurred after the user has already pressed a button,
110 // in which case the view has been detached from the delegate and this press 110 // in which case the view has been detached from the delegate and this press
111 // should be ignored. 111 // should be ignored.
112 if (!delegate_) { 112 if (!self.delegate) {
113 return; 113 return;
114 } 114 }
115 if ([sender isKindOfClass:[UIButton class]]) { 115 if ([sender isKindOfClass:[UIButton class]]) {
116 NSUInteger tag = static_cast<UIButton*>(sender).tag; 116 NSUInteger tag = static_cast<UIButton*>(sender).tag;
117 if (tag == ConfirmInfoBarUITags::CLOSE) 117 if (tag == ConfirmInfoBarUITags::CLOSE)
118 delegate_->InfoBarDidCancel(); 118 self.delegate->InfoBarDidCancel();
119 else 119 else
120 delegate_->InfoBarButtonDidPress(UITagToButton(tag)); 120 self.delegate->InfoBarButtonDidPress(UITagToButton(tag));
121 } 121 }
122 } 122 }
123 123
124 @end 124 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/infobars/infobar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698