Commit 2398014e authored by David Black's avatar David Black Committed by Commit Bot

Implements AssistantOptInView.

Currently always hidden, but a follow up CL will hide/show this view
appropriately based on the user's opt in state.

Another follow up CL will also implement click handling to launch setup.

See bug for screenshot.

Bug: b:112236931
Change-Id: I6db726e8947e9b97772f06bda7e4c55678ab3859
Reviewed-on: https://chromium-review.googlesource.com/1163283
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@{#581075}
parent e64c72b9
......@@ -89,6 +89,7 @@ component("ash") {
"assistant/ui/main_stage/assistant_footer_view.h",
"assistant/ui/main_stage/assistant_header_view.h",
"assistant/ui/main_stage/assistant_main_stage.h",
"assistant/ui/main_stage/assistant_opt_in_view.h",
"assistant/ui/main_stage/assistant_progress_indicator.h",
"assistant/ui/main_stage/assistant_query_view.h",
"assistant/ui/main_stage/assistant_text_element_view.h",
......@@ -753,6 +754,7 @@ component("ash") {
"assistant/ui/main_stage/assistant_footer_view.cc",
"assistant/ui/main_stage/assistant_header_view.cc",
"assistant/ui/main_stage/assistant_main_stage.cc",
"assistant/ui/main_stage/assistant_opt_in_view.cc",
"assistant/ui/main_stage/assistant_progress_indicator.cc",
"assistant/ui/main_stage/assistant_query_view.cc",
"assistant/ui/main_stage/assistant_text_element_view.cc",
......
......@@ -1709,6 +1709,15 @@ This file contains the strings for ash.
<message name="IDS_ASH_ASSISTANT_NOTIFICATION_DISPLAY_SOURCE" desc="The name for the source of the assistant notification.">
Assistant
</message>
<message name="IDS_ASH_ASSISTANT_OPT_IN_UNLOCK_MORE_FEATURES" desc="Message shown in Assistant UI when the user is opted out to promote an opted in experience.">
Unlock more Assistant features.
</message>
<message name="IDS_ASH_ASSISTANT_OPT_IN_GET_STARTED" desc="Message shown in Assistant UI when the user is opted out to promote an opted in experience.">
Get Started
</message>
<message name="IDS_ASH_ASSISTANT_OPT_IN_PROMPT" desc="Message shown in Assistant UI when the user is opted out to promote an opted in experience. $1 = IDS_ASH_ASSISTANT_OPT_IN_UNLOCK_MORE_FEATURES, $2 = IDS_ASH_ASSISTANT_OPT_IN_GET_STARTED">
<ph name="UNLOCK_MORE_FEATURES">$1<ex>Unlock more Assistant features.</ex></ph> <ph name="GET_STARTED">$2<ex>Get Started</ex></ph>
</message>
</messages>
</release>
</grit>
......
......@@ -4,7 +4,10 @@
#include "ash/assistant/ui/main_stage/assistant_footer_view.h"
#include <memory>
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/ui/main_stage/assistant_opt_in_view.h"
#include "ash/assistant/ui/main_stage/suggestion_container_view.h"
#include "ui/views/layout/fill_layout.h"
......@@ -41,12 +44,18 @@ void AssistantFooterView::ChildVisibilityChanged(views::View* child) {
PreferredSizeChanged();
}
// TODO(dmblack): Handle opted out/in state.
void AssistantFooterView::InitLayout() {
SetLayoutManager(std::make_unique<views::FillLayout>());
// Suggestion container.
suggestion_container_ = new SuggestionContainerView(assistant_controller_);
AddChildView(suggestion_container_);
// Opt in view.
opt_in_view_ = new AssistantOptInView();
opt_in_view_->SetVisible(false);
AddChildView(opt_in_view_);
}
} // namespace ash
......@@ -11,6 +11,7 @@
namespace ash {
class AssistantController;
class AssistantOptInView;
class SuggestionContainerView;
class AssistantFooterView : public views::View {
......@@ -30,6 +31,7 @@ class AssistantFooterView : public views::View {
AssistantController* const assistant_controller_; // Owned by Shell.
SuggestionContainerView* suggestion_container_; // Owned by view hierarchy.
AssistantOptInView* opt_in_view_; // Owned by view hierarchy.
DISALLOW_COPY_AND_ASSIGN(AssistantFooterView);
};
......
// 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/main_stage/assistant_opt_in_view.h"
#include <memory>
#include <vector>
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/strings/grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/layout/box_layout.h"
namespace ash {
namespace {
// Appearance.
constexpr int kPreferredHeightDip = 32;
// Helpers ---------------------------------------------------------------------
views::StyledLabel::RangeStyleInfo CreateStyleInfo(
gfx::Font::Weight weight = gfx::Font::Weight::NORMAL) {
views::StyledLabel::RangeStyleInfo style;
style.custom_font = assistant::ui::GetDefaultFontList()
.DeriveWithSizeDelta(2)
.DeriveWithWeight(weight);
style.override_color = SK_ColorWHITE;
return style;
}
// AssistantOptInContainer -----------------------------------------------------
class AssistantOptInContainer : public views::View {
public:
AssistantOptInContainer() = default;
~AssistantOptInContainer() override = default;
// views::View:
gfx::Size CalculatePreferredSize() const override {
const int preferred_width = views::View::CalculatePreferredSize().width();
return gfx::Size(preferred_width, GetHeightForWidth(preferred_width));
}
int GetHeightForWidth(int width) const override {
return kPreferredHeightDip;
}
void ChildPreferredSizeChanged(views::View* child) override {
PreferredSizeChanged();
}
void OnPaintBackground(gfx::Canvas* canvas) override {
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(gfx::kGoogleBlue500);
canvas->DrawRoundRect(GetContentsBounds(), height() / 2, flags);
}
private:
DISALLOW_COPY_AND_ASSIGN(AssistantOptInContainer);
};
} // namespace
// AssistantOptInView ----------------------------------------------------------
AssistantOptInView::AssistantOptInView() {
InitLayout();
}
AssistantOptInView::~AssistantOptInView() = default;
void AssistantOptInView::ChildPreferredSizeChanged(views::View* child) {
PreferredSizeChanged();
}
void AssistantOptInView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
label_->SizeToFit(width());
}
void AssistantOptInView::InitLayout() {
views::BoxLayout* layout_manager =
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
layout_manager->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::CROSS_AXIS_ALIGNMENT_END);
layout_manager->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::MAIN_AXIS_ALIGNMENT_CENTER);
// Container.
AssistantOptInContainer* container = new AssistantOptInContainer();
layout_manager =
container->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(0, kPaddingDip)));
layout_manager->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::CROSS_AXIS_ALIGNMENT_CENTER);
AddChildView(container);
// Label.
label_ = new views::StyledLabel(base::string16(), /*listener=*/nullptr);
label_->set_auto_color_readability_enabled(false);
label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_CENTER);
// First substitution string: "Unlock more Assistant features."
const base::string16 unlock_features =
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_OPT_IN_UNLOCK_MORE_FEATURES);
// Second substitution string: "Get Started".
const base::string16 get_started =
l10n_util::GetStringUTF16(IDS_ASH_ASSISTANT_OPT_IN_GET_STARTED);
// Set the text, having replaced placeholders in the opt in prompt with
// substitution strings and caching their offset positions for styling.
std::vector<size_t> offsets;
label_->SetText(l10n_util::GetStringFUTF16(
IDS_ASH_ASSISTANT_OPT_IN_PROMPT, unlock_features, get_started, &offsets));
// Style the first substitution string.
label_->AddStyleRange(
gfx::Range(offsets.at(0), offsets.at(0) + unlock_features.length()),
CreateStyleInfo());
// Style the second substitution string.
label_->AddStyleRange(
gfx::Range(offsets.at(1), offsets.at(1) + get_started.length()),
CreateStyleInfo(gfx::Font::Weight::BOLD));
container->AddChildView(label_);
}
} // 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_MAIN_STAGE_ASSISTANT_OPT_IN_VIEW_H_
#define ASH_ASSISTANT_UI_MAIN_STAGE_ASSISTANT_OPT_IN_VIEW_H_
#include "base/macros.h"
#include "ui/views/view.h"
namespace views {
class StyledLabel;
} // namespace views
namespace ash {
class AssistantOptInView : public views::View {
public:
AssistantOptInView();
~AssistantOptInView() override;
// views::View:
void ChildPreferredSizeChanged(views::View* child) override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
private:
void InitLayout();
views::StyledLabel* label_; // Owned by view hierarchy.
DISALLOW_COPY_AND_ASSIGN(AssistantOptInView);
};
} // namespace ash
#endif // ASH_ASSISTANT_UI_MAIN_STAGE_ASSISTANT_OPT_IN_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