1 // Copyright 2013 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.
5 #ifndef ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
6 #define ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "ash/display/display_controller.h"
10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/timer/timer.h"
13 #include "ui/gfx/display_observer.h"
14 #include "ui/gfx/size.h"
17 FORWARD_DECLARE_TEST(DisplayPreferencesTest
, PreventStore
);
18 } // namespace chromeos
29 // A class which manages the notification of display resolution change and
30 // also manages the timeout in case the new resolution is unusable.
31 class ASH_EXPORT ResolutionNotificationController
32 : public gfx::DisplayObserver
,
33 public DisplayController::Observer
{
35 ResolutionNotificationController();
36 virtual ~ResolutionNotificationController();
38 // Prepare a resolution change notification for |display_id| from
39 // |old_resolution| to |new_resolution|, which offers a button to revert the
40 // change in case something goes wrong. The notification times out if there's
41 // only one display connected and the user is trying to modify its resolution.
42 // In that case, the timeout has to be set since the user cannot make any
43 // changes if something goes wrong.
45 // This method does not create a notification itself. The notification will be
46 // created the next OnDisplayConfigurationChanged(), which will be called
47 // asynchronously after the resolution change is requested. So typically this
48 // method will be combined with resolution change methods like
49 // DisplayManager::SetDisplayMode().
50 void PrepareNotification(int64 display_id
,
51 const DisplayMode
& old_resolution
,
52 const DisplayMode
& new_resolution
,
53 const base::Closure
& accept_callback
);
55 // Returns true if the notification is visible or scheduled to be visible and
56 // the notification times out.
57 bool DoesNotificationTimeout();
59 // Called by the notification delegate when the user accepts the display
60 // resolution change. Set |close_notification| to true when the notification
62 void AcceptResolutionChange(bool close_notification
);
64 // Called by the notification delegate when the user wants to revert the
65 // display resolution change.
66 void RevertResolutionChange();
69 friend class ResolutionNotificationControllerTest
;
70 FRIEND_TEST_ALL_PREFIXES(ResolutionNotificationControllerTest
, Timeout
);
71 FRIEND_TEST_ALL_PREFIXES(chromeos::DisplayPreferencesTest
, PreventStore
);
73 // A struct to bundle the data for a single resolution change.
74 struct ResolutionChangeInfo
;
76 static const int kTimeoutInSec
;
77 static const char kNotificationId
[];
79 // Create a new notification, or update its content if it already exists.
80 // |enable_spoken_feedback| is set to false when the notification is updated
81 // during the countdown so the update isn't necessarily read by the spoken
83 void CreateOrUpdateNotification(bool enable_spoken_feedback
);
85 // Called every second for timeout.
88 // gfx::DisplayObserver overrides:
89 virtual void OnDisplayAdded(const gfx::Display
& new_display
) OVERRIDE
;
90 virtual void OnDisplayRemoved(const gfx::Display
& old_display
) OVERRIDE
;
91 virtual void OnDisplayMetricsChanged(const gfx::Display
& display
,
92 uint32_t metrics
) OVERRIDE
;
94 // DisplayController::Observer overrides:
95 virtual void OnDisplayConfigurationChanged() OVERRIDE
;
97 static void SuppressTimerForTest();
99 scoped_ptr
<ResolutionChangeInfo
> change_info_
;
101 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationController
);
106 #endif // ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_