Commit f7f8d201 authored by David Black's avatar David Black Committed by Commit Bot

Stubs in AssistantBubble.

This CL stubs in an AssistantBubble/AssistantContainerView as part of a
series of CLs to move the AssistantBubbleView out of the app_list.

With this CL:
- Bubble will be shown on interaction start.
- Bubble will be auto-dismissed after interaction finish (w/ delay).

See bug for demo.

Bug: b:77637813
Change-Id: I69c146f386405e33d3a0a503f9bf87072d704abe
Reviewed-on: https://chromium-review.googlesource.com/1024804
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553702}
parent f64595c1
......@@ -98,6 +98,8 @@ component("ash") {
"assistant/ash_assistant_controller.h",
"assistant/model/assistant_interaction_model_impl.cc",
"assistant/model/assistant_interaction_model_impl.h",
"assistant/ui/assistant_bubble.cc",
"assistant/ui/assistant_bubble.h",
"autoclick/autoclick_controller.cc",
"autoclick/autoclick_controller.h",
"cancel_mode.cc",
......
......@@ -4,8 +4,7 @@
#include "ash/assistant/ash_assistant_controller.h"
#include <memory>
#include "ash/assistant/ui/assistant_bubble.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
......@@ -15,9 +14,16 @@
namespace ash {
namespace {
constexpr base::TimeDelta kAutoDismissDelay = base::TimeDelta::FromSeconds(5);
} // namespace
AshAssistantController::AshAssistantController()
: assistant_controller_binding_(this),
assistant_event_subscriber_binding_(this) {
assistant_event_subscriber_binding_(this),
assistant_bubble_(std::make_unique<AssistantBubble>(this)) {
Shell::Get()->AddShellObserver(this);
}
......@@ -91,14 +97,21 @@ void AshAssistantController::RemoveInteractionModelObserver(
}
void AshAssistantController::OnInteractionStarted() {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
assistant_bubble_timer_.Stop();
assistant_bubble_->Show();
}
void AshAssistantController::OnInteractionFinished(
chromeos::assistant::mojom::AssistantInteractionResolution resolution) {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
assistant_bubble_timer_.Start(
FROM_HERE, kAutoDismissDelay, this,
&AshAssistantController::OnInteractionDismissed);
}
void AshAssistantController::OnInteractionDismissed() {
assistant_bubble_timer_.Stop();
assistant_bubble_->Dismiss();
assistant_interaction_model_.ClearInteraction();
}
void AshAssistantController::OnHtmlResponse(const std::string& response) {
......@@ -181,6 +194,7 @@ void AshAssistantController::OnSpeechLevelUpdated(float speech_level) {
void AshAssistantController::OnOpenUrlResponse(const GURL& url) {
Shell::Get()->shell_delegate()->OpenUrlFromArc(url);
OnInteractionDismissed();
}
// TODO(b/77637813): Remove when pulling Assistant out of launcher.
......
......@@ -5,6 +5,7 @@
#ifndef ASH_ASSISTANT_ASH_ASSISTANT_CONTROLLER_H_
#define ASH_ASSISTANT_ASH_ASSISTANT_CONTROLLER_H_
#include <memory>
#include <string>
#include <vector>
......@@ -13,6 +14,7 @@
#include "ash/public/interfaces/assistant_card_renderer.mojom.h"
#include "ash/shell_observer.h"
#include "base/macros.h"
#include "base/timer/timer.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/app_list/assistant_controller.h"
......@@ -31,6 +33,8 @@ class UnguessableToken;
namespace ash {
class AssistantBubble;
class AshAssistantController
: public app_list::AssistantController,
public mojom::AshAssistantController,
......@@ -84,6 +88,8 @@ class AshAssistantController
aura::Window* root_window) override;
private:
void OnInteractionDismissed();
mojo::Binding<mojom::AshAssistantController> assistant_controller_binding_;
mojo::Binding<chromeos::assistant::mojom::AssistantEventSubscriber>
assistant_event_subscriber_binding_;
......@@ -92,6 +98,9 @@ class AshAssistantController
chromeos::assistant::mojom::AssistantPtr assistant_;
mojom::AssistantCardRendererPtr assistant_card_renderer_;
std::unique_ptr<AssistantBubble> assistant_bubble_;
base::OneShotTimer assistant_bubble_timer_;
// TODO(b/77637813): Remove when pulling Assistant out of launcher.
bool is_app_list_shown_ = false;
......
// 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.
#include "ash/assistant/ui/assistant_bubble.h"
#include <memory>
#include "ash/assistant/ash_assistant_controller.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
#include "ui/wm/core/shadow_types.h"
namespace ash {
namespace {
// Appearance.
constexpr SkColor kBackgroundColor = SK_ColorWHITE;
constexpr int kCornerRadiusDip = 16;
constexpr int kMarginDip = 16;
// AssistantContainerView ------------------------------------------------------
class AssistantContainerView : public views::BubbleDialogDelegateView {
public:
explicit AssistantContainerView(
AshAssistantController* assistant_controller) {
set_accept_events(true);
SetAnchor();
set_arrow(views::BubbleBorder::Arrow::BOTTOM_LEFT);
set_can_activate(false);
set_color(kBackgroundColor);
set_margins(gfx::Insets());
set_shadow(views::BubbleBorder::Shadow::NO_ASSETS);
set_title_margins(gfx::Insets());
views::BubbleDialogDelegateView::CreateBubble(this);
// These attributes can only be set after bubble creation:
GetBubbleFrameView()->bubble_border()->SetCornerRadius(kCornerRadiusDip);
SetAlignment(
views::BubbleBorder::BubbleAlignment::ALIGN_EDGE_TO_ANCHOR_EDGE);
SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
}
~AssistantContainerView() override = default;
// views::BubbleDialogDelegateView:
void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
views::Widget* widget) const override {
params->corner_radius = kCornerRadiusDip;
params->keep_on_top = true;
params->shadow_type = views::Widget::InitParams::SHADOW_TYPE_DROP;
params->shadow_elevation = wm::kShadowElevationActiveWindow;
}
void Init() override { InitLayout(); }
void ChildPreferredSizeChanged(views::View* child) override {
SizeToContents();
}
int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; }
private:
void InitLayout() {
SetLayoutManager(std::make_unique<views::FillLayout>());
// TODO(dmblack): Replace w/ actual bubble view.
views::View* bubble_view = new views::View();
bubble_view->SetPreferredSize(gfx::Size(360, 48));
AddChildView(bubble_view);
}
void SetAnchor() {
// TODO(dmblack): Handle multiple displays, RTL orientation, dynamic shelf
// repositioning and any other corner cases.
// Anchors to bottom lefthand corner of primary display's work area.
display::Display primary_display =
display::Screen::GetScreen()->GetPrimaryDisplay();
gfx::Rect work_area = primary_display.work_area();
gfx::Rect anchor = gfx::Rect(work_area.x() + kMarginDip,
work_area.bottom() - kMarginDip, 0, 0);
SetAnchorRect(anchor);
}
DISALLOW_COPY_AND_ASSIGN(AssistantContainerView);
};
} // namespace
// AssistantBubble -------------------------------------------------------------
AssistantBubble::AssistantBubble(AshAssistantController* assistant_controller)
: assistant_controller_(assistant_controller) {}
AssistantBubble::~AssistantBubble() {
if (container_view_)
container_view_->GetWidget()->RemoveObserver(this);
}
void AssistantBubble::OnWidgetClosing(views::Widget* widget) {
widget->RemoveObserver(this);
container_view_ = nullptr;
}
void AssistantBubble::Show() {
if (!container_view_)
container_view_ = new AssistantContainerView(assistant_controller_);
container_view_->GetWidget()->AddObserver(this);
container_view_->GetWidget()->ShowInactive();
}
void AssistantBubble::Dismiss() {
if (container_view_)
container_view_->GetWidget()->Close();
}
} // namespace ash
// 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_UI_ASSISTANT_BUBBLE_H_
#define ASH_ASSISTANT_UI_ASSISTANT_BUBBLE_H_
#include "base/macros.h"
#include "ui/views/widget/widget_observer.h"
namespace views {
class Widget;
} // namespace views
namespace ash {
class AshAssistantController;
namespace {
class AssistantContainerView;
} // namespace
class AssistantBubble : public views::WidgetObserver {
public:
explicit AssistantBubble(AshAssistantController* assistant_controller);
~AssistantBubble() override;
// views::WidgetObserver:
void OnWidgetClosing(views::Widget* widget) override;
void Show();
void Dismiss();
private:
AshAssistantController* const assistant_controller_; // Owned by Shell.
// Owned by view hierarchy.
AssistantContainerView* container_view_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(AssistantBubble);
};
} // namespace ash
#endif // ASH_ASSISTANT_UI_ASSISTANT_BUBBLE_H_
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