OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/app_list/views/folder_background_view.h" |
| 6 |
| 7 #include "ui/app_list/app_list_constants.h" |
| 8 #include "ui/app_list/views/app_list_folder_view.h" |
| 9 #include "ui/app_list/views/apps_container_view.h" |
| 10 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/transform_util.h" |
| 13 |
| 14 namespace app_list { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const float kFolderInkBubbleScale = 1.2f; |
| 19 const int kBubbleTransitionDurationMs = 200; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 FolderBackgroundView::FolderBackgroundView() |
| 24 : folder_view_(NULL), |
| 25 show_state_(NO_BUBBLE) { |
| 26 SetPaintToLayer(true); |
| 27 SetFillsBoundsOpaquely(false); |
| 28 } |
| 29 |
| 30 FolderBackgroundView::~FolderBackgroundView() { |
| 31 } |
| 32 |
| 33 void FolderBackgroundView::UpdateFolderContainerBubble(ShowState state) { |
| 34 if (show_state_ == state || |
| 35 (state == HIDE_BUBBLE && show_state_ == NO_BUBBLE)) { |
| 36 return; |
| 37 } |
| 38 |
| 39 show_state_ = state; |
| 40 |
| 41 // Set the initial state before the animation starts. |
| 42 const gfx::Rect bounds(layer()->bounds().size()); |
| 43 gfx::Transform transform = |
| 44 gfx::GetScaleTransform(bounds.CenterPoint(), kFolderInkBubbleScale); |
| 45 if (show_state_ == SHOW_BUBBLE) { |
| 46 layer()->SetOpacity(0.0f); |
| 47 layer()->SetTransform(transform); |
| 48 } else { |
| 49 layer()->SetOpacity(1.0f); |
| 50 layer()->SetTransform(gfx::Transform()); |
| 51 } |
| 52 |
| 53 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| 54 settings.AddObserver(this); |
| 55 settings.SetTransitionDuration( |
| 56 base::TimeDelta::FromMilliseconds((kBubbleTransitionDurationMs))); |
| 57 if (show_state_ == SHOW_BUBBLE) { |
| 58 layer()->SetOpacity(1.0f); |
| 59 layer()->SetTransform(gfx::Transform()); |
| 60 } else { |
| 61 layer()->SetOpacity(0.0f); |
| 62 layer()->SetTransform(transform); |
| 63 } |
| 64 |
| 65 SchedulePaint(); |
| 66 } |
| 67 |
| 68 int FolderBackgroundView::GetFolderContainerBubbleRadius() const { |
| 69 return GetContentsBounds().height() / 2; |
| 70 } |
| 71 |
| 72 void FolderBackgroundView::OnPaint(gfx::Canvas* canvas) { |
| 73 if (show_state_ == NO_BUBBLE) |
| 74 return; |
| 75 |
| 76 // Draw ink bubble that shows the folder boundary. |
| 77 SkPaint paint; |
| 78 paint.setStyle(SkPaint::kFill_Style); |
| 79 paint.setAntiAlias(true); |
| 80 paint.setColor(kFolderBubbleColor); |
| 81 canvas->DrawCircle(GetContentsBounds().CenterPoint(), |
| 82 GetFolderContainerBubbleRadius(), |
| 83 paint); |
| 84 } |
| 85 |
| 86 void FolderBackgroundView::OnImplicitAnimationsCompleted() { |
| 87 // Show folder name after the ink bubble disappears. |
| 88 if (show_state_ == HIDE_BUBBLE) { |
| 89 static_cast<AppsContainerView*>(parent())->app_list_folder_view()-> |
| 90 UpdateFolderNameVisibility(true); |
| 91 } |
| 92 } |
| 93 |
| 94 } // namespace app_list |
OLD | NEW |