Commit 3aeb4361 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

assistant: make suggestion chips focusable

Bug: b:112925587
Test: locally build and test
Change-Id: I6f9385691196319b693cea98a874c7322c330e1a
Reviewed-on: https://chromium-review.googlesource.com/1192361Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587333}
parent f9aa6657
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "ash/app_list/views/suggestion_chip_view.h" #include "ash/app_list/views/suggestion_chip_view.h"
#include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include "ash/assistant/ui/assistant_ui_constants.h" #include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/public/cpp/app_list/app_list_config.h" #include "ash/public/cpp/app_list/app_list_config.h"
...@@ -26,6 +28,7 @@ namespace { ...@@ -26,6 +28,7 @@ namespace {
// Assistant specific style: // Assistant specific style:
constexpr SkColor kAssistantBackgroundColor = SK_ColorWHITE; constexpr SkColor kAssistantBackgroundColor = SK_ColorWHITE;
constexpr SkColor kAssistantFocusColor = SkColorSetA(gfx::kGoogleGrey900, 0x14);
constexpr SkColor kAssistantStrokeColor = constexpr SkColor kAssistantStrokeColor =
SkColorSetA(gfx::kGoogleGrey900, 0x24); SkColorSetA(gfx::kGoogleGrey900, 0x24);
constexpr SkColor kAssistantTextColor = gfx::kGoogleGrey700; constexpr SkColor kAssistantTextColor = gfx::kGoogleGrey700;
...@@ -61,10 +64,8 @@ SuggestionChipView::SuggestionChipView(const Params& params, ...@@ -61,10 +64,8 @@ SuggestionChipView::SuggestionChipView(const Params& params,
icon_view_(new views::ImageView()), icon_view_(new views::ImageView()),
text_view_(new views::Label()), text_view_(new views::Label()),
assistant_style_(params.assistant_style) { assistant_style_(params.assistant_style) {
if (!assistant_style_) { SetFocusBehavior(FocusBehavior::ALWAYS);
SetFocusBehavior(FocusBehavior::ALWAYS); SetInkDropMode(InkDropHostView::InkDropMode::ON);
SetInkDropMode(InkDropHostView::InkDropMode::ON);
}
InitLayout(params); InitLayout(params);
} }
...@@ -131,10 +132,17 @@ void SuggestionChipView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -131,10 +132,17 @@ void SuggestionChipView::OnPaintBackground(gfx::Canvas* canvas) {
gfx::Rect bounds = GetContentsBounds(); gfx::Rect bounds = GetContentsBounds();
// Background. // Background.
flags.setColor(assistant_style_ ? kAssistantBackgroundColor if (HasFocus()) {
: kAppListBackgroundColor); flags.setColor(assistant_style_ ? kAssistantFocusColor
canvas->DrawRoundRect(bounds, height() / 2, flags); : kAppListFocusColor);
canvas->DrawRoundRect(bounds, height() / 2, flags);
} else {
flags.setColor(assistant_style_ ? kAssistantBackgroundColor
: kAppListBackgroundColor);
canvas->DrawRoundRect(bounds, height() / 2, flags);
}
// Border.
if (assistant_style_) { if (assistant_style_) {
// Stroke should be drawn within our contents bounds. // Stroke should be drawn within our contents bounds.
bounds.Inset(gfx::Insets(kAssistantStrokeWidthDip)); bounds.Inset(gfx::Insets(kAssistantStrokeWidthDip));
...@@ -144,12 +152,6 @@ void SuggestionChipView::OnPaintBackground(gfx::Canvas* canvas) { ...@@ -144,12 +152,6 @@ void SuggestionChipView::OnPaintBackground(gfx::Canvas* canvas) {
flags.setStrokeWidth(kAssistantStrokeWidthDip); flags.setStrokeWidth(kAssistantStrokeWidthDip);
flags.setStyle(cc::PaintFlags::Style::kStroke_Style); flags.setStyle(cc::PaintFlags::Style::kStroke_Style);
canvas->DrawRoundRect(bounds, height() / 2, flags); canvas->DrawRoundRect(bounds, height() / 2, flags);
return;
}
if (HasFocus()) {
flags.setColor(kAppListFocusColor);
canvas->DrawRoundRect(bounds, height() / 2, flags);
} }
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/assistant/ui/main_stage/assistant_footer_view.h" #include "ash/assistant/ui/main_stage/assistant_footer_view.h"
#include <utility>
#include "ash/assistant/assistant_controller.h" #include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_setup_controller.h" #include "ash/assistant/assistant_setup_controller.h"
#include "ash/assistant/ui/assistant_ui_constants.h" #include "ash/assistant/ui/assistant_ui_constants.h"
...@@ -88,6 +90,7 @@ void AssistantFooterView::InitLayout() { ...@@ -88,6 +90,7 @@ void AssistantFooterView::InitLayout() {
suggestion_container_->SetPaintToLayer(); suggestion_container_->SetPaintToLayer();
suggestion_container_->layer()->SetFillsBoundsOpaquely(false); suggestion_container_->layer()->SetFillsBoundsOpaquely(false);
suggestion_container_->layer()->SetOpacity(setup_completed ? 1.f : 0.f); suggestion_container_->layer()->SetOpacity(setup_completed ? 1.f : 0.f);
suggestion_container_->SetVisible(setup_completed);
AddChildView(suggestion_container_); AddChildView(suggestion_container_);
...@@ -100,6 +103,7 @@ void AssistantFooterView::InitLayout() { ...@@ -100,6 +103,7 @@ void AssistantFooterView::InitLayout() {
opt_in_view_->SetPaintToLayer(); opt_in_view_->SetPaintToLayer();
opt_in_view_->layer()->SetFillsBoundsOpaquely(false); opt_in_view_->layer()->SetFillsBoundsOpaquely(false);
opt_in_view_->layer()->SetOpacity(setup_completed ? 0.f : 1.f); opt_in_view_->layer()->SetOpacity(setup_completed ? 0.f : 1.f);
opt_in_view_->SetVisible(!setup_completed);
AddChildView(opt_in_view_); AddChildView(opt_in_view_);
} }
...@@ -118,10 +122,15 @@ void AssistantFooterView::OnVoiceInteractionSetupCompleted(bool completed) { ...@@ -118,10 +122,15 @@ void AssistantFooterView::OnVoiceInteractionSetupCompleted(bool completed) {
completed ? static_cast<views::View*>(suggestion_container_) completed ? static_cast<views::View*>(suggestion_container_)
: static_cast<views::View*>(opt_in_view_); : static_cast<views::View*>(opt_in_view_);
// Reset visibility to enable animation.
hide_view->SetVisible(true);
show_view->SetVisible(true);
// Hide the view for the previous consent state by fading to 0% opacity. // Hide the view for the previous consent state by fading to 0% opacity.
hide_view->layer()->GetAnimator()->StartAnimation( StartLayerAnimationSequence(hide_view->layer()->GetAnimator(),
CreateLayerAnimationSequence( CreateLayerAnimationSequence(CreateOpacityElement(
CreateOpacityElement(0.f, kAnimationFadeOutDuration))); 0.f, kAnimationFadeOutDuration)),
animation_observer_.get());
// Show the view for the next consent state by fading to 100% opacity with // Show the view for the next consent state by fading to 100% opacity with
// delay. // delay.
...@@ -153,7 +162,9 @@ bool AssistantFooterView::OnAnimationEnded( ...@@ -153,7 +162,9 @@ bool AssistantFooterView::OnAnimationEnded(
// Only the view relevant to our consent state should process events. // Only the view relevant to our consent state should process events.
suggestion_container_->set_can_process_events_within_subtree(setup_completed); suggestion_container_->set_can_process_events_within_subtree(setup_completed);
suggestion_container_->SetVisible(setup_completed);
opt_in_view_->set_can_process_events_within_subtree(!setup_completed); opt_in_view_->set_can_process_events_within_subtree(!setup_completed);
opt_in_view_->SetVisible(!setup_completed);
// Return false to prevent the observer from destroying itself. // Return false to prevent the observer from destroying itself.
return false; return false;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/assistant/ui/main_stage/assistant_main_stage.h" #include "ash/assistant/ui/main_stage/assistant_main_stage.h"
#include <algorithm>
#include "ash/assistant/assistant_controller.h" #include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_interaction_controller.h" #include "ash/assistant/assistant_interaction_controller.h"
#include "ash/assistant/assistant_ui_controller.h" #include "ash/assistant/assistant_ui_controller.h"
...@@ -646,6 +648,9 @@ void AssistantMainStage::UpdateFooter() { ...@@ -646,6 +648,9 @@ void AssistantMainStage::UpdateFooter() {
// When it is not visible, it should not process events. // When it is not visible, it should not process events.
bool visible = !committed_query_view_ && !pending_query_view_; bool visible = !committed_query_view_ && !pending_query_view_;
// Reset visibility to enable animation.
footer_->SetVisible(true);
if (visible) { if (visible) {
// The footer will animate up into position so we need to set an initial // The footer will animate up into position so we need to set an initial
// offset transformation from which to animate. // offset transformation from which to animate.
...@@ -697,8 +702,9 @@ bool AssistantMainStage::OnFooterAnimationEnded( ...@@ -697,8 +702,9 @@ bool AssistantMainStage::OnFooterAnimationEnded(
const ui::CallbackLayerAnimationObserver& observer) { const ui::CallbackLayerAnimationObserver& observer) {
// The footer should only process events when visible. It is only visible when // The footer should only process events when visible. It is only visible when
// there is no committed or pending query view. // there is no committed or pending query view.
footer_->set_can_process_events_within_subtree(!committed_query_view_ && bool visible = !committed_query_view_ && !pending_query_view_;
!pending_query_view_); footer_->set_can_process_events_within_subtree(visible);
footer_->SetVisible(visible);
// Return false so that the observer does not destroy itself. // Return false so that the observer does not destroy itself.
return false; return false;
......
...@@ -39,7 +39,12 @@ views::StyledLabel::RangeStyleInfo CreateStyleInfo( ...@@ -39,7 +39,12 @@ views::StyledLabel::RangeStyleInfo CreateStyleInfo(
class AssistantOptInContainer : public views::Button { class AssistantOptInContainer : public views::Button {
public: public:
explicit AssistantOptInContainer(views::ButtonListener* listener) explicit AssistantOptInContainer(views::ButtonListener* listener)
: views::Button(listener) {} : views::Button(listener) {
constexpr float kHighlightOpacity = 0.06f;
SetFocusPainter(views::Painter::CreateSolidRoundRectPainter(
SkColorSetA(SK_ColorBLACK, 0xff * kHighlightOpacity),
kPreferredHeightDip / 2));
}
~AssistantOptInContainer() override = default; ~AssistantOptInContainer() override = default;
...@@ -127,8 +132,9 @@ void AssistantOptInView::InitLayout() { ...@@ -127,8 +132,9 @@ void AssistantOptInView::InitLayout() {
// Set the text, having replaced placeholders in the opt in prompt with // Set the text, having replaced placeholders in the opt in prompt with
// substitution strings and caching their offset positions for styling. // substitution strings and caching their offset positions for styling.
std::vector<size_t> offsets; std::vector<size_t> offsets;
label_->SetText(l10n_util::GetStringFUTF16( auto label_text = l10n_util::GetStringFUTF16(
IDS_ASH_ASSISTANT_OPT_IN_PROMPT, unlock_features, get_started, &offsets)); IDS_ASH_ASSISTANT_OPT_IN_PROMPT, unlock_features, get_started, &offsets);
label_->SetText(label_text);
// Style the first substitution string. // Style the first substitution string.
label_->AddStyleRange( label_->AddStyleRange(
...@@ -141,6 +147,9 @@ void AssistantOptInView::InitLayout() { ...@@ -141,6 +147,9 @@ void AssistantOptInView::InitLayout() {
CreateStyleInfo(gfx::Font::Weight::BOLD)); CreateStyleInfo(gfx::Font::Weight::BOLD));
container->AddChildView(label_); container->AddChildView(label_);
container->SetFocusForPlatform();
container->SetAccessibleName(label_text);
} }
void AssistantOptInView::ButtonPressed(views::Button* sender, void AssistantOptInView::ButtonPressed(views::Button* sender,
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "ash/assistant/ui/main_stage/suggestion_container_view.h" #include "ash/assistant/ui/main_stage/suggestion_container_view.h"
#include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include "ash/assistant/assistant_cache_controller.h" #include "ash/assistant/assistant_cache_controller.h"
#include "ash/assistant/assistant_controller.h" #include "ash/assistant/assistant_controller.h"
...@@ -134,6 +136,7 @@ void SuggestionContainerView::OnSuggestionsChanged( ...@@ -134,6 +136,7 @@ void SuggestionContainerView::OnSuggestionsChanged(
app_list::SuggestionChipView* suggestion_chip_view = app_list::SuggestionChipView* suggestion_chip_view =
new app_list::SuggestionChipView(params, /*listener=*/this); new app_list::SuggestionChipView(params, /*listener=*/this);
suggestion_chip_view->SetAccessibleName(params.text);
// Given a suggestion chip view, we need to be able to look up the id of // Given a suggestion chip view, we need to be able to look up the id of
// the underlying suggestion. This is used for handling press events. // the underlying suggestion. This is used for handling press events.
......
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