123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // Copyright 2018 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #ifndef ASH_SYSTEM_POWER_POWER_BUTTON_MENU_SCREEN_VIEW_H_
- #define ASH_SYSTEM_POWER_POWER_BUTTON_MENU_SCREEN_VIEW_H_
- #include <unordered_map>
- #include "ash/ash_export.h"
- #include "ash/display/screen_orientation_controller.h"
- #include "ash/system/power/power_button_controller.h"
- #include "ui/display/display_observer.h"
- #include "ui/views/view.h"
- namespace ash {
- enum class ShutdownReason;
- class PowerButtonMenuView;
- // PowerButtonMenuScreenView is the top-level view of power button menu UI. It
- // creates a PowerButtonMenuBackgroundView to display the fullscreen background
- // and a PowerButtonMenuView to display the menu.
- class ASH_EXPORT PowerButtonMenuScreenView : public views::View,
- public display::DisplayObserver {
- public:
- // |show_animation_done| is a callback for when the animation that shows the
- // power menu has finished.
- PowerButtonMenuScreenView(
- ShutdownReason shutdown_reason,
- PowerButtonController::PowerButtonPosition power_button_position,
- double power_button_offset,
- base::RepeatingClosure show_animation_done);
- PowerButtonMenuScreenView(const PowerButtonMenuScreenView&) = delete;
- PowerButtonMenuScreenView& operator=(const PowerButtonMenuScreenView&) =
- delete;
- ~PowerButtonMenuScreenView() override;
- PowerButtonMenuView* power_button_menu_view() const {
- return power_button_menu_view_;
- }
- // Schedules an animation to show or hide the view.
- void ScheduleShowHideAnimation(bool show);
- // Resets the shield and menu's opacity to 0. Used when dismissing the menu
- // without animation to prepare for the next fade in animation.
- void ResetOpacity();
- // Called when the associated widget is shown. Updates power button related
- // info and calculates |menu_bounds_origins_| if needed. Recreates menu items.
- void OnWidgetShown(PowerButtonController::PowerButtonPosition position,
- double offset_percentage);
- // views::View:
- const char* GetClassName() const override;
- private:
- class PowerButtonMenuBackgroundView;
- // views::View:
- void Layout() override;
- bool OnMousePressed(const ui::MouseEvent& event) override;
- void OnMouseReleased(const ui::MouseEvent& event) override;
- bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
- // ui::EventHandler:
- void OnGestureEvent(ui::GestureEvent* event) override;
- // display::DisplayObserver:
- void OnDisplayMetricsChanged(const display::Display& display,
- uint32_t changed_metrics) override;
- // Lays out the view without animation transform.
- void LayoutWithoutTransform();
- // Updates |menu_bounds_origins_| according to power button position info.
- void UpdateMenuBoundsOrigins();
- // Gets the bounds of power button menu.
- gfx::Rect GetMenuBounds();
- // Created by PowerButtonMenuScreenView. Owned by views hierarchy.
- PowerButtonMenuView* power_button_menu_view_ = nullptr;
- PowerButtonMenuBackgroundView* power_button_screen_background_shield_ =
- nullptr;
- // The physical display side of power button in landscape primary.
- PowerButtonController::PowerButtonPosition power_button_position_;
- // The center of the power button's offset from the top of the screen (for
- // left/right) or left side of the screen (for top/bottom) in
- // landscape_primary. Values are in [0.0, 1.0] and express a fraction of the
- // display's height or width, respectively.
- double power_button_offset_percentage_ = 0.f;
- // The origin of the menu bounds in different screen orientations.
- std::unordered_map<chromeos::OrientationType, gfx::Point>
- menu_bounds_origins_;
- display::ScopedDisplayObserver display_observer_{this};
- };
- } // namespace ash
- #endif // ASH_SYSTEM_POWER_POWER_BUTTON_MENU_SCREEN_VIEW_H_
|