Commit 71ab74de authored by David Black's avatar David Black Committed by Commit Bot

Roughs in UI.

Includes addition of interaction model/observer.
See bug for additional details.

Bug: b:77476776
Change-Id: Ic171f30f95aa66d74836213bd424a2d3a91d3869
Reviewed-on: https://chromium-review.googlesource.com/994535
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMuyuan Li <muyuanli@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550055}
parent d4c9b25b
......@@ -96,6 +96,8 @@ component("ash") {
"ash_view_ids.h",
"assistant/ash_assistant_controller.cc",
"assistant/ash_assistant_controller.h",
"assistant/model/assistant_interaction_model_impl.cc",
"assistant/model/assistant_interaction_model_impl.h",
"autoclick/autoclick_controller.cc",
"autoclick/autoclick_controller.h",
"cancel_mode.cc",
......
......@@ -6,6 +6,7 @@
#include "ash/app_list/app_list_presenter_impl.h"
#include "ash/app_list/presenter/app_list_view_delegate_factory.h"
#include "ash/assistant/ash_assistant_controller.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/shell_window_ids.h"
......@@ -20,6 +21,7 @@
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h"
#include "base/command_line.h"
#include "chromeos/chromeos_switches.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/app_list/views/app_list_view.h"
......@@ -90,6 +92,12 @@ void AppListPresenterDelegate::Init(app_list::AppListView* view,
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled();
params.is_side_shelf = IsSideShelf(root_window);
if (chromeos::switches::IsAssistantEnabled()) {
params.assistant_interaction_model =
Shell::Get()->ash_assistant_controller()->assistant_interaction_model();
}
view->Initialize(params);
wm::GetWindowState(view->GetWidget()->GetNativeWindow())
......
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// 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.
......@@ -11,11 +11,15 @@ namespace ash {
AshAssistantController::AshAssistantController()
: assistant_controller_binding_(this),
assistant_event_subscriber_binding_(this) {}
assistant_event_subscriber_binding_(this) {
Shell::Get()->AddShellObserver(this);
}
AshAssistantController::~AshAssistantController() {
assistant_controller_binding_.Close();
assistant_event_subscriber_binding_.Close();
Shell::Get()->RemoveShellObserver(this);
}
void AshAssistantController::BindRequest(
......@@ -32,45 +36,67 @@ void AshAssistantController::SetAssistant(
}
void AshAssistantController::OnHtmlResponse(const std::string& response) {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
if (!is_app_list_shown_)
return;
assistant_interaction_model_.SetCard(response);
}
void AshAssistantController::OnSuggestionsResponse(
const std::vector<std::string>& response) {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
if (!is_app_list_shown_)
return;
assistant_interaction_model_.AddSuggestions(response);
}
void AshAssistantController::OnTextResponse(const std::string& response) {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
if (!is_app_list_shown_)
return;
assistant_interaction_model_.AddText(response);
}
void AshAssistantController::OnSpeechRecognitionStarted() {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
if (!is_app_list_shown_)
return;
assistant_interaction_model_.ClearInteraction();
}
void AshAssistantController::OnSpeechRecognitionIntermediateResult(
const std::string& high_confidence_text,
const std::string& low_confidence_text) {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
if (!is_app_list_shown_)
return;
app_list::RecognizedSpeech recognized_speech{high_confidence_text,
low_confidence_text};
assistant_interaction_model_.SetRecognizedSpeech(recognized_speech);
}
void AshAssistantController::OnSpeechRecognitionEndOfUtterance() {
if (!is_app_list_shown_)
return;
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
}
void AshAssistantController::OnSpeechRecognitionFinalResult(
const std::string& final_result) {
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
if (!is_app_list_shown_)
return;
app_list::RecognizedSpeech recognized_speech;
recognized_speech.high_confidence_text = final_result;
assistant_interaction_model_.SetRecognizedSpeech(recognized_speech);
}
void AshAssistantController::OnSpeechLevelUpdated(float speech_level) {
if (!is_app_list_shown_)
return;
// TODO(dmblack): Handle.
NOTIMPLEMENTED();
}
......@@ -79,4 +105,13 @@ void AshAssistantController::OnOpenUrlResponse(const GURL& url) {
Shell::Get()->shell_delegate()->OpenUrlFromArc(url);
}
// TODO(b/77637813): Remove when pulling Assistant out of launcher.
void AshAssistantController::OnAppListVisibilityChanged(
bool shown,
aura::Window* root_window) {
is_app_list_shown_ = shown;
if (!is_app_list_shown_)
assistant_interaction_model_.ClearInteraction();
}
} // namespace ash
......@@ -5,16 +5,27 @@
#ifndef ASH_ASSISTANT_ASH_ASSISTANT_CONTROLLER_H_
#define ASH_ASSISTANT_ASH_ASSISTANT_CONTROLLER_H_
#include "ash/assistant/model/assistant_interaction_model_impl.h"
#include "ash/public/interfaces/ash_assistant_controller.mojom.h"
#include "ash/shell_observer.h"
#include "base/macros.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace app_list {
class AssistantInteractionModel;
} // namespace app_list
namespace aura {
class Window;
} // namespace aura
namespace ash {
class AshAssistantController
: public mojom::AshAssistantController,
public chromeos::assistant::mojom::AssistantEventSubscriber {
public chromeos::assistant::mojom::AssistantEventSubscriber,
public ShellObserver {
public:
AshAssistantController();
~AshAssistantController() override;
......@@ -40,10 +51,22 @@ class AshAssistantController
void SetAssistant(
chromeos::assistant::mojom::AssistantPtr assistant) override;
// ShellObserver:
void OnAppListVisibilityChanged(bool shown,
aura::Window* root_window) override;
app_list::AssistantInteractionModel* assistant_interaction_model() {
return &assistant_interaction_model_;
}
private:
mojo::Binding<mojom::AshAssistantController> assistant_controller_binding_;
mojo::Binding<chromeos::assistant::mojom::AssistantEventSubscriber>
assistant_event_subscriber_binding_;
AssistantInteractionModelImpl assistant_interaction_model_;
// TODO(b/77637813): Remove when pulling Assistant out of launcher.
bool is_app_list_shown_ = false;
DISALLOW_COPY_AND_ASSIGN(AshAssistantController);
};
......
// 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/model/assistant_interaction_model_impl.h"
#include "ui/app_list/assistant_interaction_model_observer.h"
namespace ash {
AssistantInteractionModelImpl::AssistantInteractionModelImpl() = default;
AssistantInteractionModelImpl::~AssistantInteractionModelImpl() = default;
void AssistantInteractionModelImpl::AddObserver(
app_list::AssistantInteractionModelObserver* observer) {
observers_.AddObserver(observer);
}
void AssistantInteractionModelImpl::RemoveObserver(
app_list::AssistantInteractionModelObserver* observer) {
observers_.RemoveObserver(observer);
}
void AssistantInteractionModelImpl::ClearInteraction() {
ClearCard();
ClearRecognizedSpeech();
ClearSuggestions();
ClearText();
}
void AssistantInteractionModelImpl::SetCard(const std::string& html) {
card_ = html;
NotifyCardChanged();
}
void AssistantInteractionModelImpl::ClearCard() {
card_.clear();
NotifyCardCleared();
}
void AssistantInteractionModelImpl::SetRecognizedSpeech(
const app_list::RecognizedSpeech& recognized_speech) {
recognized_speech_ = recognized_speech;
NotifyRecognizedSpeechChanged();
}
void AssistantInteractionModelImpl::ClearRecognizedSpeech() {
recognized_speech_ = {};
NotifyRecognizedSpeechCleared();
}
void AssistantInteractionModelImpl::AddSuggestions(
const std::vector<std::string>& suggestions) {
suggestions_list_.insert(suggestions_list_.end(), suggestions.begin(),
suggestions.end());
NotifySuggestionsAdded(suggestions);
}
void AssistantInteractionModelImpl::ClearSuggestions() {
suggestions_list_.clear();
NotifySuggestionsCleared();
}
void AssistantInteractionModelImpl::AddText(const std::string& text) {
text_list_.push_back(text);
NotifyTextAdded(text);
}
void AssistantInteractionModelImpl::ClearText() {
text_list_.clear();
NotifyTextCleared();
}
void AssistantInteractionModelImpl::NotifyCardChanged() {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnCardChanged(card_);
}
void AssistantInteractionModelImpl::NotifyCardCleared() {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnCardCleared();
}
void AssistantInteractionModelImpl::NotifyRecognizedSpeechChanged() {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnRecognizedSpeechChanged(recognized_speech_);
}
void AssistantInteractionModelImpl::NotifyRecognizedSpeechCleared() {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnRecognizedSpeechCleared();
}
void AssistantInteractionModelImpl::NotifySuggestionsAdded(
const std::vector<std::string>& suggestions) {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnSuggestionsAdded(suggestions);
}
void AssistantInteractionModelImpl::NotifySuggestionsCleared() {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnSuggestionsCleared();
}
void AssistantInteractionModelImpl::NotifyTextAdded(const std::string& text) {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnTextAdded(text);
}
void AssistantInteractionModelImpl::NotifyTextCleared() {
for (app_list::AssistantInteractionModelObserver& observer : observers_)
observer.OnTextCleared();
}
} // 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_MODEL_ASSISTANT_INTERACTION_MODEL_IMPL_H_
#define ASH_ASSISTANT_MODEL_ASSISTANT_INTERACTION_MODEL_IMPL_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/observer_list.h"
#include "ui/app_list/assistant_interaction_model.h"
namespace app_list {
class AssistantInteractionModelObserver;
} // namespace app_list
namespace ash {
class AssistantInteractionModelImpl
: public app_list::AssistantInteractionModel {
public:
AssistantInteractionModelImpl();
~AssistantInteractionModelImpl() override;
// app_list::AssistantInteractionModel:
void AddObserver(
app_list::AssistantInteractionModelObserver* observer) override;
void RemoveObserver(
app_list::AssistantInteractionModelObserver* observer) override;
void ClearInteraction() override;
void SetCard(const std::string& html) override;
void ClearCard() override;
void SetRecognizedSpeech(
const app_list::RecognizedSpeech& recognized_speech) override;
void ClearRecognizedSpeech() override;
void AddSuggestions(const std::vector<std::string>& suggestions) override;
void ClearSuggestions() override;
void AddText(const std::string& text) override;
void ClearText() override;
private:
void NotifyCardChanged();
void NotifyCardCleared();
void NotifyRecognizedSpeechChanged();
void NotifyRecognizedSpeechCleared();
void NotifySuggestionsAdded(const std::vector<std::string>& suggestions);
void NotifySuggestionsCleared();
void NotifyTextAdded(const std::string& text);
void NotifyTextCleared();
std::string card_;
app_list::RecognizedSpeech recognized_speech_;
std::vector<std::string> suggestions_list_;
std::vector<std::string> text_list_;
base::ObserverList<app_list::AssistantInteractionModelObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(AssistantInteractionModelImpl);
};
} // namespace ash
#endif // ASH_ASSISTANT_MODEL_ASSISTANT_INTERACTION_MODEL_IMPL_H_
......@@ -23,6 +23,8 @@ component("app_list") {
"app_list_util.cc",
"app_list_util.h",
"app_list_view_delegate.h",
"assistant_interaction_model.h",
"assistant_interaction_model_observer.h",
"pagination_controller.cc",
"pagination_controller.h",
"pagination_model.cc",
......@@ -44,6 +46,8 @@ component("app_list") {
"views/apps_grid_view.cc",
"views/apps_grid_view.h",
"views/apps_grid_view_folder_delegate.h",
"views/assistant_bubble_view.cc",
"views/assistant_bubble_view.h",
"views/assistant_container_view.cc",
"views/assistant_container_view.h",
"views/contents_view.cc",
......@@ -88,6 +92,8 @@ component("app_list") {
"views/search_result_tile_item_view.h",
"views/search_result_view.cc",
"views/search_result_view.h",
"views/suggestion_chip_view.cc",
"views/suggestion_chip_view.h",
"views/suggestions_container_view.cc",
"views/suggestions_container_view.h",
"views/top_icon_animation_view.cc",
......
// 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 UI_APP_LIST_ASSISTANT_INTERACTION_MODEL_H_
#define UI_APP_LIST_ASSISTANT_INTERACTION_MODEL_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/observer_list.h"
// TODO(b/77637813): Remove interface abstraction when removing Assistant from
// the launcher.
namespace app_list {
class AssistantInteractionModelObserver;
// Models the state of recognized speech. At start, both the high and low
// confidence text portions will be empty. As recognition continues, the low
// confidence portion will become non-empty. As recognition improves, both high
// and low confidence portions of the recognized speech will be non-empty. When
// speech is fully recognized, only the high confidence portion will be
// non-empty.
struct RecognizedSpeech {
// High confidence portion of recognized speech.
std::string high_confidence_text;
// Low confidence portion of recognized speech.
std::string low_confidence_text;
};
// Models the Assistant interaction. This includes query state, state of speech
// recognition, as well as renderable card, suggestions, and text responses.
class AssistantInteractionModel {
public:
// Adds/removes the specified interaction |observer|.
virtual void AddObserver(AssistantInteractionModelObserver* observer) = 0;
virtual void RemoveObserver(AssistantInteractionModelObserver* observer) = 0;
// Resets the interaction to its initial state.
virtual void ClearInteraction() = 0;
// Updates the card that should be rendered for the interaction.
virtual void SetCard(const std::string& html) = 0;
// Clears the card for the interaction.
virtual void ClearCard() = 0;
// Updates the recognized speech state for the interaction.
virtual void SetRecognizedSpeech(
const RecognizedSpeech& recognized_speech) = 0;
// Clears recognized speech state.
virtual void ClearRecognizedSpeech() = 0;
// Adds the specified |suggestions| that should be rendered for the
// interaction.
virtual void AddSuggestions(const std::vector<std::string>& suggestions) = 0;
// Clears all suggestions for the interaction.
virtual void ClearSuggestions() = 0;
// Adds the specified |text| that should be rendered for the interaction.
virtual void AddText(const std::string& text) = 0;
// Clears all text for the interaction.
virtual void ClearText() = 0;
protected:
AssistantInteractionModel() = default;
virtual ~AssistantInteractionModel() = default;
DISALLOW_COPY_AND_ASSIGN(AssistantInteractionModel);
};
} // namespace app_list
#endif // UI_APP_LIST_ASSISTANT_INTERACTION_MODEL_H_
// 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 UI_APP_LIST_ASSISTANT_INTERACTION_MODEL_OBSERVER_H_
#define UI_APP_LIST_ASSISTANT_INTERACTION_MODEL_OBSERVER_H_
#include <string>
#include <vector>
#include "base/macros.h"
// TODO(b/77637813): Move to /ash/assistant/model when pulling Assistant out
// of the launcher.
namespace app_list {
struct RecognizedSpeech;
// An observer which receives notification of changes to an Assistant
// interaction.
class AssistantInteractionModelObserver {
public:
// Invoked when the card associated with the interaction is changed.
virtual void OnCardChanged(const std::string& html) {}
// Invoked when the card associated with the interaction is cleared.
virtual void OnCardCleared() {}
// Invoked when recognized speech associated with the interaction is changed.
virtual void OnRecognizedSpeechChanged(
const RecognizedSpeech& recognized_speech) {}
// Invoked when recognized speech associated with the interaction is cleared.
virtual void OnRecognizedSpeechCleared() {}
// Invoked when the specified |suggestions| are added to the associated
// interaction.
virtual void OnSuggestionsAdded(const std::vector<std::string>& suggestions) {
}
// Invoked when all suggestions associated with the interaction are cleared.
virtual void OnSuggestionsCleared() {}
// Invoked the specified |text| is added to the associated interaction.
virtual void OnTextAdded(const std::string& text) {}
// Invoked all text associated with the interaction is cleared.
virtual void OnTextCleared() {}
protected:
AssistantInteractionModelObserver() = default;
virtual ~AssistantInteractionModelObserver() = default;
DISALLOW_COPY_AND_ASSIGN(AssistantInteractionModelObserver);
};
} // namespace app_list
#endif // UI_APP_LIST_ASSISTANT_INTERACTION_MODEL_OBSERVER_H_
......@@ -23,6 +23,7 @@
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_features.h"
#include "ui/app_list/app_list_util.h"
#include "ui/app_list/assistant_interaction_model.h"
#include "ui/app_list/views/app_list_folder_view.h"
#include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/apps_container_view.h"
......@@ -291,6 +292,7 @@ void AppListView::Initialize(const InitParams& params) {
base::Time start_time = base::Time::Now();
is_tablet_mode_ = params.is_tablet_mode;
is_side_shelf_ = params.is_side_shelf;
assistant_interaction_model_ = params.assistant_interaction_model;
InitContents(params.initial_apps_page);
AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
AddAccelerator(ui::Accelerator(ui::VKEY_BROWSER_BACK, ui::EF_NONE));
......
......@@ -40,6 +40,7 @@ class ApplicationDragAndDropHost;
class AppListMainView;
class AppListModel;
class AppsGridView;
class AssistantInteractionModel;
class HideViewAnimationObserver;
class PaginationModel;
class SearchBoxView;
......@@ -88,6 +89,8 @@ class APP_LIST_EXPORT AppListView : public views::WidgetDelegateView,
// Whether the shelf alignment is on the side of the display. Used for
// fullscreen style.
bool is_side_shelf = false;
// Model for Assistant interaction. Owned by AshAssistantController.
AssistantInteractionModel* assistant_interaction_model = nullptr;
};
// Does not take ownership of |delegate|.
......@@ -224,6 +227,11 @@ class APP_LIST_EXPORT AppListView : public views::WidgetDelegateView,
}
bool onscreen_keyboard_shown() const { return onscreen_keyboard_shown_; }
// TODO(b/77637813): Remove when pulling Assistant out of launcher.
AssistantInteractionModel* assistant_interaction_model() {
return assistant_interaction_model_;
}
private:
// A widget observer that is responsible for keeping the AppListView state up
// to date on closing.
......@@ -394,6 +402,10 @@ class APP_LIST_EXPORT AppListView : public views::WidgetDelegateView,
// Observes the completion of scroll animation.
std::unique_ptr<ui::ImplicitAnimationObserver> scroll_animation_observer_;
// TODO(b/77637813): Remove when pulling Assistant out of the launcher.
// Owned by AshAssistantController.
AssistantInteractionModel* assistant_interaction_model_ = nullptr;
base::WeakPtrFactory<AppListView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AppListView);
......
This diff is collapsed.
// 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 UI_APP_LIST_VIEWS_ASSISTANT_BUBBLE_VIEW_H_
#define UI_APP_LIST_VIEWS_ASSISTANT_BUBBLE_VIEW_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "ui/app_list/assistant_interaction_model_observer.h"
#include "ui/views/view.h"
namespace app_list {
class AssistantInteractionModel;
namespace {
class InteractionContainer;
class SuggestionsContainer;
class TextContainer;
} // namespace
class AssistantBubbleView : public views::View,
public AssistantInteractionModelObserver {
public:
explicit AssistantBubbleView(
AssistantInteractionModel* assistant_interaction_model);
~AssistantBubbleView() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
void ChildPreferredSizeChanged(views::View* child) override;
void ChildVisibilityChanged(views::View* child) override;
// AssistantInteractionModelObserver:
void OnCardChanged(const std::string& html) override;
void OnCardCleared() override;
void OnRecognizedSpeechChanged(
const RecognizedSpeech& recognized_speech) override;
void OnRecognizedSpeechCleared() override;
void OnSuggestionsAdded(const std::vector<std::string>& suggestions) override;
void OnSuggestionsCleared() override;
void OnTextAdded(const std::string& text) override;
void OnTextCleared() override;
private:
void InitLayout();
// Owned by AshAssistantController.
AssistantInteractionModel* assistant_interaction_model_;
InteractionContainer* interaction_container_; // Owned by view hierarchy.
TextContainer* text_container_; // Owned by view hierarchy.
views::View* card_container_; // Owned by view hierarchy.
SuggestionsContainer* suggestions_container_; // Owned by view hierarchy.
DISALLOW_COPY_AND_ASSIGN(AssistantBubbleView);
};
} // namespace app_list
#endif // UI_APP_LIST_VIEWS_ASSISTANT_BUBBLE_VIEW_H_
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// 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 "ui/app_list/views/assistant_container_view.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/app_list/views/assistant_bubble_view.h"
#include "ui/app_list/views/contents_view.h"
namespace app_list {
namespace {
constexpr int kPaddingDip = 16;
} // namespace
AssistantContainerView::AssistantContainerView(ContentsView* contents_view)
: contents_view_(contents_view) {}
: contents_view_(contents_view),
assistant_bubble_view_(new AssistantBubbleView(
contents_view->app_list_view()->assistant_interaction_model())) {
AddChildView(assistant_bubble_view_);
}
gfx::Size AssistantContainerView::CalculatePreferredSize() const {
if (!GetWidget()) {
......@@ -20,6 +32,20 @@ gfx::Size AssistantContainerView::CalculatePreferredSize() const {
contents_view_->GetDisplayHeight());
}
void AssistantContainerView::ChildPreferredSizeChanged(views::View* child) {
// TODO(dmblack): Animate layout changes.
Layout();
SchedulePaint();
}
void AssistantContainerView::Layout() {
// Pin bubble view to bottom lefthand corner.
gfx::Size size = assistant_bubble_view_->GetPreferredSize();
assistant_bubble_view_->SetBounds(kPaddingDip,
height() - size.height() - kPaddingDip,
size.width(), size.height());
}
bool AssistantContainerView::ShouldShowSearchBox() const {
return false;
}
......
......@@ -10,6 +10,7 @@
namespace app_list {
class AssistantBubbleView;
class ContentsView;
class APP_LIST_EXPORT AssistantContainerView : public HorizontalPage {
......@@ -19,12 +20,15 @@ class APP_LIST_EXPORT AssistantContainerView : public HorizontalPage {
// Overridden from views::View.
gfx::Size CalculatePreferredSize() const override;
void ChildPreferredSizeChanged(views::View* child) override;
void Layout() override;
// Overridden from HorizontalPage.
bool ShouldShowSearchBox() const override;
private:
ContentsView* const contents_view_; // Not owned.
AssistantBubbleView* assistant_bubble_view_; // Owned by view hierarchy.
DISALLOW_COPY_AND_ASSIGN(AssistantContainerView);
};
......
// 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 "ui/app_list/views/suggestion_chip_view.h"
#include "ui/gfx/canvas.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
namespace app_list {
namespace {
// Appearance.
constexpr SkColor kBackgroundColor = SkColorSetA(SK_ColorBLACK, 0x1F);
constexpr int kCornerRadiusDip = 12;
constexpr int kPaddingHorizontalDip = 8;
constexpr int kPaddingVerticalDip = 4;
// Typography.
constexpr SkColor kTextColor = SkColorSetA(SK_ColorBLACK, 0xDE);
} // namespace
SuggestionChipView::SuggestionChipView(const base::string16& text)
: views::View(), text_view_(new views::Label(text)) {
InitLayout();
}
void SuggestionChipView::InitLayout() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(kPaddingVerticalDip, kPaddingHorizontalDip)));
// TODO(dmblack): Add optional icon.
// Text view.
text_view_->SetAutoColorReadabilityEnabled(false);
text_view_->SetEnabledColor(kTextColor);
text_view_->SetFontList(text_view_->font_list().DeriveWithSizeDelta(2));
AddChildView(text_view_);
}
void SuggestionChipView::OnPaintBackground(gfx::Canvas* canvas) {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(kBackgroundColor);
canvas->DrawRoundRect(GetContentsBounds(), kCornerRadiusDip, flags);
}
} // namespace app_list
// 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 UI_APP_LIST_VIEWS_SUGGESTION_CHIP_VIEW_H_
#define UI_APP_LIST_VIEWS_SUGGESTION_CHIP_VIEW_H_
#include "base/macros.h"
#include "ui/views/view.h"
namespace views {
class Label;
} // namespace views
namespace app_list {
class SuggestionChipView : public views::View {
public:
explicit SuggestionChipView(const base::string16& text);
~SuggestionChipView() override = default;
// views::View:
void OnPaintBackground(gfx::Canvas* canvas) override;
private:
void InitLayout();
views::Label* text_view_; // Owned by view hierarchy.
DISALLOW_COPY_AND_ASSIGN(SuggestionChipView);
};
} // namespace app_list
#endif // UI_APP_LIST_VIEWS_SUGGESTION_CHIP_VIEW_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