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"
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"
18 const float kFolderInkBubbleScale
= 1.2f
;
19 const int kBubbleTransitionDurationMs
= 200;
23 FolderBackgroundView::FolderBackgroundView()
25 show_state_(NO_BUBBLE
) {
26 SetPaintToLayer(true);
27 SetFillsBoundsOpaquely(false);
30 FolderBackgroundView::~FolderBackgroundView() {
33 void FolderBackgroundView::UpdateFolderContainerBubble(ShowState state
) {
34 if (show_state_
== state
||
35 (state
== HIDE_BUBBLE
&& show_state_
== NO_BUBBLE
)) {
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
);
49 layer()->SetOpacity(1.0f
);
50 layer()->SetTransform(gfx::Transform());
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 settings
.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN
);
59 layer()->SetOpacity(1.0f
);
60 layer()->SetTransform(gfx::Transform());
62 settings
.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN
);
63 layer()->SetOpacity(0.0f
);
64 layer()->SetTransform(transform
);
70 int FolderBackgroundView::GetFolderContainerBubbleRadius() const {
71 return std::max(GetContentsBounds().width(), GetContentsBounds().height()) /
75 void FolderBackgroundView::OnPaint(gfx::Canvas
* canvas
) {
76 if (show_state_
== NO_BUBBLE
)
79 // Draw ink bubble that shows the folder boundary.
81 paint
.setStyle(SkPaint::kFill_Style
);
82 paint
.setAntiAlias(true);
83 paint
.setColor(kFolderBubbleColor
);
84 canvas
->DrawCircle(GetContentsBounds().CenterPoint(),
85 GetFolderContainerBubbleRadius(),
89 void FolderBackgroundView::OnImplicitAnimationsCompleted() {
90 // Show folder name after the ink bubble disappears.
91 if (show_state_
== HIDE_BUBBLE
) {
92 static_cast<AppsContainerView
*>(parent())->app_list_folder_view()->
93 UpdateFolderNameVisibility(true);
97 } // namespace app_list