OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
8 #include "ash/shelf/shelf_button.h" | |
9 #include "ash/shelf/shelf_button_host.h" | |
10 #include "ash/shelf/shelf_item_types.h" | 8 #include "ash/shelf/shelf_item_types.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_view.h" |
12 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 12 #include "ash/shell.h" |
14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
15 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
16 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
17 #include "ui/accessibility/ax_view_state.h" | 16 #include "ui/accessibility/ax_view_state.h" |
18 #include "ui/app_list/app_list_switches.h" | 17 #include "ui/app_list/app_list_switches.h" |
19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/base/ui_base_switches_util.h" | 20 #include "ui/base/ui_base_switches_util.h" |
22 #include "ui/compositor/layer.h" | |
23 #include "ui/compositor/layer_animation_element.h" | |
24 #include "ui/compositor/layer_animation_sequence.h" | |
25 #include "ui/compositor/scoped_layer_animation_settings.h" | |
26 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/image/image_skia_operations.h" | |
28 #include "ui/views/controls/button/image_button.h" | |
29 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
30 | 23 |
31 namespace ash { | 24 namespace ash { |
32 // static | |
33 const int AppListButton::kImageBoundsSize = 7; | |
34 | 25 |
35 | 26 AppListButton::AppListButton(ShelfView* shelf_view) |
36 AppListButton::AppListButton(views::ButtonListener* listener, | 27 : views::ImageButton(shelf_view), |
37 ShelfButtonHost* host, | |
38 ShelfWidget* shelf_widget) | |
39 : views::ImageButton(listener), | |
40 draw_background_as_active_(false), | 28 draw_background_as_active_(false), |
41 host_(host), | 29 shelf_view_(shelf_view) { |
42 shelf_widget_(shelf_widget) { | |
43 SetAccessibleName( | 30 SetAccessibleName( |
44 app_list::switches::IsExperimentalAppListEnabled() | 31 app_list::switches::IsExperimentalAppListEnabled() |
45 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) | 32 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) |
46 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); | 33 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); |
47 SetSize(gfx::Size(kShelfSize, kShelfSize)); | 34 SetSize(gfx::Size(kShelfSize, kShelfSize)); |
48 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 35 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
49 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 36 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
50 set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 37 set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
51 } | 38 } |
52 | 39 |
53 AppListButton::~AppListButton() { | 40 AppListButton::~AppListButton() {} |
54 } | |
55 | 41 |
56 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { | 42 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { |
57 ImageButton::OnMousePressed(event); | 43 ImageButton::OnMousePressed(event); |
58 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); | 44 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); |
59 return true; | 45 return true; |
60 } | 46 } |
61 | 47 |
62 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { | 48 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { |
63 ImageButton::OnMouseReleased(event); | 49 ImageButton::OnMouseReleased(event); |
64 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, false); | 50 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false); |
65 } | 51 } |
66 | 52 |
67 void AppListButton::OnMouseCaptureLost() { | 53 void AppListButton::OnMouseCaptureLost() { |
68 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, true); | 54 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true); |
69 ImageButton::OnMouseCaptureLost(); | 55 ImageButton::OnMouseCaptureLost(); |
70 } | 56 } |
71 | 57 |
72 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) { | 58 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) { |
73 ImageButton::OnMouseDragged(event); | 59 ImageButton::OnMouseDragged(event); |
74 host_->PointerDraggedOnButton(this, ShelfButtonHost::MOUSE, event); | 60 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event); |
75 return true; | 61 return true; |
76 } | 62 } |
77 | 63 |
78 void AppListButton::OnMouseMoved(const ui::MouseEvent& event) { | |
79 ImageButton::OnMouseMoved(event); | |
80 host_->MouseMovedOverButton(this); | |
81 } | |
82 | |
83 void AppListButton::OnMouseEntered(const ui::MouseEvent& event) { | |
84 ImageButton::OnMouseEntered(event); | |
85 host_->MouseEnteredButton(this); | |
86 } | |
87 | |
88 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { | |
89 ImageButton::OnMouseExited(event); | |
90 host_->MouseExitedButton(this); | |
91 } | |
92 | |
93 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { | 64 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { |
94 switch (event->type()) { | 65 switch (event->type()) { |
95 case ui::ET_GESTURE_SCROLL_BEGIN: | 66 case ui::ET_GESTURE_SCROLL_BEGIN: |
96 if (switches::IsTouchFeedbackEnabled()) | 67 if (switches::IsTouchFeedbackEnabled()) |
97 SetDrawBackgroundAsActive(false); | 68 SetDrawBackgroundAsActive(false); |
98 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); | 69 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event); |
99 event->SetHandled(); | 70 event->SetHandled(); |
100 return; | 71 return; |
101 case ui::ET_GESTURE_SCROLL_UPDATE: | 72 case ui::ET_GESTURE_SCROLL_UPDATE: |
102 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); | 73 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event); |
103 event->SetHandled(); | 74 event->SetHandled(); |
104 return; | 75 return; |
105 case ui::ET_GESTURE_SCROLL_END: | 76 case ui::ET_GESTURE_SCROLL_END: |
106 case ui::ET_SCROLL_FLING_START: | 77 case ui::ET_SCROLL_FLING_START: |
107 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); | 78 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); |
108 event->SetHandled(); | 79 event->SetHandled(); |
109 return; | 80 return; |
110 case ui::ET_GESTURE_TAP_DOWN: | 81 case ui::ET_GESTURE_TAP_DOWN: |
111 if (switches::IsTouchFeedbackEnabled()) | 82 if (switches::IsTouchFeedbackEnabled()) |
112 SetDrawBackgroundAsActive(true); | 83 SetDrawBackgroundAsActive(true); |
113 ImageButton::OnGestureEvent(event); | 84 ImageButton::OnGestureEvent(event); |
114 break; | 85 break; |
115 case ui::ET_GESTURE_TAP_CANCEL: | 86 case ui::ET_GESTURE_TAP_CANCEL: |
116 case ui::ET_GESTURE_TAP: | 87 case ui::ET_GESTURE_TAP: |
117 if (switches::IsTouchFeedbackEnabled()) | 88 if (switches::IsTouchFeedbackEnabled()) |
118 SetDrawBackgroundAsActive(false); | 89 SetDrawBackgroundAsActive(false); |
119 ImageButton::OnGestureEvent(event); | 90 ImageButton::OnGestureEvent(event); |
120 break; | 91 break; |
121 default: | 92 default: |
122 ImageButton::OnGestureEvent(event); | 93 ImageButton::OnGestureEvent(event); |
123 return; | 94 return; |
124 } | 95 } |
125 } | 96 } |
126 | 97 |
127 void AppListButton::OnPaint(gfx::Canvas* canvas) { | 98 void AppListButton::OnPaint(gfx::Canvas* canvas) { |
128 // Call the base class first to paint any background/borders. | 99 // Call the base class first to paint any background/borders. |
129 View::OnPaint(canvas); | 100 View::OnPaint(canvas); |
130 | 101 |
131 int background_image_id = 0; | 102 int background_image_id = 0; |
132 if (Shell::GetInstance()->GetAppListTargetVisibility() || | 103 if (Shell::GetInstance()->GetAppListTargetVisibility() || |
133 draw_background_as_active_) { | 104 draw_background_as_active_) { |
134 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 105 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
135 } else { | 106 } else { |
136 if (shelf_widget_->GetDimsShelf()) | 107 if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf()) |
137 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 108 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
138 else | 109 else |
139 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 110 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
140 } | 111 } |
141 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 112 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
142 const gfx::ImageSkia* background_image = | 113 const gfx::ImageSkia* background_image = |
143 rb.GetImageNamed(background_image_id).ToImageSkia(); | 114 rb.GetImageNamed(background_image_id).ToImageSkia(); |
144 // TODO(mgiuca): When the "classic" app list is removed, also remove this | 115 // TODO(mgiuca): When the "classic" app list is removed, also remove this |
145 // resource and its icon file. | 116 // resource and its icon file. |
146 int foreground_image_id = app_list::switches::IsExperimentalAppListEnabled() | 117 int foreground_image_id = app_list::switches::IsExperimentalAppListEnabled() |
147 ? IDR_ASH_SHELF_ICON_APPLIST | 118 ? IDR_ASH_SHELF_ICON_APPLIST |
148 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC; | 119 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC; |
149 const gfx::ImageSkia* forground_image = | 120 const gfx::ImageSkia* forground_image = |
150 rb.GetImageNamed(foreground_image_id).ToImageSkia(); | 121 rb.GetImageNamed(foreground_image_id).ToImageSkia(); |
151 | 122 |
152 gfx::Rect contents_bounds = GetContentsBounds(); | 123 gfx::Rect contents_bounds = GetContentsBounds(); |
153 gfx::Rect background_bounds, forground_bounds; | 124 gfx::Rect background_bounds, forground_bounds; |
154 | 125 |
155 ShelfAlignment alignment = shelf_widget_->GetAlignment(); | 126 ShelfAlignment alignment = shelf_view_->shelf()->alignment(); |
156 background_bounds.set_size(background_image->size()); | 127 background_bounds.set_size(background_image->size()); |
157 if (alignment == SHELF_ALIGNMENT_LEFT) { | 128 if (alignment == SHELF_ALIGNMENT_LEFT) { |
158 background_bounds.set_x(contents_bounds.width() - | 129 background_bounds.set_x(contents_bounds.width() - |
159 ShelfLayoutManager::kShelfItemInset - background_image->width()); | 130 ShelfLayoutManager::kShelfItemInset - background_image->width()); |
160 background_bounds.set_y(contents_bounds.y() + | 131 background_bounds.set_y(contents_bounds.y() + |
161 (contents_bounds.height() - background_image->height()) / 2); | 132 (contents_bounds.height() - background_image->height()) / 2); |
162 } else if(alignment == SHELF_ALIGNMENT_RIGHT) { | 133 } else if(alignment == SHELF_ALIGNMENT_RIGHT) { |
163 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); | 134 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); |
164 background_bounds.set_y(contents_bounds.y() + | 135 background_bounds.set_y(contents_bounds.y() + |
165 (contents_bounds.height() - background_image->height()) / 2); | 136 (contents_bounds.height() - background_image->height()) / 2); |
(...skipping 16 matching lines...) Expand all Loading... |
182 background_bounds.y()); | 153 background_bounds.y()); |
183 canvas->DrawImageInt(*forground_image, | 154 canvas->DrawImageInt(*forground_image, |
184 forground_bounds.x(), | 155 forground_bounds.x(), |
185 forground_bounds.y()); | 156 forground_bounds.y()); |
186 | 157 |
187 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); | 158 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); |
188 } | 159 } |
189 | 160 |
190 void AppListButton::GetAccessibleState(ui::AXViewState* state) { | 161 void AppListButton::GetAccessibleState(ui::AXViewState* state) { |
191 state->role = ui::AX_ROLE_BUTTON; | 162 state->role = ui::AX_ROLE_BUTTON; |
192 state->name = host_->GetAccessibleName(this); | 163 state->name = shelf_view_->GetTitleForView(this); |
193 } | 164 } |
194 | 165 |
195 void AppListButton::SetDrawBackgroundAsActive( | 166 void AppListButton::SetDrawBackgroundAsActive( |
196 bool draw_background_as_active) { | 167 bool draw_background_as_active) { |
197 if (draw_background_as_active_ == draw_background_as_active) | 168 if (draw_background_as_active_ == draw_background_as_active) |
198 return; | 169 return; |
199 draw_background_as_active_ = draw_background_as_active; | 170 draw_background_as_active_ = draw_background_as_active; |
200 SchedulePaint(); | 171 SchedulePaint(); |
201 } | 172 } |
202 | 173 |
203 } // namespace ash | 174 } // namespace ash |
OLD | NEW |