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

Side by Side Diff: ash/system/status_area_widget_delegate.cc

Issue 2099103002: Give Ash material design tray items the correct size and layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for review 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/system/status_area_widget_delegate.h" 5 #include "ash/system/status_area_widget_delegate.h"
6 6
7 #include "ash/ash_export.h" 7 #include "ash/ash_export.h"
8 #include "ash/common/ash_switches.h" 8 #include "ash/common/ash_switches.h"
9 #include "ash/common/focus_cycler.h" 9 #include "ash/common/focus_cycler.h"
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 UpdateLayout(); 176 UpdateLayout();
177 } 177 }
178 178
179 void StatusAreaWidgetDelegate::UpdateWidgetSize() { 179 void StatusAreaWidgetDelegate::UpdateWidgetSize() {
180 if (GetWidget()) 180 if (GetWidget())
181 GetWidget()->SetSize(GetPreferredSize()); 181 GetWidget()->SetSize(GetPreferredSize());
182 } 182 }
183 183
184 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child, 184 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child,
185 bool extend_border_to_edge) { 185 bool extend_border_to_edge) {
186 const int shelf_size = GetShelfConstant(SHELF_SIZE);
187 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
186 int top_edge, left_edge, bottom_edge, right_edge; 188 int top_edge, left_edge, bottom_edge, right_edge;
187 // Tray views are laid out right-to-left or bottom-to-top 189
190 // Tray views are laid out right-to-left or bottom-to-top.
188 if (MaterialDesignController::IsShelfMaterial()) { 191 if (MaterialDesignController::IsShelfMaterial()) {
189 if (extend_border_to_edge) { 192 const bool horizontal_alignment = IsHorizontalAlignment(alignment_);
190 if (IsHorizontalAlignment(alignment_)) { 193 const int padding = (shelf_size - item_height) / 2;
191 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; 194 const int extended_padding =
192 left_edge = 0; 195 GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF);
193 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; 196
194 right_edge = GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF); 197 top_edge = horizontal_alignment ? padding : 0;
195 } else { 198 left_edge = horizontal_alignment ? 0 : padding;
196 top_edge = 0; 199 bottom_edge = horizontal_alignment
197 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; 200 ? padding
198 bottom_edge = GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF); 201 : (extend_border_to_edge ? extended_padding : 0);
199 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2; 202 right_edge = horizontal_alignment
200 } 203 ? (extend_border_to_edge ? extended_padding : 0)
201 } else { 204 : padding;
yiyix 2016/06/27 18:39:43 Nice simplification!
tdanderson 2016/06/27 21:29:42 Thanks!
202 if (IsHorizontalAlignment(alignment_)) {
203 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
204 left_edge = 0;
205 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
206 right_edge = 0;
207 } else {
208 top_edge = 0;
209 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
210 bottom_edge = 0;
211 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
212 }
213 }
214 } else { 205 } else {
215 bool on_edge = (child == child_at(0)); 206 bool on_edge = (child == child_at(0));
216 if (IsHorizontalAlignment(alignment_)) { 207 if (IsHorizontalAlignment(alignment_)) {
217 top_edge = kShelfItemInset; 208 top_edge = kShelfItemInset;
218 left_edge = 0; 209 left_edge = 0;
219 bottom_edge = 210 bottom_edge = shelf_size - kShelfItemInset - item_height;
220 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
221 right_edge = 211 right_edge =
222 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; 212 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
223 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) { 213 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) {
224 top_edge = 0; 214 top_edge = 0;
225 left_edge = 215 left_edge = shelf_size - kShelfItemInset - item_height;
226 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
227 bottom_edge = 216 bottom_edge =
228 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; 217 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
229 right_edge = kShelfItemInset; 218 right_edge = kShelfItemInset;
230 } else { // SHELF_ALIGNMENT_RIGHT 219 } else { // SHELF_ALIGNMENT_RIGHT
231 top_edge = 0; 220 top_edge = 0;
232 left_edge = kShelfItemInset; 221 left_edge = kShelfItemInset;
233 bottom_edge = 222 bottom_edge =
234 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; 223 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
235 right_edge = 224 right_edge = shelf_size - kShelfItemInset - item_height;
236 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
237 } 225 }
238 } 226 }
239 child->SetBorder(views::Border::CreateEmptyBorder(top_edge, left_edge, 227 child->SetBorder(views::Border::CreateEmptyBorder(top_edge, left_edge,
240 bottom_edge, right_edge)); 228 bottom_edge, right_edge));
241 } 229 }
242 230
243 } // namespace ash 231 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698