forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
13 changed files
with
535 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
Oops, something went wrong.