OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shelf/app_list_button.h" | 5 #include "ash/shelf/app_list_button.h" |
6 | 6 |
7 #include <vector> | |
8 | |
9 #include "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
Mr4D (OOO till 08-26)
2014/01/23 19:25:08
Same here as in the .h file as descibed by jamesco
Harry McCleave
2014/01/24 22:48:47
same as .h
| |
8 #include "ash/ash_switches.h" | |
9 #include "ash/launcher/launcher_types.h" | |
10 #include "ash/shelf/shelf_button.h" | |
10 #include "ash/shelf/shelf_button_host.h" | 11 #include "ash/shelf/shelf_button_host.h" |
11 #include "ash/shelf/shelf_constants.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
13 #include "ash/shelf/shelf_widget.h" | |
14 #include "ash/shell.h" | |
12 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
13 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
14 #include "ui/base/accessibility/accessible_view_state.h" | 17 #include "ui/base/accessibility/accessible_view_state.h" |
15 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
18 #include "ui/compositor/layer_animation_element.h" | 21 #include "ui/compositor/layer_animation_element.h" |
19 #include "ui/compositor/layer_animation_sequence.h" | 22 #include "ui/compositor/layer_animation_sequence.h" |
20 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
24 #include "ui/gfx/canvas.h" | |
25 #include "ui/gfx/image/image_skia_operations.h" | |
26 #include "ui/views/controls/button/image_button.h" | |
21 #include "ui/views/painter.h" | 27 #include "ui/views/painter.h" |
22 | 28 |
23 namespace ash { | 29 namespace ash { |
24 namespace internal { | 30 namespace internal { |
25 | 31 |
26 const int kAnimationDurationInMs = 600; | 32 // static |
27 const float kAnimationOpacity[] = { 1.0f, 0.4f, 1.0f }; | 33 const int AppListButton::kImageBoundsSize = 7; |
34 | |
28 | 35 |
29 AppListButton::AppListButton(views::ButtonListener* listener, | 36 AppListButton::AppListButton(views::ButtonListener* listener, |
30 ShelfButtonHost* host) | 37 ShelfButtonHost* host, |
38 ShelfWidget* shelf_widget) | |
31 : views::ImageButton(listener), | 39 : views::ImageButton(listener), |
32 host_(host) { | 40 host_(host), |
33 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 41 shelf_widget_(shelf_widget) { |
34 SetImage( | |
35 views::CustomButton::STATE_NORMAL, | |
36 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); | |
37 SetImage( | |
38 views::CustomButton::STATE_HOVERED, | |
39 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT). | |
40 ToImageSkia()); | |
41 SetImage( | |
42 views::CustomButton::STATE_PRESSED, | |
43 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED). | |
44 ToImageSkia()); | |
45 SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE)); | 42 SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE)); |
46 SetSize(gfx::Size(kShelfPreferredSize, kShelfPreferredSize)); | 43 SetSize(gfx::Size(ShelfLayoutManager::kShelfSize, |
47 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_TOP); | 44 ShelfLayoutManager::kShelfSize)); |
48 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 45 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
49 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 46 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
50 } | 47 } |
51 | 48 |
52 AppListButton::~AppListButton() { | 49 AppListButton::~AppListButton() { |
53 } | 50 } |
54 | 51 |
55 void AppListButton::StartLoadingAnimation() { | |
56 layer()->GetAnimator()->StopAnimating(); | |
57 | |
58 scoped_ptr<ui::LayerAnimationSequence> opacity_sequence( | |
59 new ui::LayerAnimationSequence()); | |
60 | |
61 opacity_sequence->set_is_cyclic(true); | |
62 | |
63 for (size_t i = 0; i < arraysize(kAnimationOpacity); ++i) { | |
64 opacity_sequence->AddElement( | |
65 ui::LayerAnimationElement::CreateOpacityElement( | |
66 kAnimationOpacity[i], | |
67 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); | |
68 } | |
69 | |
70 opacity_sequence->AddElement( | |
71 ui::LayerAnimationElement::CreatePauseElement( | |
72 ui::LayerAnimationElement::OPACITY, | |
73 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); | |
74 | |
75 // LayerAnimator takes ownership of the sequences. | |
76 layer()->GetAnimator()->ScheduleAnimation(opacity_sequence.release()); | |
77 } | |
78 | |
79 void AppListButton::StopLoadingAnimation() { | |
80 layer()->GetAnimator()->StopAnimating(); | |
81 | |
82 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); | |
83 settings.SetTransitionDuration( | |
84 base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)); | |
85 layer()->SetOpacity(1.0f); | |
86 layer()->SetTransform(gfx::Transform()); | |
87 } | |
88 | |
89 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { | 52 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { |
90 ImageButton::OnMousePressed(event); | 53 ImageButton::OnMousePressed(event); |
91 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); | 54 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); |
92 return true; | 55 return true; |
93 } | 56 } |
94 | 57 |
95 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { | 58 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { |
96 ImageButton::OnMouseReleased(event); | 59 ImageButton::OnMouseReleased(event); |
97 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, false); | 60 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, false); |
98 } | 61 } |
(...skipping 17 matching lines...) Expand all Loading... | |
116 void AppListButton::OnMouseEntered(const ui::MouseEvent& event) { | 79 void AppListButton::OnMouseEntered(const ui::MouseEvent& event) { |
117 ImageButton::OnMouseEntered(event); | 80 ImageButton::OnMouseEntered(event); |
118 host_->MouseEnteredButton(this); | 81 host_->MouseEnteredButton(this); |
119 } | 82 } |
120 | 83 |
121 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { | 84 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { |
122 ImageButton::OnMouseExited(event); | 85 ImageButton::OnMouseExited(event); |
123 host_->MouseExitedButton(this); | 86 host_->MouseExitedButton(this); |
124 } | 87 } |
125 | 88 |
126 void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) { | 89 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { |
90 switch (event->type()) { | |
91 case ui::ET_GESTURE_SCROLL_BEGIN: | |
92 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); | |
93 event->SetHandled(); | |
94 return; | |
95 case ui::ET_GESTURE_SCROLL_UPDATE: | |
96 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); | |
97 event->SetHandled(); | |
98 return; | |
99 case ui::ET_GESTURE_SCROLL_END: | |
100 case ui::ET_SCROLL_FLING_START: | |
101 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); | |
102 event->SetHandled(); | |
103 return; | |
104 default: | |
105 ImageButton::OnGestureEvent(event); | |
106 return; | |
107 } | |
108 } | |
109 | |
110 void AppListButton::OnPaint(gfx::Canvas* canvas) { | |
111 // Call the base class first to paint any background/borders. | |
112 View::OnPaint(canvas); | |
113 | |
114 int background_image_id = 0; | |
115 if (Shell::GetInstance()->GetAppListTargetVisibility()) { | |
116 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | |
117 } else { | |
118 if (shelf_widget_->GetDimsShelf()) | |
119 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | |
120 else | |
121 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | |
122 } | |
123 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
124 const gfx::ImageSkia* background_image = | |
125 rb.GetImageNamed(background_image_id).ToImageSkia(); | |
126 const gfx::ImageSkia* forground_image = | |
127 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_ALTERNATE).ToImageSkia(); | |
128 | |
129 gfx::Rect contents_bounds = GetContentsBounds(); | |
130 gfx::Rect background_bounds, forground_bounds; | |
131 | |
132 ShelfAlignment alignment = shelf_widget_->GetAlignment(); | |
133 background_bounds.set_size(background_image->size()); | |
134 if (alignment == SHELF_ALIGNMENT_LEFT) { | |
135 background_bounds.set_x(contents_bounds.width() - | |
136 ShelfLayoutManager::kShelfItemInset - background_image->width()); | |
137 background_bounds.set_y(contents_bounds.y() + | |
138 (contents_bounds.height() - background_image->height()) / 2); | |
139 } else if(alignment == SHELF_ALIGNMENT_RIGHT) { | |
140 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); | |
141 background_bounds.set_y(contents_bounds.y() + | |
142 (contents_bounds.height() - background_image->height()) / 2); | |
143 } else { | |
144 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); | |
145 background_bounds.set_x(contents_bounds.x() + | |
146 (contents_bounds.width() - background_image->width()) / 2); | |
147 } | |
148 | |
149 forground_bounds.set_size(forground_image->size()); | |
150 forground_bounds.set_x(background_bounds.x() + | |
151 std::max(0, | |
152 (background_bounds.width() - forground_bounds.width()) / 2)); | |
153 forground_bounds.set_y(background_bounds.y() + | |
154 std::max(0, | |
155 (background_bounds.height() - forground_bounds.height()) / 2)); | |
156 | |
157 canvas->DrawImageInt(*background_image, | |
158 background_bounds.x(), | |
159 background_bounds.y()); | |
160 canvas->DrawImageInt(*forground_image, | |
161 forground_bounds.x(), | |
162 forground_bounds.y()); | |
163 | |
164 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); | |
165 } | |
166 | |
167 void AppListButton::GetAccessibleState( | |
168 ui::AccessibleViewState* state) { | |
127 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 169 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
128 state->name = host_->GetAccessibleName(this); | 170 state->name = host_->GetAccessibleName(this); |
129 } | 171 } |
130 | 172 |
131 } // namespace internal | 173 } // namespace internal |
132 } // namespace ash | 174 } // namespace ash |
OLD | NEW |