OLD | NEW |
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 "ash/system/tray/system_tray_bubble.h" | 5 #include "ash/system/tray/system_tray_bubble.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
9 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
10 #include "ash/system/tray/system_tray_item.h" | 10 #include "ash/system/tray/system_tray_item.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Normally a detailed view is the same size as the default view. However, | 29 // Normally a detailed view is the same size as the default view. However, |
30 // when showing a detailed view directly (e.g. clicking on a notification), | 30 // when showing a detailed view directly (e.g. clicking on a notification), |
31 // we may not know the height of the default view, or the default view may | 31 // we may not know the height of the default view, or the default view may |
32 // be too short, so we use this as a default and minimum height for any | 32 // be too short, so we use this as a default and minimum height for any |
33 // detailed view. | 33 // detailed view. |
34 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; | 34 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; |
35 | 35 |
| 36 // Duration of swipe animation used when transitioning from a default to |
| 37 // detailed view or vice versa. |
| 38 const int kSwipeDelayMS = 150; |
| 39 |
36 // A view with some special behaviour for tray items in the popup: | 40 // A view with some special behaviour for tray items in the popup: |
37 // - optionally changes background color on hover. | 41 // - optionally changes background color on hover. |
38 class TrayPopupItemContainer : public views::View { | 42 class TrayPopupItemContainer : public views::View { |
39 public: | 43 public: |
40 TrayPopupItemContainer(views::View* view, | 44 TrayPopupItemContainer(views::View* view, |
41 bool change_background, | 45 bool change_background, |
42 bool draw_border) | 46 bool draw_border) |
43 : hover_(false), | 47 : hover_(false), |
44 change_background_(change_background) { | 48 change_background_(change_background) { |
45 set_notify_enter_exit_on_child(true); | 49 set_notify_enter_exit_on_child(true); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 DestroyItemViews(); | 146 DestroyItemViews(); |
143 // Reset the host pointer in bubble_view_ in case its destruction is deferred. | 147 // Reset the host pointer in bubble_view_ in case its destruction is deferred. |
144 if (bubble_view_) | 148 if (bubble_view_) |
145 bubble_view_->reset_delegate(); | 149 bubble_view_->reset_delegate(); |
146 } | 150 } |
147 | 151 |
148 void SystemTrayBubble::UpdateView( | 152 void SystemTrayBubble::UpdateView( |
149 const std::vector<ash::SystemTrayItem*>& items, | 153 const std::vector<ash::SystemTrayItem*>& items, |
150 BubbleType bubble_type) { | 154 BubbleType bubble_type) { |
151 DCHECK(bubble_type != BUBBLE_TYPE_NOTIFICATION); | 155 DCHECK(bubble_type != BUBBLE_TYPE_NOTIFICATION); |
152 DCHECK(bubble_type != bubble_type_); | |
153 | 156 |
154 const int kSwipeDelayMS = 150; | 157 scoped_ptr<ui::Layer> scoped_layer; |
155 base::TimeDelta swipe_duration = | 158 if (bubble_type != bubble_type_) { |
156 base::TimeDelta::FromMilliseconds(kSwipeDelayMS); | 159 base::TimeDelta swipe_duration = |
157 scoped_ptr<ui::Layer> scoped_layer(bubble_view_->RecreateLayer()); | 160 base::TimeDelta::FromMilliseconds(kSwipeDelayMS); |
158 // Keep the reference to layer as we need it after releasing it. | 161 scoped_layer.reset(bubble_view_->RecreateLayer()); |
159 ui::Layer* layer = scoped_layer.get(); | 162 // Keep the reference to layer as we need it after releasing it. |
160 DCHECK(layer); | 163 ui::Layer* layer = scoped_layer.get(); |
161 layer->SuppressPaint(); | 164 DCHECK(layer); |
| 165 layer->SuppressPaint(); |
162 | 166 |
163 // When transitioning from detailed view to default view, animate the existing | 167 // When transitioning from detailed view to default view, animate the |
164 // view (slide out towards the right). | 168 // existing view (slide out towards the right). |
165 if (bubble_type == BUBBLE_TYPE_DEFAULT) { | 169 if (bubble_type == BUBBLE_TYPE_DEFAULT) { |
166 // Make sure the old view is visibile over the new view during the | 170 // Make sure the old view is visibile over the new view during the |
167 // animation. | 171 // animation. |
168 layer->parent()->StackAbove(layer, bubble_view_->layer()); | 172 layer->parent()->StackAbove(layer, bubble_view_->layer()); |
169 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 173 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
170 settings.AddObserver( | 174 settings.AddObserver( |
171 new AnimationObserverDeleteLayer(scoped_layer.release())); | 175 new AnimationObserverDeleteLayer(scoped_layer.release())); |
172 settings.SetTransitionDuration(swipe_duration); | 176 settings.SetTransitionDuration(swipe_duration); |
173 settings.SetTweenType(ui::Tween::EASE_OUT); | 177 settings.SetTweenType(ui::Tween::EASE_OUT); |
174 gfx::Transform transform; | 178 gfx::Transform transform; |
175 transform.Translate(layer->bounds().width(), 0.0); | 179 transform.Translate(layer->bounds().width(), 0.0); |
176 layer->SetTransform(transform); | 180 layer->SetTransform(transform); |
177 } | 181 } |
178 | 182 |
179 { | |
180 // Add a shadow layer to make the old layer darker as the animation | |
181 // progresses. | |
182 ui::Layer* shadow = new ui::Layer(ui::LAYER_SOLID_COLOR); | |
183 shadow->SetColor(SK_ColorBLACK); | |
184 shadow->SetOpacity(0.01f); | |
185 shadow->SetBounds(layer->bounds()); | |
186 layer->Add(shadow); | |
187 layer->StackAtTop(shadow); | |
188 { | 183 { |
189 // Animate the darkening effect a little longer than the swipe-in. This is | 184 // Add a shadow layer to make the old layer darker as the animation |
190 // to make sure the darkening animation does not end up finishing early, | 185 // progresses. |
191 // because the dark layer goes away at the end of the animation, and there | 186 ui::Layer* shadow = new ui::Layer(ui::LAYER_SOLID_COLOR); |
192 // is a brief moment when the old view is still visible, but it does not | 187 shadow->SetColor(SK_ColorBLACK); |
193 // have the shadow layer on top. | 188 shadow->SetOpacity(0.01f); |
194 ui::ScopedLayerAnimationSettings settings(shadow->GetAnimator()); | 189 shadow->SetBounds(layer->bounds()); |
195 settings.AddObserver(new AnimationObserverDeleteLayer(shadow)); | 190 layer->Add(shadow); |
196 settings.SetTransitionDuration(swipe_duration + | 191 layer->StackAtTop(shadow); |
197 base::TimeDelta::FromMilliseconds(150)); | 192 { |
198 settings.SetTweenType(ui::Tween::LINEAR); | 193 // Animate the darkening effect a little longer than the swipe-in. This |
199 shadow->SetOpacity(0.15f); | 194 // is to make sure the darkening animation does not end up finishing |
| 195 // early, because the dark layer goes away at the end of the animation, |
| 196 // and there is a brief moment when the old view is still visible, but |
| 197 // it does not have the shadow layer on top. |
| 198 ui::ScopedLayerAnimationSettings settings(shadow->GetAnimator()); |
| 199 settings.AddObserver(new AnimationObserverDeleteLayer(shadow)); |
| 200 settings.SetTransitionDuration(swipe_duration + |
| 201 base::TimeDelta::FromMilliseconds(150)); |
| 202 settings.SetTweenType(ui::Tween::LINEAR); |
| 203 shadow->SetOpacity(0.15f); |
| 204 } |
200 } | 205 } |
201 } | 206 } |
202 | 207 |
203 DestroyItemViews(); | 208 DestroyItemViews(); |
204 bubble_view_->RemoveAllChildViews(true); | 209 bubble_view_->RemoveAllChildViews(true); |
205 | 210 |
206 items_ = items; | 211 items_ = items; |
207 bubble_type_ = bubble_type; | 212 bubble_type_ = bubble_type; |
208 CreateItemViews( | 213 CreateItemViews( |
209 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); | 214 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); |
210 | 215 |
211 // Close bubble view if we failed to create the item view. | 216 // Close bubble view if we failed to create the item view. |
212 if (!bubble_view_->has_children()) { | 217 if (!bubble_view_->has_children()) { |
213 Close(); | 218 Close(); |
214 return; | 219 return; |
215 } | 220 } |
216 | 221 |
217 bubble_view_->GetWidget()->GetContentsView()->Layout(); | 222 bubble_view_->GetWidget()->GetContentsView()->Layout(); |
218 // Make sure that the bubble is large enough for the default view. | 223 // Make sure that the bubble is large enough for the default view. |
219 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { | 224 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { |
220 bubble_view_->SetMaxHeight(0); // Clear max height limit. | 225 bubble_view_->SetMaxHeight(0); // Clear max height limit. |
221 } | 226 } |
222 | 227 |
223 // When transitioning from default view to detailed view, animate the new | 228 if (scoped_layer.get()) { |
224 // view (slide in from the right). | 229 // When transitioning from default view to detailed view, animate the new |
225 if (bubble_type == BUBBLE_TYPE_DETAILED) { | 230 // view (slide in from the right). |
226 ui::Layer* new_layer = bubble_view_->layer(); | 231 if (bubble_type == BUBBLE_TYPE_DETAILED) { |
227 gfx::Rect bounds = new_layer->bounds(); | 232 ui::Layer* new_layer = bubble_view_->layer(); |
228 gfx::Transform transform; | 233 gfx::Rect bounds = new_layer->bounds(); |
229 transform.Translate(bounds.width(), 0.0); | 234 gfx::Transform transform; |
230 new_layer->SetTransform(transform); | 235 transform.Translate(bounds.width(), 0.0); |
231 { | 236 new_layer->SetTransform(transform); |
232 ui::ScopedLayerAnimationSettings settings(new_layer->GetAnimator()); | 237 { |
233 settings.AddObserver( | 238 ui::ScopedLayerAnimationSettings settings(new_layer->GetAnimator()); |
234 new AnimationObserverDeleteLayer(scoped_layer.release())); | 239 settings.AddObserver( |
235 settings.SetTransitionDuration(swipe_duration); | 240 new AnimationObserverDeleteLayer(scoped_layer.release())); |
236 settings.SetTweenType(ui::Tween::EASE_OUT); | 241 settings.SetTransitionDuration( |
237 new_layer->SetTransform(gfx::Transform()); | 242 base::TimeDelta::FromMilliseconds(kSwipeDelayMS)); |
| 243 settings.SetTweenType(ui::Tween::EASE_OUT); |
| 244 new_layer->SetTransform(gfx::Transform()); |
| 245 } |
238 } | 246 } |
239 } | 247 } |
240 } | 248 } |
241 | 249 |
242 void SystemTrayBubble::InitView(views::View* anchor, | 250 void SystemTrayBubble::InitView(views::View* anchor, |
243 user::LoginStatus login_status, | 251 user::LoginStatus login_status, |
244 TrayBubbleView::InitParams* init_params) { | 252 TrayBubbleView::InitParams* init_params) { |
245 DCHECK(bubble_view_ == NULL); | 253 DCHECK(bubble_view_ == NULL); |
246 | 254 |
247 if (bubble_type_ == BUBBLE_TYPE_DETAILED && | 255 if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; | 353 bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; |
346 bubble_view_->AddChildView(new TrayPopupItemContainer( | 354 bubble_view_->AddChildView(new TrayPopupItemContainer( |
347 view, is_default_bubble, | 355 view, is_default_bubble, |
348 is_default_bubble && (i < items_.size() - 2))); | 356 is_default_bubble && (i < items_.size() - 2))); |
349 } | 357 } |
350 } | 358 } |
351 } | 359 } |
352 | 360 |
353 } // namespace internal | 361 } // namespace internal |
354 } // namespace ash | 362 } // namespace ash |
OLD | NEW |