Skip to content

Commit

Permalink
[M74 merge] app_list: Handle stylus in embedded Assistant Ui
Browse files Browse the repository at this point in the history
This patch adds the support to handle stylus in embedded Assistant Ui.
Because this attempt is temporary and no UX is specified, we will show a
toast instead implementing a mini view for embedded mode.

TBR=xiyuan@chromium.org,xiaohuic@chromium.org

Bug: 924624
Test: manual
Change-Id: I7a6c971d1ef49a1b759ddab5a0f6962195805662
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1507119
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: Tao Wu <wutao@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#638957}(cherry picked from commit 63b7ec453380483702fd357dfff2152560c4ca03)
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1513041
Cr-Commit-Position: refs/branch-heads/3729@{#8}
Cr-Branched-From: d4a8972-refs/heads/master@{#638880}
  • Loading branch information
wutao committed Mar 10, 2019
1 parent 4df9c29 commit 0facb2c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
3 changes: 0 additions & 3 deletions ash/app_list/app_list_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,6 @@ void AppListControllerImpl::OnUiVisibilityChanged(
// TODO(wutao): Handle tablet mode.
switch (new_visibility) {
case AssistantVisibility::kVisible:
if (!assistant::util::IsEmbeddedUiEntryPoint(entry_point.value()))
break;

if (IsTabletMode()) {
MinimizeAllWindows();
} else if (!IsVisible()) {
Expand Down
14 changes: 11 additions & 3 deletions ash/assistant/assistant_interaction_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ash/assistant/util/assistant_util.h"
#include "ash/assistant/util/deep_link_util.h"
#include "ash/assistant/util/histogram_util.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "ash/session/session_controller.h"
Expand Down Expand Up @@ -210,10 +211,13 @@ void AssistantInteractionController::OnHighlighterEnabledChanged(
HighlighterEnabledState state) {
switch (state) {
case HighlighterEnabledState::kEnabled:
model_.SetInputModality(InputModality::kStylus);
// Skip setting input modality to stylus when the embedded Assistant
// feature is enabled to prevent highlighter aborting sessions in
// OnUiModeChanged.
if (!app_list_features::IsEmbeddedAssistantUIEnabled())
model_.SetInputModality(InputModality::kStylus);
break;
case HighlighterEnabledState::kDisabledByUser:
FALLTHROUGH;
case HighlighterEnabledState::kDisabledBySessionComplete:
model_.SetInputModality(InputModality::kKeyboard);
break;
Expand All @@ -228,6 +232,7 @@ void AssistantInteractionController::OnHighlighterEnabledChanged(

void AssistantInteractionController::OnHighlighterSelectionRecognized(
const gfx::Rect& rect) {
assistant_controller_->ui_controller()->ShowUi(AssistantEntryPoint::kStylus);
StartMetalayerInteraction(/*region=*/rect);
}

Expand Down Expand Up @@ -637,7 +642,10 @@ void AssistantInteractionController::OnUiVisible(

if (entry_point == AssistantEntryPoint::kStylus) {
should_attempt_warmer_welcome_ = false;
model_.SetInputModality(InputModality::kStylus);
// When the embedded Assistant feature is enabled, we call ShowUi(kStylus)
// OnHighlighterSelectionRecognized. But we are not actually using stylus.
if (!app_list_features::IsEmbeddedAssistantUIEnabled())
model_.SetInputModality(InputModality::kStylus);
return;
}

Expand Down
29 changes: 18 additions & 11 deletions ash/assistant/assistant_ui_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ constexpr base::TimeDelta kAutoCloseThreshold = base::TimeDelta::FromMinutes(5);
// Toast -----------------------------------------------------------------------

constexpr int kToastDurationMs = 2500;

constexpr char kStylusPromptToastId[] = "stylus_prompt_for_embedded_ui";
constexpr char kUnboundServiceToastId[] =
"assistant_controller_unbound_service";

Expand Down Expand Up @@ -188,9 +190,13 @@ void AssistantUiController::OnMiniViewPressed() {

void AssistantUiController::OnHighlighterEnabledChanged(
HighlighterEnabledState state) {
// TODO(wutao): Behavior is not defined.
if (model_.ui_mode() == AssistantUiMode::kLauncherEmbeddedUi)
if (app_list_features::IsEmbeddedAssistantUIEnabled()) {
if (state == HighlighterEnabledState::kEnabled) {
ShowToast(kStylusPromptToastId, IDS_ASH_ASSISTANT_PROMPT_STYLUS);
CloseUi(AssistantExitPoint::kStylus);
}
return;
}

switch (state) {
case HighlighterEnabledState::kEnabled:
Expand Down Expand Up @@ -328,10 +334,11 @@ void AssistantUiController::OnUiVisibilityChanged(

// Metalayer should not be sticky. Disable when the UI is no longer visible.
if (old_visibility == AssistantVisibility::kVisible) {
Shell::Get()->highlighter_controller()->AbortSession();
if (exit_point != AssistantExitPoint::kStylus)
Shell::Get()->highlighter_controller()->AbortSession();

// Only record the exit point when Assistant UI becomes invisible to
// avoid duplicate happens (e.g., pressing ESC key).
// avoid recording duplicate events (e.g. pressing ESC key).
assistant::util::RecordAssistantExitPoint(exit_point.value());
}
}
Expand All @@ -356,11 +363,7 @@ void AssistantUiController::ShowUi(AssistantEntryPoint entry_point) {
return;
}

if (app_list_features::IsEmbeddedAssistantUIEnabled() &&
assistant::util::IsEmbeddedUiEntryPoint(entry_point)) {
// No container view when embedded in launcher.
DCHECK(!container_view_);

if (app_list_features::IsEmbeddedAssistantUIEnabled()) {
model_.SetUiMode(AssistantUiMode::kLauncherEmbeddedUi);
model_.SetVisible(entry_point);
return;
Expand Down Expand Up @@ -445,9 +448,10 @@ void AssistantUiController::UpdateUiMode(
return;
}

// TODO(wutao): Behavior is not defined.
if (model_.ui_mode() == AssistantUiMode::kLauncherEmbeddedUi)
if (app_list_features::IsEmbeddedAssistantUIEnabled()) {
model_.SetUiMode(AssistantUiMode::kLauncherEmbeddedUi);
return;
}

InputModality input_modality = assistant_controller_->interaction_controller()
->model()
Expand Down Expand Up @@ -567,6 +571,9 @@ AssistantContainerView* AssistantUiController::GetViewForTest() {
}

void AssistantUiController::CreateContainerView() {
DCHECK(!container_view_);
DCHECK(!app_list_features::IsEmbeddedAssistantUIEnabled());

container_view_ =
new AssistantContainerView(assistant_controller_->view_delegate());
container_view_->GetWidget()->AddObserver(this);
Expand Down
11 changes: 0 additions & 11 deletions ash/assistant/util/assistant_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ bool IsFinishingSession(AssistantVisibility new_visibility) {
return new_visibility == AssistantVisibility::kClosed;
}

bool IsEmbeddedUiEntryPoint(AssistantEntryPoint entry_point) {
return entry_point == AssistantEntryPoint::kDeepLink ||
entry_point == AssistantEntryPoint::kHotkey ||
entry_point == AssistantEntryPoint::kHotword ||
entry_point == AssistantEntryPoint::kLauncherSearchBox ||
entry_point == AssistantEntryPoint::kLauncherSearchBoxMic ||
entry_point == AssistantEntryPoint::kLauncherSearchResult ||
entry_point == AssistantEntryPoint::kLongPressLauncher ||
entry_point == AssistantEntryPoint::kUnspecified;
}

bool IsVoiceEntryPoint(AssistantEntryPoint entry_point, bool prefer_voice) {
switch (entry_point) {
case AssistantEntryPoint::kHotword:
Expand Down
5 changes: 0 additions & 5 deletions ash/assistant/util/assistant_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ bool IsStartingSession(AssistantVisibility new_visibility,
COMPONENT_EXPORT(ASSISTANT_UTIL)
bool IsFinishingSession(AssistantVisibility new_visibility);

// Returns true if the |entry_point| should show the embedded Assistant UI in
// Launcher.
COMPONENT_EXPORT(ASSISTANT_UTIL)
bool IsEmbeddedUiEntryPoint(AssistantEntryPoint entry_point);

// Returns true if the |entry_point| should start Assistant with a voice
// interaction.
// |prefer_voice| is true if user prefers voice input modality or if the device
Expand Down

0 comments on commit 0facb2c

Please sign in to comment.