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

Side by Side Diff: chrome/browser/infobars/infobar_container.cc

Issue 211273007: Split InfoBarService core code into InfoBarManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android compilation Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
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 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/infobars/infobar_container.h" 7 #include "chrome/browser/infobars/infobar_container.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "chrome/browser/infobars/infobar.h" 12 #include "chrome/browser/infobars/infobar.h"
13 #include "chrome/browser/infobars/infobar_delegate.h" 13 #include "chrome/browser/infobars/infobar_delegate.h"
14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "ui/gfx/animation/slide_animation.h" 14 #include "ui/gfx/animation/slide_animation.h"
16 15
17 InfoBarContainer::Delegate::~Delegate() { 16 InfoBarContainer::Delegate::~Delegate() {
18 } 17 }
19 18
20 InfoBarContainer::InfoBarContainer(Delegate* delegate) 19 InfoBarContainer::InfoBarContainer(Delegate* delegate)
21 : delegate_(delegate), 20 : delegate_(delegate),
22 infobar_service_(NULL), 21 infobar_manager_(NULL),
23 top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) { 22 top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) {}
Peter Kasting 2014/03/26 23:51:30 Nit: Don't modify wrapping here
24 }
25 23
26 InfoBarContainer::~InfoBarContainer() { 24 InfoBarContainer::~InfoBarContainer() {
27 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. 25 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars.
28 DCHECK(infobars_.empty()); 26 DCHECK(infobars_.empty());
29 if (infobar_service_) 27 if (infobar_manager_)
30 infobar_service_->RemoveObserver(this); 28 infobar_manager_->RemoveObserver(this);
31 } 29 }
32 30
33 void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { 31 void InfoBarContainer::ChangeInfoBarManager(InfoBarManager* infobar_manager) {
34 if (infobar_service_) 32 if (infobar_manager_)
35 infobar_service_->RemoveObserver(this); 33 infobar_manager_->RemoveObserver(this);
36 34
37 // Hides all infobars in this container without animation. 35 // Hides all infobars in this container without animation.
38 while (!infobars_.empty()) { 36 while (!infobars_.empty()) {
39 InfoBar* infobar = infobars_.front(); 37 InfoBar* infobar = infobars_.front();
40 // Inform the infobar that it's hidden. If it was already closing, this 38 // Inform the infobar that it's hidden. If it was already closing, this
41 // deletes it. Otherwise, this ensures the infobar will be deleted if it's 39 // deletes it. Otherwise, this ensures the infobar will be deleted if it's
42 // closed while it's not in an InfoBarContainer. 40 // closed while it's not in an InfoBarContainer.
43 infobar->Hide(false); 41 infobar->Hide(false);
44 } 42 }
45 43
46 infobar_service_ = infobar_service; 44 infobar_manager_ = infobar_manager;
47 if (infobar_service_) { 45 if (infobar_manager_) {
48 infobar_service_->AddObserver(this); 46 infobar_manager_->AddObserver(this);
49 47
50 for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { 48 for (size_t i = 0; i < infobar_manager_->infobar_count(); ++i) {
51 // As when we removed the infobars above, we prevent callbacks to 49 // As when we removed the infobars above, we prevent callbacks to
52 // OnInfoBarStateChanged() for each infobar. 50 // OnInfoBarStateChanged() for each infobar.
53 AddInfoBar(infobar_service_->infobar_at(i), i, false, NO_CALLBACK); 51 AddInfoBar(infobar_manager_->infobar_at(i), i, false, NO_CALLBACK);
54 } 52 }
55 } 53 }
56 54
57 // Now that everything is up to date, signal the delegate to re-layout. 55 // Now that everything is up to date, signal the delegate to re-layout.
58 OnInfoBarStateChanged(false); 56 OnInfoBarStateChanged(false);
59 } 57 }
60 58
61 int InfoBarContainer::GetVerticalOverlap(int* total_height) { 59 int InfoBarContainer::GetVerticalOverlap(int* total_height) {
62 // Our |total_height| is the sum of the preferred heights of the InfoBars 60 // Our |total_height| is the sum of the preferred heights of the InfoBars
63 // contained within us plus the |vertical_overlap|. 61 // contained within us plus the |vertical_overlap|.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 infobars_.erase(i); 98 infobars_.erase(i);
101 } 99 }
102 100
103 void InfoBarContainer::RemoveAllInfoBarsForDestruction() { 101 void InfoBarContainer::RemoveAllInfoBarsForDestruction() {
104 // Before we remove any children, we reset |delegate_|, so that no removals 102 // Before we remove any children, we reset |delegate_|, so that no removals
105 // will result in us trying to call 103 // will result in us trying to call
106 // delegate_->InfoBarContainerStateChanged(). This is important because at 104 // delegate_->InfoBarContainerStateChanged(). This is important because at
107 // this point |delegate_| may be shutting down, and it's at best unimportant 105 // this point |delegate_| may be shutting down, and it's at best unimportant
108 // and at worst disastrous to call that. 106 // and at worst disastrous to call that.
109 delegate_ = NULL; 107 delegate_ = NULL;
110 ChangeInfoBarService(NULL); 108 ChangeInfoBarManager(NULL);
111 } 109 }
112 110
113 void InfoBarContainer::OnInfoBarAdded(InfoBar* infobar) { 111 void InfoBarContainer::OnInfoBarAdded(InfoBar* infobar) {
114 AddInfoBar(infobar, infobars_.size(), true, WANT_CALLBACK); 112 AddInfoBar(infobar, infobars_.size(), true, WANT_CALLBACK);
115 } 113 }
116 114
117 void InfoBarContainer::OnInfoBarRemoved(InfoBar* infobar, bool animate) { 115 void InfoBarContainer::OnInfoBarRemoved(InfoBar* infobar, bool animate) {
118 infobar->Hide(animate); 116 infobar->Hide(animate);
119 UpdateInfoBarArrowTargetHeights(); 117 UpdateInfoBarArrowTargetHeights();
120 } 118 }
121 119
122 void InfoBarContainer::OnInfoBarReplaced(InfoBar* old_infobar, 120 void InfoBarContainer::OnInfoBarReplaced(InfoBar* old_infobar,
123 InfoBar* new_infobar) { 121 InfoBar* new_infobar) {
124 PlatformSpecificReplaceInfoBar(old_infobar, new_infobar); 122 PlatformSpecificReplaceInfoBar(old_infobar, new_infobar);
125 InfoBars::const_iterator i(std::find(infobars_.begin(), infobars_.end(), 123 InfoBars::const_iterator i(std::find(infobars_.begin(), infobars_.end(),
126 old_infobar)); 124 old_infobar));
127 DCHECK(i != infobars_.end()); 125 DCHECK(i != infobars_.end());
128 size_t position = i - infobars_.begin(); 126 size_t position = i - infobars_.begin();
129 old_infobar->Hide(false); 127 old_infobar->Hide(false);
130 AddInfoBar(new_infobar, position, false, WANT_CALLBACK); 128 AddInfoBar(new_infobar, position, false, WANT_CALLBACK);
131 } 129 }
132 130
133 void InfoBarContainer::OnServiceShuttingDown(InfoBarService* service) { 131 void InfoBarContainer::OnManagerShuttingDown(InfoBarManager* manager) {
134 DCHECK_EQ(infobar_service_, service); 132 DCHECK_EQ(infobar_manager_, manager);
135 infobar_service_->RemoveObserver(this); 133 infobar_manager_->RemoveObserver(this);
136 infobar_service_ = NULL; 134 infobar_manager_ = NULL;
137 } 135 }
138 136
139 void InfoBarContainer::AddInfoBar(InfoBar* infobar, 137 void InfoBarContainer::AddInfoBar(InfoBar* infobar,
140 size_t position, 138 size_t position,
141 bool animate, 139 bool animate,
142 CallbackStatus callback_status) { 140 CallbackStatus callback_status) {
143 DCHECK(std::find(infobars_.begin(), infobars_.end(), infobar) == 141 DCHECK(std::find(infobars_.begin(), infobars_.end(), infobar) ==
144 infobars_.end()); 142 infobars_.end());
145 DCHECK_LE(position, infobars_.size()); 143 DCHECK_LE(position, infobars_.size());
146 infobars_.insert(infobars_.begin() + position, infobar); 144 infobars_.insert(infobars_.begin() + position, infobar);
(...skipping 20 matching lines...) Expand all
167 const_cast<const InfoBar*>(infobars_.front())->animation(); 165 const_cast<const InfoBar*>(infobars_.front())->animation();
168 if ((infobar_index > 1) || first_infobar_animation.IsShowing()) 166 if ((infobar_index > 1) || first_infobar_animation.IsShowing())
169 return InfoBar::kDefaultArrowTargetHeight; 167 return InfoBar::kDefaultArrowTargetHeight;
170 // When the first infobar is animating closed, we animate the second infobar's 168 // When the first infobar is animating closed, we animate the second infobar's
171 // arrow target height from the default to the top target height. Note that 169 // arrow target height from the default to the top target height. Note that
172 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. 170 // the animation values here are going from 1.0 -> 0.0 as the top bar closes.
173 return top_arrow_target_height_ + static_cast<int>( 171 return top_arrow_target_height_ + static_cast<int>(
174 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * 172 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
175 first_infobar_animation.GetCurrentValue()); 173 first_infobar_animation.GetCurrentValue());
176 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698