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

Unified Diff: components/infobars/core/infobar_container.cc

Issue 793783003: Move infobar constants and the code that uses them from components/ to chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NULL -> nullptr Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: components/infobars/core/infobar_container.cc
diff --git a/components/infobars/core/infobar_container.cc b/components/infobars/core/infobar_container.cc
index b6831129e69a830c970b632e9baed4c66a298b86..90ba064d4e0b6dca083a14c0e7c0c1589c5e166d 100644
--- a/components/infobars/core/infobar_container.cc
+++ b/components/infobars/core/infobar_container.cc
@@ -6,11 +6,11 @@
#include <algorithm>
+#include "base/auto_reset.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h"
-#include "ui/gfx/animation/slide_animation.h"
namespace infobars {
@@ -20,7 +20,7 @@ InfoBarContainer::Delegate::~Delegate() {
InfoBarContainer::InfoBarContainer(Delegate* delegate)
: delegate_(delegate),
infobar_manager_(NULL),
- top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) {
+ ignore_infobar_state_changed_(false) {
}
InfoBarContainer::~InfoBarContainer() {
@@ -34,23 +34,26 @@ void InfoBarContainer::ChangeInfoBarManager(InfoBarManager* infobar_manager) {
if (infobar_manager_)
infobar_manager_->RemoveObserver(this);
- // Hides all infobars in this container without animation.
- while (!infobars_.empty()) {
- InfoBar* infobar = infobars_.front();
- // Inform the infobar that it's hidden. If it was already closing, this
- // deletes it. Otherwise, this ensures the infobar will be deleted if it's
- // closed while it's not in an InfoBarContainer.
- infobar->Hide(false);
- }
+ {
+ // Ignore intermediate state changes. We'll manually trigger processing
+ // once we're finished.
+ base::AutoReset<bool> ignore_changes(&ignore_infobar_state_changed_, true);
+
+ // Hides all infobars in this container without animation.
+ while (!infobars_.empty()) {
+ InfoBar* infobar = infobars_.front();
+ // Inform the infobar that it's hidden. If it was already closing, this
+ // deletes it. Otherwise, this ensures the infobar will be deleted if
+ // it's closed while it's not in an InfoBarContainer.
+ infobar->Hide(false);
+ }
- infobar_manager_ = infobar_manager;
- if (infobar_manager_) {
- infobar_manager_->AddObserver(this);
+ infobar_manager_ = infobar_manager;
+ if (infobar_manager_) {
+ infobar_manager_->AddObserver(this);
- for (size_t i = 0; i < infobar_manager_->infobar_count(); ++i) {
- // As when we removed the infobars above, we prevent callbacks to
- // OnInfoBarStateChanged() for each infobar.
- AddInfoBar(infobar_manager_->infobar_at(i), i, false, NO_CALLBACK);
+ for (size_t i = 0; i < infobar_manager_->infobar_count(); ++i)
+ AddInfoBar(infobar_manager_->infobar_at(i), i, false);
}
}
@@ -77,16 +80,17 @@ int InfoBarContainer::GetVerticalOverlap(int* total_height) const {
return vertical_overlap;
}
-void InfoBarContainer::SetMaxTopArrowHeight(int height) {
- // Decrease the height by the arrow stroke thickness, which is the separator
- // line height, because the infobar arrow target heights are without-stroke.
- top_arrow_target_height_ = std::min(
- std::max(height - InfoBar::kSeparatorLineHeight, 0),
- InfoBar::kMaximumArrowTargetHeight);
- UpdateInfoBarArrowTargetHeights();
+void InfoBarContainer::UpdateInfoBarArrowTargetHeights() {
+ for (size_t i = 0; i < infobars_.size(); ++i) {
+ infobars_[i]->SetArrowTargetHeight(delegate_ ?
+ delegate_->ArrowTargetHeightForInfoBar(
+ i, const_cast<const InfoBar*>(infobars_[i])->animation()) : 0);
+ }
}
void InfoBarContainer::OnInfoBarStateChanged(bool is_animating) {
+ if (ignore_infobar_state_changed_)
+ return;
if (delegate_)
delegate_->InfoBarContainerStateChanged(is_animating);
UpdateInfoBarArrowTargetHeights();
@@ -112,7 +116,7 @@ void InfoBarContainer::RemoveAllInfoBarsForDestruction() {
}
void InfoBarContainer::OnInfoBarAdded(InfoBar* infobar) {
- AddInfoBar(infobar, infobars_.size(), true, WANT_CALLBACK);
+ AddInfoBar(infobar, infobars_.size(), true);
}
void InfoBarContainer::OnInfoBarRemoved(InfoBar* infobar, bool animate) {
@@ -128,7 +132,7 @@ void InfoBarContainer::OnInfoBarReplaced(InfoBar* old_infobar,
DCHECK(i != infobars_.end());
size_t position = i - infobars_.begin();
old_infobar->Hide(false);
- AddInfoBar(new_infobar, position, false, WANT_CALLBACK);
+ AddInfoBar(new_infobar, position, false);
}
void InfoBarContainer::OnManagerShuttingDown(InfoBarManager* manager) {
@@ -139,41 +143,15 @@ void InfoBarContainer::OnManagerShuttingDown(InfoBarManager* manager) {
void InfoBarContainer::AddInfoBar(InfoBar* infobar,
size_t position,
- bool animate,
- CallbackStatus callback_status) {
+ bool animate) {
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->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;
- // When the first infobar is animating closed, we animate the second infobar's
- // arrow target height from the default to the top target height. Note that
- // the animation values here are going from 1.0 -> 0.0 as the top bar closes.
- return top_arrow_target_height_ + static_cast<int>(
- (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) *
- first_infobar_animation.GetCurrentValue());
}
} // namespace infobars

Powered by Google App Engine
This is Rietveld 408576698