Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: ash/common/shelf/app_list_button.cc

Issue 2169533002: mash: Migrate shelf app list button to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/shelf/app_list_button.h ('k') | ash/common/shelf/app_list_shelf_item_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/shelf/app_list_button.h"
6 6
7 #include "ash/common/ash_constants.h" 7 #include "ash/common/ash_constants.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/shelf/ink_drop_button_listener.h" 9 #include "ash/common/shelf/ink_drop_button_listener.h"
10 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
11 #include "ash/common/shelf/shelf_item_types.h" 11 #include "ash/common/shelf/shelf_item_types.h"
12 #include "ash/common/shelf/shelf_types.h" 12 #include "ash/common/shelf/shelf_types.h"
13 #include "ash/common/shelf/wm_shelf.h"
13 #include "ash/common/shelf/wm_shelf_util.h" 14 #include "ash/common/shelf/wm_shelf_util.h"
14 #include "ash/shelf/shelf_layout_manager.h" 15 #include "ash/common/wm_shell.h"
15 #include "ash/shelf/shelf_view.h" 16 #include "ash/shelf/shelf_view.h"
16 #include "ash/shelf/shelf_widget.h"
17 #include "ash/shell.h"
18 #include "base/command_line.h" 17 #include "base/command_line.h"
19 #include "grit/ash_resources.h" 18 #include "grit/ash_resources.h"
20 #include "grit/ash_strings.h" 19 #include "grit/ash_strings.h"
21 #include "ui/accessibility/ax_view_state.h" 20 #include "ui/accessibility/ax_view_state.h"
22 #include "ui/app_list/app_list_switches.h" 21 #include "ui/app_list/app_list_switches.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/ui_base_switches_util.h" 24 #include "ui/base/ui_base_switches_util.h"
26 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
27 #include "ui/gfx/paint_vector_icon.h" 26 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/gfx/vector_icons_public.h" 27 #include "ui/gfx/vector_icons_public.h"
29 #include "ui/views/animation/square_ink_drop_ripple.h" 28 #include "ui/views/animation/square_ink_drop_ripple.h"
30 #include "ui/views/painter.h" 29 #include "ui/views/painter.h"
31 30
32 namespace ash { 31 namespace ash {
33 32
34 AppListButton::AppListButton(InkDropButtonListener* listener, 33 AppListButton::AppListButton(InkDropButtonListener* listener,
35 ShelfView* shelf_view) 34 ShelfView* shelf_view,
35 WmShelf* wm_shelf)
36 : views::ImageButton(nullptr), 36 : views::ImageButton(nullptr),
37 draw_background_as_active_(false), 37 draw_background_as_active_(false),
38 listener_(listener), 38 listener_(listener),
39 shelf_view_(shelf_view) { 39 shelf_view_(shelf_view),
40 wm_shelf_(wm_shelf) {
41 DCHECK(listener_);
42 DCHECK(shelf_view_);
43 DCHECK(wm_shelf_);
40 if (ash::MaterialDesignController::IsShelfMaterial()) { 44 if (ash::MaterialDesignController::IsShelfMaterial()) {
41 SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER); 45 SetInkDropMode(InkDropMode::ON_NO_GESTURE_HANDLER);
42 set_ink_drop_base_color(kShelfInkDropBaseColor); 46 set_ink_drop_base_color(kShelfInkDropBaseColor);
43 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); 47 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
44 } 48 }
45 SetAccessibleName( 49 SetAccessibleName(
46 app_list::switches::IsExperimentalAppListEnabled() 50 app_list::switches::IsExperimentalAppListEnabled()
47 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) 51 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)
48 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); 52 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE));
49 SetSize( 53 SetSize(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 event->SetHandled(); 113 event->SetHandled();
110 return; 114 return;
111 case ui::ET_GESTURE_SCROLL_END: 115 case ui::ET_GESTURE_SCROLL_END:
112 case ui::ET_SCROLL_FLING_START: 116 case ui::ET_SCROLL_FLING_START:
113 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); 117 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false);
114 event->SetHandled(); 118 event->SetHandled();
115 return; 119 return;
116 case ui::ET_GESTURE_TAP_DOWN: 120 case ui::ET_GESTURE_TAP_DOWN:
117 if (touch_feedback) 121 if (touch_feedback)
118 SetDrawBackgroundAsActive(true); 122 SetDrawBackgroundAsActive(true);
119 else if (is_material && !Shell::GetInstance()->IsApplistVisible()) 123 else if (is_material && !WmShell::Get()->IsApplistVisible())
120 AnimateInkDrop(views::InkDropState::ACTION_PENDING, event); 124 AnimateInkDrop(views::InkDropState::ACTION_PENDING, event);
121 ImageButton::OnGestureEvent(event); 125 ImageButton::OnGestureEvent(event);
122 break; 126 break;
123 case ui::ET_GESTURE_TAP_CANCEL: 127 case ui::ET_GESTURE_TAP_CANCEL:
124 case ui::ET_GESTURE_TAP: 128 case ui::ET_GESTURE_TAP:
125 if (touch_feedback) 129 if (touch_feedback)
126 SetDrawBackgroundAsActive(false); 130 SetDrawBackgroundAsActive(false);
127 ImageButton::OnGestureEvent(event); 131 ImageButton::OnGestureEvent(event);
128 break; 132 break;
129 default: 133 default:
(...skipping 21 matching lines...) Expand all
151 155
152 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); 156 views::Painter::PaintFocusPainter(this, canvas, focus_painter());
153 } 157 }
154 158
155 void AppListButton::PaintBackgroundMD(gfx::Canvas* canvas) { 159 void AppListButton::PaintBackgroundMD(gfx::Canvas* canvas) {
156 SkPaint background_paint; 160 SkPaint background_paint;
157 background_paint.setColor(SK_ColorTRANSPARENT); 161 background_paint.setColor(SK_ColorTRANSPARENT);
158 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 162 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
159 background_paint.setStyle(SkPaint::kFill_Style); 163 background_paint.setStyle(SkPaint::kFill_Style);
160 164
161 const ShelfWidget* shelf_widget = shelf_view_->shelf()->shelf_widget(); 165 if (wm_shelf_->GetBackgroundType() ==
162 if (shelf_widget && 166 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) {
163 shelf_widget->GetBackgroundType() ==
164 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) {
165 background_paint.setColor( 167 background_paint.setColor(
166 SkColorSetA(kShelfBaseColor, GetShelfConstant(SHELF_BACKGROUND_ALPHA))); 168 SkColorSetA(kShelfBaseColor, GetShelfConstant(SHELF_BACKGROUND_ALPHA)));
167 } 169 }
168 170
169 // Paint the circular background of AppList button. 171 // Paint the circular background of AppList button.
170 gfx::Point circle_center = GetContentsBounds().CenterPoint(); 172 gfx::Point circle_center = GetContentsBounds().CenterPoint();
171 if (!IsHorizontalAlignment(shelf_view_->shelf()->alignment())) 173 if (!IsHorizontalAlignment(wm_shelf_->GetAlignment()))
172 circle_center = gfx::Point(circle_center.y(), circle_center.x()); 174 circle_center = gfx::Point(circle_center.y(), circle_center.x());
173 175
174 canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint); 176 canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint);
175 } 177 }
176 178
177 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas, 179 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas,
178 const gfx::ImageSkia& foreground_image) { 180 const gfx::ImageSkia& foreground_image) {
179 gfx::Rect foreground_bounds(foreground_image.size()); 181 gfx::Rect foreground_bounds(foreground_image.size());
180 gfx::Rect contents_bounds = GetContentsBounds(); 182 gfx::Rect contents_bounds = GetContentsBounds();
181 183
182 if (IsHorizontalAlignment(shelf_view_->shelf()->alignment())) { 184 if (IsHorizontalAlignment(wm_shelf_->GetAlignment())) {
183 foreground_bounds.set_x( 185 foreground_bounds.set_x(
184 (contents_bounds.width() - foreground_bounds.width()) / 2); 186 (contents_bounds.width() - foreground_bounds.width()) / 2);
185 foreground_bounds.set_y( 187 foreground_bounds.set_y(
186 (contents_bounds.height() - foreground_bounds.height()) / 2); 188 (contents_bounds.height() - foreground_bounds.height()) / 2);
187 } else { 189 } else {
188 foreground_bounds.set_x( 190 foreground_bounds.set_x(
189 (contents_bounds.height() - foreground_bounds.height()) / 2); 191 (contents_bounds.height() - foreground_bounds.height()) / 2);
190 foreground_bounds.set_y( 192 foreground_bounds.set_y(
191 (contents_bounds.width() - foreground_bounds.width()) / 2); 193 (contents_bounds.width() - foreground_bounds.width()) / 2);
192 } 194 }
193 canvas->DrawImageInt(foreground_image, foreground_bounds.x(), 195 canvas->DrawImageInt(foreground_image, foreground_bounds.x(),
194 foreground_bounds.y()); 196 foreground_bounds.y());
195 } 197 }
196 198
197 void AppListButton::PaintAppListButton(gfx::Canvas* canvas, 199 void AppListButton::PaintAppListButton(gfx::Canvas* canvas,
198 const gfx::ImageSkia& foreground_image) { 200 const gfx::ImageSkia& foreground_image) {
199 int background_image_id = 0; 201 int background_image_id = 0;
200 202
201 if (Shell::GetInstance()->GetAppListTargetVisibility() || 203 if (WmShell::Get()->GetAppListTargetVisibility() ||
202 draw_background_as_active_) { 204 draw_background_as_active_) {
203 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; 205 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
204 } else { 206 } else {
205 if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf()) { 207 if (wm_shelf_->IsDimmed()) {
206 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; 208 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
207 } else { 209 } else {
208 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; 210 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
209 } 211 }
210 } 212 }
211 213
212 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 214 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
213 gfx::ImageSkia background_image = 215 gfx::ImageSkia background_image =
214 *rb.GetImageNamed(background_image_id).ToImageSkia(); 216 *rb.GetImageNamed(background_image_id).ToImageSkia();
215 gfx::Rect background_bounds(background_image.size()); 217 gfx::Rect background_bounds(background_image.size());
216 ShelfAlignment alignment = shelf_view_->shelf()->alignment(); 218 ShelfAlignment alignment = wm_shelf_->GetAlignment();
217 gfx::Rect contents_bounds = GetContentsBounds(); 219 gfx::Rect contents_bounds = GetContentsBounds();
218 220
219 if (alignment == SHELF_ALIGNMENT_LEFT) { 221 if (alignment == SHELF_ALIGNMENT_LEFT) {
220 background_bounds.set_x(contents_bounds.width() - kShelfItemInset - 222 background_bounds.set_x(contents_bounds.width() - kShelfItemInset -
221 background_image.width()); 223 background_image.width());
222 background_bounds.set_y( 224 background_bounds.set_y(
223 contents_bounds.y() + 225 contents_bounds.y() +
224 (contents_bounds.height() - background_image.height()) / 2); 226 (contents_bounds.height() - background_image.height()) / 2);
225 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { 227 } else if (alignment == SHELF_ALIGNMENT_RIGHT) {
226 background_bounds.set_x(kShelfItemInset); 228 background_bounds.set_x(kShelfItemInset);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 270
269 void AppListButton::NotifyClick(const ui::Event& event) { 271 void AppListButton::NotifyClick(const ui::Event& event) {
270 ImageButton::NotifyClick(event); 272 ImageButton::NotifyClick(event);
271 if (listener_) 273 if (listener_)
272 listener_->ButtonPressed(this, event, ink_drop()); 274 listener_->ButtonPressed(this, event, ink_drop());
273 } 275 }
274 276
275 bool AppListButton::ShouldEnterPushedState(const ui::Event& event) { 277 bool AppListButton::ShouldEnterPushedState(const ui::Event& event) {
276 if (!shelf_view_->ShouldEventActivateButton(this, event)) 278 if (!shelf_view_->ShouldEventActivateButton(this, event))
277 return false; 279 return false;
278 if (Shell::GetInstance()->IsApplistVisible()) 280 if (WmShell::Get()->IsApplistVisible())
279 return false; 281 return false;
280 return views::ImageButton::ShouldEnterPushedState(event); 282 return views::ImageButton::ShouldEnterPushedState(event);
281 } 283 }
282 284
283 bool AppListButton::ShouldShowInkDropHighlight() const { 285 bool AppListButton::ShouldShowInkDropHighlight() const {
284 return false; 286 return false;
285 } 287 }
286 288
287 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) { 289 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) {
288 if (draw_background_as_active_ == draw_background_as_active) 290 if (draw_background_as_active_ == draw_background_as_active)
289 return; 291 return;
290 draw_background_as_active_ = draw_background_as_active; 292 draw_background_as_active_ = draw_background_as_active;
291 SchedulePaint(); 293 SchedulePaint();
292 } 294 }
293 295
294 } // namespace ash 296 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/app_list_button.h ('k') | ash/common/shelf/app_list_shelf_item_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698