blob: 715ef62506e8d21760b6d938548ecf8f36b259dc [file] [log] [blame]
David Blackf7f8d2012018-04-25 19:48:021// Copyright 2018 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
David Black1d1b1b672018-06-20 21:41:575#ifndef ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_
6#define ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_
David Blackf7f8d2012018-04-25 19:48:027
Xiaohui Chen6c60ed32018-09-05 17:55:358#include <map>
9#include <string>
10
Qiang Xu89e5fa52018-05-25 18:26:0811#include "ash/ash_export.h"
David Blacke802d4062018-06-29 01:59:0512#include "ash/assistant/assistant_controller_observer.h"
David Black5318ec12018-05-02 01:54:3213#include "ash/assistant/model/assistant_interaction_model_observer.h"
David Blackc22e4352018-07-11 21:29:4814#include "ash/assistant/model/assistant_screen_context_model_observer.h"
David Black1d1b1b672018-06-20 21:41:5715#include "ash/assistant/model/assistant_ui_model.h"
David Blackad1f2f592018-07-09 23:28:1016#include "ash/assistant/model/assistant_ui_model_observer.h"
David Blacka867c6f2018-07-17 02:44:0917#include "ash/assistant/ui/assistant_mini_view.h"
David Blacke4b8cc1b2018-06-06 17:45:2618#include "ash/assistant/ui/caption_bar.h"
David Black9766ecd2018-06-20 18:29:1119#include "ash/assistant/ui/dialog_plate/dialog_plate.h"
David Black4703d7b2018-06-22 00:16:3920#include "ash/highlighter/highlighter_controller.h"
David Blackf7f8d2012018-04-25 19:48:0221#include "base/macros.h"
David Blackf6bedc92018-08-27 21:13:5722#include "base/timer/timer.h"
David Blackf7f8d2012018-04-25 19:48:0223#include "ui/views/widget/widget_observer.h"
24
David Black4703d7b2018-06-22 00:16:3925namespace chromeos {
26namespace assistant {
27namespace mojom {
28class Assistant;
29} // namespace mojom
30} // namespace assistant
31} // namespace chromeos
32
David Blackf7f8d2012018-04-25 19:48:0233namespace views {
34class Widget;
35} // namespace views
36
37namespace ash {
38
David Black1d1b1b672018-06-20 21:41:5739class AssistantContainerView;
David Black00fdce32018-05-10 20:59:1440class AssistantController;
David Black4703d7b2018-06-22 00:16:3941
David Black1d1b1b672018-06-20 21:41:5742class ASH_EXPORT AssistantUiController
David Black6cc6de72018-06-06 00:34:4143 : public views::WidgetObserver,
David Blacke802d4062018-06-29 01:59:0544 public AssistantControllerObserver,
David Blacke4b8cc1b2018-06-06 17:45:2645 public AssistantInteractionModelObserver,
David Blackc22e4352018-07-11 21:29:4846 public AssistantScreenContextModelObserver,
David Blackad1f2f592018-07-09 23:28:1047 public AssistantUiModelObserver,
David Blacka867c6f2018-07-17 02:44:0948 public AssistantMiniViewDelegate,
David Black9766ecd2018-06-20 18:29:1149 public CaptionBarDelegate,
David Blackafee78372018-06-25 23:44:4550 public DialogPlateObserver,
David Blackc153e3172018-08-21 18:17:5851 public HighlighterController::Observer {
David Blackf7f8d2012018-04-25 19:48:0252 public:
David Black1d1b1b672018-06-20 21:41:5753 explicit AssistantUiController(AssistantController* assistant_controller);
54 ~AssistantUiController() override;
David Blackf7f8d2012018-04-25 19:48:0255
David Black4703d7b2018-06-22 00:16:3956 // Provides a pointer to the |assistant| owned by AssistantController.
57 void SetAssistant(chromeos::assistant::mojom::Assistant* assistant);
58
David Black9531544b2018-06-05 22:44:2459 // Returns the underlying model.
David Blackcdc2b972018-09-14 01:18:2760 const AssistantUiModel* model() const { return &model_; }
David Black9531544b2018-06-05 22:44:2461
62 // Adds/removes the specified model |observer|.
David Black1d1b1b672018-06-20 21:41:5763 void AddModelObserver(AssistantUiModelObserver* observer);
64 void RemoveModelObserver(AssistantUiModelObserver* observer);
David Black9531544b2018-06-05 22:44:2465
David Blackf7f8d2012018-04-25 19:48:0266 // views::WidgetObserver:
David Black8777aaa2018-05-08 17:37:2567 void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
David Blacke4b8cc1b2018-06-06 17:45:2668 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
Qiang Xubd6d84e72018-05-09 01:31:5169 void OnWidgetDestroying(views::Widget* widget) override;
David Blackf7f8d2012018-04-25 19:48:0270
David Black5318ec12018-05-02 01:54:3271 // AssistantInteractionModelObserver:
David Black9531544b2018-06-05 22:44:2472 void OnInputModalityChanged(InputModality input_modality) override;
David Black5318ec12018-05-02 01:54:3273 void OnInteractionStateChanged(InteractionState interaction_state) override;
David Blacke4b8cc1b2018-06-06 17:45:2674 void OnMicStateChanged(MicState mic_state) override;
75
David Blackc22e4352018-07-11 21:29:4876 // AssistantScreenContextModelObserver:
77 void OnScreenContextRequestStateChanged(
78 ScreenContextRequestState request_state) override;
79
David Blacka867c6f2018-07-17 02:44:0980 // AssistantMiniViewDelegate:
81 void OnAssistantMiniViewPressed() override;
82
David Blacke4b8cc1b2018-06-06 17:45:2683 // CaptionBarDelegate:
84 bool OnCaptionButtonPressed(CaptionButtonId id) override;
David Black5318ec12018-05-02 01:54:3285
David Blackafee78372018-06-25 23:44:4586 // DialogPlateObserver:
David Black9766ecd2018-06-20 18:29:1187 void OnDialogPlateButtonPressed(DialogPlateButtonId id) override;
David Black46d1ff042018-06-20 01:19:0488
David Black4703d7b2018-06-22 00:16:3989 // HighlighterController::Observer:
90 void OnHighlighterEnabledChanged(HighlighterEnabledState state) override;
91
David Blacke802d4062018-06-29 01:59:0592 // AssistantControllerObserver:
David Black1f58bcc2018-07-12 17:59:4093 void OnAssistantControllerConstructed() override;
94 void OnAssistantControllerDestroying() override;
David Blackb0749ca52018-07-13 21:30:0295 void OnDeepLinkReceived(
96 assistant::util::DeepLinkType type,
97 const std::map<std::string, std::string>& params) override;
David Blacke802d4062018-06-29 01:59:0598 void OnUrlOpened(const GURL& url) override;
99
David Blackad1f2f592018-07-09 23:28:10100 // AssistantUiModelObserver:
David Black4c6b9e22018-08-27 20:31:31101 void OnUiVisibilityChanged(AssistantVisibility new_visibility,
102 AssistantVisibility old_visibility,
103 AssistantSource source) override;
David Blackad1f2f592018-07-09 23:28:10104
David Black4703d7b2018-06-22 00:16:39105 void ShowUi(AssistantSource source);
106 void HideUi(AssistantSource source);
David Black4c6b9e22018-08-27 20:31:31107 void CloseUi(AssistantSource source);
David Black4703d7b2018-06-22 00:16:39108 void ToggleUi(AssistantSource source);
Qiang Xu89e5fa52018-05-25 18:26:08109
David Black3171a7b2018-08-10 18:11:40110 AssistantContainerView* GetViewForTest();
111
David Black5318ec12018-05-02 01:54:32112 private:
David Blacke4b8cc1b2018-06-06 17:45:26113 // Updates UI mode to |ui_mode| if specified. Otherwise UI mode is updated on
114 // the basis of interaction/widget visibility state.
115 void UpdateUiMode(base::Optional<AssistantUiMode> ui_mode = base::nullopt);
116
David Black00fdce32018-05-10 20:59:14117 AssistantController* const assistant_controller_; // Owned by Shell.
David Blackf7f8d2012018-04-25 19:48:02118
David Black4703d7b2018-06-22 00:16:39119 // Owned by AssistantController.
120 chromeos::assistant::mojom::Assistant* assistant_ = nullptr;
121
David Blackcdc2b972018-09-14 01:18:27122 AssistantUiModel model_;
David Black9766ecd2018-06-20 18:29:11123
David Black1d1b1b672018-06-20 21:41:57124 AssistantContainerView* container_view_ =
125 nullptr; // Owned by view hierarchy.
David Blackf7f8d2012018-04-25 19:48:02126
David Blackf6bedc92018-08-27 21:13:57127 // When hidden, Assistant automatically closes itself to finish the previous
128 // session. We delay this behavior to allow the user an opportunity to resume.
129 base::OneShotTimer auto_close_timer_;
130
131 base::WeakPtrFactory<AssistantUiController> weak_factory_;
132
David Black1d1b1b672018-06-20 21:41:57133 DISALLOW_COPY_AND_ASSIGN(AssistantUiController);
David Blackf7f8d2012018-04-25 19:48:02134};
135
136} // namespace ash
137
David Black1d1b1b672018-06-20 21:41:57138#endif // ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_