OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/launcher/app_list_button.h" | 5 #include "ash/launcher/app_list_button.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/launcher/launcher_button_host.h" | 9 #include "ash/launcher/launcher_button_host.h" |
10 #include "ash/launcher/launcher_types.h" | 10 #include "ash/launcher/launcher_types.h" |
| 11 #include "ash/shell.h" |
| 12 #include "ash/wm/app_list_controller.h" |
11 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
12 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
| 15 #include "ui/aura/window.h" |
13 #include "ui/base/accessibility/accessible_view_state.h" | 16 #include "ui/base/accessibility/accessible_view_state.h" |
14 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
17 #include "ui/compositor/layer_animation_element.h" | 20 #include "ui/compositor/layer_animation_element.h" |
18 #include "ui/compositor/layer_animation_sequence.h" | 21 #include "ui/compositor/layer_animation_sequence.h" |
19 #include "ui/compositor/scoped_layer_animation_settings.h" | 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/views/widget/widget.h" |
20 | 24 |
21 namespace ash { | 25 namespace ash { |
22 namespace internal { | 26 namespace internal { |
23 | 27 |
24 namespace { | 28 namespace { |
25 | 29 |
26 const int kAnimationDurationInMs = 600; | 30 const int kAnimationDurationInMs = 600; |
27 const float kAnimationOpacity[] = { 1.0f, 0.4f, 1.0f }; | 31 const float kAnimationOpacity[] = { 1.0f, 0.4f, 1.0f }; |
28 const int kBorderSize = 9; | 32 const int kBorderSize = 9; |
29 } // namespace | 33 } // namespace |
30 | 34 |
31 AppListButton::AppListButton(views::ButtonListener* listener, | 35 AppListButton::AppListButton(views::ButtonListener* listener, |
32 LauncherButtonHost* host) | 36 LauncherButtonHost* host) |
33 : views::ImageButton(listener), | 37 : views::ToggleImageButton(listener), |
34 host_(host) { | 38 host_(host) { |
35 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 39 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
36 SetImage( | 40 SetImage( |
37 views::CustomButton::STATE_NORMAL, | 41 views::CustomButton::STATE_NORMAL, |
38 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); | 42 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); |
39 SetImage( | 43 SetImage( |
40 views::CustomButton::STATE_HOVERED, | 44 views::CustomButton::STATE_HOVERED, |
41 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT). | 45 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT). |
42 ToImageSkia()); | 46 ToImageSkia()); |
43 SetImage( | 47 SetImage( |
44 views::CustomButton::STATE_PRESSED, | 48 views::CustomButton::STATE_PRESSED, |
45 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED). | 49 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED). |
46 ToImageSkia()); | 50 ToImageSkia()); |
| 51 |
| 52 const gfx::ImageSkia* toggled_image = |
| 53 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED). |
| 54 ToImageSkia(); |
| 55 SetToggledImage(views::CustomButton::STATE_NORMAL, toggled_image); |
| 56 SetToggledImage(views::CustomButton::STATE_HOVERED, toggled_image); |
| 57 SetToggledImage(views::CustomButton::STATE_PRESSED, toggled_image); |
| 58 |
47 SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE)); | 59 SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE)); |
48 SetSize(gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize)); | 60 SetSize(gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize)); |
49 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_TOP); | 61 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); |
| 62 |
| 63 Shell::GetInstance()->app_list_controller()->AddObserver(this); |
50 } | 64 } |
51 | 65 |
52 AppListButton::~AppListButton() { | 66 AppListButton::~AppListButton() { |
| 67 Shell::GetInstance()->app_list_controller()->RemoveObserver(this); |
53 } | 68 } |
54 | 69 |
55 void AppListButton::StartLoadingAnimation() { | 70 void AppListButton::StartLoadingAnimation() { |
56 layer()->GetAnimator()->StopAnimating(); | 71 layer()->GetAnimator()->StopAnimating(); |
57 | 72 |
58 scoped_ptr<ui::LayerAnimationSequence> opacity_sequence( | 73 scoped_ptr<ui::LayerAnimationSequence> opacity_sequence( |
59 new ui::LayerAnimationSequence()); | 74 new ui::LayerAnimationSequence()); |
60 | 75 |
61 opacity_sequence->set_is_cyclic(true); | 76 opacity_sequence->set_is_cyclic(true); |
62 | 77 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { | 138 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { |
124 ImageButton::OnMouseExited(event); | 139 ImageButton::OnMouseExited(event); |
125 host_->MouseExitedButton(this); | 140 host_->MouseExitedButton(this); |
126 } | 141 } |
127 | 142 |
128 void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) { | 143 void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) { |
129 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 144 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
130 state->name = host_->GetAccessibleName(this); | 145 state->name = host_->GetAccessibleName(this); |
131 } | 146 } |
132 | 147 |
| 148 void AppListButton::OnAppLauncherVisibilityChanged( |
| 149 bool visible, const aura::RootWindow* root_window) { |
| 150 if (!GetWidget() || |
| 151 GetWidget()->GetNativeView()->GetRootWindow() != root_window) { |
| 152 return; |
| 153 } |
| 154 |
| 155 SetToggled(visible); |
| 156 } |
| 157 |
133 } // namespace internal | 158 } // namespace internal |
134 } // namespace ash | 159 } // namespace ash |
OLD | NEW |