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

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

Issue 2103113003: Fix shelf layout when switching from left-aligned shelf to right-aligned shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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.h" 5 #include "ash/system/status_area_widget.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/shelf_constants.h"
7 #include "ash/common/shelf/wm_shelf.h" 9 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/shelf/wm_shelf_util.h"
8 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
9 #include "ash/common/system/tray/system_tray_delegate.h" 12 #include "ash/common/system/tray/system_tray_delegate.h"
13 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/web_notification/web_notification_tray.h" 14 #include "ash/common/system/web_notification/web_notification_tray.h"
11 #include "ash/common/wm_lookup.h" 15 #include "ash/common/wm_lookup.h"
12 #include "ash/common/wm_root_window_controller.h" 16 #include "ash/common/wm_root_window_controller.h"
13 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
14 #include "ash/common/wm_window.h" 18 #include "ash/common/wm_window.h"
15 #include "ash/system/overview/overview_button_tray.h" 19 #include "ash/system/overview/overview_button_tray.h"
16 #include "ash/system/status_area_widget_delegate.h" 20 #include "ash/system/status_area_widget_delegate.h"
17 #include "ash/system/tray/system_tray.h" 21 #include "ash/system/tray/system_tray.h"
18 #include "base/i18n/time_formatting.h" 22 #include "base/i18n/time_formatting.h"
19 23
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 AddOverviewButtonTray(); 59 AddOverviewButtonTray();
56 AddSystemTray(); 60 AddSystemTray();
57 AddWebNotificationTray(); 61 AddWebNotificationTray();
58 #if defined(OS_CHROMEOS) 62 #if defined(OS_CHROMEOS)
59 AddLogoutButtonTray(); 63 AddLogoutButtonTray();
60 AddVirtualKeyboardTray(); 64 AddVirtualKeyboardTray();
61 #endif 65 #endif
62 66
63 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 67 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
64 DCHECK(delegate); 68 DCHECK(delegate);
65 // Initialize after all trays have been created. 69
66 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); 70 if (MaterialDesignController::IsShelfMaterial()) {
67 web_notification_tray_->Initialize(); 71 gfx::Insets edge_border;
72 gfx::Insets no_edge_border;
73 CalculateBorderMD(&edge_border, system_tray_->shelf_alignment(), true);
74 CalculateBorderMD(&no_edge_border, system_tray_->shelf_alignment(), false);
tdanderson 2016/06/29 17:46:19 The generally preferred pattern in a case like thi
yiyix 2016/06/29 18:56:39 Done.
75 // Initialize after all trays have been created.
76 system_tray_->InitializeTrayItems(
77 delegate, web_notification_tray_,
78 overview_button_tray_->visible() ? no_edge_border : edge_border);
79 web_notification_tray_->Initialize(no_edge_border);
68 #if defined(OS_CHROMEOS) 80 #if defined(OS_CHROMEOS)
69 logout_button_tray_->Initialize(); 81 logout_button_tray_->Initialize(no_edge_border);
70 virtual_keyboard_tray_->Initialize(); 82 virtual_keyboard_tray_->Initialize(no_edge_border);
71 #endif 83 #endif
72 overview_button_tray_->Initialize(); 84 overview_button_tray_->Initialize(edge_border);
85 } else {
86 gfx::Insets border;
87 gfx::Insets overview_border;
88 CalculateBorderNonMD(&border, system_tray_->shelf_alignment(), false);
89 CalculateBorderNonMD(&overview_border, system_tray_->shelf_alignment(),
90 true);
91 // Initialize after all trays have been created.
92 system_tray_->InitializeTrayItems(delegate, web_notification_tray_, border);
93 web_notification_tray_->Initialize(border);
94 #if defined(OS_CHROMEOS)
95 logout_button_tray_->Initialize(border);
96 virtual_keyboard_tray_->Initialize(border);
97 #endif
98 overview_button_tray_->Initialize(overview_border);
99 }
100
73 SetShelfAlignment(system_tray_->shelf_alignment()); 101 SetShelfAlignment(system_tray_->shelf_alignment());
74 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); 102 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus());
75 } 103 }
76 104
77 void StatusAreaWidget::Shutdown() { 105 void StatusAreaWidget::Shutdown() {
78 system_tray_->Shutdown(); 106 system_tray_->Shutdown();
79 // Destroy the trays early, causing them to be removed from the view 107 // Destroy the trays early, causing them to be removed from the view
80 // hierarchy. Do not used scoped pointers since we don't want to destroy them 108 // hierarchy. Do not used scoped pointers since we don't want to destroy them
81 // in the destructor if Shutdown() is not called (e.g. in tests). 109 // in the destructor if Shutdown() is not called (e.g. in tests).
82 delete web_notification_tray_; 110 delete web_notification_tray_;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); 193 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_);
166 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); 194 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_);
167 } 195 }
168 #endif 196 #endif
169 197
170 void StatusAreaWidget::AddOverviewButtonTray() { 198 void StatusAreaWidget::AddOverviewButtonTray() {
171 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); 199 overview_button_tray_ = new OverviewButtonTray(wm_shelf_);
172 status_area_widget_delegate_->AddTray(overview_button_tray_); 200 status_area_widget_delegate_->AddTray(overview_button_tray_);
173 } 201 }
174 202
203 // TODO(yiyix): Once Chrome OS material design is enabled by default,
204 // remove all code related to Non Md Border setup code. See crbug.com/614453.
tdanderson 2016/06/29 17:46:19 Thanks for adding this. Though in this specific ca
yiyix 2016/06/29 18:56:39 I will remove this comment
175 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { 205 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
176 status_area_widget_delegate_->set_alignment(alignment); 206 status_area_widget_delegate_->set_alignment(alignment);
177 if (system_tray_) 207
178 system_tray_->SetShelfAlignment(alignment); 208 if (MaterialDesignController::IsShelfMaterial()) {
179 if (web_notification_tray_) 209 gfx::Insets insets_on_edge;
180 web_notification_tray_->SetShelfAlignment(alignment); 210 gfx::Insets insets_not_on_edge;
211 CalculateBorderMD(&insets_on_edge, alignment, true);
212 CalculateBorderMD(&insets_not_on_edge, alignment, false);
213 if (system_tray_)
214 system_tray_->SetShelfAlignment(
215 alignment, overview_button_tray_->visible() ? insets_not_on_edge
216 : insets_on_edge);
217 if (web_notification_tray_)
218 web_notification_tray_->SetShelfAlignment(alignment, insets_not_on_edge);
181 #if defined(OS_CHROMEOS) 219 #if defined(OS_CHROMEOS)
182 if (logout_button_tray_) 220 if (logout_button_tray_)
183 logout_button_tray_->SetShelfAlignment(alignment); 221 logout_button_tray_->SetShelfAlignment(alignment, insets_not_on_edge);
184 if (virtual_keyboard_tray_) 222 if (virtual_keyboard_tray_)
185 virtual_keyboard_tray_->SetShelfAlignment(alignment); 223 virtual_keyboard_tray_->SetShelfAlignment(alignment, insets_not_on_edge);
186 #endif 224 #endif
187 if (overview_button_tray_) 225 if (overview_button_tray_)
188 overview_button_tray_->SetShelfAlignment(alignment); 226 overview_button_tray_->SetShelfAlignment(alignment, insets_on_edge);
227 } else {
228 gfx::Insets insets;
229 gfx::Insets insets_overview;
230 CalculateBorderNonMD(&insets, alignment, false);
231 CalculateBorderNonMD(&insets_overview, alignment, true);
tdanderson 2016/06/29 17:46:19 Consider only performing this calculation inside t
yiyix 2016/06/29 18:56:39 Done.
232 if (system_tray_)
233 system_tray_->SetShelfAlignment(alignment, insets);
234 if (web_notification_tray_)
235 web_notification_tray_->SetShelfAlignment(alignment, insets);
236 #if defined(OS_CHROMEOS)
237 if (logout_button_tray_)
238 logout_button_tray_->SetShelfAlignment(alignment, insets);
239 if (virtual_keyboard_tray_)
240 virtual_keyboard_tray_->SetShelfAlignment(alignment, insets);
241 #endif
242 if (overview_button_tray_)
243 overview_button_tray_->SetShelfAlignment(alignment, insets_overview);
244 }
245
189 status_area_widget_delegate_->UpdateLayout(); 246 status_area_widget_delegate_->UpdateLayout();
190 } 247 }
191 248
192 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { 249 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) {
193 if (login_status_ == login_status) 250 if (login_status_ == login_status)
194 return; 251 return;
195 login_status_ = login_status; 252 login_status_ = login_status;
196 if (system_tray_) 253 if (system_tray_)
197 system_tray_->UpdateAfterLoginStatusChange(login_status); 254 system_tray_->UpdateAfterLoginStatusChange(login_status);
198 if (web_notification_tray_) 255 if (web_notification_tray_)
199 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); 256 web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
200 #if defined(OS_CHROMEOS) 257 #if defined(OS_CHROMEOS)
201 if (logout_button_tray_) 258 if (logout_button_tray_)
202 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); 259 logout_button_tray_->UpdateAfterLoginStatusChange(login_status);
203 #endif 260 #endif
204 if (overview_button_tray_) 261 if (overview_button_tray_)
205 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); 262 overview_button_tray_->UpdateAfterLoginStatusChange(login_status);
206 } 263 }
207 264
265 void StatusAreaWidget::CalculateBorderMD(gfx::Insets* insets,
266 ShelfAlignment alignment,
267 bool is_on_edge) {
268 const int shelf_size = GetShelfConstant(SHELF_SIZE);
269 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
270 int top_edge, left_edge, bottom_edge, right_edge;
271
272 // Tray views are laid out right-to-left or bottom-to-top.
273 const bool horizontal_alignment = IsHorizontalAlignment(alignment);
274 const int padding = (shelf_size - item_height) / 2;
275 const int extended_padding = GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF);
276
277 top_edge = horizontal_alignment ? padding : 0;
278 left_edge = horizontal_alignment ? 0 : padding;
279 bottom_edge =
280 horizontal_alignment ? padding : (is_on_edge ? extended_padding : 0);
281 right_edge =
282 horizontal_alignment ? (is_on_edge ? extended_padding : 0) : padding;
283
284 insets->Set(top_edge, left_edge, bottom_edge, right_edge);
285 }
286
287 void StatusAreaWidget::CalculateBorderNonMD(gfx::Insets* insets,
288 ShelfAlignment alignment,
289 bool is_overview) {
290 const int shelf_size = GetShelfConstant(SHELF_SIZE);
291 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
292 int top_edge, left_edge, bottom_edge, right_edge;
293 if (IsHorizontalAlignment(alignment)) {
294 top_edge = kShelfItemInset;
295 left_edge = 0;
296 bottom_edge = shelf_size - kShelfItemInset - item_height;
297 right_edge =
298 is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
299 } else if (alignment == SHELF_ALIGNMENT_LEFT) {
300 top_edge = 0;
301 left_edge = shelf_size - kShelfItemInset - item_height;
302 bottom_edge =
303 is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
304 right_edge = kShelfItemInset;
305 } else { // SHELF_ALIGNMENT_RIGHT
306 top_edge = 0;
307 left_edge = kShelfItemInset;
308 bottom_edge =
309 is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
310 right_edge = shelf_size - kShelfItemInset - item_height;
311 }
312 insets->Set(top_edge, left_edge, bottom_edge, right_edge);
tdanderson 2016/06/29 17:46:19 Some refactoring may be advisable here, but I will
yiyix 2016/06/29 18:56:39 Ok, I agree that some trick we used in space calcu
313 }
314
208 } // namespace ash 315 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698