1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
#define ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
#include <stdint.h>
#include "ash/ash_export.h"
#include "ash/display/display_change_dialog.h"
#include "base/functional/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/crosapi/mojom/cros_display_config.mojom.h"
#include "ui/display/display_observer.h"
#include "ui/display/manager/display_manager_observer.h"
#include "ui/display/manager/managed_display_info.h"
namespace ash {
FORWARD_DECLARE_TEST(DisplayPrefsTest, PreventStore);
// A class which manages the dialog displayed to notify the user that
// the display configuration has been changed.
class ASH_EXPORT ResolutionNotificationController
: public display::DisplayObserver,
public display::DisplayManagerObserver {
public:
ResolutionNotificationController();
ResolutionNotificationController(const ResolutionNotificationController&) =
delete;
ResolutionNotificationController& operator=(
const ResolutionNotificationController&) = delete;
~ResolutionNotificationController() override;
// If |display_id| is not the internal display and |source| is |kSourceUser|
// (which means user initiated the change), Prepare a resolution change
// notification for |display_id| from |old_resolution| to |new_resolution|,
// which offers a button to revert the change in case something goes wrong.
// The dialog is not dismissed by the user, the change is reverted.
//
// Then call DisplayManager::SetDisplayMode() to apply the resolution change,
// and return the result; true if success, false otherwise.
// In case SetDisplayMode() fails, the prepared notification will be
// discarded.
//
// If |display_id| is the internal display or |source| is |kSourcePolicy|, the
// resolution change is applied directly without preparing the confirm/revert
// notification (this kind of notification is only useful for external
// displays).
//
// This method does not create a notification itself. The notification will be
// created the next OnDisplayConfigurationChanged(), which will be called
// asynchronously after the resolution change is requested by this method.
//
// |accept_callback| will be called when the user accepts the resoltion change
// by closing the notification bubble or clicking on the accept button (if
// any).
[[nodiscard]] bool PrepareNotificationAndSetDisplayMode(
int64_t display_id,
const display::ManagedDisplayMode& old_resolution,
const display::ManagedDisplayMode& new_resolution,
crosapi::mojom::DisplayConfigSource source,
base::OnceClosure accept_callback);
DisplayChangeDialog* dialog_for_testing() const {
return confirmation_dialog_.get();
}
bool ShouldShowDisplayChangeDialog() const;
private:
friend class ResolutionNotificationControllerTest;
FRIEND_TEST_ALL_PREFIXES(ResolutionNotificationControllerTest, Timeout);
FRIEND_TEST_ALL_PREFIXES(DisplayPrefsTest, PreventStore);
// A struct to bundle the data for a single resolution change.
struct ResolutionChangeInfo;
// Create a new modal dialog, or replace the dialog if it already exists.
void CreateOrReplaceModalDialog();
// Called when the user accepts the display resolution change. Set
// |close_notification| to true when the notification should be removed.
void AcceptResolutionChange();
// Called when the user wants to revert the display resolution change.
void RevertResolutionChange(bool display_was_removed);
// display::DisplayObserver overrides:
void OnDisplaysRemoved(const display::Displays& removed_displays) override;
// display::DisplayManagerObserver overrides:
void OnDidApplyDisplayChanges() override;
std::unique_ptr<ResolutionChangeInfo> change_info_;
display::ScopedDisplayObserver display_observer_{this};
base::WeakPtr<DisplayChangeDialog> confirmation_dialog_;
base::WeakPtrFactory<ResolutionNotificationController> weak_factory_{this};
};
} // namespace ash
#endif // ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
|