This source file includes following definitions.
- top_arrow_target_height_
- ChangeInfoBarManager
- GetVerticalOverlap
- SetMaxTopArrowHeight
- OnInfoBarStateChanged
- RemoveInfoBar
- RemoveAllInfoBarsForDestruction
- OnInfoBarAdded
- OnInfoBarRemoved
- OnInfoBarReplaced
- OnManagerShuttingDown
- AddInfoBar
- UpdateInfoBarArrowTargetHeights
- ArrowTargetHeightForInfoBar
#include "build/build_config.h"
#include "chrome/browser/infobars/infobar_container.h"
#include <algorithm>
#include "base/logging.h"
#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/infobars/infobar_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
InfoBarContainer::Delegate::~Delegate() {
}
InfoBarContainer::InfoBarContainer(Delegate* delegate)
: delegate_(delegate),
infobar_manager_(NULL),
top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) {
}
InfoBarContainer::~InfoBarContainer() {
DCHECK(infobars_.empty());
if (infobar_manager_)
infobar_manager_->RemoveObserver(this);
}
void InfoBarContainer::ChangeInfoBarManager(InfoBarManager* infobar_manager) {
if (infobar_manager_)
infobar_manager_->RemoveObserver(this);
while (!infobars_.empty()) {
InfoBar* infobar = infobars_.front();
infobar->Hide(false);
}
infobar_manager_ = infobar_manager;
if (infobar_manager_) {
infobar_manager_->AddObserver(this);
for (size_t i = 0; i < infobar_manager_->infobar_count(); ++i) {
AddInfoBar(infobar_manager_->infobar_at(i), i, false, NO_CALLBACK);
}
}
OnInfoBarStateChanged(false);
}
int InfoBarContainer::GetVerticalOverlap(int* total_height) {
int vertical_overlap = 0;
int next_infobar_y = 0;
for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) {
InfoBar* infobar = *i;
next_infobar_y -= infobar->arrow_height();
vertical_overlap = std::max(vertical_overlap, -next_infobar_y);
next_infobar_y += infobar->total_height();
}
if (total_height)
*total_height = next_infobar_y + vertical_overlap;
return vertical_overlap;
}
void InfoBarContainer::SetMaxTopArrowHeight(int height) {
top_arrow_target_height_ = std::min(
std::max(height - InfoBar::kSeparatorLineHeight, 0),
InfoBar::kMaximumArrowTargetHeight);
UpdateInfoBarArrowTargetHeights();
}
void InfoBarContainer::OnInfoBarStateChanged(bool is_animating) {
if (delegate_)
delegate_->InfoBarContainerStateChanged(is_animating);
UpdateInfoBarArrowTargetHeights();
PlatformSpecificInfoBarStateChanged(is_animating);
}
void InfoBarContainer::RemoveInfoBar(InfoBar* infobar) {
infobar->set_container(NULL);
InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar));
DCHECK(i != infobars_.end());
PlatformSpecificRemoveInfoBar(infobar);
infobars_.erase(i);
}
void InfoBarContainer::RemoveAllInfoBarsForDestruction() {
delegate_ = NULL;
ChangeInfoBarManager(NULL);
}
void InfoBarContainer::OnInfoBarAdded(InfoBar* infobar) {
AddInfoBar(infobar, infobars_.size(), true, WANT_CALLBACK);
}
void InfoBarContainer::OnInfoBarRemoved(InfoBar* infobar, bool animate) {
infobar->Hide(animate);
UpdateInfoBarArrowTargetHeights();
}
void InfoBarContainer::OnInfoBarReplaced(InfoBar* old_infobar,
InfoBar* new_infobar) {
PlatformSpecificReplaceInfoBar(old_infobar, new_infobar);
InfoBars::const_iterator i(std::find(infobars_.begin(), infobars_.end(),
old_infobar));
DCHECK(i != infobars_.end());
size_t position = i - infobars_.begin();
old_infobar->Hide(false);
AddInfoBar(new_infobar, position, false, WANT_CALLBACK);
}
void InfoBarContainer::OnManagerShuttingDown(InfoBarManager* manager) {
DCHECK_EQ(infobar_manager_, manager);
infobar_manager_->RemoveObserver(this);
infobar_manager_ = NULL;
}
void InfoBarContainer::AddInfoBar(InfoBar* infobar,
size_t position,
bool animate,
CallbackStatus callback_status) {
DCHECK(std::find(infobars_.begin(), infobars_.end(), infobar) ==
infobars_.end());
DCHECK_LE(position, infobars_.size());
infobars_.insert(infobars_.begin() + position, infobar);
UpdateInfoBarArrowTargetHeights();
PlatformSpecificAddInfoBar(infobar, position);
if (callback_status == WANT_CALLBACK)
infobar->set_container(this);
infobar->Show(animate);
if (callback_status == NO_CALLBACK)
infobar->set_container(this);
}
void InfoBarContainer::UpdateInfoBarArrowTargetHeights() {
for (size_t i = 0; i < infobars_.size(); ++i)
infobars_[i]->SetArrowTargetHeight(ArrowTargetHeightForInfoBar(i));
}
int InfoBarContainer::ArrowTargetHeightForInfoBar(size_t infobar_index) const {
if (!delegate_ || !delegate_->DrawInfoBarArrows(NULL))
return 0;
if (infobar_index == 0)
return top_arrow_target_height_;
const gfx::SlideAnimation& first_infobar_animation =
const_cast<const InfoBar*>(infobars_.front())->animation();
if ((infobar_index > 1) || first_infobar_animation.IsShowing())
return InfoBar::kDefaultArrowTargetHeight;
return top_arrow_target_height_ + static_cast<int>(
(InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
first_infobar_animation.GetCurrentValue());
}