1 // Copyright 2019 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_DISPLAY_CHANGE_DIALOG_H_ 6 #define ASH_DISPLAY_DISPLAY_CHANGE_DIALOG_H_ 7 8 #include "ash/ash_export.h" 9 #include "base/callback.h" 10 #include "base/memory/weak_ptr.h" 11 #include "base/strings/string16.h" 12 #include "base/timer/timer.h" 13 #include "ui/views/window/dialog_delegate.h" 14 15 namespace views { 16 class Label; 17 } // namespace views 18 19 namespace ash { 20 21 // Modal system dialog that is displayed when a user changes the configuration 22 // of an external display. 23 class ASH_EXPORT DisplayChangeDialog : public views::DialogDelegateView { 24 public: 25 using CancelCallback = base::OnceCallback<void(bool display_was_removed)>; 26 27 DisplayChangeDialog(base::string16 window_title, 28 base::string16 timeout_message_with_placeholder, 29 base::OnceClosure on_accept_callback, 30 CancelCallback on_cancel_callback); 31 ~DisplayChangeDialog() override; 32 33 DisplayChangeDialog(const DisplayChangeDialog&) = delete; 34 DisplayChangeDialog& operator=(const DisplayChangeDialog&) = delete; 35 36 // views::View: 37 gfx::Size CalculatePreferredSize() const override; 38 39 base::WeakPtr<DisplayChangeDialog> GetWeakPtr(); 40 41 private: 42 friend class ResolutionNotificationControllerTest; 43 FRIEND_TEST_ALL_PREFIXES(ResolutionNotificationControllerTest, Timeout); 44 45 static constexpr uint16_t kDefaultTimeoutInSeconds = 15; 46 47 void OnConfirmButtonClicked(); 48 49 void OnCancelButtonClicked(); 50 51 void OnTimerTick(); 52 53 // Returns the string displayed as a message in the dialog which includes a 54 // countdown timer. 55 base::string16 GetRevertTimeoutString() const; 56 57 // The remaining timeout in seconds. 58 uint16_t timeout_count_ = kDefaultTimeoutInSeconds; 59 60 const base::string16 timeout_message_with_placeholder_; 61 62 views::Label* label_ = nullptr; // Not owned. 63 base::OnceClosure on_accept_callback_; 64 CancelCallback on_cancel_callback_; 65 66 // The timer to invoke OnTimerTick() every second. This cannot be 67 // OneShotTimer since the message contains text "automatically closed in xx 68 // seconds..." which has to be updated every second. 69 base::RepeatingTimer timer_; 70 71 base::WeakPtrFactory<DisplayChangeDialog> weak_factory_{this}; 72 }; 73 74 } // namespace ash 75 76 #endif // ASH_DISPLAY_DISPLAY_CHANGE_DIALOG_H_ 77