Commit 0b3114da authored by wutao's avatar wutao Committed by Commit Bot

app_list: Make the Assistant card scrollable

This patch addes a window property to make the Assistant answer card
scrollable in the embedded UI.
Changes:
1. Refactor current code so that app_list_view can access the window
   property.
2. Modify app_list_view event targeter to handle Assistant answer card
   events.

Bug: 924624
Test: manual
Change-Id: Iad9650ca98589793ff065574b3971aa97c3ec3f5
Reviewed-on: https://chromium-review.googlesource.com/c/1482591Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634774}
parent 15ce5f03
......@@ -15,6 +15,7 @@
#include "ash/app_list/views/apps_container_view.h"
#include "ash/app_list/views/contents_view.h"
#include "ash/app_list/views/search_box_view.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_features.h"
#include "ash/public/cpp/shell_window_ids.h"
......@@ -157,6 +158,14 @@ class AppListEventTargeter : public aura::WindowTargeter {
if (event.type() != ui::ET_MOUSE_MOVED)
return false;
}
if (window->GetProperty(ash::assistant::ui::kOnlyAllowMouseClickEvents)) {
if (event.type() != ui::ET_MOUSE_PRESSED &&
event.type() != ui::ET_MOUSE_RELEASED) {
return false;
}
}
return aura::WindowTargeter::SubtreeShouldBeExploredForEvent(window, event);
}
......
......@@ -7,7 +7,11 @@ import("//chromeos/assistant/assistant.gni")
assert(is_chromeos)
source_set("constants") {
component("constants") {
output_name = "assistant_ui_constants"
defines = [ "IS_ASSISTANT_UI_CONSTANTS_IMPL" ]
sources = [
"assistant_ui_constants.cc",
"assistant_ui_constants.h",
......@@ -16,6 +20,8 @@ source_set("constants") {
deps = [
"//base",
"//skia",
"//ui/aura",
"//ui/base",
"//ui/gfx",
]
}
......
......@@ -37,9 +37,6 @@ namespace {
// Appearance.
constexpr SkColor kBackgroundColor = SK_ColorWHITE;
// Window properties.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kOnlyAllowMouseClickEvents, false)
// AssistantContainerClientView ------------------------------------------------
// AssistantContainerClientView is the client view for AssistantContainerView
......@@ -130,7 +127,7 @@ class AssistantContainerEventTargeter : public aura::WindowTargeter {
// aura::WindowTargeter:
bool SubtreeShouldBeExploredForEvent(aura::Window* window,
const ui::LocatedEvent& event) override {
if (window->GetProperty(kOnlyAllowMouseClickEvents)) {
if (window->GetProperty(assistant::ui::kOnlyAllowMouseClickEvents)) {
if (event.type() != ui::ET_MOUSE_PRESSED &&
event.type() != ui::ET_MOUSE_RELEASED) {
return false;
......@@ -273,11 +270,6 @@ AssistantContainerView::~AssistantContainerView() {
delegate_->RemoveUiModelObserver(this);
}
// static
void AssistantContainerView::OnlyAllowMouseClickEvents(aura::Window* window) {
window->SetProperty(kOnlyAllowMouseClickEvents, true);
}
const char* AssistantContainerView::GetClassName() const {
return "AssistantContainerView";
}
......
......@@ -13,10 +13,6 @@
#include "base/macros.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
namespace aura {
class Window;
} // namespace aura
namespace ash {
class AssistantContainerViewAnimator;
......@@ -32,11 +28,6 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantContainerView
explicit AssistantContainerView(AssistantViewDelegate* delegate);
~AssistantContainerView() override;
// Instructs the event targeter for the Assistant window to only allow mouse
// click events to reach the specified |window|. All other events will not
// be explored by |window|'s subtree for handling.
static void OnlyAllowMouseClickEvents(aura::Window* window);
// views::BubbleDialogDelegateView:
const char* GetClassName() const override;
void AddedToWidget() override;
......
......@@ -5,12 +5,15 @@
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "base/no_destructor.h"
#include "ui/base/class_property.h"
#include "ui/gfx/font_list.h"
namespace ash {
namespace assistant {
namespace ui {
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kOnlyAllowMouseClickEvents, false)
const gfx::FontList& GetDefaultFontList() {
static const base::NoDestructor<gfx::FontList> font_list("Google Sans, 12px");
return *font_list;
......@@ -18,4 +21,4 @@ const gfx::FontList& GetDefaultFontList() {
} // namespace ui
} // namespace assistant
} // namespace ash
\ No newline at end of file
} // namespace ash
......@@ -5,7 +5,9 @@
#ifndef ASH_ASSISTANT_UI_ASSISTANT_UI_CONSTANTS_H_
#define ASH_ASSISTANT_UI_ASSISTANT_UI_CONSTANTS_H_
#include "base/component_export.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window.h"
#include "ui/gfx/color_palette.h"
namespace gfx {
......@@ -32,7 +34,14 @@ constexpr SkColor kTextColorSecondary = gfx::kGoogleGrey700;
namespace assistant {
namespace ui {
// Window property to instruct the event targeter for the Assistant window to
// only allow mouse click events to reach the specified |window|. All other
// events will not be explored by |window|'s subtree for handling.
COMPONENT_EXPORT(ASSISTANT_UI_CONSTANTS)
extern const aura::WindowProperty<bool>* const kOnlyAllowMouseClickEvents;
// Returns the default font list for Assistant UI.
COMPONENT_EXPORT(ASSISTANT_UI_CONSTANTS)
const gfx::FontList& GetDefaultFontList();
} // namespace ui
......
......@@ -8,7 +8,9 @@
#include "ash/assistant/model/assistant_ui_element.h"
#include "ash/assistant/ui/assistant_container_view.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/event.h"
#include "ui/events/event_sink.h"
......@@ -80,7 +82,7 @@ void AssistantCardElementView::AddedToWidget() {
// vertically. As such, we need to prevent the Assistant card window from
// receiving events it doesn't need. It needs mouse click events for
// handling links.
AssistantContainerView::OnlyAllowMouseClickEvents(window);
window->SetProperty(ash::assistant::ui::kOnlyAllowMouseClickEvents, true);
}
void AssistantCardElementView::ChildPreferredSizeChanged(views::View* child) {
......
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