Chromium Code Reviews| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 | 147 |
| 148 void SystemTrayBubble::UpdateView( | 148 void SystemTrayBubble::UpdateView( |
| 149 const std::vector<ash::SystemTrayItem*>& items, | 149 const std::vector<ash::SystemTrayItem*>& items, |
| 150 BubbleType bubble_type) { | 150 BubbleType bubble_type) { |
| 151 DCHECK(bubble_type != BUBBLE_TYPE_NOTIFICATION); | 151 DCHECK(bubble_type != BUBBLE_TYPE_NOTIFICATION); |
| 152 DCHECK(bubble_type != bubble_type_); | 152 DCHECK(bubble_type != bubble_type_); |
| 153 | 153 |
| 154 const int kSwipeDelayMS = 150; | 154 const int kSwipeDelayMS = 150; |
| 155 base::TimeDelta swipe_duration = | 155 base::TimeDelta swipe_duration = |
| 156 base::TimeDelta::FromMilliseconds(kSwipeDelayMS); | 156 base::TimeDelta::FromMilliseconds(kSwipeDelayMS); |
| 157 bool delete_layer = true; | |
| 157 ui::Layer* layer = bubble_view_->RecreateLayer(); | 158 ui::Layer* layer = bubble_view_->RecreateLayer(); |
|
sadrul
2012/12/19 23:50:33
Does it make sense to make |layer| a scoped_ptr, a
oshima
2012/12/20 00:05:19
As I mentioned in the bug description, layer is be
sadrul
2012/12/20 00:08:01
release() wouldn't destroy the layer, right? So it
| |
| 158 DCHECK(layer); | 159 DCHECK(layer); |
| 159 layer->SuppressPaint(); | 160 layer->SuppressPaint(); |
| 160 | 161 |
| 161 // When transitioning from detailed view to default view, animate the existing | 162 // When transitioning from detailed view to default view, animate the existing |
| 162 // view (slide out towards the right). | 163 // view (slide out towards the right). |
| 163 if (bubble_type == BUBBLE_TYPE_DEFAULT) { | 164 if (bubble_type == BUBBLE_TYPE_DEFAULT) { |
| 164 // Make sure the old view is visibile over the new view during the | 165 // Make sure the old view is visibile over the new view during the |
| 165 // animation. | 166 // animation. |
| 166 layer->parent()->StackAbove(layer, bubble_view_->layer()); | 167 layer->parent()->StackAbove(layer, bubble_view_->layer()); |
| 167 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 168 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| 169 delete_layer = false; | |
| 168 settings.AddObserver(new AnimationObserverDeleteLayer(layer)); | 170 settings.AddObserver(new AnimationObserverDeleteLayer(layer)); |
| 169 settings.SetTransitionDuration(swipe_duration); | 171 settings.SetTransitionDuration(swipe_duration); |
| 170 settings.SetTweenType(ui::Tween::EASE_OUT); | 172 settings.SetTweenType(ui::Tween::EASE_OUT); |
| 171 gfx::Transform transform; | 173 gfx::Transform transform; |
| 172 transform.Translate(layer->bounds().width(), 0.0); | 174 transform.Translate(layer->bounds().width(), 0.0); |
| 173 layer->SetTransform(transform); | 175 layer->SetTransform(transform); |
| 174 } | 176 } |
| 175 | 177 |
| 176 { | 178 { |
| 177 // Add a shadow layer to make the old layer darker as the animation | 179 // Add a shadow layer to make the old layer darker as the animation |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 200 DestroyItemViews(); | 202 DestroyItemViews(); |
| 201 bubble_view_->RemoveAllChildViews(true); | 203 bubble_view_->RemoveAllChildViews(true); |
| 202 | 204 |
| 203 items_ = items; | 205 items_ = items; |
| 204 bubble_type_ = bubble_type; | 206 bubble_type_ = bubble_type; |
| 205 CreateItemViews( | 207 CreateItemViews( |
| 206 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); | 208 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); |
| 207 | 209 |
| 208 // Close bubble view if we failed to create the item view. | 210 // Close bubble view if we failed to create the item view. |
| 209 if (!bubble_view_->has_children()) { | 211 if (!bubble_view_->has_children()) { |
| 212 if (delete_layer) | |
| 213 delete layer; | |
| 210 Close(); | 214 Close(); |
| 211 return; | 215 return; |
| 212 } | 216 } |
| 213 | 217 |
| 214 bubble_view_->GetWidget()->GetContentsView()->Layout(); | 218 bubble_view_->GetWidget()->GetContentsView()->Layout(); |
| 215 // Make sure that the bubble is large enough for the default view. | 219 // Make sure that the bubble is large enough for the default view. |
| 216 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { | 220 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { |
| 217 bubble_view_->SetMaxHeight(0); // Clear max height limit. | 221 bubble_view_->SetMaxHeight(0); // Clear max height limit. |
| 218 } | 222 } |
| 219 | 223 |
| 220 // When transitioning from default view to detailed view, animate the new | 224 // When transitioning from default view to detailed view, animate the new |
| 221 // view (slide in from the right). | 225 // view (slide in from the right). |
| 222 if (bubble_type == BUBBLE_TYPE_DETAILED) { | 226 if (bubble_type == BUBBLE_TYPE_DETAILED) { |
| 223 ui::Layer* new_layer = bubble_view_->layer(); | 227 ui::Layer* new_layer = bubble_view_->layer(); |
| 224 gfx::Rect bounds = new_layer->bounds(); | 228 gfx::Rect bounds = new_layer->bounds(); |
| 225 gfx::Transform transform; | 229 gfx::Transform transform; |
| 226 transform.Translate(bounds.width(), 0.0); | 230 transform.Translate(bounds.width(), 0.0); |
| 227 new_layer->SetTransform(transform); | 231 new_layer->SetTransform(transform); |
| 228 { | 232 { |
| 229 ui::ScopedLayerAnimationSettings settings(new_layer->GetAnimator()); | 233 ui::ScopedLayerAnimationSettings settings(new_layer->GetAnimator()); |
| 234 delete_layer = false; | |
| 230 settings.AddObserver(new AnimationObserverDeleteLayer(layer)); | 235 settings.AddObserver(new AnimationObserverDeleteLayer(layer)); |
| 231 settings.SetTransitionDuration(swipe_duration); | 236 settings.SetTransitionDuration(swipe_duration); |
| 232 settings.SetTweenType(ui::Tween::EASE_OUT); | 237 settings.SetTweenType(ui::Tween::EASE_OUT); |
| 233 new_layer->SetTransform(gfx::Transform()); | 238 new_layer->SetTransform(gfx::Transform()); |
| 234 } | 239 } |
| 235 } | 240 } |
| 241 if (delete_layer) | |
| 242 delete layer; | |
| 236 } | 243 } |
| 237 | 244 |
| 238 void SystemTrayBubble::InitView(views::View* anchor, | 245 void SystemTrayBubble::InitView(views::View* anchor, |
| 239 user::LoginStatus login_status, | 246 user::LoginStatus login_status, |
| 240 TrayBubbleView::InitParams* init_params) { | 247 TrayBubbleView::InitParams* init_params) { |
| 241 DCHECK(bubble_view_ == NULL); | 248 DCHECK(bubble_view_ == NULL); |
| 242 | 249 |
| 243 if (bubble_type_ == BUBBLE_TYPE_DETAILED && | 250 if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
| 244 init_params->max_height < kDetailedBubbleMaxHeight) { | 251 init_params->max_height < kDetailedBubbleMaxHeight) { |
| 245 init_params->max_height = kDetailedBubbleMaxHeight; | 252 init_params->max_height = kDetailedBubbleMaxHeight; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; | 348 bool is_default_bubble = bubble_type_ == BUBBLE_TYPE_DEFAULT; |
| 342 bubble_view_->AddChildView(new TrayPopupItemContainer( | 349 bubble_view_->AddChildView(new TrayPopupItemContainer( |
| 343 view, is_default_bubble, | 350 view, is_default_bubble, |
| 344 is_default_bubble && (i < items_.size() - 2))); | 351 is_default_bubble && (i < items_.size() - 2))); |
| 345 } | 352 } |
| 346 } | 353 } |
| 347 } | 354 } |
| 348 | 355 |
| 349 } // namespace internal | 356 } // namespace internal |
| 350 } // namespace ash | 357 } // namespace ash |
| OLD | NEW |