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

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: Merge 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 CalculateBorderMD(system_tray_->shelf_alignment(), true);
73 gfx::Insets no_edge_border =
74 CalculateBorderMD(system_tray_->shelf_alignment(), false);
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 CalculateBorderNonMD(system_tray_->shelf_alignment(), false);
88 // Initialize after all trays have been created.
89 system_tray_->InitializeTrayItems(delegate, web_notification_tray_, border);
90 web_notification_tray_->Initialize(border);
91 #if defined(OS_CHROMEOS)
92 logout_button_tray_->Initialize(border);
93 virtual_keyboard_tray_->Initialize(border);
94 #endif
95 overview_button_tray_->Initialize(
96 CalculateBorderNonMD(system_tray_->shelf_alignment(), true));
97 }
98
73 SetShelfAlignment(system_tray_->shelf_alignment()); 99 SetShelfAlignment(system_tray_->shelf_alignment());
74 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); 100 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus());
75 } 101 }
76 102
77 void StatusAreaWidget::Shutdown() { 103 void StatusAreaWidget::Shutdown() {
78 system_tray_->Shutdown(); 104 system_tray_->Shutdown();
79 // Destroy the trays early, causing them to be removed from the view 105 // 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 106 // 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). 107 // in the destructor if Shutdown() is not called (e.g. in tests).
82 delete web_notification_tray_; 108 delete web_notification_tray_;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 193 }
168 #endif 194 #endif
169 195
170 void StatusAreaWidget::AddOverviewButtonTray() { 196 void StatusAreaWidget::AddOverviewButtonTray() {
171 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); 197 overview_button_tray_ = new OverviewButtonTray(wm_shelf_);
172 status_area_widget_delegate_->AddTray(overview_button_tray_); 198 status_area_widget_delegate_->AddTray(overview_button_tray_);
173 } 199 }
174 200
175 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { 201 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
176 status_area_widget_delegate_->set_alignment(alignment); 202 status_area_widget_delegate_->set_alignment(alignment);
177 if (system_tray_) 203
178 system_tray_->SetShelfAlignment(alignment); 204 if (MaterialDesignController::IsShelfMaterial()) {
179 if (web_notification_tray_) 205 gfx::Insets insets_on_edge = CalculateBorderMD(alignment, true);
180 web_notification_tray_->SetShelfAlignment(alignment); 206 gfx::Insets insets_not_on_edge = CalculateBorderMD(alignment, false);
207
208 if (system_tray_)
209 system_tray_->SetShelfAlignment(
210 alignment, overview_button_tray_->visible() ? insets_not_on_edge
211 : insets_on_edge);
212 if (web_notification_tray_)
213 web_notification_tray_->SetShelfAlignment(alignment, insets_not_on_edge);
181 #if defined(OS_CHROMEOS) 214 #if defined(OS_CHROMEOS)
182 if (logout_button_tray_) 215 if (logout_button_tray_)
183 logout_button_tray_->SetShelfAlignment(alignment); 216 logout_button_tray_->SetShelfAlignment(alignment, insets_not_on_edge);
184 if (virtual_keyboard_tray_) 217 if (virtual_keyboard_tray_)
185 virtual_keyboard_tray_->SetShelfAlignment(alignment); 218 virtual_keyboard_tray_->SetShelfAlignment(alignment, insets_not_on_edge);
186 #endif 219 #endif
187 if (overview_button_tray_) 220 if (overview_button_tray_)
188 overview_button_tray_->SetShelfAlignment(alignment); 221 overview_button_tray_->SetShelfAlignment(alignment, insets_on_edge);
222 } else {
223 gfx::Insets insets = CalculateBorderNonMD(alignment, false);
224 if (system_tray_)
225 system_tray_->SetShelfAlignment(alignment, insets);
226 if (web_notification_tray_)
227 web_notification_tray_->SetShelfAlignment(alignment, insets);
228 #if defined(OS_CHROMEOS)
229 if (logout_button_tray_)
230 logout_button_tray_->SetShelfAlignment(alignment, insets);
231 if (virtual_keyboard_tray_)
232 virtual_keyboard_tray_->SetShelfAlignment(alignment, insets);
233 #endif
234 if (overview_button_tray_)
235 overview_button_tray_->SetShelfAlignment(
236 alignment, CalculateBorderNonMD(alignment, true));
237 }
238
189 status_area_widget_delegate_->UpdateLayout(); 239 status_area_widget_delegate_->UpdateLayout();
190 } 240 }
191 241
192 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { 242 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) {
193 if (login_status_ == login_status) 243 if (login_status_ == login_status)
194 return; 244 return;
195 login_status_ = login_status; 245 login_status_ = login_status;
196 if (system_tray_) 246 if (system_tray_)
197 system_tray_->UpdateAfterLoginStatusChange(login_status); 247 system_tray_->UpdateAfterLoginStatusChange(login_status);
198 if (web_notification_tray_) 248 if (web_notification_tray_)
199 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); 249 web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
200 #if defined(OS_CHROMEOS) 250 #if defined(OS_CHROMEOS)
201 if (logout_button_tray_) 251 if (logout_button_tray_)
202 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); 252 logout_button_tray_->UpdateAfterLoginStatusChange(login_status);
203 #endif 253 #endif
204 if (overview_button_tray_) 254 if (overview_button_tray_)
205 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); 255 overview_button_tray_->UpdateAfterLoginStatusChange(login_status);
206 } 256 }
207 257
258 gfx::Insets StatusAreaWidget::CalculateBorderMD(ShelfAlignment alignment,
James Cook 2016/06/29 19:34:14 Can these methods be static? Then they could move
259 bool is_on_edge) {
260 const int shelf_size = GetShelfConstant(SHELF_SIZE);
261 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
262 int top_edge, left_edge, bottom_edge, right_edge;
263
264 // Tray views are laid out right-to-left or bottom-to-top.
265 const bool horizontal_alignment = IsHorizontalAlignment(alignment);
266 const int padding = (shelf_size - item_height) / 2;
267 const int extended_padding = GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF);
268
269 top_edge = horizontal_alignment ? padding : 0;
270 left_edge = horizontal_alignment ? 0 : padding;
271 bottom_edge =
272 horizontal_alignment ? padding : (is_on_edge ? extended_padding : 0);
273 right_edge =
274 horizontal_alignment ? (is_on_edge ? extended_padding : 0) : padding;
275
276 return gfx::Insets(top_edge, left_edge, bottom_edge, right_edge);
277 }
278
279 gfx::Insets StatusAreaWidget::CalculateBorderNonMD(ShelfAlignment alignment,
280 bool is_overview) {
281 const int shelf_size = GetShelfConstant(SHELF_SIZE);
282 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY);
283 int top_edge, left_edge, bottom_edge, right_edge;
284 if (IsHorizontalAlignment(alignment)) {
285 top_edge = kShelfItemInset;
286 left_edge = 0;
287 bottom_edge = shelf_size - kShelfItemInset - item_height;
288 right_edge =
289 is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
290 } else if (alignment == SHELF_ALIGNMENT_LEFT) {
291 top_edge = 0;
292 left_edge = shelf_size - kShelfItemInset - item_height;
293 bottom_edge =
294 is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
295 right_edge = kShelfItemInset;
296 } else { // SHELF_ALIGNMENT_RIGHT
297 top_edge = 0;
298 left_edge = kShelfItemInset;
299 bottom_edge =
300 is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0;
301 right_edge = shelf_size - kShelfItemInset - item_height;
302 }
303 return gfx::Insets(top_edge, left_edge, bottom_edge, right_edge);
304 }
305
208 } // namespace ash 306 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698