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/system/status_area_widget_delegate.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: fix tests 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 (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/ash_switches.h" 8 #include "ash/ash_switches.h"
9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/shelf/shelf_constants.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 11 #include "ash/common/shelf/wm_shelf_util.h"
10 #include "ash/common/shell_window_ids.h" 12 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/system/tray/tray_constants.h" 13 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/focus_cycler.h" 14 #include "ash/focus_cycler.h"
13 #include "ash/shelf/shelf_util.h" 15 #include "ash/shelf/shelf_util.h"
14 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "ash/system/tray/tray_background_view.h"
James Cook 2016/06/13 21:43:17 Do you need this include?
yiyix 2016/06/14 05:55:26 Done.
15 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
16 #include "ui/aura/window_event_dispatcher.h" 19 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/compositor/layer.h" 20 #include "ui/compositor/layer.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h" 21 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/gfx/animation/tween.h" 22 #include "ui/gfx/animation/tween.h"
20 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
22 #include "ui/views/accessible_pane_view.h" 25 #include "ui/views/accessible_pane_view.h"
23 #include "ui/views/layout/grid_layout.h" 26 #include "ui/views/layout/grid_layout.h"
24 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Set the layout manager with the new list of children. 108 // Set the layout manager with the new list of children.
106 UpdateLayout(); 109 UpdateLayout();
107 } 110 }
108 111
109 void StatusAreaWidgetDelegate::UpdateLayout() { 112 void StatusAreaWidgetDelegate::UpdateLayout() {
110 // Use a grid layout so that the trays can be centered in each cell, and 113 // Use a grid layout so that the trays can be centered in each cell, and
111 // so that the widget gets laid out correctly when tray sizes change. 114 // so that the widget gets laid out correctly when tray sizes change.
112 views::GridLayout* layout = new views::GridLayout(this); 115 views::GridLayout* layout = new views::GridLayout(this);
113 SetLayoutManager(layout); 116 SetLayoutManager(layout);
114 117
118 // Update tray border based on layout.
119 bool is_child_on_edge = true;
120 for (int c = 0; c < child_count(); ++c) {
121 views::View* child = child_at(c);
122 if (!child->visible())
123 continue;
124 SetBorderOnChild(child, is_child_on_edge);
125 is_child_on_edge = false;
126 }
127
115 views::ColumnSet* columns = layout->AddColumnSet(0); 128 views::ColumnSet* columns = layout->AddColumnSet(0);
129
116 if (IsHorizontalAlignment(alignment_)) { 130 if (IsHorizontalAlignment(alignment_)) {
117 bool is_first_visible_child = true; 131 bool is_first_visible_child = true;
118 for (int c = 0; c < child_count(); ++c) { 132 for (int c = child_count() - 1; c >= 0; --c) {
119 views::View* child = child_at(c); 133 views::View* child = child_at(c);
120 if (!child->visible()) 134 if (!child->visible())
121 continue; 135 continue;
122 if (!is_first_visible_child) 136 if (!is_first_visible_child)
123 columns->AddPaddingColumn(0, kTraySpacing); 137 columns->AddPaddingColumn(0, GetTrayConstant(TRAY_SPACING));
124 is_first_visible_child = false; 138 is_first_visible_child = false;
125 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 139 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL,
126 0, /* resize percent */ 140 0, /* resize percent */
127 views::GridLayout::USE_PREF, 0, 0); 141 views::GridLayout::USE_PREF, 0, 0);
128 } 142 }
129 layout->StartRow(0, 0); 143 layout->StartRow(0, 0);
130 for (int c = child_count() - 1; c >= 0; --c) { 144 for (int c = child_count() - 1; c >= 0; --c) {
131 views::View* child = child_at(c); 145 views::View* child = child_at(c);
132 if (child->visible()) 146 if (child->visible())
133 layout->AddView(child); 147 layout->AddView(child);
134 } 148 }
135 } else { 149 } else {
150 bool is_first_visible_child = true;
James Cook 2016/06/13 21:43:17 move this back down to where it was before
yiyix 2016/06/14 05:55:26 Done.
136 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 151 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
137 0, /* resize percent */ 152 0, /* resize percent */
138 views::GridLayout::USE_PREF, 0, 0); 153 views::GridLayout::USE_PREF, 0, 0);
139 bool is_first_visible_child = true;
140 for (int c = child_count() - 1; c >= 0; --c) { 154 for (int c = child_count() - 1; c >= 0; --c) {
141 views::View* child = child_at(c); 155 views::View* child = child_at(c);
142 if (!child->visible()) 156 if (!child->visible())
143 continue; 157 continue;
144 if (!is_first_visible_child) 158 if (!is_first_visible_child)
145 layout->AddPaddingRow(0, kTraySpacing); 159 layout->AddPaddingRow(0, GetTrayConstant(TRAY_SPACING));
146 is_first_visible_child = false; 160 is_first_visible_child = false;
147 layout->StartRow(0, 0); 161 layout->StartRow(0, 0);
148 layout->AddView(child); 162 layout->AddView(child);
149 } 163 }
150 } 164 }
151 165
152 layer()->GetAnimator()->StopAnimating(); 166 layer()->GetAnimator()->StopAnimating();
153 StatusAreaWidgetDelegateAnimationSettings settings(layer()); 167 StatusAreaWidgetDelegateAnimationSettings settings(layer());
154 168
155 Layout(); 169 Layout();
156 UpdateWidgetSize(); 170 UpdateWidgetSize();
157 } 171 }
158 172
159 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { 173 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) {
160 // Need to resize the window when trays or items are added/removed. 174 // Need to resize the window when trays or items are added/removed.
161 StatusAreaWidgetDelegateAnimationSettings settings(layer()); 175 StatusAreaWidgetDelegateAnimationSettings settings(layer());
162 UpdateWidgetSize(); 176 UpdateWidgetSize();
163 } 177 }
164 178
165 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { 179 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) {
166 UpdateLayout(); 180 UpdateLayout();
167 } 181 }
168 182
169 void StatusAreaWidgetDelegate::UpdateWidgetSize() { 183 void StatusAreaWidgetDelegate::UpdateWidgetSize() {
170 if (GetWidget()) 184 if (GetWidget())
171 GetWidget()->SetSize(GetPreferredSize()); 185 GetWidget()->SetSize(GetPreferredSize());
172 } 186 }
173 187
188 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child,
189 bool extend_border_to_edge) {
190 int top_edge, left_edge, bottom_edge, right_edge;
191 // Tray views are laid out right-to-left or bottom-to-top
192 if (MaterialDesignController::IsShelfMaterial()) {
193 if (extend_border_to_edge) {
194 if (IsHorizontalAlignment(alignment_)) {
195 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
196 left_edge = 0;
197 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
198 right_edge = GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF);
199 } else {
200 top_edge = 0;
201 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
202 bottom_edge = GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF);
203 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
204 }
205 } else {
206 if (IsHorizontalAlignment(alignment_)) {
207 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
208 left_edge = 0;
209 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
210 right_edge = 0;
211 } else {
212 top_edge = 0;
213 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
214 bottom_edge = 0;
215 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
216 }
217 }
218 } else {
219 bool on_edge = (child == child_at(0));
220 if (IsHorizontalAlignment(alignment_)) {
221 top_edge = kShelfItemInset;
222 left_edge = 0;
223 bottom_edge =
224 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
225 right_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0;
226 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) {
227 top_edge = 0;
228 left_edge =
229 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
230 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0;
231 right_edge = kShelfItemInset;
232 } else { // SHELF_ALIGNMENT_RIGHT
233 top_edge = 0;
234 left_edge = kShelfItemInset;
235 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0;
236 right_edge =
237 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
238 }
239 }
240 child->SetBorder(views::Border::CreateEmptyBorder(top_edge, left_edge,
241 bottom_edge, right_edge));
242 }
243
174 } // namespace ash 244 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698