Skip to content

Commit

Permalink
Add Quick Answers View
Browse files Browse the repository at this point in the history
1. Implement quick answers native view which supports rich content and
will be placed outside of context menu.
2. Update quick_answer_model to provide QuickAnswers data to
QuickAnswers View.


Bug: 1020004
Change-Id: Id6ee62352e143559170fe58ba1d928f16187d488
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026114
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiao Yang <yanxiao@google.com>
Cr-Commit-Position: refs/heads/master@{#742192}
  • Loading branch information
Xiao Yang authored and Commit Bot committed Feb 18, 2020
1 parent ace7aab commit d1ef444
Show file tree
Hide file tree
Showing 13 changed files with 535 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ component("ash") {
"power/hid_battery_util.h",
"power/peripheral_battery_tracker.cc",
"power/peripheral_battery_tracker.h",
"quick_answers/quick_answers_ui_controller.cc",
"quick_answers/quick_answers_ui_controller.h",
"quick_answers/ui/quick_answers_view.cc",
"quick_answers/ui/quick_answers_view.h",
"root_window_controller.cc",
"root_window_settings.cc",
"root_window_settings.h",
Expand Down Expand Up @@ -1435,6 +1439,7 @@ component("ash") {
"//cc/debug",
"//cc/paint:paint",
"//chromeos/assistant:buildflags",
"//chromeos/components/quick_answers",

# TODO(https://crbug.com/644336): Make CrasAudioHandler Chrome or Ash only.
"//chromeos/audio",
Expand Down
1 change: 1 addition & 0 deletions ash/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ include_rules = [
"+chromeos/audio",
"+chromeos/components/multidevice/logging/logging.h",
"+chromeos/components/proximity_auth/public/mojom",
"+chromeos/components/quick_answers",
"+chromeos/constants",
# TODO(https://crbug.com/940810): Eliminate this.
"+chromeos/dbus/initialize_dbus_client.h",
Expand Down
78 changes: 78 additions & 0 deletions ash/quick_answers/quick_answers_ui_controller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2020 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/quick_answers/quick_answers_ui_controller.h"

#include "ash/public/cpp/assistant/assistant_interface_binder.h"
#include "ash/quick_answers/ui/quick_answers_view.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/bind.h"
#include "base/optional.h"
#include "chromeos/components/quick_answers/quick_answers_model.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/widget/widget.h"

using chromeos::quick_answers::QuickAnswer;
namespace ash {

QuickAnswersUiController::~QuickAnswersUiController() {
Close();
}

void QuickAnswersUiController::CreateQuickAnswersView(
const gfx::Rect& bounds,
const std::string& title) {
DCHECK(!quick_answers_view_);
SetActiveQuery(title);
quick_answers_view_ = new QuickAnswersView(bounds, title, this);
quick_answers_view_->GetWidget()->ShowInactive();
}

void QuickAnswersUiController::OnQuickAnswersViewPressed() {
Close();
mojo::Remote<chromeos::assistant::mojom::AssistantController>
assistant_controller;
ash::AssistantInterfaceBinder::GetInstance()->BindController(
assistant_controller.BindNewPipeAndPassReceiver());
assistant_controller->StartTextInteraction(
query_, /*allow_tts=*/false,
chromeos::assistant::mojom::AssistantQuerySource::kQuickAnswers);
}

void QuickAnswersUiController::Close() {
if (!quick_answers_view_)
return;

quick_answers_view_->GetWidget()->Close();
quick_answers_view_ = nullptr;
}

void QuickAnswersUiController::RenderQuickAnswersViewWithResult(
const gfx::Rect& bounds,
const QuickAnswer& quick_answer) {
if (!quick_answers_view_)
return;

// QuickAnswersView was initiated with a loading page and will be updated
// when quick answers result from server side is ready.
quick_answers_view_->UpdateView(bounds, quick_answer);
}

void QuickAnswersUiController::SetActiveQuery(const std::string& query) {
query_ = query;
}

void QuickAnswersUiController::UpdateQuickAnswersBounds(
const gfx::Rect& bounds) {
if (!quick_answers_view_)
return;

quick_answers_view_->UpdateAnchorViewBounds(bounds);
}
} // namespace ash
56 changes: 56 additions & 0 deletions ash/quick_answers/quick_answers_ui_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2020 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_QUICK_ANSWERS_QUICK_ANSWERS_UI_CONTROLLER_H_
#define ASH_QUICK_ANSWERS_QUICK_ANSWERS_UI_CONTROLLER_H_

#include <string>

#include "ash/ash_export.h"
#include "ui/gfx/geometry/rect.h"

namespace chromeos {
namespace quick_answers {
struct QuickAnswer;
} // namespace quick_answers
} // namespace chromeos

namespace ash {
class QuickAnswersView;

// A controller to show/hide and handle interactions for quick
// answers view.
class ASH_EXPORT QuickAnswersUiController {
public:
QuickAnswersUiController() = default;
~QuickAnswersUiController();

QuickAnswersUiController(const QuickAnswersUiController&) = delete;
QuickAnswersUiController& operator=(const QuickAnswersUiController&) = delete;

void Close();
// Constructs/resets |quick_answers_view_|.
void CreateQuickAnswersView(const gfx::Rect& bounds,
const std::string& title);

void OnQuickAnswersViewPressed();

// |bounds| is the bound of context menu.
void RenderQuickAnswersViewWithResult(
const gfx::Rect& bounds,
const chromeos::quick_answers::QuickAnswer& quick_answer);

void SetActiveQuery(const std::string& query);

void UpdateQuickAnswersBounds(const gfx::Rect& bounds);

private:
// Owned by view hierarchy.
QuickAnswersView* quick_answers_view_ = nullptr;
std::string query_;
};

} // namespace ash

#endif // ASH_QUICK_ANSWERS_QUICK_ANSWERS_UI_CONTROLLER_H_
Loading

0 comments on commit d1ef444

Please sign in to comment.