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

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: Address comments from @tdanderson 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"
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // We don't want mouse clicks to activate us, but we need to allow 95 // We don't want mouse clicks to activate us, but we need to allow
93 // activation when the user is using the keyboard (FocusCycler). 96 // activation when the user is using the keyboard (FocusCycler).
94 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ? 97 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ?
95 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler(); 98 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler();
96 return focus_cycler->widget_activating() == GetWidget(); 99 return focus_cycler->widget_activating() == GetWidget();
97 } 100 }
98 101
99 void StatusAreaWidgetDelegate::DeleteDelegate() { 102 void StatusAreaWidgetDelegate::DeleteDelegate() {
100 } 103 }
101 104
102 void StatusAreaWidgetDelegate::AddTray(views::View* tray) { 105 void StatusAreaWidgetDelegate::AddTray(TrayBackgroundView* tray) {
tdanderson 2016/06/13 19:02:51 views::View*
yiyix 2016/06/13 19:14:00 Done.
103 SetLayoutManager(NULL); // Reset layout manager before adding a child. 106 SetLayoutManager(NULL); // Reset layout manager before adding a child.
104 AddChildView(tray); 107 AddChildView(tray);
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 if (is_child_on_edge) {
125 SetBorderOnChild(child, true);
126 } else {
127 SetBorderOnChild(child, false);
128 }
tdanderson 2016/06/13 19:02:51 replace lines 124-128 with just SetBorderOnChild(c
yiyix 2016/06/13 19:14:00 haha....lol... that's true, i not using is_child_o
129 is_child_on_edge = false;
130 }
131
115 views::ColumnSet* columns = layout->AddColumnSet(0); 132 views::ColumnSet* columns = layout->AddColumnSet(0);
133
116 if (IsHorizontalAlignment(alignment_)) { 134 if (IsHorizontalAlignment(alignment_)) {
117 bool is_first_visible_child = true; 135 bool is_first_visible_child = true;
118 for (int c = 0; c < child_count(); ++c) { 136 for (int c = child_count() - 1; c >= 0; --c) {
119 views::View* child = child_at(c); 137 views::View* child = child_at(c);
120 if (!child->visible()) 138 if (!child->visible())
121 continue; 139 continue;
122 if (!is_first_visible_child) 140 if (!is_first_visible_child)
123 columns->AddPaddingColumn(0, kTraySpacing); 141 columns->AddPaddingColumn(0, GetTrayConstant(TRAY_SPACING));
124 is_first_visible_child = false; 142 is_first_visible_child = false;
125 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 143 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL,
126 0, /* resize percent */ 144 0, /* resize percent */
127 views::GridLayout::USE_PREF, 0, 0); 145 views::GridLayout::USE_PREF, 0, 0);
128 } 146 }
129 layout->StartRow(0, 0); 147 layout->StartRow(0, 0);
130 for (int c = child_count() - 1; c >= 0; --c) { 148 for (int c = child_count() - 1; c >= 0; --c) {
131 views::View* child = child_at(c); 149 views::View* child = child_at(c);
132 if (child->visible()) 150 if (child->visible())
133 layout->AddView(child); 151 layout->AddView(child);
134 } 152 }
135 } else { 153 } else {
154 bool is_first_visible_child = true;
136 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 155 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
137 0, /* resize percent */ 156 0, /* resize percent */
138 views::GridLayout::USE_PREF, 0, 0); 157 views::GridLayout::USE_PREF, 0, 0);
139 bool is_first_visible_child = true;
140 for (int c = child_count() - 1; c >= 0; --c) { 158 for (int c = child_count() - 1; c >= 0; --c) {
141 views::View* child = child_at(c); 159 views::View* child = child_at(c);
142 if (!child->visible()) 160 if (!child->visible())
143 continue; 161 continue;
144 if (!is_first_visible_child) 162 if (!is_first_visible_child) {
tdanderson 2016/06/13 19:02:51 nit: remove {}
yiyix 2016/06/13 19:14:00 Done.
145 layout->AddPaddingRow(0, kTraySpacing); 163 layout->AddPaddingRow(0, GetTrayConstant(TRAY_SPACING));
164 }
146 is_first_visible_child = false; 165 is_first_visible_child = false;
147 layout->StartRow(0, 0); 166 layout->StartRow(0, 0);
148 layout->AddView(child); 167 layout->AddView(child);
149 } 168 }
150 } 169 }
151 170
152 layer()->GetAnimator()->StopAnimating(); 171 layer()->GetAnimator()->StopAnimating();
153 StatusAreaWidgetDelegateAnimationSettings settings(layer()); 172 StatusAreaWidgetDelegateAnimationSettings settings(layer());
154 173
155 Layout(); 174 Layout();
156 UpdateWidgetSize(); 175 UpdateWidgetSize();
157 } 176 }
158 177
159 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { 178 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) {
160 // Need to resize the window when trays or items are added/removed. 179 // Need to resize the window when trays or items are added/removed.
161 StatusAreaWidgetDelegateAnimationSettings settings(layer()); 180 StatusAreaWidgetDelegateAnimationSettings settings(layer());
162 UpdateWidgetSize(); 181 UpdateWidgetSize();
163 } 182 }
164 183
165 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { 184 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) {
166 UpdateLayout(); 185 UpdateLayout();
167 } 186 }
168 187
169 void StatusAreaWidgetDelegate::UpdateWidgetSize() { 188 void StatusAreaWidgetDelegate::UpdateWidgetSize() {
170 if (GetWidget()) 189 if (GetWidget())
171 GetWidget()->SetSize(GetPreferredSize()); 190 GetWidget()->SetSize(GetPreferredSize());
172 } 191 }
173 192
193 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child,
tdanderson 2016/06/13 19:02:51 Can probably still be split up into helpers. Will
194 bool extend_border_to_edge) {
195 int top_edge, left_edge, bottom_edge, right_edge;
196 // Tray views are laid out right-to-left or bottom-to-top
197 if (MaterialDesignController::IsShelfMaterial()) {
198 if (extend_border_to_edge) {
199 if (IsHorizontalAlignment(alignment_)) {
200 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
201 left_edge = 0;
202 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
203 right_edge = GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF);
204 } else {
205 top_edge = 0;
206 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
207 bottom_edge = GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF);
208 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
209 }
210 } else {
211 if (IsHorizontalAlignment(alignment_)) {
212 top_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
213 left_edge = 0;
214 bottom_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
215 right_edge = 0;
216 } else {
217 top_edge = 0;
218 left_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
219 bottom_edge = 0;
220 right_edge = (GetShelfConstant(SHELF_SIZE) - kShelfItemHeight) / 2;
221 }
222 }
223 } else {
224 bool on_edge = (child == child_at(0));
225 if (IsHorizontalAlignment(alignment_)) {
226 top_edge = kShelfItemInset;
227 left_edge = 0;
228 bottom_edge =
229 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
230 right_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0;
231 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) {
232 top_edge = 0;
233 left_edge =
234 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
235 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0;
236 right_edge = kShelfItemInset;
237 } else { // SHELF_ALIGNMENT_RIGHT
238 top_edge = 0;
239 left_edge = kShelfItemInset;
240 bottom_edge = on_edge ? GetTrayConstant(PADDING_FROM_EDGE_OF_SHELF) : 0;
241 right_edge =
242 GetShelfConstant(SHELF_SIZE) - kShelfItemInset - kShelfItemHeight;
243 }
244 }
245 child->SetBorder(views::Border::CreateEmptyBorder(top_edge, left_edge,
246 bottom_edge, right_edge));
247 }
248
174 } // namespace ash 249 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698