Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / app_list / views / folder_background_view.cc
blob36318ef4001ab2caaa68d7a20ea8ac2158aac239
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 <algorithm>
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"
16 namespace app_list {
18 namespace {
20 const float kFolderInkBubbleScale = 1.2f;
21 const int kBubbleTransitionDurationMs = 200;
23 } // namespace
25 FolderBackgroundView::FolderBackgroundView()
26 : folder_view_(NULL),
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)) {
38 return;
41 show_state_ = state;
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);
50 } else {
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());
63 } else {
64 settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN);
65 layer()->SetOpacity(0.0f);
66 layer()->SetTransform(transform);
69 SchedulePaint();
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)
79 return;
81 // Draw ink bubble that shows the folder boundary.
82 SkPaint paint;
83 paint.setStyle(SkPaint::kFill_Style);
84 paint.setAntiAlias(true);
85 paint.setColor(kFolderBubbleColor);
86 canvas->DrawCircle(GetContentsBounds().CenterPoint(),
87 GetFolderContainerBubbleRadius(),
88 paint);
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