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.
5 #include "ui/app_list/views/folder_background_view.h"
9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/views/app_list_folder_view.h"
11 #include "ui/app_list/views/apps_container_view.h"
12 #include "ui/compositor/scoped_layer_animation_settings.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/transform_util.h"
20 const float kFolderInkBubbleScale
= 1.2f
;
21 const int kBubbleTransitionDurationMs
= 200;
25 FolderBackgroundView::FolderBackgroundView()
27 show_state_(NO_BUBBLE
) {
28 SetPaintToLayer(true);
29 SetFillsBoundsOpaquely(false);
32 FolderBackgroundView::~FolderBackgroundView() {
35 void FolderBackgroundView::UpdateFolderContainerBubble(ShowState state
) {
36 if (show_state_
== state
||
37 (state
== HIDE_BUBBLE
&& show_state_
== NO_BUBBLE
)) {
43 // Set the initial state before the animation starts.
44 const gfx::Rect
bounds(layer()->bounds().size());
45 gfx::Transform transform
=
46 gfx::GetScaleTransform(bounds
.CenterPoint(), kFolderInkBubbleScale
);
47 if (show_state_
== SHOW_BUBBLE
) {
48 layer()->SetOpacity(0.0f
);
49 layer()->SetTransform(transform
);
51 layer()->SetOpacity(1.0f
);
52 layer()->SetTransform(gfx::Transform());
55 ui::ScopedLayerAnimationSettings
settings(layer()->GetAnimator());
56 settings
.AddObserver(this);
57 settings
.SetTransitionDuration(
58 base::TimeDelta::FromMilliseconds((kBubbleTransitionDurationMs
)));
59 if (show_state_
== SHOW_BUBBLE
) {
60 settings
.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN
);
61 layer()->SetOpacity(1.0f
);
62 layer()->SetTransform(gfx::Transform());
64 settings
.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN
);
65 layer()->SetOpacity(0.0f
);
66 layer()->SetTransform(transform
);
72 int FolderBackgroundView::GetFolderContainerBubbleRadius() const {
73 return std::max(GetContentsBounds().width(), GetContentsBounds().height()) /
77 void FolderBackgroundView::OnPaint(gfx::Canvas
* canvas
) {
78 if (show_state_
== NO_BUBBLE
)
81 // Draw ink bubble that shows the folder boundary.
83 paint
.setStyle(SkPaint::kFill_Style
);
84 paint
.setAntiAlias(true);
85 paint
.setColor(kFolderBubbleColor
);
86 canvas
->DrawCircle(GetContentsBounds().CenterPoint(),
87 GetFolderContainerBubbleRadius(),
91 void FolderBackgroundView::OnImplicitAnimationsCompleted() {
92 // Show folder name after the ink bubble disappears.
93 if (show_state_
== HIDE_BUBBLE
) {
94 static_cast<AppsContainerView
*>(parent())->app_list_folder_view()->
95 UpdateFolderNameVisibility(true);
99 } // namespace app_list