| // Copyright 2022 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef ASH_CAPTURE_MODE_CAPTURE_MODE_TOAST_CONTROLLER_H_ |
| #define ASH_CAPTURE_MODE_CAPTURE_MODE_TOAST_CONTROLLER_H_ |
| |
| #include "ash/ash_export.h" |
| #include "base/timer/timer.h" |
| #include "third_party/abseil-cpp/absl/types/optional.h" |
| #include "ui/views/widget/unique_widget_ptr.h" |
| |
| namespace gfx { |
| class Rect; |
| } // namespace gfx |
| |
| namespace views { |
| class Widget; |
| class Label; |
| } // namespace views |
| |
| namespace ui { |
| class Layer; |
| } // namespace ui |
| |
| namespace ash { |
| |
| class CaptureModeSession; |
| |
| // Defines the capture toast type that Capture Mode is currently using. |
| enum class CaptureToastType { |
| kUserNudge, |
| kCameraPreview, |
| }; |
| |
| // Controls the capture mode toast shown in the capture session. |
| class ASH_EXPORT CaptureModeToastController { |
| public: |
| explicit CaptureModeToastController(CaptureModeSession* session); |
| CaptureModeToastController(const CaptureModeToastController&) = delete; |
| CaptureModeToastController& operator=(const CaptureModeToastController&) = |
| delete; |
| ~CaptureModeToastController(); |
| |
| const CaptureToastType* current_toast_type() const { |
| return current_toast_type_ ? &(*current_toast_type_) : nullptr; |
| } |
| views::Widget* capture_toast_widget() const { |
| return capture_toast_widget_.get(); |
| } |
| |
| // Shows `capture_toast_widget_` with label text defined by the given |
| // `capture_toast_type`; if `capture_toast_widget_` doesn't exist, creates |
| // one. Otherwise, just updates the label text for it if needed. |
| void ShowCaptureToast(CaptureToastType capture_toast_type); |
| |
| void MaybeDismissCaptureToast(CaptureToastType capture_toast_type, |
| bool animate = true); |
| |
| // Called when we need to dismiss the current toast in spite of the toast |
| // type. For example, when the settings menu is shown, the toast should be |
| // dismissed no matter what type it is. |
| void DismissCurrentToastIfAny(); |
| |
| void MaybeRepositionCaptureToast(); |
| |
| // Return the layer of `capture_toast_widget_` if it exists. |
| ui::Layer* MaybeGetToastLayer(); |
| |
| base::OneShotTimer* capture_toast_dismiss_timer_for_test() { |
| return &capture_toast_dismiss_timer_; |
| } |
| |
| private: |
| // Initializes the toast widget and its contents. |
| void BuildCaptureToastWidget(const std::u16string& label); |
| |
| gfx::Rect CalculateToastWidgetScreenBounds() const; |
| |
| // The session that owns `this`. Guaranteed to be non null for the lifetime of |
| // `this`. |
| CaptureModeSession* const capture_session_; |
| |
| // The capture toast widget and its contents view. |
| views::UniqueWidgetPtr capture_toast_widget_; |
| views::Label* toast_label_view_ = nullptr; |
| |
| // Stores the toast type of the `capture_toast_widget_` after it's created. |
| absl::optional<CaptureToastType> current_toast_type_; |
| |
| // Started when `capture_toast_widget_` is shown for `kCameraPreview`. Runs |
| // MaybeDismissCaptureToast() to fade out the capture toast if possible. |
| base::OneShotTimer capture_toast_dismiss_timer_; |
| |
| base::WeakPtrFactory<CaptureModeToastController> weak_ptr_factory_{this}; |
| }; |
| |
| } // namespace ash |
| |
| #endif // ASH_CAPTURE_MODE_CAPTURE_MODE_TOAST_CONTROLLER_H_ |