15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/app_list/views/folder_background_view.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/app_list/app_list_constants.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/app_list/views/app_list_folder_view.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/app_list/views/apps_container_view.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/compositor/scoped_layer_animation_settings.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/canvas.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/transform_util.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace app_list { 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const float kFolderInkBubbleScale = 1.2f; 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kBubbleTransitionDurationMs = 200; 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FolderBackgroundView::FolderBackgroundView() 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : folder_view_(NULL), 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) show_state_(NO_BUBBLE) { 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetPaintToLayer(true); 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetFillsBoundsOpaquely(false); 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)FolderBackgroundView::~FolderBackgroundView() { 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void FolderBackgroundView::UpdateFolderContainerBubble(ShowState state) { 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (show_state_ == state || 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) (state == HIDE_BUBBLE && show_state_ == NO_BUBBLE)) { 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) show_state_ = state; 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set the initial state before the animation starts. 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect bounds(layer()->bounds().size()); 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Transform transform = 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::GetScaleTransform(bounds.CenterPoint(), kFolderInkBubbleScale); 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (show_state_ == SHOW_BUBBLE) { 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetOpacity(0.0f); 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetTransform(transform); 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetOpacity(1.0f); 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetTransform(gfx::Transform()); 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) settings.AddObserver(this); 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) settings.SetTransitionDuration( 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::TimeDelta::FromMilliseconds((kBubbleTransitionDurationMs))); 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (show_state_ == SHOW_BUBBLE) { 58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) settings.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetOpacity(1.0f); 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetTransform(gfx::Transform()); 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) settings.SetTweenType(gfx::Tween::FAST_OUT_LINEAR_IN); 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetOpacity(0.0f); 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layer()->SetTransform(transform); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SchedulePaint(); 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int FolderBackgroundView::GetFolderContainerBubbleRadius() const { 7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) return std::max(GetContentsBounds().width(), GetContentsBounds().height()) / 7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 2; 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void FolderBackgroundView::OnPaint(gfx::Canvas* canvas) { 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (show_state_ == NO_BUBBLE) 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Draw ink bubble that shows the folder boundary. 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SkPaint paint; 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) paint.setStyle(SkPaint::kFill_Style); 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) paint.setAntiAlias(true); 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) paint.setColor(kFolderBubbleColor); 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) canvas->DrawCircle(GetContentsBounds().CenterPoint(), 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetFolderContainerBubbleRadius(), 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) paint); 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void FolderBackgroundView::OnImplicitAnimationsCompleted() { 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Show folder name after the ink bubble disappears. 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (show_state_ == HIDE_BUBBLE) { 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<AppsContainerView*>(parent())->app_list_folder_view()-> 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) UpdateFolderNameVisibility(true); 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace app_list 98