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

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: 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/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"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "grit/ash_resources.h" 15 #include "grit/ash_resources.h"
15 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
16 #include "ui/accessibility/ax_view_state.h" 17 #include "ui/accessibility/ax_view_state.h"
17 #include "ui/app_list/app_list_switches.h" 18 #include "ui/app_list/app_list_switches.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/base/ui_base_switches_util.h" 21 #include "ui/base/ui_base_switches_util.h"
21 #include "ui/gfx/canvas.h" 22 #include "ui/gfx/canvas.h"
22 #include "ui/views/painter.h" 23 #include "ui/views/painter.h"
23 24
24 namespace ash { 25 namespace ash {
25 26
26 AppListButton::AppListButton(ShelfView* shelf_view) 27 AppListButton::AppListButton(ShelfView* shelf_view)
27 : views::ImageButton(shelf_view), 28 : views::ImageButton(shelf_view),
28 draw_background_as_active_(false), 29 draw_background_as_active_(false),
29 shelf_view_(shelf_view) { 30 shelf_view_(shelf_view) {
30 SetAccessibleName( 31 SetAccessibleName(
31 app_list::switches::IsExperimentalAppListEnabled() 32 app_list::switches::IsExperimentalAppListEnabled()
32 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) 33 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)
33 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); 34 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE));
34 SetSize(gfx::Size(kShelfSize, kShelfSize)); 35 SetSize(gfx::Size(GetShelfLayoutConstant(SHELF_SIZE),
36 GetShelfLayoutConstant(SHELF_SIZE)));
35 SetFocusPainter(views::Painter::CreateSolidFocusPainter( 37 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
36 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); 38 kFocusBorderColor, gfx::Insets(1, 1, 1, 1)));
37 set_notify_action(CustomButton::NOTIFY_ON_PRESS); 39 set_notify_action(CustomButton::NOTIFY_ON_PRESS);
38 } 40 }
39 41
40 AppListButton::~AppListButton() {} 42 AppListButton::~AppListButton() {}
41 43
42 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { 44 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) {
43 ImageButton::OnMousePressed(event); 45 ImageButton::OnMousePressed(event);
44 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); 46 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 120 ? IDR_ASH_SHELF_ICON_APPLIST
119 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC; 121 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC;
120 const gfx::ImageSkia* forground_image = 122 const gfx::ImageSkia* forground_image =
121 rb.GetImageNamed(foreground_image_id).ToImageSkia(); 123 rb.GetImageNamed(foreground_image_id).ToImageSkia();
122 124
123 gfx::Rect contents_bounds = GetContentsBounds(); 125 gfx::Rect contents_bounds = GetContentsBounds();
124 gfx::Rect background_bounds, forground_bounds; 126 gfx::Rect background_bounds, forground_bounds;
125 127
126 wm::ShelfAlignment alignment = shelf_view_->shelf()->alignment(); 128 wm::ShelfAlignment alignment = shelf_view_->shelf()->alignment();
127 background_bounds.set_size(background_image->size()); 129 background_bounds.set_size(background_image->size());
128 if (alignment == wm::SHELF_ALIGNMENT_LEFT) { 130
129 background_bounds.set_x(contents_bounds.width() - 131 // If Material Design for Chrome OS shelf is enabled.
130 ShelfLayoutManager::kShelfItemInset - background_image->width()); 132 if (MaterialDesignController::IsShelfMaterial()) {
131 background_bounds.set_y(contents_bounds.y() + 133 if (alignment == wm::SHELF_ALIGNMENT_LEFT ||
132 (contents_bounds.height() - background_image->height()) / 2); 134 alignment == wm::SHELF_ALIGNMENT_RIGHT) {
133 } else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) { 135 background_bounds.set_x(
134 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); 136 (contents_bounds.width() - background_image->width()) / 2);
135 background_bounds.set_y(contents_bounds.y() + 137 background_bounds.set_y(
136 (contents_bounds.height() - background_image->height()) / 2); 138 contents_bounds.y() + ShelfLayoutManager::GetShelfItemInset(
139 ShelfLayoutManager::SHELF_ITEM_INSET) +
140 (contents_bounds.height() - background_image->height()) / 2);
141 } else { // SHELF_ALIGNMENT_BOTTOM
142 background_bounds.set_y(
143 (contents_bounds.height() - background_image->height()) / 2);
144 background_bounds.set_x(
145 contents_bounds.x() +
146 (contents_bounds.width() - background_image->width()) / 2 +
147 ShelfLayoutManager::GetShelfItemInset(
148 ShelfLayoutManager::SHELF_ITEM_INSET));
149 }
137 } else { 150 } else {
138 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); 151 if (alignment == wm::SHELF_ALIGNMENT_LEFT) {
139 background_bounds.set_x(contents_bounds.x() + 152 background_bounds.set_x(contents_bounds.width() -
140 (contents_bounds.width() - background_image->width()) / 2); 153 ShelfLayoutManager::GetShelfItemInset(
154 ShelfLayoutManager::SHELF_ITEM_INSET) -
155 background_image->width());
156 background_bounds.set_y(
157 contents_bounds.y() +
158 (contents_bounds.height() - background_image->height()) / 2);
159 } else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) {
160 background_bounds.set_x(ShelfLayoutManager::GetShelfItemInset(
161 ShelfLayoutManager::SHELF_ITEM_INSET));
162 background_bounds.set_y(
163 contents_bounds.y() +
164 (contents_bounds.height() - background_image->height()) / 2);
165 } else { // SHELF_ALIGNMENT_BOTTOM
166 background_bounds.set_y(ShelfLayoutManager::GetShelfItemInset(
167 ShelfLayoutManager::SHELF_ITEM_INSET));
168 background_bounds.set_x(
169 contents_bounds.x() +
170 (contents_bounds.width() - background_image->width()) / 2);
171 }
141 } 172 }
142 173
143 forground_bounds.set_size(forground_image->size()); 174 forground_bounds.set_size(forground_image->size());
144 forground_bounds.set_x(background_bounds.x() + 175 forground_bounds.set_x(background_bounds.x() +
145 std::max(0, 176 std::max(0,
146 (background_bounds.width() - forground_bounds.width()) / 2)); 177 (background_bounds.width() - forground_bounds.width()) / 2));
147 forground_bounds.set_y(background_bounds.y() + 178 forground_bounds.set_y(background_bounds.y() +
148 std::max(0, 179 std::max(0,
149 (background_bounds.height() - forground_bounds.height()) / 2)); 180 (background_bounds.height() - forground_bounds.height()) / 2));
150 181
(...skipping 14 matching lines...) Expand all
165 196
166 void AppListButton::SetDrawBackgroundAsActive( 197 void AppListButton::SetDrawBackgroundAsActive(
167 bool draw_background_as_active) { 198 bool draw_background_as_active) {
168 if (draw_background_as_active_ == draw_background_as_active) 199 if (draw_background_as_active_ == draw_background_as_active)
169 return; 200 return;
170 draw_background_as_active_ = draw_background_as_active; 201 draw_background_as_active_ = draw_background_as_active;
171 SchedulePaint(); 202 SchedulePaint();
172 } 203 }
173 204
174 } // namespace ash 205 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698