| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/system/overview/overview_button_tray.h" | 5 #include "ash/common/system/overview/overview_button_tray.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 #include "ash/common/session/session_state_delegate.h" | 7 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/shelf_constants.h" | 8 #include "ash/common/shelf/shelf_constants.h" |
| 10 #include "ash/common/shelf/wm_shelf_util.h" | |
| 11 #include "ash/common/system/tray/system_tray_delegate.h" | 9 #include "ash/common/system/tray/system_tray_delegate.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_utils.h" | |
| 14 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 15 #include "ash/common/wm/overview/window_selector_controller.h" | 12 #include "ash/common/wm/overview/window_selector_controller.h" |
| 16 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 17 #include "ash/public/cpp/shelf_types.h" | |
| 18 #include "ash/resources/grit/ash_resources.h" | |
| 19 #include "ash/resources/vector_icons/vector_icons.h" | 14 #include "ash/resources/vector_icons/vector_icons.h" |
| 20 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | |
| 23 #include "ui/gfx/paint_vector_icon.h" | 17 #include "ui/gfx/paint_vector_icon.h" |
| 24 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 25 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
| 26 | 20 |
| 27 namespace { | |
| 28 | |
| 29 // Predefined padding for the icon used in this tray. These are to be set to the | |
| 30 // border of the icon, depending on the current shelf_alignment() | |
| 31 const int kHorizontalShelfHorizontalPadding = 8; | |
| 32 const int kHorizontalShelfVerticalPadding = 4; | |
| 33 const int kVerticalShelfHorizontalPadding = 2; | |
| 34 const int kVerticalShelfVerticalPadding = 5; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 namespace ash { | 21 namespace ash { |
| 39 | 22 |
| 40 OverviewButtonTray::OverviewButtonTray(WmShelf* wm_shelf) | 23 OverviewButtonTray::OverviewButtonTray(WmShelf* wm_shelf) |
| 41 : TrayBackgroundView(wm_shelf), icon_(nullptr) { | 24 : TrayBackgroundView(wm_shelf), icon_(new views::ImageView()) { |
| 42 icon_ = new views::ImageView(); | 25 SetInkDropMode(InkDropMode::ON); |
| 43 if (MaterialDesignController::IsShelfMaterial()) { | 26 SetContentsBackground(false); |
| 44 SetInkDropMode(InkDropMode::ON); | 27 |
| 45 SetContentsBackground(false); | 28 icon_->SetImage(CreateVectorIcon(kShelfOverviewIcon, kShelfIconColor)); |
| 46 gfx::ImageSkia image_md = | |
| 47 CreateVectorIcon(kShelfOverviewIcon, kShelfIconColor); | |
| 48 icon_->SetImage(image_md); | |
| 49 } else { | |
| 50 SetContentsBackground(true); | |
| 51 gfx::ImageSkia* image_non_md = | |
| 52 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 53 IDR_AURA_UBER_TRAY_OVERVIEW_MODE); | |
| 54 icon_->SetImage(image_non_md); | |
| 55 } | |
| 56 SetIconBorderForShelfAlignment(); | 29 SetIconBorderForShelfAlignment(); |
| 57 tray_container()->AddChildView(icon_); | 30 tray_container()->AddChildView(icon_); |
| 58 | 31 |
| 59 // Since OverviewButtonTray is located on the rightmost position of a | 32 // Since OverviewButtonTray is located on the rightmost position of a |
| 60 // horizontal shelf, no separator is required. | 33 // horizontal shelf, no separator is required. |
| 61 set_separator_visibility(false); | 34 set_separator_visibility(false); |
| 62 | 35 |
| 63 WmShell::Get()->AddShellObserver(this); | 36 WmShell::Get()->AddShellObserver(this); |
| 64 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); | 37 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); |
| 65 } | 38 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 89 |
| 117 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) { | 90 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 118 if (alignment == shelf_alignment()) | 91 if (alignment == shelf_alignment()) |
| 119 return; | 92 return; |
| 120 | 93 |
| 121 TrayBackgroundView::SetShelfAlignment(alignment); | 94 TrayBackgroundView::SetShelfAlignment(alignment); |
| 122 SetIconBorderForShelfAlignment(); | 95 SetIconBorderForShelfAlignment(); |
| 123 } | 96 } |
| 124 | 97 |
| 125 void OverviewButtonTray::SetIconBorderForShelfAlignment() { | 98 void OverviewButtonTray::SetIconBorderForShelfAlignment() { |
| 126 gfx::Insets insets; | 99 // Pad button size to align with other controls in the system tray. |
| 127 if (ash::MaterialDesignController::IsShelfMaterial()) { | 100 const gfx::ImageSkia& image = icon_->GetImage(); |
| 128 // Pad button size to align with other controls in the system tray. | 101 const int vertical_padding = (kTrayItemSize - image.height()) / 2; |
| 129 const gfx::ImageSkia image = icon_->GetImage(); | 102 const int horizontal_padding = (kTrayItemSize - image.width()) / 2; |
| 130 const int vertical_padding = (kTrayItemSize - image.height()) / 2; | 103 icon_->SetBorder(views::CreateEmptyBorder( |
| 131 const int horizontal_padding = (kTrayItemSize - image.width()) / 2; | 104 gfx::Insets(vertical_padding, horizontal_padding))); |
| 132 insets = gfx::Insets(vertical_padding, horizontal_padding); | |
| 133 } else { | |
| 134 insets = IsHorizontalAlignment(shelf_alignment()) | |
| 135 ? gfx::Insets(kHorizontalShelfVerticalPadding, | |
| 136 kHorizontalShelfHorizontalPadding) | |
| 137 : gfx::Insets(kVerticalShelfVerticalPadding, | |
| 138 kVerticalShelfHorizontalPadding); | |
| 139 } | |
| 140 icon_->SetBorder(views::CreateEmptyBorder(insets)); | |
| 141 } | 105 } |
| 142 | 106 |
| 143 void OverviewButtonTray::UpdateIconVisibility() { | 107 void OverviewButtonTray::UpdateIconVisibility() { |
| 144 // The visibility of the OverviewButtonTray has diverge from | 108 // The visibility of the OverviewButtonTray has diverged from |
| 145 // WindowSelectorController::CanSelect. The visibility of the button should | 109 // WindowSelectorController::CanSelect. The visibility of the button should |
| 146 // not change during transient times in which CanSelect is false. Such as when | 110 // not change during transient times in which CanSelect is false. Such as when |
| 147 // a modal dialog is present. | 111 // a modal dialog is present. |
| 148 WmShell* shell = WmShell::Get(); | 112 WmShell* shell = WmShell::Get(); |
| 149 SessionStateDelegate* session_state_delegate = | 113 SessionStateDelegate* session_state_delegate = |
| 150 shell->GetSessionStateDelegate(); | 114 shell->GetSessionStateDelegate(); |
| 151 | 115 |
| 152 SetVisible( | 116 SetVisible( |
| 153 shell->maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled() && | 117 shell->maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled() && |
| 154 session_state_delegate->IsActiveUserSessionStarted() && | 118 session_state_delegate->IsActiveUserSessionStarted() && |
| 155 !session_state_delegate->IsScreenLocked() && | 119 !session_state_delegate->IsScreenLocked() && |
| 156 session_state_delegate->GetSessionState() == | 120 session_state_delegate->GetSessionState() == |
| 157 session_manager::SessionState::ACTIVE && | 121 session_manager::SessionState::ACTIVE && |
| 158 shell->system_tray_delegate()->GetUserLoginStatus() != | 122 shell->system_tray_delegate()->GetUserLoginStatus() != |
| 159 LoginStatus::KIOSK_APP && | 123 LoginStatus::KIOSK_APP && |
| 160 shell->system_tray_delegate()->GetUserLoginStatus() != | 124 shell->system_tray_delegate()->GetUserLoginStatus() != |
| 161 LoginStatus::ARC_KIOSK_APP); | 125 LoginStatus::ARC_KIOSK_APP); |
| 162 } | 126 } |
| 163 | 127 |
| 164 } // namespace ash | 128 } // namespace ash |
| OLD | NEW |