power_button_menu_screen_view.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef ASH_SYSTEM_POWER_POWER_BUTTON_MENU_SCREEN_VIEW_H_
  5. #define ASH_SYSTEM_POWER_POWER_BUTTON_MENU_SCREEN_VIEW_H_
  6. #include <unordered_map>
  7. #include "ash/ash_export.h"
  8. #include "ash/display/screen_orientation_controller.h"
  9. #include "ash/system/power/power_button_controller.h"
  10. #include "ui/display/display_observer.h"
  11. #include "ui/views/view.h"
  12. namespace ash {
  13. enum class ShutdownReason;
  14. class PowerButtonMenuView;
  15. // PowerButtonMenuScreenView is the top-level view of power button menu UI. It
  16. // creates a PowerButtonMenuBackgroundView to display the fullscreen background
  17. // and a PowerButtonMenuView to display the menu.
  18. class ASH_EXPORT PowerButtonMenuScreenView : public views::View,
  19. public display::DisplayObserver {
  20. public:
  21. // |show_animation_done| is a callback for when the animation that shows the
  22. // power menu has finished.
  23. PowerButtonMenuScreenView(
  24. ShutdownReason shutdown_reason,
  25. PowerButtonController::PowerButtonPosition power_button_position,
  26. double power_button_offset,
  27. base::RepeatingClosure show_animation_done);
  28. PowerButtonMenuScreenView(const PowerButtonMenuScreenView&) = delete;
  29. PowerButtonMenuScreenView& operator=(const PowerButtonMenuScreenView&) =
  30. delete;
  31. ~PowerButtonMenuScreenView() override;
  32. PowerButtonMenuView* power_button_menu_view() const {
  33. return power_button_menu_view_;
  34. }
  35. // Schedules an animation to show or hide the view.
  36. void ScheduleShowHideAnimation(bool show);
  37. // Resets the shield and menu's opacity to 0. Used when dismissing the menu
  38. // without animation to prepare for the next fade in animation.
  39. void ResetOpacity();
  40. // Called when the associated widget is shown. Updates power button related
  41. // info and calculates |menu_bounds_origins_| if needed. Recreates menu items.
  42. void OnWidgetShown(PowerButtonController::PowerButtonPosition position,
  43. double offset_percentage);
  44. // views::View:
  45. const char* GetClassName() const override;
  46. private:
  47. class PowerButtonMenuBackgroundView;
  48. // views::View:
  49. void Layout() override;
  50. bool OnMousePressed(const ui::MouseEvent& event) override;
  51. void OnMouseReleased(const ui::MouseEvent& event) override;
  52. bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
  53. // ui::EventHandler:
  54. void OnGestureEvent(ui::GestureEvent* event) override;
  55. // display::DisplayObserver:
  56. void OnDisplayMetricsChanged(const display::Display& display,
  57. uint32_t changed_metrics) override;
  58. // Lays out the view without animation transform.
  59. void LayoutWithoutTransform();
  60. // Updates |menu_bounds_origins_| according to power button position info.
  61. void UpdateMenuBoundsOrigins();
  62. // Gets the bounds of power button menu.
  63. gfx::Rect GetMenuBounds();
  64. // Created by PowerButtonMenuScreenView. Owned by views hierarchy.
  65. PowerButtonMenuView* power_button_menu_view_ = nullptr;
  66. PowerButtonMenuBackgroundView* power_button_screen_background_shield_ =
  67. nullptr;
  68. // The physical display side of power button in landscape primary.
  69. PowerButtonController::PowerButtonPosition power_button_position_;
  70. // The center of the power button's offset from the top of the screen (for
  71. // left/right) or left side of the screen (for top/bottom) in
  72. // landscape_primary. Values are in [0.0, 1.0] and express a fraction of the
  73. // display's height or width, respectively.
  74. double power_button_offset_percentage_ = 0.f;
  75. // The origin of the menu bounds in different screen orientations.
  76. std::unordered_map<chromeos::OrientationType, gfx::Point>
  77. menu_bounds_origins_;
  78. display::ScopedDisplayObserver display_observer_{this};
  79. };
  80. } // namespace ash
  81. #endif // ASH_SYSTEM_POWER_POWER_BUTTON_MENU_SCREEN_VIEW_H_