David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 1 | // 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 Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 5 | #ifndef ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_ |
| 6 | #define ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_ |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 7 | |
Xiaohui Chen | 6c60ed3 | 2018-09-05 17:55:35 | [diff] [blame] | 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
Qiang Xu | 89e5fa5 | 2018-05-25 18:26:08 | [diff] [blame] | 11 | #include "ash/ash_export.h" |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 12 | #include "ash/assistant/assistant_controller_observer.h" |
David Black | 5318ec1 | 2018-05-02 01:54:32 | [diff] [blame] | 13 | #include "ash/assistant/model/assistant_interaction_model_observer.h" |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 14 | #include "ash/assistant/model/assistant_screen_context_model_observer.h" |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 15 | #include "ash/assistant/model/assistant_ui_model.h" |
David Black | ad1f2f59 | 2018-07-09 23:28:10 | [diff] [blame] | 16 | #include "ash/assistant/model/assistant_ui_model_observer.h" |
David Black | a867c6f | 2018-07-17 02:44:09 | [diff] [blame] | 17 | #include "ash/assistant/ui/assistant_mini_view.h" |
David Black | e4b8cc1b | 2018-06-06 17:45:26 | [diff] [blame] | 18 | #include "ash/assistant/ui/caption_bar.h" |
David Black | 9766ecd | 2018-06-20 18:29:11 | [diff] [blame] | 19 | #include "ash/assistant/ui/dialog_plate/dialog_plate.h" |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 20 | #include "ash/highlighter/highlighter_controller.h" |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 21 | #include "base/macros.h" |
David Black | f6bedc9 | 2018-08-27 21:13:57 | [diff] [blame] | 22 | #include "base/timer/timer.h" |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 23 | #include "ui/views/widget/widget_observer.h" |
| 24 | |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 25 | namespace chromeos { |
| 26 | namespace assistant { |
| 27 | namespace mojom { |
| 28 | class Assistant; |
| 29 | } // namespace mojom |
| 30 | } // namespace assistant |
| 31 | } // namespace chromeos |
| 32 | |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 33 | namespace views { |
| 34 | class Widget; |
| 35 | } // namespace views |
| 36 | |
| 37 | namespace ash { |
| 38 | |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 39 | class AssistantContainerView; |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 40 | class AssistantController; |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 41 | |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 42 | class ASH_EXPORT AssistantUiController |
David Black | 6cc6de7 | 2018-06-06 00:34:41 | [diff] [blame] | 43 | : public views::WidgetObserver, |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 44 | public AssistantControllerObserver, |
David Black | e4b8cc1b | 2018-06-06 17:45:26 | [diff] [blame] | 45 | public AssistantInteractionModelObserver, |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 46 | public AssistantScreenContextModelObserver, |
David Black | ad1f2f59 | 2018-07-09 23:28:10 | [diff] [blame] | 47 | public AssistantUiModelObserver, |
David Black | a867c6f | 2018-07-17 02:44:09 | [diff] [blame] | 48 | public AssistantMiniViewDelegate, |
David Black | 9766ecd | 2018-06-20 18:29:11 | [diff] [blame] | 49 | public CaptionBarDelegate, |
David Black | afee7837 | 2018-06-25 23:44:45 | [diff] [blame] | 50 | public DialogPlateObserver, |
David Black | c153e317 | 2018-08-21 18:17:58 | [diff] [blame] | 51 | public HighlighterController::Observer { |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 52 | public: |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 53 | explicit AssistantUiController(AssistantController* assistant_controller); |
| 54 | ~AssistantUiController() override; |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 55 | |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 56 | // Provides a pointer to the |assistant| owned by AssistantController. |
| 57 | void SetAssistant(chromeos::assistant::mojom::Assistant* assistant); |
| 58 | |
David Black | 9531544b | 2018-06-05 22:44:24 | [diff] [blame] | 59 | // Returns the underlying model. |
David Black | cdc2b97 | 2018-09-14 01:18:27 | [diff] [blame] | 60 | const AssistantUiModel* model() const { return &model_; } |
David Black | 9531544b | 2018-06-05 22:44:24 | [diff] [blame] | 61 | |
| 62 | // Adds/removes the specified model |observer|. |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 63 | void AddModelObserver(AssistantUiModelObserver* observer); |
| 64 | void RemoveModelObserver(AssistantUiModelObserver* observer); |
David Black | 9531544b | 2018-06-05 22:44:24 | [diff] [blame] | 65 | |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 66 | // views::WidgetObserver: |
David Black | 8777aaa | 2018-05-08 17:37:25 | [diff] [blame] | 67 | void OnWidgetActivationChanged(views::Widget* widget, bool active) override; |
David Black | e4b8cc1b | 2018-06-06 17:45:26 | [diff] [blame] | 68 | void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override; |
Qiang Xu | bd6d84e7 | 2018-05-09 01:31:51 | [diff] [blame] | 69 | void OnWidgetDestroying(views::Widget* widget) override; |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 70 | |
David Black | 5318ec1 | 2018-05-02 01:54:32 | [diff] [blame] | 71 | // AssistantInteractionModelObserver: |
David Black | 9531544b | 2018-06-05 22:44:24 | [diff] [blame] | 72 | void OnInputModalityChanged(InputModality input_modality) override; |
David Black | 5318ec1 | 2018-05-02 01:54:32 | [diff] [blame] | 73 | void OnInteractionStateChanged(InteractionState interaction_state) override; |
David Black | e4b8cc1b | 2018-06-06 17:45:26 | [diff] [blame] | 74 | void OnMicStateChanged(MicState mic_state) override; |
| 75 | |
David Black | c22e435 | 2018-07-11 21:29:48 | [diff] [blame] | 76 | // AssistantScreenContextModelObserver: |
| 77 | void OnScreenContextRequestStateChanged( |
| 78 | ScreenContextRequestState request_state) override; |
| 79 | |
David Black | a867c6f | 2018-07-17 02:44:09 | [diff] [blame] | 80 | // AssistantMiniViewDelegate: |
| 81 | void OnAssistantMiniViewPressed() override; |
| 82 | |
David Black | e4b8cc1b | 2018-06-06 17:45:26 | [diff] [blame] | 83 | // CaptionBarDelegate: |
| 84 | bool OnCaptionButtonPressed(CaptionButtonId id) override; |
David Black | 5318ec1 | 2018-05-02 01:54:32 | [diff] [blame] | 85 | |
David Black | afee7837 | 2018-06-25 23:44:45 | [diff] [blame] | 86 | // DialogPlateObserver: |
David Black | 9766ecd | 2018-06-20 18:29:11 | [diff] [blame] | 87 | void OnDialogPlateButtonPressed(DialogPlateButtonId id) override; |
David Black | 46d1ff04 | 2018-06-20 01:19:04 | [diff] [blame] | 88 | |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 89 | // HighlighterController::Observer: |
| 90 | void OnHighlighterEnabledChanged(HighlighterEnabledState state) override; |
| 91 | |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 92 | // AssistantControllerObserver: |
David Black | 1f58bcc | 2018-07-12 17:59:40 | [diff] [blame] | 93 | void OnAssistantControllerConstructed() override; |
| 94 | void OnAssistantControllerDestroying() override; |
David Black | b0749ca5 | 2018-07-13 21:30:02 | [diff] [blame] | 95 | void OnDeepLinkReceived( |
| 96 | assistant::util::DeepLinkType type, |
| 97 | const std::map<std::string, std::string>& params) override; |
David Black | e802d406 | 2018-06-29 01:59:05 | [diff] [blame] | 98 | void OnUrlOpened(const GURL& url) override; |
| 99 | |
David Black | ad1f2f59 | 2018-07-09 23:28:10 | [diff] [blame] | 100 | // AssistantUiModelObserver: |
David Black | 4c6b9e2 | 2018-08-27 20:31:31 | [diff] [blame] | 101 | void OnUiVisibilityChanged(AssistantVisibility new_visibility, |
| 102 | AssistantVisibility old_visibility, |
| 103 | AssistantSource source) override; |
David Black | ad1f2f59 | 2018-07-09 23:28:10 | [diff] [blame] | 104 | |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 105 | void ShowUi(AssistantSource source); |
| 106 | void HideUi(AssistantSource source); |
David Black | 4c6b9e2 | 2018-08-27 20:31:31 | [diff] [blame] | 107 | void CloseUi(AssistantSource source); |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 108 | void ToggleUi(AssistantSource source); |
Qiang Xu | 89e5fa5 | 2018-05-25 18:26:08 | [diff] [blame] | 109 | |
David Black | 3171a7b | 2018-08-10 18:11:40 | [diff] [blame] | 110 | AssistantContainerView* GetViewForTest(); |
| 111 | |
David Black | 5318ec1 | 2018-05-02 01:54:32 | [diff] [blame] | 112 | private: |
David Black | e4b8cc1b | 2018-06-06 17:45:26 | [diff] [blame] | 113 | // 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 Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 117 | AssistantController* const assistant_controller_; // Owned by Shell. |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 118 | |
David Black | 4703d7b | 2018-06-22 00:16:39 | [diff] [blame] | 119 | // Owned by AssistantController. |
| 120 | chromeos::assistant::mojom::Assistant* assistant_ = nullptr; |
| 121 | |
David Black | cdc2b97 | 2018-09-14 01:18:27 | [diff] [blame] | 122 | AssistantUiModel model_; |
David Black | 9766ecd | 2018-06-20 18:29:11 | [diff] [blame] | 123 | |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 124 | AssistantContainerView* container_view_ = |
| 125 | nullptr; // Owned by view hierarchy. |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 126 | |
David Black | f6bedc9 | 2018-08-27 21:13:57 | [diff] [blame] | 127 | // 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 Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(AssistantUiController); |
David Black | f7f8d201 | 2018-04-25 19:48:02 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | } // namespace ash |
| 137 | |
David Black | 1d1b1b67 | 2018-06-20 21:41:57 | [diff] [blame] | 138 | #endif // ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_ |