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

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

Issue 1998933002: Update shelf spacing in Chrome OS according to the MD specs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments & Refactor border around item implementation Created 4 years, 6 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/material_design/material_design_controller.h"
8 #include "ash/shelf/shelf_item_types.h" 9 #include "ash/shelf/shelf_item_types.h"
9 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_view.h" 11 #include "ash/shelf/shelf_view.h"
11 #include "ash/shelf/shelf_widget.h" 12 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/wm/common/shelf/wm_shelf_util.h"
13 #include "base/command_line.h" 15 #include "base/command_line.h"
14 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
15 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
16 #include "ui/accessibility/ax_view_state.h" 18 #include "ui/accessibility/ax_view_state.h"
17 #include "ui/app_list/app_list_switches.h" 19 #include "ui/app_list/app_list_switches.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/base/ui_base_switches_util.h" 22 #include "ui/base/ui_base_switches_util.h"
21 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
22 #include "ui/views/painter.h" 24 #include "ui/views/painter.h"
23 25
24 namespace ash { 26 namespace ash {
25 27
26 AppListButton::AppListButton(ShelfView* shelf_view) 28 AppListButton::AppListButton(ShelfView* shelf_view)
27 : views::ImageButton(shelf_view), 29 : views::ImageButton(shelf_view),
28 draw_background_as_active_(false), 30 draw_background_as_active_(false),
29 shelf_view_(shelf_view) { 31 shelf_view_(shelf_view) {
30 SetAccessibleName( 32 SetAccessibleName(
31 app_list::switches::IsExperimentalAppListEnabled() 33 app_list::switches::IsExperimentalAppListEnabled()
32 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) 34 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)
33 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); 35 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE));
34 SetSize(gfx::Size(kShelfSize, kShelfSize)); 36 SetSize(gfx::Size(GetShelfLayoutConstant(SHELF_SIZE),
37 GetShelfLayoutConstant(SHELF_SIZE)));
35 SetFocusPainter(views::Painter::CreateSolidFocusPainter( 38 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
36 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); 39 kFocusBorderColor, gfx::Insets(1, 1, 1, 1)));
37 set_notify_action(CustomButton::NOTIFY_ON_PRESS); 40 set_notify_action(CustomButton::NOTIFY_ON_PRESS);
38 } 41 }
39 42
40 AppListButton::~AppListButton() {} 43 AppListButton::~AppListButton() {}
41 44
42 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { 45 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
43 ImageButton::OnMousePressed(event); 46 ImageButton::OnMousePressed(event);
44 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); 47 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 ? IDR_ASH_SHELF_ICON_APPLIST 121 ? IDR_ASH_SHELF_ICON_APPLIST
119 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC; 122 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC;
120 const gfx::ImageSkia* forground_image = 123 const gfx::ImageSkia* forground_image =
121 rb.GetImageNamed(foreground_image_id).ToImageSkia(); 124 rb.GetImageNamed(foreground_image_id).ToImageSkia();
122 125
123 gfx::Rect contents_bounds = GetContentsBounds(); 126 gfx::Rect contents_bounds = GetContentsBounds();
124 gfx::Rect background_bounds, forground_bounds; 127 gfx::Rect background_bounds, forground_bounds;
125 128
126 wm::ShelfAlignment alignment = shelf_view_->shelf()->alignment(); 129 wm::ShelfAlignment alignment = shelf_view_->shelf()->alignment();
127 background_bounds.set_size(background_image->size()); 130 background_bounds.set_size(background_image->size());
128 if (alignment == wm::SHELF_ALIGNMENT_LEFT) { 131
129 background_bounds.set_x(contents_bounds.width() - 132 if (MaterialDesignController::IsShelfMaterial()) {
130 ShelfLayoutManager::kShelfItemInset - background_image->width()); 133 // SHELF_ALIGHTMENT_RIGHT AND SHELF_ALIGHMENT_LEFT
tdanderson 2016/06/03 19:25:23 nit: comment not needed
yiyix 2016/06/10 19:26:04 Done.
131 background_bounds.set_y(contents_bounds.y() + 134 if (!wm::IsHorizontalAlignment(alignment)) {
tdanderson 2016/06/03 19:25:23 super nit: swap if/else to structure this as: if
yiyix 2016/06/10 19:26:04 Done.
132 (contents_bounds.height() - background_image->height()) / 2); 135 background_bounds.set_x(
133 } else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) { 136 (contents_bounds.width() - background_image->width()) / 2);
134 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); 137 background_bounds.set_y(
135 background_bounds.set_y(contents_bounds.y() + 138 contents_bounds.y() +
136 (contents_bounds.height() - background_image->height()) / 2); 139 (contents_bounds.height() - background_image->height()) / 2);
140 } else { // SHELF_ALIGNMENT_BOTTOM
tdanderson 2016/06/03 19:25:23 nit: remove comment
yiyix 2016/06/10 19:26:04 Done.
141 background_bounds.set_y(
142 (contents_bounds.height() - background_image->height()) / 2);
143 background_bounds.set_x(
144 contents_bounds.x() +
145 (contents_bounds.width() - background_image->width()) / 2);
146 }
137 } else { 147 } else {
138 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); 148 if (alignment == wm::SHELF_ALIGNMENT_LEFT) {
139 background_bounds.set_x(contents_bounds.x() + 149 background_bounds.set_x(contents_bounds.width() - kShelfItemInset -
140 (contents_bounds.width() - background_image->width()) / 2); 150 background_image->width());
151 background_bounds.set_y(
152 contents_bounds.y() +
153 (contents_bounds.height() - background_image->height()) / 2);
154 } else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) {
155 background_bounds.set_x(kShelfItemInset);
156 background_bounds.set_y(
157 contents_bounds.y() +
158 (contents_bounds.height() - background_image->height()) / 2);
159 } else { // SHELF_ALIGNMENT_BOTTOM
160 background_bounds.set_y(kShelfItemInset);
161 background_bounds.set_x(
162 contents_bounds.x() +
163 (contents_bounds.width() - background_image->width()) / 2);
164 }
141 } 165 }
142 166
143 forground_bounds.set_size(forground_image->size()); 167 forground_bounds.set_size(forground_image->size());
144 forground_bounds.set_x(background_bounds.x() + 168 forground_bounds.set_x(background_bounds.x() +
145 std::max(0, 169 std::max(0,
146 (background_bounds.width() - forground_bounds.width()) / 2)); 170 (background_bounds.width() - forground_bounds.width()) / 2));
147 forground_bounds.set_y(background_bounds.y() + 171 forground_bounds.set_y(background_bounds.y() +
148 std::max(0, 172 std::max(0,
149 (background_bounds.height() - forground_bounds.height()) / 2)); 173 (background_bounds.height() - forground_bounds.height()) / 2));
150 174
(...skipping 14 matching lines...) Expand all
165 189
166 void AppListButton::SetDrawBackgroundAsActive( 190 void AppListButton::SetDrawBackgroundAsActive(
167 bool draw_background_as_active) { 191 bool draw_background_as_active) {
168 if (draw_background_as_active_ == draw_background_as_active) 192 if (draw_background_as_active_ == draw_background_as_active)
169 return; 193 return;
170 draw_background_as_active_ = draw_background_as_active; 194 draw_background_as_active_ = draw_background_as_active;
171 SchedulePaint(); 195 SchedulePaint();
172 } 196 }
173 197
174 } // namespace ash 198 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698