Handle AssistantMiniView pressed event.

Pressing Assistant UI when it is in mini state should cause it to
re-expand. We only do this when NOT using stylus input modality.

The implementation uses a delegate pattern analogously to what was
done previously with CaptionBar(Delegate).

Bug: b:110986383
Change-Id: I3dfdb85542b9ae591e3ec3f2f74eb4e7065a3859
Reviewed-on: https://chromium-review.googlesource.com/1137483
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575528}
diff --git a/ash/assistant/assistant_ui_controller.cc b/ash/assistant/assistant_ui_controller.cc
index 98d001e3..cb68116 100644
--- a/ash/assistant/assistant_ui_controller.cc
+++ b/ash/assistant/assistant_ui_controller.cc
@@ -138,6 +138,17 @@
     container_view_->GetWidget()->Activate();
 }
 
+void AssistantUiController::OnAssistantMiniViewPressed() {
+  InputModality input_modality = assistant_controller_->interaction_controller()
+                                     ->model()
+                                     ->input_modality();
+
+  // When not using stylus input modality, pressing the Assistant mini view
+  // will cause the UI to expand.
+  if (input_modality != InputModality::kStylus)
+    UpdateUiMode(AssistantUiMode::kMainUi);
+}
+
 bool AssistantUiController::OnCaptionButtonPressed(CaptionButtonId id) {
   switch (id) {
     case CaptionButtonId::kBack:
diff --git a/ash/assistant/assistant_ui_controller.h b/ash/assistant/assistant_ui_controller.h
index 9ae4b96..7f11bb1 100644
--- a/ash/assistant/assistant_ui_controller.h
+++ b/ash/assistant/assistant_ui_controller.h
@@ -11,6 +11,7 @@
 #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/assistant_mini_view.h"
 #include "ash/assistant/ui/caption_bar.h"
 #include "ash/assistant/ui/dialog_plate/dialog_plate.h"
 #include "ash/highlighter/highlighter_controller.h"
@@ -44,6 +45,7 @@
       public AssistantInteractionModelObserver,
       public AssistantScreenContextModelObserver,
       public AssistantUiModelObserver,
+      public AssistantMiniViewDelegate,
       public CaptionBarDelegate,
       public DialogPlateObserver,
       public HighlighterController::Observer {
@@ -78,6 +80,9 @@
   void OnScreenContextRequestStateChanged(
       ScreenContextRequestState request_state) override;
 
+  // AssistantMiniViewDelegate:
+  void OnAssistantMiniViewPressed() override;
+
   // CaptionBarDelegate:
   bool OnCaptionButtonPressed(CaptionButtonId id) override;
 
diff --git a/ash/assistant/ui/assistant_container_view.cc b/ash/assistant/ui/assistant_container_view.cc
index 47786da..7998c29 100644
--- a/ash/assistant/ui/assistant_container_view.cc
+++ b/ash/assistant/ui/assistant_container_view.cc
@@ -103,6 +103,7 @@
   // Mini view.
   assistant_mini_view_ =
       std::make_unique<AssistantMiniView>(assistant_controller_);
+  assistant_mini_view_->set_delegate(assistant_controller_->ui_controller());
   assistant_mini_view_->set_owned_by_client();
 
   // Web view.
diff --git a/ash/assistant/ui/assistant_mini_view.cc b/ash/assistant/ui/assistant_mini_view.cc
index 14589de..0b49a43 100644
--- a/ash/assistant/ui/assistant_mini_view.cc
+++ b/ash/assistant/ui/assistant_mini_view.cc
@@ -30,7 +30,9 @@
 }  // namespace
 
 AssistantMiniView::AssistantMiniView(AssistantController* assistant_controller)
-    : assistant_controller_(assistant_controller), label_(new views::Label()) {
+    : views::Button(this),
+      assistant_controller_(assistant_controller),
+      label_(new views::Label()) {
   InitLayout();
 
   // AssistantController indirectly owns the view hierarchy to which
@@ -85,6 +87,12 @@
                              ->input_modality());
 }
 
+void AssistantMiniView::ButtonPressed(views::Button* sender,
+                                      const ui::Event& event) {
+  if (delegate_)
+    delegate_->OnAssistantMiniViewPressed();
+}
+
 void AssistantMiniView::OnInputModalityChanged(InputModality input_modality) {
   switch (input_modality) {
     case InputModality::kStylus:
diff --git a/ash/assistant/ui/assistant_mini_view.h b/ash/assistant/ui/assistant_mini_view.h
index 413aad9..969c414 100644
--- a/ash/assistant/ui/assistant_mini_view.h
+++ b/ash/assistant/ui/assistant_mini_view.h
@@ -7,7 +7,7 @@
 
 #include "ash/assistant/model/assistant_interaction_model_observer.h"
 #include "base/macros.h"
-#include "ui/views/view.h"
+#include "ui/views/controls/button/button.h"
 
 namespace views {
 class Label;
@@ -17,7 +17,21 @@
 
 class AssistantController;
 
-class AssistantMiniView : public views::View,
+// AssistantMiniViewDelegate ---------------------------------------------------
+
+class AssistantMiniViewDelegate {
+ public:
+  // Invoked when the AssistantMiniView is pressed.
+  virtual void OnAssistantMiniViewPressed() {}
+
+ protected:
+  virtual ~AssistantMiniViewDelegate() = default;
+};
+
+// AssistantMiniView -----------------------------------------------------------
+
+class AssistantMiniView : public views::Button,
+                          public views::ButtonListener,
                           public AssistantInteractionModelObserver {
  public:
   explicit AssistantMiniView(AssistantController* assistant_controller);
@@ -28,15 +42,24 @@
   int GetHeightForWidth(int width) const override;
   void ChildPreferredSizeChanged(views::View* child) override;
 
+  // views::ButtonListener:
+  void ButtonPressed(views::Button* sender, const ui::Event& event) override;
+
   // AssistantInteractionModelObserver:
   void OnInputModalityChanged(InputModality input_modality) override;
 
+  void set_delegate(AssistantMiniViewDelegate* delegate) {
+    delegate_ = delegate;
+  }
+
  private:
   void InitLayout();
 
   AssistantController* const assistant_controller_;  // Owned by Shell.
   views::Label* label_;                              // Owned by view hierarchy.
 
+  AssistantMiniViewDelegate* delegate_ = nullptr;
+
   DISALLOW_COPY_AND_ASSIGN(AssistantMiniView);
 };