Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 if the resolution change is potentially dangerous. | |
|
Daniel Erat
2013/08/09 15:50:24
nit: "potentially dangerous" seems like too-strong
Jun Mukai
2013/08/09 16:49:16
done, but I think 'in case' would be better than '
Daniel Erat
2013/08/09 16:55:46
"in case" seems more precise to me too :-)
| |
| 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 timeouts if the | |
|
Daniel Erat
2013/08/09 15:50:24
nit: s/timeouts if/times out in case/
("timeout"
Jun Mukai
2013/08/09 16:49:16
Done.
| |
| 35 // display resolution change operation is potentially dangerous, i.e. there's | |
|
Daniel Erat
2013/08/09 15:50:24
same here -- "potentially dangerous" makes it soun
Jun Mukai
2013/08/09 16:49:16
just removed that sentence and write the condition
| |
| 36 // only one display connected and the user is trying to modify its resolution. | |
| 37 // In that case, the timeout has to be set since the user cannot make any | |
| 38 // operations if something goes wrong. | |
|
Daniel Erat
2013/08/09 15:50:24
nit: s/operations/changes/
Jun Mukai
2013/08/09 16:49:16
Done.
| |
| 39 void SetDisplayResolutionAndNotify( | |
| 40 int64 display_id, | |
| 41 const gfx::Size& old_resolution, | |
| 42 const gfx::Size& new_resolution, | |
| 43 const base::Closure& accept_callback); | |
| 44 | |
| 45 // Returns true if the notification is visible or scheduled to be visible and | |
| 46 // the notification timeouts. | |
|
Daniel Erat
2013/08/09 15:50:24
nit: s/timeouts/times out/
Jun Mukai
2013/08/09 16:49:16
Done.
| |
| 47 bool DoesNotificationTimeout(); | |
| 48 | |
| 49 // Called by the notification delegate when the user accepts the display | |
| 50 // resolution change. | |
| 51 void AcceptResolutionChange(); | |
| 52 | |
| 53 // Called by the notification delegate when the user wants to revert the | |
| 54 // display resolution change. | |
| 55 void RevertResolutionChange(); | |
| 56 | |
| 57 private: | |
| 58 friend class ResolutionNotificationControllerTest; | |
| 59 FRIEND_TEST_ALL_PREFIXES(ResolutionNotificationControllerTest, Timeout); | |
| 60 | |
| 61 // A struct to bundle the data for a single resolution change. | |
| 62 struct ResolutionChangeInfo { | |
| 63 // The id of the display where the resolution change happens. | |
| 64 int64 display_id; | |
| 65 | |
| 66 // The resolution before the change. | |
| 67 gfx::Size old_resolution; | |
| 68 | |
| 69 // The new resolution after the change. | |
| 70 gfx::Size new_resolution; | |
| 71 | |
| 72 // The callback when accept is chosen. | |
| 73 base::Closure accept_callback; | |
| 74 | |
| 75 // The remaining timeout in seconds. 0 if the change does not timeout. | |
|
Daniel Erat
2013/08/09 15:50:24
nit: s/does not timeout/does not time out/
Jun Mukai
2013/08/09 16:49:16
Done.
| |
| 76 uint8 timeout_count; | |
| 77 | |
| 78 // The timer to invoke OnTimerTick() every second. This cannot be | |
| 79 // OneShotTimer since the message contains text "automatically closed in xx | |
| 80 // seconds..." which has to be updated every second. | |
| 81 base::RepeatingTimer<ResolutionNotificationController> timer; | |
| 82 | |
| 83 ResolutionChangeInfo(int64 display_id, | |
|
Daniel Erat
2013/08/09 15:50:24
nit: move c'tor and d'tor to top of members
Jun Mukai
2013/08/09 16:49:16
Done.
| |
| 84 const gfx::Size& old_resolution, | |
| 85 const gfx::Size& new_resolution, | |
| 86 const base::Closure& accept_callback); | |
| 87 ~ResolutionChangeInfo(); | |
| 88 }; | |
|
Daniel Erat
2013/08/09 15:50:24
nit: DISALLOW_COPY_AND_ASSIGN() (Timer isn't copya
Jun Mukai
2013/08/09 16:49:16
Done.
| |
| 89 | |
| 90 // Create a new notification, or update its content if it already exists. | |
| 91 void CreateOrUpdateNotification(); | |
| 92 | |
| 93 // Called every second for timeout. | |
| 94 void OnTimerTick(); | |
| 95 | |
| 96 // gfx::DisplayObserver overrides: | |
| 97 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; | |
| 98 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; | |
| 99 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; | |
| 100 | |
| 101 // DisplayController::Observer overrides: | |
| 102 virtual void OnDisplayConfigurationChanged() OVERRIDE; | |
| 103 | |
| 104 static void SuppressTimerForTest(); | |
| 105 | |
| 106 static const int kTimeoutInSec; | |
|
Daniel Erat
2013/08/09 15:50:24
nit: static const members should be near the top o
Jun Mukai
2013/08/09 16:49:16
moved.
| |
| 107 static const char kNotificationId[]; | |
| 108 | |
| 109 scoped_ptr<ResolutionChangeInfo> change_info_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationController); | |
| 112 }; | |
| 113 | |
| 114 } // namespace internal | |
| 115 } // namespace ash | |
| 116 | |
| 117 #endif // ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_ | |
| OLD | NEW |