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 chromeos { |
| 17 FORWARD_DECLARE_TEST(DisplayPreferencesTest, PreventStore); |
| 18 } // namespace chromeos |
| 19 |
| 20 namespace views { |
| 21 class Label; |
| 22 class Widget; |
| 23 } // namespace views |
| 24 |
| 25 namespace ash { |
| 26 namespace internal { |
| 27 // A class which manages the notification of display resolution change and |
| 28 // also manages the timeout in case the new resolution is unusable. |
| 29 class ASH_EXPORT ResolutionNotificationController |
| 30 : public gfx::DisplayObserver, |
| 31 public DisplayController::Observer { |
| 32 public: |
| 33 ResolutionNotificationController(); |
| 34 virtual ~ResolutionNotificationController(); |
| 35 |
| 36 // Updates the display resolution for |display_id| to |new_resolution| and |
| 37 // creates a notification for this change which offers a button to revert the |
| 38 // change in case something goes wrong. The notification times out if there's |
| 39 // only one display connected and the user is trying to modify its resolution. |
| 40 // In that case, the timeout has to be set since the user cannot make any |
| 41 // changes if something goes wrong. |
| 42 void SetDisplayResolutionAndNotify( |
| 43 int64 display_id, |
| 44 const gfx::Size& old_resolution, |
| 45 const gfx::Size& new_resolution, |
| 46 const base::Closure& accept_callback); |
| 47 |
| 48 // Returns true if the notification is visible or scheduled to be visible and |
| 49 // the notification times out. |
| 50 bool DoesNotificationTimeout(); |
| 51 |
| 52 // Called by the notification delegate when the user accepts the display |
| 53 // resolution change. |
| 54 void AcceptResolutionChange(); |
| 55 |
| 56 // Called by the notification delegate when the user wants to revert the |
| 57 // display resolution change. |
| 58 void RevertResolutionChange(); |
| 59 |
| 60 private: |
| 61 friend class ResolutionNotificationControllerTest; |
| 62 FRIEND_TEST_ALL_PREFIXES(ResolutionNotificationControllerTest, Timeout); |
| 63 FRIEND_TEST_ALL_PREFIXES(chromeos::DisplayPreferencesTest, PreventStore); |
| 64 |
| 65 // A struct to bundle the data for a single resolution change. |
| 66 struct ResolutionChangeInfo; |
| 67 |
| 68 static const int kTimeoutInSec; |
| 69 static const char kNotificationId[]; |
| 70 |
| 71 // Create a new notification, or update its content if it already exists. |
| 72 void CreateOrUpdateNotification(); |
| 73 |
| 74 // Called every second for timeout. |
| 75 void OnTimerTick(); |
| 76 |
| 77 // gfx::DisplayObserver overrides: |
| 78 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; |
| 79 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; |
| 80 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; |
| 81 |
| 82 // DisplayController::Observer overrides: |
| 83 virtual void OnDisplayConfigurationChanged() OVERRIDE; |
| 84 |
| 85 static void SuppressTimerForTest(); |
| 86 |
| 87 scoped_ptr<ResolutionChangeInfo> change_info_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationController); |
| 90 }; |
| 91 |
| 92 } // namespace internal |
| 93 } // namespace ash |
| 94 |
| 95 #endif // ASH_DISPLAY_RESOLUTION_NOTIFICATION_CONTROLLER_H_ |
OLD | NEW |