1 // Copyright (c) 2012 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 "ash/launcher/tabbed_launcher_button.h"
9 #include "ash/launcher/launcher_button_host.h"
10 #include "ash/launcher/launcher_types.h"
11 #include "grit/ash_resources.h"
12 #include "ui/base/accessibility/accessible_view_state.h"
13 #include "ui/base/animation/multi_animation.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/image/image.h"
17 #include "ui/gfx/insets.h"
20 const int kIconOffsetY
= 7;
26 TabbedLauncherButton::IconView::IconView(
27 TabbedLauncherButton
* host
)
29 if (!browser_image_
) {
30 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
32 browser_image_
= rb
.GetImageNamed(IDR_AURA_LAUNCHER_BROWSER
).ToImageSkia();
33 incognito_browser_image_
=
34 rb
.GetImageNamed(IDR_AURA_LAUNCHER_INCOGNITO_BROWSER
).ToImageSkia();
35 browser_panel_image_
=
36 rb
.GetImageNamed(IDR_AURA_LAUNCHER_BROWSER_PANEL
).ToImageSkia();
37 incognito_browser_panel_image_
=
39 IDR_AURA_LAUNCHER_INCOGNITO_BROWSER_PANEL
).ToImageSkia();
42 if (host
->is_incognito() == STATE_NOT_INCOGNITO
)
43 LauncherButton::IconView::SetImage(*browser_image_
);
45 LauncherButton::IconView::SetImage(*incognito_browser_image_
);
48 TabbedLauncherButton::IconView::~IconView() {
51 void TabbedLauncherButton::IconView::AnimationEnded(
52 const ui::Animation
* animation
) {
53 AnimationProgressed(animation
);
54 animating_image_
= gfx::ImageSkia();
57 void TabbedLauncherButton::IconView::AnimationProgressed(
58 const ui::Animation
* animation
) {
59 if (animation_
->current_part_index() == 1)
63 void TabbedLauncherButton::IconView::SetTabImage(const gfx::ImageSkia
& image
) {
65 if (!image_
.isNull()) {
66 // Pause for 500ms, then ease out for 200ms.
67 ui::MultiAnimation::Parts animation_parts
;
68 animation_parts
.push_back(ui::MultiAnimation::Part(500, ui::Tween::ZERO
));
69 animation_parts
.push_back(
70 ui::MultiAnimation::Part(200, ui::Tween::EASE_OUT
));
71 animation_
.reset(new ui::MultiAnimation(
73 ui::MultiAnimation::GetDefaultTimerInterval()));
74 animation_
->set_continuous(false);
75 animation_
->set_delegate(this);
77 animating_image_
= image_
;
87 void TabbedLauncherButton::IconView::OnPaint(gfx::Canvas
* canvas
) {
88 LauncherButton::IconView::OnPaint(canvas
);
90 // Only non incognito icons show the tab image.
91 if (host_
->is_incognito() != STATE_NOT_INCOGNITO
)
94 if ((animation_
.get() && animation_
->is_animating() &&
95 animation_
->current_part_index() == 1)) {
96 int x
= (width() - animating_image_
.width()) / 2;
97 canvas
->SaveLayerAlpha(animation_
->CurrentValueBetween(255, 0));
98 canvas
->DrawImageInt(animating_image_
, x
, kIconOffsetY
);
101 int x
= (width() - image_
.width()) / 2;
102 canvas
->DrawImageInt(image_
, x
, kIconOffsetY
);
107 const gfx::ImageSkia
* TabbedLauncherButton::IconView::browser_image_
= NULL
;
108 const gfx::ImageSkia
* TabbedLauncherButton::IconView::incognito_browser_image_
=
110 const gfx::ImageSkia
* TabbedLauncherButton::IconView::browser_panel_image_
=
112 const gfx::ImageSkia
*
113 TabbedLauncherButton::IconView::incognito_browser_panel_image_
= NULL
;
115 TabbedLauncherButton
* TabbedLauncherButton::Create(
116 views::ButtonListener
* listener
,
117 LauncherButtonHost
* host
,
118 ShelfLayoutManager
* shelf_layout_manager
,
119 IncognitoState is_incognito
) {
120 TabbedLauncherButton
* button
= new TabbedLauncherButton(
121 listener
, host
, shelf_layout_manager
, is_incognito
);
126 TabbedLauncherButton::TabbedLauncherButton(
127 views::ButtonListener
* listener
,
128 LauncherButtonHost
* host
,
129 ShelfLayoutManager
* shelf_layout_manager
,
130 IncognitoState is_incognito
)
131 : LauncherButton(listener
, host
, shelf_layout_manager
),
132 is_incognito_(is_incognito
) {
133 set_accessibility_focusable(true);
136 TabbedLauncherButton::~TabbedLauncherButton() {
139 void TabbedLauncherButton::SetTabImage(const gfx::ImageSkia
& image
) {
140 tabbed_icon_view()->SetTabImage(image
);
143 void TabbedLauncherButton::GetAccessibleState(ui::AccessibleViewState
* state
) {
144 state
->role
= ui::AccessibilityTypes::ROLE_PUSHBUTTON
;
145 state
->name
= host()->GetAccessibleName(this);
148 LauncherButton::IconView
* TabbedLauncherButton::CreateIconView() {
149 return new IconView(this);
152 } // namespace internal