OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" | 5 #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 // Called when someone clicks on the close button. | 110 // Called when someone clicks on the close button. |
111 - (void)dismiss:(id)sender { | 111 - (void)dismiss:(id)sender { |
112 if (![self isOwned]) | 112 if (![self isOwned]) |
113 return; | 113 return; |
114 [self delegate]->InfoBarDismissed(); | 114 [self delegate]->InfoBarDismissed(); |
115 [self removeSelf]; | 115 [self removeSelf]; |
116 } | 116 } |
117 | 117 |
118 - (void)removeSelf { | 118 - (void)removeSelf { |
119 infobar_->RemoveSelfCocoa(); | 119 infobar_->RemoveSelf(); |
120 } | 120 } |
121 | 121 |
122 - (void)addAdditionalControls { | 122 - (void)addAdditionalControls { |
123 // Default implementation does nothing. | 123 // Default implementation does nothing. |
124 } | 124 } |
125 | 125 |
| 126 - (void)infobarWillHide { |
| 127 } |
| 128 |
126 - (void)infobarWillClose { | 129 - (void)infobarWillClose { |
127 } | 130 } |
128 | 131 |
129 - (void)removeButtons { | 132 - (void)removeButtons { |
130 // Extend the label all the way across. | 133 // Extend the label all the way across. |
131 NSRect labelFrame = [label_.get() frame]; | 134 NSRect labelFrame = [label_.get() frame]; |
132 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame); | 135 labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame); |
133 [okButton_ removeFromSuperview]; | 136 [okButton_ removeFromSuperview]; |
134 okButton_ = nil; | 137 okButton_ = nil; |
135 [cancelButton_ removeFromSuperview]; | 138 [cancelButton_ removeFromSuperview]; |
136 cancelButton_ = nil; | 139 cancelButton_ = nil; |
137 [label_.get() setFrame:labelFrame]; | 140 [label_.get() setFrame:labelFrame]; |
138 } | 141 } |
139 | 142 |
140 - (void)layoutArrow { | 143 - (void)layoutArrow { |
141 [infoBarView_ setArrowHeight:infobar_->arrow_height()]; | 144 [infoBarView_ setArrowHeight:infobar_->arrow_height()]; |
142 [infoBarView_ setArrowHalfWidth:infobar_->arrow_half_width()]; | 145 [infoBarView_ setArrowHalfWidth:infobar_->arrow_half_width()]; |
143 [infoBarView_ setHasTip:![containerController_ shouldSuppressTopInfoBarTip]]; | 146 [infoBarView_ setHasTip:![containerController_ shouldSuppressTopInfoBarTip]]; |
144 | 147 |
145 // Convert from window to view coordinates. | 148 // Convert from window to view coordinates. |
146 NSPoint point = NSMakePoint([containerController_ infobarArrowX], 0); | 149 NSPoint point = NSMakePoint([containerController_ infobarArrowX], 0); |
147 point = [infoBarView_ convertPoint:point fromView:nil]; | 150 point = [infoBarView_ convertPoint:point fromView:nil]; |
148 [infoBarView_ setArrowX:point.x]; | 151 [infoBarView_ setArrowX:point.x]; |
149 } | 152 } |
150 | 153 |
151 - (void)disablePopUpMenu:(NSMenu*)menu { | 154 - (void)disablePopUpMenu:(NSMenu*)menu { |
152 // Remove the menu if visible. | |
153 [menu cancelTracking]; | |
154 | |
155 // If the menu is re-opened, prevent queries to update items. | 155 // If the menu is re-opened, prevent queries to update items. |
156 [menu setDelegate:nil]; | 156 [menu setDelegate:nil]; |
157 | 157 |
158 // Prevent target/action messages to the controller. | 158 // Prevent target/action messages to the controller. |
159 for (NSMenuItem* item in [menu itemArray]) { | 159 for (NSMenuItem* item in [menu itemArray]) { |
160 [item setEnabled:NO]; | 160 [item setEnabled:NO]; |
161 [item setTarget:nil]; | 161 [item setTarget:nil]; |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 - (InfoBarDelegate*)delegate { | 165 - (InfoBarDelegate*)delegate { |
166 return infobar_->delegate(); | 166 return infobar_->delegate(); |
167 } | 167 } |
168 | 168 |
169 - (void)initializeLabel { | 169 - (void)initializeLabel { |
170 // Replace the label placeholder NSTextField with the real label NSTextView. | 170 // Replace the label placeholder NSTextField with the real label NSTextView. |
171 // The former doesn't show links in a nice way, but the latter can't be added | 171 // The former doesn't show links in a nice way, but the latter can't be added |
172 // in IB without a containing scroll view, so create the NSTextView | 172 // in IB without a containing scroll view, so create the NSTextView |
173 // programmatically. | 173 // programmatically. |
174 label_.reset([[HyperlinkTextView alloc] | 174 label_.reset([[HyperlinkTextView alloc] |
175 initWithFrame:[labelPlaceholder_ frame]]); | 175 initWithFrame:[labelPlaceholder_ frame]]); |
176 [label_.get() setAutoresizingMask:[labelPlaceholder_ autoresizingMask]]; | 176 [label_.get() setAutoresizingMask:[labelPlaceholder_ autoresizingMask]]; |
177 [[labelPlaceholder_ superview] | 177 [[labelPlaceholder_ superview] |
178 replaceSubview:labelPlaceholder_ with:label_.get()]; | 178 replaceSubview:labelPlaceholder_ with:label_.get()]; |
179 labelPlaceholder_ = nil; // Now released. | 179 labelPlaceholder_ = nil; // Now released. |
180 [label_.get() setDelegate:self]; | 180 [label_.get() setDelegate:self]; |
181 } | 181 } |
182 | 182 |
183 @end | 183 @end |
OLD | NEW |