OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/infobars/core/infobar_container.h" | 5 #include "components/infobars/core/infobar_container.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "components/infobars/core/infobar.h" | 11 #include "components/infobars/core/infobar.h" |
12 #include "components/infobars/core/infobar_delegate.h" | 12 #include "components/infobars/core/infobar_delegate.h" |
13 #include "ui/gfx/animation/slide_animation.h" | 13 #include "ui/gfx/animation/slide_animation.h" |
14 | 14 |
15 namespace infobars { | 15 namespace infobars { |
16 | 16 |
17 InfoBarContainer::Delegate::~Delegate() { | 17 InfoBarContainer::Delegate::~Delegate() { |
18 } | 18 } |
19 | 19 |
20 InfoBarContainer::InfoBarContainer(Delegate* delegate) | 20 InfoBarContainer::InfoBarContainer(Delegate* delegate) |
21 : delegate_(delegate), | 21 : delegate_(delegate), |
22 infobar_manager_(NULL), | 22 infobar_manager_(NULL), |
23 top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) { | 23 top_arrow_target_height_(InfoBar::gDefaultArrowTargetHeight) { |
24 } | 24 } |
25 | 25 |
26 InfoBarContainer::~InfoBarContainer() { | 26 InfoBarContainer::~InfoBarContainer() { |
27 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. | 27 // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. |
28 DCHECK(infobars_.empty()); | 28 DCHECK(infobars_.empty()); |
29 if (infobar_manager_) | 29 if (infobar_manager_) |
30 infobar_manager_->RemoveObserver(this); | 30 infobar_manager_->RemoveObserver(this); |
31 } | 31 } |
32 | 32 |
33 void InfoBarContainer::ChangeInfoBarManager(InfoBarManager* infobar_manager) { | 33 void InfoBarContainer::ChangeInfoBarManager(InfoBarManager* infobar_manager) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 if (total_height) | 75 if (total_height) |
76 *total_height = next_infobar_y + vertical_overlap; | 76 *total_height = next_infobar_y + vertical_overlap; |
77 return vertical_overlap; | 77 return vertical_overlap; |
78 } | 78 } |
79 | 79 |
80 void InfoBarContainer::SetMaxTopArrowHeight(int height) { | 80 void InfoBarContainer::SetMaxTopArrowHeight(int height) { |
81 // Decrease the height by the arrow stroke thickness, which is the separator | 81 // Decrease the height by the arrow stroke thickness, which is the separator |
82 // line height, because the infobar arrow target heights are without-stroke. | 82 // line height, because the infobar arrow target heights are without-stroke. |
83 top_arrow_target_height_ = std::min( | 83 top_arrow_target_height_ = std::min( |
84 std::max(height - InfoBar::kSeparatorLineHeight, 0), | 84 std::max(height - InfoBar::gSeparatorLineHeight, 0), |
85 InfoBar::kMaximumArrowTargetHeight); | 85 InfoBar::gMaximumArrowTargetHeight); |
86 UpdateInfoBarArrowTargetHeights(); | 86 UpdateInfoBarArrowTargetHeights(); |
87 } | 87 } |
88 | 88 |
89 void InfoBarContainer::OnInfoBarStateChanged(bool is_animating) { | 89 void InfoBarContainer::OnInfoBarStateChanged(bool is_animating) { |
90 if (delegate_) | 90 if (delegate_) |
91 delegate_->InfoBarContainerStateChanged(is_animating); | 91 delegate_->InfoBarContainerStateChanged(is_animating); |
92 UpdateInfoBarArrowTargetHeights(); | 92 UpdateInfoBarArrowTargetHeights(); |
93 PlatformSpecificInfoBarStateChanged(is_animating); | 93 PlatformSpecificInfoBarStateChanged(is_animating); |
94 } | 94 } |
95 | 95 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 int InfoBarContainer::ArrowTargetHeightForInfoBar(size_t infobar_index) const { | 162 int InfoBarContainer::ArrowTargetHeightForInfoBar(size_t infobar_index) const { |
163 if (!delegate_ || !delegate_->DrawInfoBarArrows(NULL)) | 163 if (!delegate_ || !delegate_->DrawInfoBarArrows(NULL)) |
164 return 0; | 164 return 0; |
165 if (infobar_index == 0) | 165 if (infobar_index == 0) |
166 return top_arrow_target_height_; | 166 return top_arrow_target_height_; |
167 const gfx::SlideAnimation& first_infobar_animation = | 167 const gfx::SlideAnimation& first_infobar_animation = |
168 const_cast<const InfoBar*>(infobars_.front())->animation(); | 168 const_cast<const InfoBar*>(infobars_.front())->animation(); |
169 if ((infobar_index > 1) || first_infobar_animation.IsShowing()) | 169 if ((infobar_index > 1) || first_infobar_animation.IsShowing()) |
170 return InfoBar::kDefaultArrowTargetHeight; | 170 return InfoBar::gDefaultArrowTargetHeight; |
171 // When the first infobar is animating closed, we animate the second infobar's | 171 // When the first infobar is animating closed, we animate the second infobar's |
172 // arrow target height from the default to the top target height. Note that | 172 // arrow target height from the default to the top target height. Note that |
173 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. | 173 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. |
174 return top_arrow_target_height_ + static_cast<int>( | 174 return top_arrow_target_height_ + static_cast<int>( |
175 (InfoBar::kDefaultArrowTargetHeight - top_arrow_target_height_) * | 175 (InfoBar::gDefaultArrowTargetHeight - top_arrow_target_height_) * |
176 first_infobar_animation.GetCurrentValue()); | 176 first_infobar_animation.GetCurrentValue()); |
177 } | 177 } |
178 | 178 |
179 } // namespace infobars | 179 } // namespace infobars |
OLD | NEW |