1 // Copyright 2016 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_SYSTEM_TOAST_TOAST_OVERLAY_H_ 6 #define ASH_SYSTEM_TOAST_TOAST_OVERLAY_H_ 7 8 #include <memory> 9 10 #include "ash/ash_export.h" 11 #include "ash/public/cpp/keyboard/keyboard_controller_observer.h" 12 #include "base/optional.h" 13 #include "base/strings/string16.h" 14 #include "ui/compositor/layer_animation_observer.h" 15 #include "ui/events/event.h" 16 #include "ui/events/event_constants.h" 17 #include "ui/gfx/geometry/size.h" 18 19 namespace gfx { 20 class Rect; 21 } 22 23 namespace views { 24 class Widget; 25 } 26 27 namespace ash { 28 29 class ToastManagerImplTest; 30 class ToastOverlayView; 31 class ToastOverlayButton; 32 33 class ASH_EXPORT ToastOverlay : public ui::ImplicitAnimationObserver, 34 public KeyboardControllerObserver { 35 public: 36 class ASH_EXPORT Delegate { 37 public: ~Delegate()38 virtual ~Delegate() {} 39 virtual void OnClosed() = 0; 40 }; 41 42 // Offset of the overlay from the edge of the work area. 43 static constexpr int kOffset = 16; 44 45 // Creates the Toast overlay UI. |text| is the message to be shown, and 46 // |dismiss_text| is the message for the button to dismiss the toast message. 47 // If |dismiss_text| is null, no dismiss button will be shown. If 48 // |dismiss_text| has a value but the string is empty, the default text is 49 // used. If |is_managed| is true, a managed icon will be added to the toast. 50 ToastOverlay(Delegate* delegate, 51 const base::string16& text, 52 base::Optional<base::string16> dismiss_text, 53 bool show_on_lock_screen, 54 bool is_managed); 55 ~ToastOverlay() override; 56 57 // Shows or hides the overlay. 58 void Show(bool visible); 59 60 // Update the position and size of toast. 61 void UpdateOverlayBounds(); 62 63 private: 64 friend class ToastManagerImplTest; 65 66 class ToastDisplayObserver; 67 68 // Returns the current bounds of the overlay, which is based on visibility. 69 gfx::Rect CalculateOverlayBounds(); 70 71 // ui::ImplicitAnimationObserver: 72 void OnImplicitAnimationsScheduled() override; 73 void OnImplicitAnimationsCompleted() override; 74 75 // KeyboardControllerObserver: 76 void OnKeyboardOccludedBoundsChanged(const gfx::Rect& new_bounds) override; 77 78 views::Widget* widget_for_testing(); 79 ToastOverlayButton* dismiss_button_for_testing(); 80 void ClickDismissButtonForTesting(const ui::Event& event); 81 82 Delegate* const delegate_; 83 const base::string16 text_; 84 const base::Optional<base::string16> dismiss_text_; 85 std::unique_ptr<views::Widget> overlay_widget_; 86 std::unique_ptr<ToastOverlayView> overlay_view_; 87 std::unique_ptr<ToastDisplayObserver> display_observer_; 88 89 gfx::Size widget_size_; 90 91 DISALLOW_COPY_AND_ASSIGN(ToastOverlay); 92 }; 93 94 } // namespace ash 95 96 #endif // ASH_SYSTEM_TOAST_TOAST_OVERLAY_H_ 97