Chromium Code Reviews| Index: ash/system/status_area_widget.cc |
| diff --git a/ash/system/status_area_widget.cc b/ash/system/status_area_widget.cc |
| index 6a03d2487f077e90ce6ff8b315116ee486145f60..6da46116258bca38331f0453662a517d521be705 100644 |
| --- a/ash/system/status_area_widget.cc |
| +++ b/ash/system/status_area_widget.cc |
| @@ -4,9 +4,13 @@ |
| #include "ash/system/status_area_widget.h" |
| +#include "ash/common/material_design/material_design_controller.h" |
| +#include "ash/common/shelf/shelf_constants.h" |
| #include "ash/common/shelf/wm_shelf.h" |
| +#include "ash/common/shelf/wm_shelf_util.h" |
| #include "ash/common/shell_window_ids.h" |
| #include "ash/common/system/tray/system_tray_delegate.h" |
| +#include "ash/common/system/tray/tray_constants.h" |
| #include "ash/common/system/web_notification/web_notification_tray.h" |
| #include "ash/common/wm_lookup.h" |
| #include "ash/common/wm_root_window_controller.h" |
| @@ -62,14 +66,36 @@ void StatusAreaWidget::CreateTrayViews() { |
| SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| DCHECK(delegate); |
| - // Initialize after all trays have been created. |
| - system_tray_->InitializeTrayItems(delegate, web_notification_tray_); |
| - web_notification_tray_->Initialize(); |
| + |
| + if (MaterialDesignController::IsShelfMaterial()) { |
| + gfx::Insets edge_border = |
| + CalculateBorderMD(system_tray_->shelf_alignment(), true); |
| + gfx::Insets no_edge_border = |
| + CalculateBorderMD(system_tray_->shelf_alignment(), false); |
| + // Initialize after all trays have been created. |
| + system_tray_->InitializeTrayItems( |
| + delegate, web_notification_tray_, |
| + overview_button_tray_->visible() ? no_edge_border : edge_border); |
| + web_notification_tray_->Initialize(no_edge_border); |
| +#if defined(OS_CHROMEOS) |
| + logout_button_tray_->Initialize(no_edge_border); |
| + virtual_keyboard_tray_->Initialize(no_edge_border); |
| +#endif |
| + overview_button_tray_->Initialize(edge_border); |
| + } else { |
| + gfx::Insets border = |
| + CalculateBorderNonMD(system_tray_->shelf_alignment(), false); |
| + // Initialize after all trays have been created. |
| + system_tray_->InitializeTrayItems(delegate, web_notification_tray_, border); |
| + web_notification_tray_->Initialize(border); |
| #if defined(OS_CHROMEOS) |
| - logout_button_tray_->Initialize(); |
| - virtual_keyboard_tray_->Initialize(); |
| + logout_button_tray_->Initialize(border); |
| + virtual_keyboard_tray_->Initialize(border); |
| #endif |
| - overview_button_tray_->Initialize(); |
| + overview_button_tray_->Initialize( |
| + CalculateBorderNonMD(system_tray_->shelf_alignment(), true)); |
| + } |
| + |
| SetShelfAlignment(system_tray_->shelf_alignment()); |
| UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
| } |
| @@ -174,18 +200,42 @@ void StatusAreaWidget::AddOverviewButtonTray() { |
| void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
| status_area_widget_delegate_->set_alignment(alignment); |
| - if (system_tray_) |
| - system_tray_->SetShelfAlignment(alignment); |
| - if (web_notification_tray_) |
| - web_notification_tray_->SetShelfAlignment(alignment); |
| + |
| + if (MaterialDesignController::IsShelfMaterial()) { |
| + gfx::Insets insets_on_edge = CalculateBorderMD(alignment, true); |
| + gfx::Insets insets_not_on_edge = CalculateBorderMD(alignment, false); |
| + |
| + if (system_tray_) |
| + system_tray_->SetShelfAlignment( |
| + alignment, overview_button_tray_->visible() ? insets_not_on_edge |
| + : insets_on_edge); |
| + if (web_notification_tray_) |
| + web_notification_tray_->SetShelfAlignment(alignment, insets_not_on_edge); |
| #if defined(OS_CHROMEOS) |
| if (logout_button_tray_) |
| - logout_button_tray_->SetShelfAlignment(alignment); |
| + logout_button_tray_->SetShelfAlignment(alignment, insets_not_on_edge); |
| if (virtual_keyboard_tray_) |
| - virtual_keyboard_tray_->SetShelfAlignment(alignment); |
| + virtual_keyboard_tray_->SetShelfAlignment(alignment, insets_not_on_edge); |
| #endif |
| if (overview_button_tray_) |
| - overview_button_tray_->SetShelfAlignment(alignment); |
| + overview_button_tray_->SetShelfAlignment(alignment, insets_on_edge); |
| + } else { |
| + gfx::Insets insets = CalculateBorderNonMD(alignment, false); |
| + if (system_tray_) |
| + system_tray_->SetShelfAlignment(alignment, insets); |
| + if (web_notification_tray_) |
| + web_notification_tray_->SetShelfAlignment(alignment, insets); |
| +#if defined(OS_CHROMEOS) |
| + if (logout_button_tray_) |
| + logout_button_tray_->SetShelfAlignment(alignment, insets); |
| + if (virtual_keyboard_tray_) |
| + virtual_keyboard_tray_->SetShelfAlignment(alignment, insets); |
| +#endif |
| + if (overview_button_tray_) |
| + overview_button_tray_->SetShelfAlignment( |
| + alignment, CalculateBorderNonMD(alignment, true)); |
| + } |
| + |
| status_area_widget_delegate_->UpdateLayout(); |
| } |
| @@ -205,4 +255,52 @@ void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { |
| overview_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| } |
| +gfx::Insets StatusAreaWidget::CalculateBorderMD(ShelfAlignment alignment, |
|
James Cook
2016/06/29 19:34:14
Can these methods be static? Then they could move
|
| + bool is_on_edge) { |
| + const int shelf_size = GetShelfConstant(SHELF_SIZE); |
| + const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY); |
| + int top_edge, left_edge, bottom_edge, right_edge; |
| + |
| + // Tray views are laid out right-to-left or bottom-to-top. |
| + const bool horizontal_alignment = IsHorizontalAlignment(alignment); |
| + const int padding = (shelf_size - item_height) / 2; |
| + const int extended_padding = GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF); |
| + |
| + top_edge = horizontal_alignment ? padding : 0; |
| + left_edge = horizontal_alignment ? 0 : padding; |
| + bottom_edge = |
| + horizontal_alignment ? padding : (is_on_edge ? extended_padding : 0); |
| + right_edge = |
| + horizontal_alignment ? (is_on_edge ? extended_padding : 0) : padding; |
| + |
| + return gfx::Insets(top_edge, left_edge, bottom_edge, right_edge); |
| +} |
| + |
| +gfx::Insets StatusAreaWidget::CalculateBorderNonMD(ShelfAlignment alignment, |
| + bool is_overview) { |
| + const int shelf_size = GetShelfConstant(SHELF_SIZE); |
| + const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY); |
| + int top_edge, left_edge, bottom_edge, right_edge; |
| + if (IsHorizontalAlignment(alignment)) { |
| + top_edge = kShelfItemInset; |
| + left_edge = 0; |
| + bottom_edge = shelf_size - kShelfItemInset - item_height; |
| + right_edge = |
| + is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; |
| + } else if (alignment == SHELF_ALIGNMENT_LEFT) { |
| + top_edge = 0; |
| + left_edge = shelf_size - kShelfItemInset - item_height; |
| + bottom_edge = |
| + is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; |
| + right_edge = kShelfItemInset; |
| + } else { // SHELF_ALIGNMENT_RIGHT |
| + top_edge = 0; |
| + left_edge = kShelfItemInset; |
| + bottom_edge = |
| + is_overview ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; |
| + right_edge = shelf_size - kShelfItemInset - item_height; |
| + } |
| + return gfx::Insets(top_edge, left_edge, bottom_edge, right_edge); |
| +} |
| + |
| } // namespace ash |