Commit 5318ec14 authored by David Black's avatar David Black Committed by Commit Bot

Adds InteractionState to AssistantInteractionModel.

State is simplified to {kInactive, kActive} for now but will need more
granularity later on.

Bug: b:78913434
Change-Id: I558c4f2c9b2b266a621a36fc67ecd5af1d28eed6
Reviewed-on: https://chromium-review.googlesource.com/1036729Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#555283}
parent 096b5311
...@@ -24,9 +24,12 @@ AshAssistantController::AshAssistantController() ...@@ -24,9 +24,12 @@ AshAssistantController::AshAssistantController()
: assistant_controller_binding_(this), : assistant_controller_binding_(this),
assistant_event_subscriber_binding_(this), assistant_event_subscriber_binding_(this),
assistant_bubble_(std::make_unique<AssistantBubble>(this)) { assistant_bubble_(std::make_unique<AssistantBubble>(this)) {
AddInteractionModelObserver(this);
} }
AshAssistantController::~AshAssistantController() { AshAssistantController::~AshAssistantController() {
RemoveInteractionModelObserver(this);
assistant_controller_binding_.Close(); assistant_controller_binding_.Close();
assistant_event_subscriber_binding_.Close(); assistant_event_subscriber_binding_.Close();
} }
...@@ -95,32 +98,39 @@ void AshAssistantController::RemoveInteractionModelObserver( ...@@ -95,32 +98,39 @@ void AshAssistantController::RemoveInteractionModelObserver(
void AshAssistantController::StartInteraction() { void AshAssistantController::StartInteraction() {
// TODO(dmblack): Instruct underlying service to start listening if current // TODO(dmblack): Instruct underlying service to start listening if current
// input modality is VOICE. Also modify to check against state in // input modality is VOICE.
// AssistantInteractionModel when available. if (assistant_interaction_model_.interaction_state() ==
if (!assistant_bubble_->IsShowing()) InteractionState::kInactive) {
OnInteractionStarted(); OnInteractionStarted();
}
} }
void AshAssistantController::StopInteraction() { void AshAssistantController::StopInteraction() {
// TODO(dmblack): Instruct underlying service to stop listening. Also modify // TODO(dmblack): Instruct underlying service to stop listening.
// to check against state in AssistantInteractionModel when available. if (assistant_interaction_model_.interaction_state() !=
if (assistant_bubble_->IsShowing()) InteractionState::kInactive) {
OnInteractionDismissed(); OnInteractionDismissed();
}
} }
void AshAssistantController::ToggleInteraction() { void AshAssistantController::ToggleInteraction() {
// TODO(dmblack): Add interaction state to AssistantInteractionModel. Bubble if (assistant_interaction_model_.interaction_state() ==
// should observe interaction model state changes and show/hide itself InteractionState::kInactive) {
// appropriately.
if (!assistant_bubble_->IsShowing())
StartInteraction(); StartInteraction();
else } else {
StopInteraction(); StopInteraction();
}
}
void AshAssistantController::OnInteractionStateChanged(
InteractionState interaction_state) {
if (interaction_state == InteractionState::kInactive)
assistant_interaction_model_.ClearInteraction();
} }
void AshAssistantController::OnInteractionStarted() { void AshAssistantController::OnInteractionStarted() {
assistant_bubble_timer_.Stop(); assistant_bubble_timer_.Stop();
assistant_bubble_->Show(); assistant_interaction_model_.SetInteractionState(InteractionState::kActive);
} }
void AshAssistantController::OnInteractionFinished( void AshAssistantController::OnInteractionFinished(
...@@ -132,8 +142,7 @@ void AshAssistantController::OnInteractionFinished( ...@@ -132,8 +142,7 @@ void AshAssistantController::OnInteractionFinished(
void AshAssistantController::OnInteractionDismissed() { void AshAssistantController::OnInteractionDismissed() {
assistant_bubble_timer_.Stop(); assistant_bubble_timer_.Stop();
assistant_bubble_->Dismiss(); assistant_interaction_model_.SetInteractionState(InteractionState::kInactive);
assistant_interaction_model_.ClearInteraction();
} }
void AshAssistantController::OnHtmlResponse(const std::string& response) { void AshAssistantController::OnHtmlResponse(const std::string& response) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "ash/assistant/model/assistant_interaction_model.h" #include "ash/assistant/model/assistant_interaction_model.h"
#include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/public/interfaces/ash_assistant_controller.mojom.h" #include "ash/public/interfaces/ash_assistant_controller.mojom.h"
#include "ash/public/interfaces/assistant_card_renderer.mojom.h" #include "ash/public/interfaces/assistant_card_renderer.mojom.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -28,7 +29,8 @@ class AssistantInteractionModelObserver; ...@@ -28,7 +29,8 @@ class AssistantInteractionModelObserver;
class AshAssistantController class AshAssistantController
: public mojom::AshAssistantController, : public mojom::AshAssistantController,
public chromeos::assistant::mojom::AssistantEventSubscriber { public chromeos::assistant::mojom::AssistantEventSubscriber,
public AssistantInteractionModelObserver {
public: public:
AshAssistantController(); AshAssistantController();
~AshAssistantController() override; ~AshAssistantController() override;
...@@ -70,6 +72,9 @@ class AshAssistantController ...@@ -70,6 +72,9 @@ class AshAssistantController
// Invoked on suggestion chip pressed event. // Invoked on suggestion chip pressed event.
void OnSuggestionChipPressed(const std::string& text); void OnSuggestionChipPressed(const std::string& text);
// AssistantInteractionModelObserver:
void OnInteractionStateChanged(InteractionState interaction_state) override;
// chromeos::assistant::mojom::AssistantEventSubscriber: // chromeos::assistant::mojom::AssistantEventSubscriber:
void OnInteractionStarted() override; void OnInteractionStarted() override;
void OnInteractionFinished( void OnInteractionFinished(
......
...@@ -32,6 +32,15 @@ void AssistantInteractionModel::ClearInteraction() { ...@@ -32,6 +32,15 @@ void AssistantInteractionModel::ClearInteraction() {
ClearSuggestions(); ClearSuggestions();
} }
void AssistantInteractionModel::SetInteractionState(
InteractionState interaction_state) {
if (interaction_state == interaction_state_)
return;
interaction_state_ = interaction_state;
NotifyInteractionStateChanged();
}
void AssistantInteractionModel::SetInputModality(InputModality input_modality) { void AssistantInteractionModel::SetInputModality(InputModality input_modality) {
if (input_modality == input_modality_) if (input_modality == input_modality_)
return; return;
...@@ -74,6 +83,11 @@ void AssistantInteractionModel::ClearSuggestions() { ...@@ -74,6 +83,11 @@ void AssistantInteractionModel::ClearSuggestions() {
NotifySuggestionsCleared(); NotifySuggestionsCleared();
} }
void AssistantInteractionModel::NotifyInteractionStateChanged() {
for (AssistantInteractionModelObserver& observer : observers_)
observer.OnInteractionStateChanged(interaction_state_);
}
void AssistantInteractionModel::NotifyInputModalityChanged() { void AssistantInteractionModel::NotifyInputModalityChanged() {
for (AssistantInteractionModelObserver& observer : observers_) { for (AssistantInteractionModelObserver& observer : observers_) {
observer.OnInputModalityChanged(input_modality_); observer.OnInputModalityChanged(input_modality_);
......
...@@ -24,6 +24,15 @@ enum class InputModality { ...@@ -24,6 +24,15 @@ enum class InputModality {
kVoice, kVoice,
}; };
// TODO(dmblack): This is an oversimplification. We will eventually want to
// distinctly represent listening/thinking/etc. states explicitly so they can
// be adequately represented in the UI.
// Enumeration of interaction states.
enum class InteractionState {
kActive,
kInactive,
};
// Models the state of the query. For a text query, only the high confidence // Models the state of the query. For a text query, only the high confidence
// text portion will be populated. At start of a voice query, both the high and // text portion will be populated. At start of a voice query, both the high and
// low confidence text portions will be empty. As speech recognition continues, // low confidence text portions will be empty. As speech recognition continues,
...@@ -54,6 +63,12 @@ class AssistantInteractionModel { ...@@ -54,6 +63,12 @@ class AssistantInteractionModel {
void AddObserver(AssistantInteractionModelObserver* observer); void AddObserver(AssistantInteractionModelObserver* observer);
void RemoveObserver(AssistantInteractionModelObserver* observer); void RemoveObserver(AssistantInteractionModelObserver* observer);
// Sets the interaction state.
void SetInteractionState(InteractionState interaction_state);
// Returns the interaction state.
InteractionState interaction_state() const { return interaction_state_; }
// Resets the interaction to its initial state. // Resets the interaction to its initial state.
void ClearInteraction(); void ClearInteraction();
...@@ -87,6 +102,7 @@ class AssistantInteractionModel { ...@@ -87,6 +102,7 @@ class AssistantInteractionModel {
void ClearSuggestions(); void ClearSuggestions();
private: private:
void NotifyInteractionStateChanged();
void NotifyInputModalityChanged(); void NotifyInputModalityChanged();
void NotifyUiElementAdded(const AssistantUiElement* ui_element); void NotifyUiElementAdded(const AssistantUiElement* ui_element);
void NotifyUiElementsCleared(); void NotifyUiElementsCleared();
...@@ -95,6 +111,7 @@ class AssistantInteractionModel { ...@@ -95,6 +111,7 @@ class AssistantInteractionModel {
void NotifySuggestionsAdded(const std::vector<std::string>& suggestions); void NotifySuggestionsAdded(const std::vector<std::string>& suggestions);
void NotifySuggestionsCleared(); void NotifySuggestionsCleared();
InteractionState interaction_state_ = InteractionState::kInactive;
InputModality input_modality_; InputModality input_modality_;
Query query_; Query query_;
std::vector<std::string> suggestions_list_; std::vector<std::string> suggestions_list_;
......
...@@ -14,12 +14,16 @@ namespace ash { ...@@ -14,12 +14,16 @@ namespace ash {
class AssistantUiElement; class AssistantUiElement;
enum class InputModality; enum class InputModality;
enum class InteractionState;
struct Query; struct Query;
// An observer which receives notification of changes to an Assistant // An observer which receives notification of changes to an Assistant
// interaction. // interaction.
class AssistantInteractionModelObserver { class AssistantInteractionModelObserver {
public: public:
// Invoked when the interaction state is changed.
virtual void OnInteractionStateChanged(InteractionState interaction_state) {}
// Invoked when the input modality associated with the interaction is changed. // Invoked when the input modality associated with the interaction is changed.
virtual void OnInputModalityChanged(InputModality input_modality) {} virtual void OnInputModalityChanged(InputModality input_modality) {}
......
...@@ -99,9 +99,13 @@ class AssistantContainerView : public views::BubbleDialogDelegateView { ...@@ -99,9 +99,13 @@ class AssistantContainerView : public views::BubbleDialogDelegateView {
// AssistantBubble ------------------------------------------------------------- // AssistantBubble -------------------------------------------------------------
AssistantBubble::AssistantBubble(AshAssistantController* assistant_controller) AssistantBubble::AssistantBubble(AshAssistantController* assistant_controller)
: assistant_controller_(assistant_controller) {} : assistant_controller_(assistant_controller) {
assistant_controller_->AddInteractionModelObserver(this);
}
AssistantBubble::~AssistantBubble() { AssistantBubble::~AssistantBubble() {
assistant_controller_->RemoveInteractionModelObserver(this);
if (container_view_) if (container_view_)
container_view_->GetWidget()->RemoveObserver(this); container_view_->GetWidget()->RemoveObserver(this);
} }
...@@ -111,6 +115,18 @@ void AssistantBubble::OnWidgetClosing(views::Widget* widget) { ...@@ -111,6 +115,18 @@ void AssistantBubble::OnWidgetClosing(views::Widget* widget) {
container_view_ = nullptr; container_view_ = nullptr;
} }
void AssistantBubble::OnInteractionStateChanged(
InteractionState interaction_state) {
switch (interaction_state) {
case InteractionState::kActive:
Show();
break;
case InteractionState::kInactive:
Dismiss();
break;
}
}
void AssistantBubble::Show() { void AssistantBubble::Show() {
if (!container_view_) if (!container_view_)
container_view_ = new AssistantContainerView(assistant_controller_); container_view_ = new AssistantContainerView(assistant_controller_);
...@@ -124,8 +140,4 @@ void AssistantBubble::Dismiss() { ...@@ -124,8 +140,4 @@ void AssistantBubble::Dismiss() {
container_view_->GetWidget()->Close(); container_view_->GetWidget()->Close();
} }
bool AssistantBubble::IsShowing() const {
return container_view_ && container_view_->GetWidget()->IsVisible();
}
} // namespace ash } // namespace ash
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef ASH_ASSISTANT_UI_ASSISTANT_BUBBLE_H_ #ifndef ASH_ASSISTANT_UI_ASSISTANT_BUBBLE_H_
#define ASH_ASSISTANT_UI_ASSISTANT_BUBBLE_H_ #define ASH_ASSISTANT_UI_ASSISTANT_BUBBLE_H_
#include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
...@@ -20,7 +21,8 @@ namespace { ...@@ -20,7 +21,8 @@ namespace {
class AssistantContainerView; class AssistantContainerView;
} // namespace } // namespace
class AssistantBubble : public views::WidgetObserver { class AssistantBubble : public views::WidgetObserver,
public AssistantInteractionModelObserver {
public: public:
explicit AssistantBubble(AshAssistantController* assistant_controller); explicit AssistantBubble(AshAssistantController* assistant_controller);
~AssistantBubble() override; ~AssistantBubble() override;
...@@ -28,12 +30,13 @@ class AssistantBubble : public views::WidgetObserver { ...@@ -28,12 +30,13 @@ class AssistantBubble : public views::WidgetObserver {
// views::WidgetObserver: // views::WidgetObserver:
void OnWidgetClosing(views::Widget* widget) override; void OnWidgetClosing(views::Widget* widget) override;
// AssistantInteractionModelObserver:
void OnInteractionStateChanged(InteractionState interaction_state) override;
private:
void Show(); void Show();
void Dismiss(); void Dismiss();
bool IsShowing() const;
private:
AshAssistantController* const assistant_controller_; // Owned by Shell. AshAssistantController* const assistant_controller_; // Owned by Shell.
// Owned by view hierarchy. // Owned by view hierarchy.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment