blob: 9ae4b9616c11af48ac8d163caee0acb6a5e41ee2 [file] [log] [blame]
// Copyright 2018 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_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_
#define ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/assistant/assistant_controller_observer.h"
#include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/assistant/model/assistant_screen_context_model_observer.h"
#include "ash/assistant/model/assistant_ui_model.h"
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "ash/assistant/ui/caption_bar.h"
#include "ash/assistant/ui/dialog_plate/dialog_plate.h"
#include "ash/highlighter/highlighter_controller.h"
#include "base/macros.h"
#include "ui/views/widget/widget_observer.h"
namespace chromeos {
namespace assistant {
namespace mojom {
class Assistant;
} // namespace mojom
} // namespace assistant
} // namespace chromeos
namespace views {
class Widget;
} // namespace views
namespace ash {
class AssistantContainerView;
class AssistantController;
namespace mojom {
class AssistantSetup;
} // namespace mojom
class ASH_EXPORT AssistantUiController
: public views::WidgetObserver,
public AssistantControllerObserver,
public AssistantInteractionModelObserver,
public AssistantScreenContextModelObserver,
public AssistantUiModelObserver,
public CaptionBarDelegate,
public DialogPlateObserver,
public HighlighterController::Observer {
public:
explicit AssistantUiController(AssistantController* assistant_controller);
~AssistantUiController() override;
// Provides a pointer to the |assistant| owned by AssistantController.
void SetAssistant(chromeos::assistant::mojom::Assistant* assistant);
// Provides a pointer to the |assistant_setup| owned by AssistantController.
void SetAssistantSetup(mojom::AssistantSetup* assistant_setup);
// Returns the underlying model.
const AssistantUiModel* model() const { return &assistant_ui_model_; }
// Adds/removes the specified model |observer|.
void AddModelObserver(AssistantUiModelObserver* observer);
void RemoveModelObserver(AssistantUiModelObserver* observer);
// views::WidgetObserver:
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
void OnWidgetDestroying(views::Widget* widget) override;
// AssistantInteractionModelObserver:
void OnInputModalityChanged(InputModality input_modality) override;
void OnInteractionStateChanged(InteractionState interaction_state) override;
void OnMicStateChanged(MicState mic_state) override;
// AssistantScreenContextModelObserver:
void OnScreenContextRequestStateChanged(
ScreenContextRequestState request_state) override;
// CaptionBarDelegate:
bool OnCaptionButtonPressed(CaptionButtonId id) override;
// DialogPlateObserver:
void OnDialogPlateButtonPressed(DialogPlateButtonId id) override;
// HighlighterController::Observer:
void OnHighlighterEnabledChanged(HighlighterEnabledState state) override;
// AssistantControllerObserver:
void OnAssistantControllerConstructed() override;
void OnAssistantControllerDestroying() override;
void OnDeepLinkReceived(
assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) override;
void OnUrlOpened(const GURL& url) override;
// AssistantUiModelObserver:
void OnUiVisibilityChanged(bool visible, AssistantSource source) override;
void ShowUi(AssistantSource source);
void HideUi(AssistantSource source);
void ToggleUi(AssistantSource source);
private:
// Updates UI mode to |ui_mode| if specified. Otherwise UI mode is updated on
// the basis of interaction/widget visibility state.
void UpdateUiMode(base::Optional<AssistantUiMode> ui_mode = base::nullopt);
AssistantController* const assistant_controller_; // Owned by Shell.
// Owned by AssistantController.
chromeos::assistant::mojom::Assistant* assistant_ = nullptr;
// Owned by AssistantController.
mojom::AssistantSetup* assistant_setup_ = nullptr;
AssistantUiModel assistant_ui_model_;
AssistantContainerView* container_view_ =
nullptr; // Owned by view hierarchy.
DISALLOW_COPY_AND_ASSIGN(AssistantUiController);
};
} // namespace ash
#endif // ASH_ASSISTANT_ASSISTANT_UI_CONTROLLER_H_