Chromium Code Reviews| 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 break; | 35 break; |
| 36 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: | 36 |
| 37 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: { | |
| 38 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails; | |
| 39 RemoveDetails* remove_details = Details<RemoveDetails>(details).ptr(); | |
| 37 [controller_ | 40 [controller_ |
| 38 closeInfoBarsForDelegate:Details<InfoBarDelegate>(details).ptr() | 41 closeInfoBarsForDelegate:remove_details->first |
| 39 animate:YES]; | 42 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; | 43 break; |
| 49 } | 44 } |
| 45 | |
| 46 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: { | |
| 47 typedef std::pair<InfoBarDelegate*, InfoBar*> ReplaceDetails; | |
| 48 ReplaceDetails* replace_details = | |
| 49 Details<ReplaceDetails>(details).ptr(); | |
| 50 [controller_ replaceInfoBarsForDelegate:replace_details->first | |
| 51 with:replace_details->second]; | |
| 52 break; | |
| 53 } | |
| 54 | |
| 50 default: | 55 default: |
| 51 NOTREACHED(); // we don't ask for anything else! | 56 NOTREACHED(); // we don't ask for anything else! |
| 52 break; | 57 break; |
| 53 } | 58 } |
| 54 | 59 |
| 55 [controller_ positionInfoBarsAndRedraw]; | 60 [controller_ positionInfoBarsAndRedraw]; |
| 56 } | 61 } |
| 57 | 62 |
| 58 InfoBarContainerController* controller_; // weak, owns us. | 63 InfoBarContainerController* controller_; // weak, owns us. |
| 59 }; | 64 }; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 [self positionInfoBarsAndRedraw]; | 125 [self positionInfoBarsAndRedraw]; |
| 121 } | 126 } |
| 122 | 127 |
| 123 - (void)changeTabContents:(TabContentsWrapper*)contents { | 128 - (void)changeTabContents:(TabContentsWrapper*)contents { |
| 124 registrar_.RemoveAll(); | 129 registrar_.RemoveAll(); |
| 125 [self removeAllInfoBars]; | 130 [self removeAllInfoBars]; |
| 126 | 131 |
| 127 currentTabContents_ = contents; | 132 currentTabContents_ = contents; |
| 128 if (currentTabContents_) { | 133 if (currentTabContents_) { |
| 129 for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) { | 134 for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) { |
| 130 [self addInfoBar:currentTabContents_->GetInfoBarDelegateAt(i) | 135 InfoBar* infobar = currentTabContents_->GetInfoBarDelegateAt(i)-> |
| 131 animate:NO]; | 136 CreateInfoBar(currentTabContents_)); |
|
rohitrao (ping after 24h)
2011/06/01 20:58:41
Extra ) at the end.
| |
| 137 [self addInfoBar:infobar animate:NO]; | |
| 132 } | 138 } |
| 133 | 139 |
| 134 Source<TabContents> source(currentTabContents_->tab_contents()); | 140 Source<TabContentsWrapper> source(currentTabContents_); |
| 135 registrar_.Add(infoBarObserver_.get(), | 141 registrar_.Add(infoBarObserver_.get(), |
| 136 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); | 142 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); |
| 137 registrar_.Add(infoBarObserver_.get(), | 143 registrar_.Add(infoBarObserver_.get(), |
| 138 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); | 144 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); |
| 139 registrar_.Add(infoBarObserver_.get(), | 145 registrar_.Add(infoBarObserver_.get(), |
| 140 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, source); | 146 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, source); |
| 141 } | 147 } |
| 142 | 148 |
| 143 [self positionInfoBarsAndRedraw]; | 149 [self positionInfoBarsAndRedraw]; |
| 144 } | 150 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 | 178 |
| 173 @implementation InfoBarContainerController (PrivateMethods) | 179 @implementation InfoBarContainerController (PrivateMethods) |
| 174 | 180 |
| 175 - (CGFloat)desiredHeight { | 181 - (CGFloat)desiredHeight { |
| 176 CGFloat height = 0; | 182 CGFloat height = 0; |
| 177 for (InfoBarController* controller in infobarControllers_.get()) | 183 for (InfoBarController* controller in infobarControllers_.get()) |
| 178 height += NSHeight([[controller view] frame]); | 184 height += NSHeight([[controller view] frame]); |
| 179 return height; | 185 return height; |
| 180 } | 186 } |
| 181 | 187 |
| 182 - (void)addInfoBar:(InfoBarDelegate*)delegate animate:(BOOL)animate { | 188 - (void)addInfoBar:(InfoBar*)infobar animate:(BOOL)animate { |
| 183 scoped_ptr<InfoBar> infobar(delegate->CreateInfoBar(currentTabContents_)); | 189 scoped_ptr<InfoBar> infobar_deleter(infobar); |
| 184 InfoBarController* controller = infobar->controller(); | 190 InfoBarController* controller = infobar->controller(); |
| 185 [controller setContainerController:self]; | 191 [controller setContainerController:self]; |
| 186 [[controller animatableView] setResizeDelegate:self]; | 192 [[controller animatableView] setResizeDelegate:self]; |
| 187 [[self view] addSubview:[controller view]]; | 193 [[self view] addSubview:[controller view]]; |
| 188 [infobarControllers_ addObject:[controller autorelease]]; | 194 [infobarControllers_ addObject:[controller autorelease]]; |
| 189 | 195 |
| 190 if (animate) | 196 if (animate) |
| 191 [controller animateOpen]; | 197 [controller animateOpen]; |
| 192 else | 198 else |
| 193 [controller open]; | 199 [controller open]; |
| 194 } | 200 } |
| 195 | 201 |
| 196 - (void)closeInfoBarsForDelegate:(InfoBarDelegate*)delegate | 202 - (void)closeInfoBarsForDelegate:(InfoBarDelegate*)delegate |
| 197 animate:(BOOL)animate { | 203 animate:(BOOL)animate { |
| 198 for (InfoBarController* controller in | 204 for (InfoBarController* controller in |
| 199 [NSArray arrayWithArray:infobarControllers_.get()]) { | 205 [NSArray arrayWithArray:infobarControllers_.get()]) { |
| 200 if ([controller delegate] == delegate) { | 206 if ([controller delegate] == delegate) { |
| 201 [controller infobarWillClose]; | 207 [controller infobarWillClose]; |
| 202 if (animate) | 208 if (animate) |
| 203 [controller animateClosed]; | 209 [controller animateClosed]; |
| 204 else | 210 else |
| 205 [controller close]; | 211 [controller close]; |
| 206 } | 212 } |
| 207 } | 213 } |
| 208 } | 214 } |
| 209 | 215 |
| 210 - (void)replaceInfoBarsForDelegate:(InfoBarDelegate*)old_delegate | 216 - (void)replaceInfoBarsForDelegate:(InfoBarDelegate*)old_delegate |
| 211 with:(InfoBarDelegate*)new_delegate { | 217 with:(InfoBar*)new_infobar { |
| 212 [self closeInfoBarsForDelegate:old_delegate animate:NO]; | 218 [self closeInfoBarsForDelegate:old_delegate animate:NO]; |
| 213 [self addInfoBar:new_delegate animate:NO]; | 219 [self addInfoBar:new_infobar animate:NO]; |
| 214 } | 220 } |
| 215 | 221 |
| 216 - (void)removeAllInfoBars { | 222 - (void)removeAllInfoBars { |
| 217 // stopAnimation can remove the infobar from infobarControllers_ if it was in | 223 // 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. | 224 // the midst of closing, so copy the array so mutations won't cause problems. |
| 219 for (InfoBarController* controller in | 225 for (InfoBarController* controller in |
| 220 [NSArray arrayWithArray:infobarControllers_.get()]) { | 226 [NSArray arrayWithArray:infobarControllers_.get()]) { |
| 221 [[controller animatableView] stopAnimation]; | 227 [[controller animatableView] stopAnimation]; |
| 222 [[controller view] removeFromSuperview]; | 228 [[controller view] removeFromSuperview]; |
| 223 } | 229 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 242 frame.size.width = NSWidth(containerBounds); | 248 frame.size.width = NSWidth(containerBounds); |
| 243 [view setFrame:frame]; | 249 [view setFrame:frame]; |
| 244 | 250 |
| 245 minY += NSHeight(frame); | 251 minY += NSHeight(frame); |
| 246 } | 252 } |
| 247 | 253 |
| 248 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; | 254 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; |
| 249 } | 255 } |
| 250 | 256 |
| 251 @end | 257 @end |
| OLD | NEW |