Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_util.h" | 6 #include "base/mac_util.h" |
| 7 #include "chrome/browser/cocoa/infobar.h" | 7 #include "chrome/browser/cocoa/infobar.h" |
| 8 #import "chrome/browser/cocoa/infobar_container_controller.h" | 8 #import "chrome/browser/cocoa/infobar_container_controller.h" |
| 9 #import "chrome/browser/cocoa/infobar_controller.h" | 9 #import "chrome/browser/cocoa/infobar_controller.h" |
| 10 #include "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" | 10 #include "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 const NotificationSource& source, | 26 const NotificationSource& source, |
| 27 const NotificationDetails& details) { | 27 const NotificationDetails& details) { |
| 28 switch (type.value) { | 28 switch (type.value) { |
| 29 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: | 29 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: |
| 30 [controller_ addInfoBar:Details<InfoBarDelegate>(details).ptr()]; | 30 [controller_ addInfoBar:Details<InfoBarDelegate>(details).ptr()]; |
| 31 break; | 31 break; |
| 32 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: | 32 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: |
| 33 [controller_ | 33 [controller_ |
| 34 removeInfoBarsForDelegate:Details<InfoBarDelegate>(details).ptr()]; | 34 removeInfoBarsForDelegate:Details<InfoBarDelegate>(details).ptr()]; |
| 35 break; | 35 break; |
| 36 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: { | |
| 37 typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> | |
| 38 InfoBarDelegatePair; | |
| 39 InfoBarDelegatePair* delegates = | |
| 40 Details<InfoBarDelegatePair>(details).ptr(); | |
| 41 [controller_ | |
| 42 replaceInfoBarsForDelegate:delegates->first with:delegates->second]; | |
| 43 break; | |
| 44 } | |
| 36 default: | 45 default: |
| 37 NOTREACHED(); // we don't ask for anything else! | 46 NOTREACHED(); // we don't ask for anything else! |
| 38 break; | 47 break; |
| 39 } | 48 } |
| 40 | 49 |
| 41 [controller_ positionInfoBarsAndRedraw]; | 50 [controller_ positionInfoBarsAndRedraw]; |
| 42 } | 51 } |
| 43 | 52 |
| 44 InfoBarContainerController* controller_; // weak, owns us. | 53 InfoBarContainerController* controller_; // weak, owns us. |
| 45 }; | 54 }; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 if (currentTabContents_) { | 132 if (currentTabContents_) { |
| 124 for (int i = 0; i < currentTabContents_->infobar_delegate_count(); ++i) { | 133 for (int i = 0; i < currentTabContents_->infobar_delegate_count(); ++i) { |
| 125 [self addInfoBar:currentTabContents_->GetInfoBarDelegateAt(i)]; | 134 [self addInfoBar:currentTabContents_->GetInfoBarDelegateAt(i)]; |
| 126 } | 135 } |
| 127 | 136 |
| 128 Source<TabContents> source(currentTabContents_); | 137 Source<TabContents> source(currentTabContents_); |
| 129 registrar_.Add(infoBarObserver_.get(), | 138 registrar_.Add(infoBarObserver_.get(), |
| 130 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); | 139 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); |
| 131 registrar_.Add(infoBarObserver_.get(), | 140 registrar_.Add(infoBarObserver_.get(), |
| 132 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); | 141 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, source); |
| 142 registrar_.Add(infoBarObserver_.get(), | |
| 143 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, source); | |
| 133 } | 144 } |
| 134 | 145 |
| 135 [self positionInfoBarsAndRedraw]; | 146 [self positionInfoBarsAndRedraw]; |
| 136 } | 147 } |
| 137 | 148 |
| 138 - (void)addInfoBar:(InfoBarDelegate*)delegate { | 149 - (void)addInfoBar:(InfoBarDelegate*)delegate { |
| 139 scoped_ptr<InfoBar> infobar(delegate->CreateInfoBar()); | 150 scoped_ptr<InfoBar> infobar(delegate->CreateInfoBar()); |
| 140 InfoBarController* controller = infobar->controller(); | 151 InfoBarController* controller = infobar->controller(); |
| 141 [controller setContainerController:self]; | 152 [controller setContainerController:self]; |
| 142 [[self view] addSubview:[controller view]]; | 153 [[self view] addSubview:[controller view]]; |
| 143 [infobarControllers_ addObject:[controller autorelease]]; | 154 [infobarControllers_ addObject:[controller autorelease]]; |
| 144 } | 155 } |
| 145 | 156 |
| 146 - (void)removeInfoBarsForDelegate:(InfoBarDelegate*)delegate { | 157 - (void)removeInfoBarsForDelegate:(InfoBarDelegate*)delegate { |
| 147 for (InfoBarController* controller in | 158 for (InfoBarController* controller in |
| 148 [NSArray arrayWithArray:infobarControllers_.get()]) { | 159 [NSArray arrayWithArray:infobarControllers_.get()]) { |
| 149 if ([controller delegate] == delegate) { | 160 if ([controller delegate] == delegate) { |
| 150 // This code can be executed while -[InfoBarController closeInfoBar] is | 161 // This code can be executed while -[InfoBarController closeInfoBar] is |
| 151 // still on the stack, so we retain and autorelease the controller to | 162 // still on the stack, so we retain and autorelease the controller to |
| 152 // prevent it from being dealloc'ed too early. | 163 // prevent it from being dealloc'ed too early. |
| 153 [[controller retain] autorelease]; | 164 [[controller retain] autorelease]; |
| 154 [[controller view] removeFromSuperview]; | 165 [[controller view] removeFromSuperview]; |
| 155 [infobarControllers_ removeObject:controller]; | 166 [infobarControllers_ removeObject:controller]; |
| 156 } | 167 } |
| 157 } | 168 } |
| 158 } | 169 } |
| 159 | 170 |
| 171 - (void)replaceInfoBarsForDelegate:(InfoBarDelegate*)old_delegate | |
| 172 with:(InfoBarDelegate*)new_delegate { | |
| 173 // TODO(port): This should avoid animation when we add it. | |
|
Aaron Boodman
2009/08/24 21:29:07
Cool, thanks for adding this TODO
rohitrao (ping after 24h)
2009/08/25 15:57:35
Feel free to assign this TODO to me.
| |
| 174 [self removeInfoBarsForDelegate:old_delegate]; | |
| 175 [self addInfoBar:new_delegate]; | |
| 176 } | |
| 177 | |
| 160 - (void)removeAllInfoBars { | 178 - (void)removeAllInfoBars { |
| 161 for (InfoBarController* controller in infobarControllers_.get()) { | 179 for (InfoBarController* controller in infobarControllers_.get()) { |
| 162 [[controller view] removeFromSuperview]; | 180 [[controller view] removeFromSuperview]; |
| 163 } | 181 } |
| 164 [infobarControllers_ removeAllObjects]; | 182 [infobarControllers_ removeAllObjects]; |
| 165 } | 183 } |
| 166 | 184 |
| 167 - (void)positionInfoBarsAndRedraw { | 185 - (void)positionInfoBarsAndRedraw { |
| 168 NSRect containerBounds = [[self view] bounds]; | 186 NSRect containerBounds = [[self view] bounds]; |
| 169 int minY = 0; | 187 int minY = 0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 181 frame.origin.y = minY; | 199 frame.origin.y = minY; |
| 182 minY += frame.size.height; | 200 minY += frame.size.height; |
| 183 // TODO(rohitrao, jrg): Replace with an animator. | 201 // TODO(rohitrao, jrg): Replace with an animator. |
| 184 [view setFrame:frame]; | 202 [view setFrame:frame]; |
| 185 } | 203 } |
| 186 | 204 |
| 187 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; | 205 [resizeDelegate_ resizeView:[self view] newHeight:[self desiredHeight]]; |
| 188 } | 206 } |
| 189 | 207 |
| 190 @end | 208 @end |
| OLD | NEW |