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

Adds ProactiveSuggestionsRichView.

Extends ProactiveSuggestionsView as the implementation of the entry
point that is shown when the new "show-rich-entry-point" feature param
is enabled.

Note that this view hosts embedded web content and is currently
stubbed. Follow up CLs will:

- Replace hard-coded HTML w/ server provided HTML.
- Parameterize corner radius.
- Handle navigation attempts.

See bug for screenshots.

Bug: b:145056104
Change-Id: I17be0951e707317b4903b185043c41f17deebe5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1932463
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718878}
parent f947670c
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/assistant/assistant_controller.h" #include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_suggestions_controller.h" #include "ash/assistant/assistant_suggestions_controller.h"
#include "ash/assistant/assistant_ui_controller.h" #include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/ui/proactive_suggestions_rich_view.h"
#include "ash/assistant/ui/proactive_suggestions_simple_view.h" #include "ash/assistant/ui/proactive_suggestions_simple_view.h"
#include "ash/assistant/ui/proactive_suggestions_view.h" #include "ash/assistant/ui/proactive_suggestions_view.h"
#include "ash/public/cpp/assistant/proactive_suggestions.h" #include "ash/public/cpp/assistant/proactive_suggestions.h"
...@@ -209,10 +210,16 @@ void AssistantProactiveSuggestionsController::MaybeShowUi() { ...@@ -209,10 +210,16 @@ void AssistantProactiveSuggestionsController::MaybeShowUi() {
return; return;
} }
// TODO(dmblack): Use a different ProactiveSuggestionsView implementation to // Depending on which is enabled, we'll either use a rich, content-forward UI
// instead show a richer affordance (if enabled via feature param). // affordance or a simple UI affordance as the feature entry point.
view_ = new ProactiveSuggestionsSimpleView( if (chromeos::assistant::features::
assistant_controller_->view_delegate()); IsProactiveSuggestionsShowRichEntryPointEnabled()) {
view_ = new ProactiveSuggestionsRichView(
assistant_controller_->view_delegate());
} else {
view_ = new ProactiveSuggestionsSimpleView(
assistant_controller_->view_delegate());
}
view_->Init(); view_->Init();
view_->GetWidget()->ShowInactive(); view_->GetWidget()->ShowInactive();
......
...@@ -97,6 +97,8 @@ component("ui") { ...@@ -97,6 +97,8 @@ component("ui") {
"main_stage/suggestion_container_view.h", "main_stage/suggestion_container_view.h",
"main_stage/ui_element_container_view.cc", "main_stage/ui_element_container_view.cc",
"main_stage/ui_element_container_view.h", "main_stage/ui_element_container_view.h",
"proactive_suggestions_rich_view.cc",
"proactive_suggestions_rich_view.h",
"proactive_suggestions_simple_view.cc", "proactive_suggestions_simple_view.cc",
"proactive_suggestions_simple_view.h", "proactive_suggestions_simple_view.h",
"proactive_suggestions_view.cc", "proactive_suggestions_view.cc",
......
// Copyright 2019 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/proactive_suggestions_rich_view.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "base/base64.h"
#include "ui/aura/window.h"
#include "ui/views/layout/fill_layout.h"
namespace ash {
ProactiveSuggestionsRichView::ProactiveSuggestionsRichView(
AssistantViewDelegate* delegate)
: ProactiveSuggestionsView(delegate) {}
ProactiveSuggestionsRichView::~ProactiveSuggestionsRichView() {
if (contents_)
contents_->RemoveObserver(this);
}
const char* ProactiveSuggestionsRichView::GetClassName() const {
return "ProactiveSuggestionsRichView";
}
void ProactiveSuggestionsRichView::InitLayout() {
SetLayoutManager(std::make_unique<views::FillLayout>());
// Initialize NavigableContentsFactory.
delegate()->GetNavigableContentsFactoryForView(
contents_factory_.BindNewPipeAndPassReceiver());
// Initialize NavigableContentsParams.
auto params = content::mojom::NavigableContentsParams::New();
params->enable_view_auto_resize = true;
params->auto_resize_min_size = gfx::Size(1, 1);
params->auto_resize_max_size = gfx::Size(INT_MAX, INT_MAX);
params->suppress_navigations = true;
// Initialize NavigableContents.
contents_ = std::make_unique<content::NavigableContents>(
contents_factory_.get(), std::move(params));
contents_->AddObserver(this);
// TODO(dmblack): Replace w/ server provided HTML.
std::string encoded_html;
base::Base64Encode(R"(
<!DOCTYPE html>
<html>
<body>
<style>
* {
box-sizing: border-box;
cursor: default;
margin: 0;
padding: 0;
user-select: none;
}
body {
align-items: center;
background-color: #3c4043;
display: flex;
height: 32px;
overflow: hidden;
max-width: 280px;
}
.Icon {
background-image:
url("https://www.gstatic.com/images/branding/product/2x/assistant_24dp.png");
background-position: center;
background-repeat: no-repeat;
background-size: 100%;
flex: 0 0 auto;
height: 16px;
margin-left: 8px;
width: 16px;
}
.Label {
color: #f1f3f4;
flex: 1 1 auto;
font-family: Google Sans, sans-serif;
font-size: 13px;
font-weight: normal;
line-height: 20px;
margin-left: 8px;
overflow: hidden;
white-space: nowrap;
}
.Close {
background-color: #f1f3f4;
flex: 0 0 auto;
height: 32px;
width: 32px;
-webkit-mask-image:
url("https://www.gstatic.com/images/icons/material/system/2x/close_black_24dp.png");
-webkit-mask-position: center;
-webkit-mask-repeat: no-repeat;
-webkit-mask-size: 16px;
}
</style>
<div class="Icon"></div>
<p class="Label">Related pages</p>
<div class="Close"></div>
</body>
</html>
)",
&encoded_html);
// Navigate to the data URL representing our encoded HTML.
constexpr char kDataUriPrefix[] = "data:text/html;base64,";
contents_->Navigate(GURL(kDataUriPrefix + encoded_html));
}
void ProactiveSuggestionsRichView::DidAutoResizeView(
const gfx::Size& new_size) {
contents_->GetView()->view()->SetPreferredSize(new_size);
PreferredSizeChanged();
}
void ProactiveSuggestionsRichView::DidStopLoading() {
AddChildView(contents_->GetView()->view());
PreferredSizeChanged();
// TODO(dmblack): Parameterize corner radius.
constexpr int kCornerRadiusDip = 16;
contents_->GetView()->native_view()->layer()->SetRoundedCornerRadius(
gfx::RoundedCornersF(kCornerRadiusDip));
}
void ProactiveSuggestionsRichView::DidSuppressNavigation(
const GURL& url,
WindowOpenDisposition disposition,
bool from_user_gesture) {
if (!from_user_gesture)
return;
// TODO(dmblack): Handle clicks.
NOTIMPLEMENTED();
}
} // namespace ash
// Copyright 2019 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_PROACTIVE_SUGGESTIONS_RICH_VIEW_H_
#define ASH_ASSISTANT_UI_PROACTIVE_SUGGESTIONS_RICH_VIEW_H_
#include <memory>
#include "ash/assistant/ui/proactive_suggestions_view.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/content/public/cpp/navigable_contents.h"
#include "services/content/public/cpp/navigable_contents_view.h"
namespace ash {
class AssistantViewDelegate;
// Rich entry point for the proactive suggestions feature.
class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsRichView
: public ProactiveSuggestionsView,
public content::NavigableContentsObserver {
public:
explicit ProactiveSuggestionsRichView(AssistantViewDelegate* delegate);
explicit ProactiveSuggestionsRichView(ProactiveSuggestionsRichView&) = delete;
ProactiveSuggestionsRichView& operator=(ProactiveSuggestionsRichView&) =
delete;
~ProactiveSuggestionsRichView() override;
// ProactiveSuggestionsView:
const char* GetClassName() const override;
void InitLayout() override;
// content::NavigableContentsObserver:
void DidAutoResizeView(const gfx::Size& new_size) override;
void DidStopLoading() override;
void DidSuppressNavigation(const GURL& url,
WindowOpenDisposition disposition,
bool from_user_gesture) override;
private:
mojo::Remote<content::mojom::NavigableContentsFactory> contents_factory_;
std::unique_ptr<content::NavigableContents> contents_;
};
} // namespace ash
#endif // ASH_ASSISTANT_UI_PROACTIVE_SUGGESTIONS_RICH_VIEW_H_
...@@ -50,6 +50,11 @@ const char* ProactiveSuggestionsView::GetClassName() const { ...@@ -50,6 +50,11 @@ const char* ProactiveSuggestionsView::GetClassName() const {
return "ProactiveSuggestionsView"; return "ProactiveSuggestionsView";
} }
void ProactiveSuggestionsView::PreferredSizeChanged() {
if (GetWidget())
UpdateBounds();
}
void ProactiveSuggestionsView::OnMouseEntered(const ui::MouseEvent& event) { void ProactiveSuggestionsView::OnMouseEntered(const ui::MouseEvent& event) {
views::Button::OnMouseEntered(event); views::Button::OnMouseEntered(event);
delegate_->OnProactiveSuggestionsViewHoverChanged(/*is_hovering=*/true); delegate_->OnProactiveSuggestionsViewHoverChanged(/*is_hovering=*/true);
......
...@@ -33,6 +33,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView ...@@ -33,6 +33,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView
// views::Button: // views::Button:
const char* GetClassName() const override; const char* GetClassName() const override;
void PreferredSizeChanged() override;
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
void OnMouseEntered(const ui::MouseEvent& event) override; void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override; void OnMouseExited(const ui::MouseEvent& event) override;
......
...@@ -40,6 +40,11 @@ const base::FeatureParam<std::string> ...@@ -40,6 +40,11 @@ const base::FeatureParam<std::string>
const base::FeatureParam<bool> kAssistantProactiveSuggestionsShowOnScroll{ const base::FeatureParam<bool> kAssistantProactiveSuggestionsShowOnScroll{
&kAssistantProactiveSuggestions, "show-on-scroll", true}; &kAssistantProactiveSuggestions, "show-on-scroll", true};
// When enabled, we will use the rich, content-forward entry point for the
// proactive suggestions feature in lieu of the simple entry point affordance.
const base::FeatureParam<bool> kAssistantProactiveSuggestionsShowRichEntryPoint{
&kAssistantProactiveSuggestions, "show-rich-entry-point", false};
const base::FeatureParam<bool> kAssistantProactiveSuggestionsSuppressDuplicates{ const base::FeatureParam<bool> kAssistantProactiveSuggestionsSuppressDuplicates{
&kAssistantProactiveSuggestions, "suppress-duplicates", false}; &kAssistantProactiveSuggestions, "suppress-duplicates", false};
...@@ -137,6 +142,10 @@ bool IsProactiveSuggestionsShowOnScrollEnabled() { ...@@ -137,6 +142,10 @@ bool IsProactiveSuggestionsShowOnScrollEnabled() {
return kAssistantProactiveSuggestionsShowOnScroll.Get(); return kAssistantProactiveSuggestionsShowOnScroll.Get();
} }
bool IsProactiveSuggestionsShowRichEntryPointEnabled() {
return kAssistantProactiveSuggestionsShowRichEntryPoint.Get();
}
bool IsProactiveSuggestionsSuppressDuplicatesEnabled() { bool IsProactiveSuggestionsSuppressDuplicatesEnabled() {
return kAssistantProactiveSuggestionsSuppressDuplicates.Get(); return kAssistantProactiveSuggestionsSuppressDuplicates.Get();
} }
......
...@@ -117,6 +117,9 @@ COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) bool IsProactiveSuggestionsEnabled(); ...@@ -117,6 +117,9 @@ COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) bool IsProactiveSuggestionsEnabled();
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC)
bool IsProactiveSuggestionsShowOnScrollEnabled(); bool IsProactiveSuggestionsShowOnScrollEnabled();
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC)
bool IsProactiveSuggestionsShowRichEntryPointEnabled();
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC)
bool IsProactiveSuggestionsSuppressDuplicatesEnabled(); bool IsProactiveSuggestionsSuppressDuplicatesEnabled();
......
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