 Chromium Code Reviews
 Chromium Code Reviews Issue 136303008:
  Implement ui for re-parenting an item from an app list folder to another position or folder in the …  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 136303008:
  Implement ui for re-parenting an item from an app list folder to another position or folder in the …  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 | |
| 
xiyuan
2014/02/06 22:45:12
nit: nuke one empty line
 
jennyz
2014/02/07 00:03:10
Done.
 | |
| 6 #include "ui/app_list/views/top_icon_animation_view.h" | |
| 7 | |
| 8 #include "ui/app_list/app_list_constants.h" | |
| 9 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 10 #include "ui/gfx/image/image_skia_operations.h" | |
| 11 #include "ui/views/controls/image_view.h" | |
| 12 | |
| 13 namespace app_list { | |
| 14 | |
| 15 TopIconAnimationView::TopIconAnimationView(const gfx::ImageSkia& icon, | |
| 16 const gfx::Rect& scaled_rect, | |
| 17 bool open_folder, | |
| 18 bool self_clean) | |
| 19 : icon_size_(kPreferredIconDimension, kPreferredIconDimension), | |
| 20 icon_(new views::ImageView), | |
| 21 scaled_rect_(scaled_rect), | |
| 22 open_folder_(open_folder), | |
| 23 self_clean_(self_clean) { | |
| 24 DCHECK(!icon.isNull()); | |
| 25 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage( | |
| 26 icon, | |
| 27 skia::ImageOperations::RESIZE_BEST, icon_size_)); | |
| 28 icon_->SetImage(resized); | |
| 29 AddChildView(icon_); | |
| 30 | |
| 31 #if defined(USE_AURA) | |
| 
xiyuan
2014/02/06 22:45:12
nit: Not sure if we still need this any more.
 
jennyz
2014/02/07 00:03:10
Remove them, will watch if it breaks any compiler.
 | |
| 32 SetPaintToLayer(true); | |
| 33 SetFillsBoundsOpaquely(false); | |
| 34 #endif | |
| 35 } | |
| 36 | |
| 37 TopIconAnimationView::~TopIconAnimationView() { | |
| 38 } | |
| 39 | |
| 40 void TopIconAnimationView::AddObserver(TopIconAnimationObserver* observer) { | |
| 41 observers_.AddObserver(observer); | |
| 42 } | |
| 43 | |
| 44 void TopIconAnimationView::RemoveObserver(TopIconAnimationObserver* observer) { | |
| 45 observers_.RemoveObserver(observer); | |
| 46 } | |
| 47 | |
| 48 void TopIconAnimationView::TransformView() { | |
| 49 // Transform used for scaling down the icon and move it back inside to the | |
| 50 // original folder icon. | |
| 51 const float kIconTransformScale = 0.33333f; | |
| 52 gfx::Transform transform; | |
| 53 transform.Translate(scaled_rect_.x() - layer()->bounds().x(), | |
| 54 scaled_rect_.y() - layer()->bounds().y()); | |
| 55 transform.Scale(kIconTransformScale, kIconTransformScale); | |
| 56 | |
| 57 if (open_folder_) { | |
| 58 // Transform to a scaled down icon inside the original folder icon. | |
| 59 layer()->SetTransform(transform); | |
| 60 } | |
| 61 | |
| 62 // Animate the icon to its target location and scale when opening or | |
| 63 // closing a folder. | |
| 64 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); | |
| 65 settings.AddObserver(this); | |
| 66 settings.SetTransitionDuration( | |
| 67 base::TimeDelta::FromMilliseconds(kFolderTransitionInDurationMs)); | |
| 68 layer()->SetTransform(open_folder_ ? gfx::Transform() : transform); | |
| 69 } | |
| 70 | |
| 71 gfx::Size TopIconAnimationView::GetPreferredSize() { | |
| 72 return icon_size_; | |
| 73 } | |
| 74 | |
| 75 void TopIconAnimationView::Layout() { | |
| 76 icon_->SetBoundsRect(GetContentsBounds()); | |
| 77 } | |
| 78 | |
| 79 void TopIconAnimationView::OnImplicitAnimationsCompleted() { | |
| 80 SetVisible(false); | |
| 81 | |
| 82 if (self_clean_) | |
| 83 delete this; | |
| 
xiyuan
2014/02/06 22:45:12
This would cause use-after-free for the FOR_EACH_O
 
jennyz
2014/02/07 00:03:10
Yes, this's wrong. Now make TopIconAnimation alway
 | |
| 84 | |
| 85 FOR_EACH_OBSERVER(TopIconAnimationObserver, | |
| 86 observers_, | |
| 87 OnTopIconAnimationsComplete(this)); | |
| 88 } | |
| 89 | |
| 90 } // namespace app_list | |
| OLD | NEW |