1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ASH_SYSTEM_POWER_POWER_BUTTON_MENU_VIEW_H_ 6 #define ASH_SYSTEM_POWER_POWER_BUTTON_MENU_VIEW_H_ 7 8 #include "ash/ash_export.h" 9 #include "ash/system/power/power_button_controller.h" 10 #include "base/macros.h" 11 #include "ui/compositor/layer_animation_observer.h" 12 #include "ui/views/view.h" 13 14 namespace ash { 15 enum class PowerButtonMenuActionType; 16 class PowerButtonMenuItemView; 17 18 // PowerButtonMenuView displays the menu items of the power button menu. It 19 // includes power off and sign out items currently. 20 class ASH_EXPORT PowerButtonMenuView : public views::View, 21 public ui::ImplicitAnimationObserver { 22 public: 23 // The duration of showing or dismissing power button menu animation. 24 static constexpr base::TimeDelta kMenuAnimationDuration = 25 base::TimeDelta::FromMilliseconds(250); 26 27 // Distance of the menu animation transform. 28 static constexpr int kMenuViewTransformDistanceDp = 16; 29 30 // Direction of the animation transform. X means to translate from 31 // x-coordinate. Y means to translate from y-coordinate. 32 enum class TransformDirection { NONE, X, Y }; 33 34 // The translate direction and distance of the animation transform. 35 struct TransformDisplacement { 36 TransformDirection direction; 37 int distance; 38 }; 39 40 explicit PowerButtonMenuView( 41 PowerButtonController::PowerButtonPosition power_button_position); 42 PowerButtonMenuView(const PowerButtonMenuView&) = delete; 43 PowerButtonMenuView& operator=(const PowerButtonMenuView&) = delete; 44 ~PowerButtonMenuView() override; 45 sign_out_item_for_test()46 PowerButtonMenuItemView* sign_out_item_for_test() const { 47 return sign_out_item_; 48 } power_off_item_for_test()49 PowerButtonMenuItemView* power_off_item_for_test() const { 50 return power_off_item_; 51 } lock_screen_item_for_test()52 PowerButtonMenuItemView* lock_screen_item_for_test() const { 53 return lock_screen_item_; 54 } feedback_item_for_test()55 PowerButtonMenuItemView* feedback_item_for_test() const { 56 return feedback_item_; 57 } 58 59 // Requests focus for |power_off_item_|. 60 void FocusPowerOffButton(); 61 62 // Schedules an animation to show or hide the view. 63 void ScheduleShowHideAnimation(bool show); 64 65 // Gets the transform displacement, which contains direction and distance. 66 TransformDisplacement GetTransformDisplacement() const; 67 68 // Called whenever the associated widget is shown and when |this| is 69 // constructed. Adds/removes menu items as needed. 70 void RecreateItems(); 71 72 // views::View: 73 const char* GetClassName() const override; 74 75 private: 76 // views::View: 77 void Layout() override; 78 gfx::Size CalculatePreferredSize() const override; 79 void OnThemeChanged() override; 80 81 // ui::ImplicitAnimationObserver: 82 void OnImplicitAnimationsCompleted() override; 83 84 void ButtonPressed(PowerButtonMenuActionType action, 85 base::RepeatingClosure callback); 86 87 // Items in the menu. Owned by views hierarchy. 88 PowerButtonMenuItemView* power_off_item_ = nullptr; 89 PowerButtonMenuItemView* sign_out_item_ = nullptr; 90 PowerButtonMenuItemView* lock_screen_item_ = nullptr; 91 PowerButtonMenuItemView* capture_mode_item_ = nullptr; 92 PowerButtonMenuItemView* feedback_item_ = nullptr; 93 94 // The physical display side of power button in landscape primary. 95 PowerButtonController::PowerButtonPosition power_button_position_; 96 }; 97 98 } // namespace ash 99 100 #endif // ASH_SYSTEM_POWER_POWER_BUTTON_MENU_VIEW_H_ 101