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

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

Issue 2002293002: Use vector icon for Ash shelf launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove include Created 4 years, 7 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
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/shelf/app_list_button.h"
6 6
7 #include "ash/ash_constants.h" 7 #include "ash/ash_constants.h"
8 #include "ash/shelf/shelf_item_types.h" 8 #include "ash/shelf/shelf_item_types.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_view.h" 10 #include "ash/shelf/shelf_view.h"
11 #include "ash/shelf/shelf_widget.h" 11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "grit/ash_resources.h" 14 #include "grit/ash_resources.h"
15 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
16 #include "ui/accessibility/ax_view_state.h" 16 #include "ui/accessibility/ax_view_state.h"
17 #include "ui/app_list/app_list_switches.h" 17 #include "ui/app_list/app_list_switches.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/base/ui_base_switches_util.h" 20 #include "ui/base/ui_base_switches_util.h"
21 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/paint_vector_icon.h"
23 #include "ui/gfx/vector_icons_public.h"
22 #include "ui/views/painter.h" 24 #include "ui/views/painter.h"
23 25
26 namespace {
27 // Width and height of the launcher icon, which includes 2px of internal
28 // padding at each side.
29 const int kLauncherIconSize = 18;
tdanderson 2016/05/23 21:18:24 So if I remember our conversation correctly, the v
Evan Stade 2016/05/23 22:11:57 Overall, yes. One way to add to the padding would
30
31 // Color of the launcher icon.
32 // TODO(tdanderson): Move Ash color constants to a common location.
33 const SkColor kLauncherIconColor = SK_ColorWHITE;
34 } // namespace
35
24 namespace ash { 36 namespace ash {
25 37
26 AppListButton::AppListButton(ShelfView* shelf_view) 38 AppListButton::AppListButton(ShelfView* shelf_view)
27 : views::ImageButton(shelf_view), 39 : views::ImageButton(shelf_view),
28 draw_background_as_active_(false), 40 draw_background_as_active_(false),
29 shelf_view_(shelf_view) { 41 shelf_view_(shelf_view) {
30 SetAccessibleName( 42 SetAccessibleName(
31 app_list::switches::IsExperimentalAppListEnabled() 43 app_list::switches::IsExperimentalAppListEnabled()
32 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) 44 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)
33 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); 45 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 int background_image_id = 0; 114 int background_image_id = 0;
103 if (Shell::GetInstance()->GetAppListTargetVisibility() || 115 if (Shell::GetInstance()->GetAppListTargetVisibility() ||
104 draw_background_as_active_) { 116 draw_background_as_active_) {
105 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; 117 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
106 } else { 118 } else {
107 if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf()) 119 if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf())
108 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; 120 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
109 else 121 else
110 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; 122 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
111 } 123 }
124
112 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 125 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
113 const gfx::ImageSkia* background_image = 126 const gfx::ImageSkia* background_image =
114 rb.GetImageNamed(background_image_id).ToImageSkia(); 127 rb.GetImageNamed(background_image_id).ToImageSkia();
115 // TODO(mgiuca): When the "classic" app list is removed, also remove this 128
116 // resource and its icon file. 129 const gfx::ImageSkia& foreground_image =
117 int foreground_image_id = app_list::switches::IsExperimentalAppListEnabled() 130 gfx::CreateVectorIcon(gfx::VectorIconId::SEARCH,
118 ? IDR_ASH_SHELF_ICON_APPLIST 131 kLauncherIconSize, kLauncherIconColor);
119 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC;
120 const gfx::ImageSkia* forground_image =
121 rb.GetImageNamed(foreground_image_id).ToImageSkia();
122 132
123 gfx::Rect contents_bounds = GetContentsBounds(); 133 gfx::Rect contents_bounds = GetContentsBounds();
124 gfx::Rect background_bounds, forground_bounds; 134 gfx::Rect background_bounds, foreground_bounds;
125 135
126 wm::ShelfAlignment alignment = shelf_view_->shelf()->alignment(); 136 wm::ShelfAlignment alignment = shelf_view_->shelf()->alignment();
127 background_bounds.set_size(background_image->size()); 137 background_bounds.set_size(background_image->size());
128 if (alignment == wm::SHELF_ALIGNMENT_LEFT) { 138 if (alignment == wm::SHELF_ALIGNMENT_LEFT) {
129 background_bounds.set_x(contents_bounds.width() - 139 background_bounds.set_x(contents_bounds.width() -
130 ShelfLayoutManager::kShelfItemInset - background_image->width()); 140 ShelfLayoutManager::kShelfItemInset - background_image->width());
131 background_bounds.set_y(contents_bounds.y() + 141 background_bounds.set_y(contents_bounds.y() +
132 (contents_bounds.height() - background_image->height()) / 2); 142 (contents_bounds.height() - background_image->height()) / 2);
133 } else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) { 143 } else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) {
134 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); 144 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset);
135 background_bounds.set_y(contents_bounds.y() + 145 background_bounds.set_y(contents_bounds.y() +
136 (contents_bounds.height() - background_image->height()) / 2); 146 (contents_bounds.height() - background_image->height()) / 2);
137 } else { 147 } else {
138 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); 148 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset);
139 background_bounds.set_x(contents_bounds.x() + 149 background_bounds.set_x(contents_bounds.x() +
140 (contents_bounds.width() - background_image->width()) / 2); 150 (contents_bounds.width() - background_image->width()) / 2);
141 } 151 }
142 152
143 forground_bounds.set_size(forground_image->size()); 153 foreground_bounds.set_size(foreground_image.size());
144 forground_bounds.set_x(background_bounds.x() + 154 foreground_bounds.set_x(background_bounds.x() +
145 std::max(0, 155 std::max(0,
146 (background_bounds.width() - forground_bounds.width()) / 2)); 156 (background_bounds.width() - foreground_bounds.width()) / 2));
147 forground_bounds.set_y(background_bounds.y() + 157 foreground_bounds.set_y(background_bounds.y() +
148 std::max(0, 158 std::max(0,
149 (background_bounds.height() - forground_bounds.height()) / 2)); 159 (background_bounds.height() - foreground_bounds.height()) / 2));
150 160
151 canvas->DrawImageInt(*background_image, 161 canvas->DrawImageInt(*background_image,
152 background_bounds.x(), 162 background_bounds.x(),
153 background_bounds.y()); 163 background_bounds.y());
154 canvas->DrawImageInt(*forground_image, 164 canvas->DrawImageInt(foreground_image,
155 forground_bounds.x(), 165 foreground_bounds.x(),
156 forground_bounds.y()); 166 foreground_bounds.y());
157 167
158 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); 168 views::Painter::PaintFocusPainter(this, canvas, focus_painter());
159 } 169 }
160 170
161 void AppListButton::GetAccessibleState(ui::AXViewState* state) { 171 void AppListButton::GetAccessibleState(ui::AXViewState* state) {
162 state->role = ui::AX_ROLE_BUTTON; 172 state->role = ui::AX_ROLE_BUTTON;
163 state->name = shelf_view_->GetTitleForView(this); 173 state->name = shelf_view_->GetTitleForView(this);
164 } 174 }
165 175
166 void AppListButton::SetDrawBackgroundAsActive( 176 void AppListButton::SetDrawBackgroundAsActive(
167 bool draw_background_as_active) { 177 bool draw_background_as_active) {
168 if (draw_background_as_active_ == draw_background_as_active) 178 if (draw_background_as_active_ == draw_background_as_active)
169 return; 179 return;
170 draw_background_as_active_ = draw_background_as_active; 180 draw_background_as_active_ = draw_background_as_active;
171 SchedulePaint(); 181 SchedulePaint();
172 } 182 }
173 183
174 } // namespace ash 184 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698