| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/mac/mac_util.h" | 6 #include "base/mac/mac_util.h" |
| 7 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 7 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 8 #import "chrome/browser/ui/cocoa/animatable_view.h" | 8 #import "chrome/browser/ui/cocoa/animatable_view.h" |
| 9 #include "chrome/browser/ui/cocoa/infobars/infobar.h" | 9 #include "chrome/browser/ui/cocoa/infobars/infobar.h" |
| 10 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 10 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 : controller_(controller) { | 23 : controller_(controller) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 // NotificationObserver implementation | 27 // NotificationObserver implementation |
| 28 void Observe(NotificationType type, | 28 void Observe(NotificationType type, |
| 29 const NotificationSource& source, | 29 const NotificationSource& source, |
| 30 const NotificationDetails& details) { | 30 const NotificationDetails& details) { |
| 31 switch (type.value) { | 31 switch (type.value) { |
| 32 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: | 32 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: |
| 33 [controller_ addInfoBar:Details<InfoBarDelegate>(details).ptr() | 33 [controller_ addInfoBar:Details<InfoBar>(details).ptr() |
| 34 animate:YES]; | 34 animate:YES |
| 35 deleteImmediately:NO]; |
| 35 break; | 36 break; |
| 36 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: | 37 |
| 38 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: { |
| 39 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails; |
| 40 RemoveDetails* remove_details = Details<RemoveDetails>(details).ptr(); |
| 37 [controller_ | 41 [controller_ |
| 38 closeInfoBarsForDelegate:Details<InfoBarDelegate>(details).ptr() | 42 closeInfoBarsForDelegate:remove_details->first |
| 39 animate:YES]; | 43 animate:(remove_details->second ? YES : NO)]; |
| 40 break; | |
| 41 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: { | |
| 42 typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> | |
| 43 InfoBarDelegatePair; | |
| 44 InfoBarDelegatePair* delegates = | |
| 45 Details<InfoBarDelegatePair>(details).ptr(); | |
| 46 [controller_ | |
| 47 replaceInfoBarsForDelegate:delegates->first with:delegates->second]; | |
| 48 break; | 44 break; |
| 49 } | 45 } |
| 46 |
| 47 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: { |
| 48 typedef std::pair<InfoBarDelegate*, InfoBar*> ReplaceDetails; |
| 49 ReplaceDetails* replace_details = |
| 50 Details<ReplaceDetails>(details).ptr(); |
| 51 [controller_ closeInfoBarsForDelegate:replace_details->first |
| 52 animate:NO]; |
| 53 [controller_ addInfoBar:replace_details->second |
| 54 animate:NO |
| 55 deleteImmediately:NO]; |
| 56 break; |
| 57 } |
| 58 |
| 50 default: | 59 default: |
| 51 NOTREACHED(); // we don't ask for anything else! | 60 NOTREACHED(); // we don't ask for anything else! |
| 52 break; | 61 break; |
| 53 } | 62 } |
| 54 | 63 |
| 55 [controller_ positionInfoBarsAndRedraw]; | 64 [controller_ positionInfoBarsAndRedraw]; |
| 56 } | 65 } |
| 57 | 66 |
| 58 InfoBarContainerController* controller_; // weak, owns us. | 67 InfoBarContainerController* controller_; // weak, owns us. |
| 59 }; | 68 }; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 [self positionInfoBarsAndRedraw]; | 129 [self positionInfoBarsAndRedraw]; |
| 121 } | 130 } |
| 122 | 131 |
| 123 - (void)changeTabContents:(TabContentsWrapper*)contents { | 132 - (void)changeTabContents:(TabContentsWrapper*)contents { |
| 124 registrar_.RemoveAll(); | 133 registrar_.RemoveAll(); |
| 125 [self removeAllInfoBars]; | 134 [self removeAllInfoBars]; |
| 126 | 135 |
| 127 currentTabContents_ = contents; | 136 currentTabContents_ = contents; |
| 128 if (currentTabContents_) { | 137 if (currentTabContents_) { |
| 129 for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) { | 138 for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) { |
| 130 [self addInfoBar:currentTabContents_->GetInfoBarDelegateAt(i) | 139 InfoBar* infobar = currentTabContents_->GetInfoBarDelegateAt(i)-> |
| 131 animate:NO]; | 140 CreateInfoBar(currentTabContents_); |
| 141 [self addInfoBar:infobar animate:NO deleteImmediately:YES]; |
| 132 } | 142 } |
| 133 | 143 |
| 134 Source<TabContents> source(currentTabContents_->tab_contents()); | 144 Source<TabContentsWrapper> source(currentTabContents_); |
| 135 registrar_.Add(infoBarObserver_.get(), | 145 registrar_.Add(infoBarObserver_.get(), |
| 136 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); | 146 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); |
| 137 registrar_.Add(infoBarObserver_.get(), | 147 registrar_.Add(infoBarObserver_.get(), |
| 138 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); | 148 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); |
| 139 registrar_.Add(infoBarObserver_.get(), | 149 registrar_.Add(infoBarObserver_.get(), |
| 140 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, source); | 150 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, source); |
| 141 } | 151 } |
| 142 | 152 |
| 143 [self positionInfoBarsAndRedraw]; | 153 [self positionInfoBarsAndRedraw]; |
| 144 } | 154 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 | 182 |
| 173 @implementation InfoBarContainerController (PrivateMethods) | 183 @implementation InfoBarContainerController (PrivateMethods) |
| 174 | 184 |
| 175 - (CGFloat)desiredHeight { | 185 - (CGFloat)desiredHeight { |
| 176 CGFloat height = 0; | 186 CGFloat height = 0; |
| 177 for (InfoBarController* controller in infobarControllers_.get()) | 187 for (InfoBarController* controller in infobarControllers_.get()) |
| 178 height += NSHeight([[controller view] frame]); | 188 height += NSHeight([[controller view] frame]); |
| 179 return height; | 189 return height; |
| 180 } | 190 } |
| 181 | 191 |
| 182 - (void)addInfoBar:(InfoBarDelegate*)delegate animate:(BOOL)animate { | 192 - (void)addInfoBar:(InfoBar*)infobar |
| 183 scoped_ptr<InfoBar> infobar(delegate->CreateInfoBar(currentTabContents_)); | 193 animate:(BOOL)animate |
| 194 deleteImmediately:(BOOL)deleteImmediately { |
| 184 InfoBarController* controller = infobar->controller(); | 195 InfoBarController* controller = infobar->controller(); |
| 185 [controller setContainerController:self]; | 196 [controller setContainerController:self]; |
| 186 [[controller animatableView] setResizeDelegate:self]; | 197 [[controller animatableView] setResizeDelegate:self]; |
| 187 [[self view] addSubview:[controller view]]; | 198 [[self view] addSubview:[controller view]]; |
| 188 [infobarControllers_ addObject:[controller autorelease]]; | 199 [infobarControllers_ addObject:[controller autorelease]]; |
| 189 | 200 |
| 190 if (animate) | 201 if (animate) |
| 191 [controller animateOpen]; | 202 [controller animateOpen]; |
| 192 else | 203 else |
| 193 [controller open]; | 204 [controller open]; |
| 205 |
| 206 if (deleteImmediately) |
| 207 delete infobar; |
| 208 else |
| 209 MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); |
| 194 } | 210 } |
| 195 | 211 |
| 196 - (void)closeInfoBarsForDelegate:(InfoBarDelegate*)delegate | 212 - (void)closeInfoBarsForDelegate:(InfoBarDelegate*)delegate |
| 197 animate:(BOOL)animate { | 213 animate:(BOOL)animate { |
| 198 for (InfoBarController* controller in | 214 for (InfoBarController* controller in |
| 199 [NSArray arrayWithArray:infobarControllers_.get()]) { | 215 [NSArray arrayWithArray:infobarControllers_.get()]) { |
| 200 if ([controller delegate] == delegate) { | 216 if ([controller delegate] == delegate) { |
| 201 [controller infobarWillClose]; | 217 [controller infobarWillClose]; |
| 202 if (animate) | 218 if (animate) |
| 203 [controller animateClosed]; | 219 [controller animateClosed]; |
| 204 else | 220 else |
| 205 [controller close]; | 221 [controller close]; |
| 206 } | 222 } |
| 207 } | 223 } |
| 208 } | 224 } |
| 209 | 225 |
| 210 - (void)replaceInfoBarsForDelegate:(InfoBarDelegate*)old_delegate | |
| 211 with:(InfoBarDelegate*)new_delegate { | |
| 212 [self closeInfoBarsForDelegate:old_delegate animate:NO]; | |
| 213 [self addInfoBar:new_delegate animate:NO]; | |
| 214 } | |
| 215 | |
| 216 - (void)removeAllInfoBars { | 226 - (void)removeAllInfoBars { |
| 217 // stopAnimation can remove the infobar from infobarControllers_ if it was in | 227 // stopAnimation can remove the infobar from infobarControllers_ if it was in |
| 218 // the midst of closing, so copy the array so mutations won't cause problems. | 228 // the midst of closing, so copy the array so mutations won't cause problems. |
| 219 for (InfoBarController* controller in | 229 for (InfoBarController* controller in |
| 220 [NSArray arrayWithArray:infobarControllers_.get()]) { | 230 [NSArray arrayWithArray:infobarControllers_.get()]) { |
| 221 [[controller animatableView] stopAnimation]; | 231 [[controller animatableView] stopAnimation]; |
| 222 [[controller view] removeFromSuperview]; | 232 [[controller view] removeFromSuperview]; |
| 223 } | 233 } |
| 224 [infobarControllers_ removeAllObjects]; | 234 [infobarControllers_ removeAllObjects]; |
| 225 [closingInfoBars_ removeAllObjects]; | 235 [closingInfoBars_ removeAllObjects]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 242 frame.size.width = NSWidth(containerBounds); | 252 frame.size.width = NSWidth(containerBounds); |
| 243 [view setFrame:frame]; | 253 [view setFrame:frame]; |
| 244 | 254 |
| 245 minY += NSHeight(frame); | 255 minY += NSHeight(frame); |
| 246 } | 256 } |
| 247 | 257 |
| 248 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; | 258 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; |
| 249 } | 259 } |
| 250 | 260 |
| 251 @end | 261 @end |
| OLD | NEW |