Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: ash/display/resolution_notification_controller.h

Issue 22703004: Creates notifications for display resolution change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
6 #define ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
7
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"
15
16 namespace views {
17 class Label;
18 class Widget;
19 } // namespace views
20
21 namespace ash {
22 namespace internal {
23 // A class which manages the notification of display resolution change and
24 // also manages the timeout in case the new resolution is unusable.
25 class ASH_EXPORT ResolutionNotificationController
26 : public gfx::DisplayObserver,
27 public DisplayController::Observer {
28 public:
29 ResolutionNotificationController();
30 virtual ~ResolutionNotificationController();
31
32 // Updates the display resolution for |display_id| to |new_resolution| and
33 // creates a notification for this change which offers a button to revert the
34 // change in case something goes wrong. The notification times out if there's
35 // only one display connected and the user is trying to modify its resolution.
36 // In that case, the timeout has to be set since the user cannot make any
37 // changes if something goes wrong.
38 void SetDisplayResolutionAndNotify(
39 int64 display_id,
40 const gfx::Size& old_resolution,
41 const gfx::Size& new_resolution,
42 const base::Closure& accept_callback);
43
44 // Returns true if the notification is visible or scheduled to be visible and
45 // the notification times out.
46 bool DoesNotificationTimeout();
47
48 // Called by the notification delegate when the user accepts the display
49 // resolution change.
50 void AcceptResolutionChange();
51
52 // Called by the notification delegate when the user wants to revert the
53 // display resolution change.
54 void RevertResolutionChange();
55
56 private:
57 friend class ResolutionNotificationControllerTest;
58 FRIEND_TEST_ALL_PREFIXES(ResolutionNotificationControllerTest, Timeout);
59
60 // A struct to bundle the data for a single resolution change.
61 struct ResolutionChangeInfo {
oshima 2013/08/09 17:42:56 can you move the definition to .cc because this is
Jun Mukai 2013/08/09 21:04:58 Done.
62 ResolutionChangeInfo(int64 display_id,
63 const gfx::Size& old_resolution,
64 const gfx::Size& new_resolution,
65 const base::Closure& accept_callback);
66 ~ResolutionChangeInfo();
67
68 // The id of the display where the resolution change happens.
69 int64 display_id;
70
71 // The resolution before the change.
72 gfx::Size old_resolution;
73
74 // The new resolution after the change.
75 gfx::Size new_resolution;
76
77 // The callback when accept is chosen.
78 base::Closure accept_callback;
79
80 // The remaining timeout in seconds. 0 if the change does not time out.
81 uint8 timeout_count;
82
83 // The timer to invoke OnTimerTick() every second. This cannot be
84 // OneShotTimer since the message contains text "automatically closed in xx
85 // seconds..." which has to be updated every second.
86 base::RepeatingTimer<ResolutionNotificationController> timer;
87
88 private:
89 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeInfo);
90 };
91
92 static const int kTimeoutInSec;
93 static const char kNotificationId[];
94
95 // Create a new notification, or update its content if it already exists.
96 void CreateOrUpdateNotification();
97
98 // Called every second for timeout.
99 void OnTimerTick();
100
101 // gfx::DisplayObserver overrides:
102 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
103 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
104 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
105
106 // DisplayController::Observer overrides:
107 virtual void OnDisplayConfigurationChanged() OVERRIDE;
108
109 static void SuppressTimerForTest();
110
111 scoped_ptr<ResolutionChangeInfo> change_info_;
112
113 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationController);
114 };
115
116 } // namespace internal
117 } // namespace ash
118
119 #endif // ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698