Commit 92a232ad authored by wutao's avatar wutao Committed by Commit Bot

assistant: Handle scrolls in AssistantCardElementView

When AssistantCardElementView is focused, the true focused item is a
node in the contained web contents. We override ScrollRectToVisible()
to defer the scroll to FocusedNodeChanged() called by the contents.

In addition, when
View::HandleAccessibleAction(ax::mojom::Action::kScrollToMakeVisible)
is called on AssistantCardElementView, it will scroll to currently
focused node.

Bug: b/143370952
Test: manual
Change-Id: I315db0131e5517bf98d3e76f41203d00555237b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902709
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715093}
parent 11a729bb
......@@ -17,6 +17,7 @@
#include "ui/events/event_utils.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
namespace ash {
......@@ -91,6 +92,8 @@ void AssistantCardElementView::ChildPreferredSizeChanged(views::View* child) {
void AssistantCardElementView::AboutToRequestFocusFromTabTraversal(
bool reverse) {
// Focus in the web contents will be reset in FocusThroughTabTraversal().
focused_node_rect_ = gfx::Rect();
contents_->FocusThroughTabTraversal(reverse);
}
......@@ -141,6 +144,24 @@ void AssistantCardElementView::OnGestureEvent(ui::GestureEvent* event) {
cursor_manager->UnlockCursor();
}
void AssistantCardElementView::ScrollRectToVisible(const gfx::Rect& rect) {
// We expect this method is called outside this class to show its local
// bounds. Inside this class, should call views::View::ScrollRectToVisible()
// to show the focused node in the web contents.
DCHECK(rect == GetLocalBounds());
// When this view is focused, View::Focus() calls ScrollViewToVisible(), which
// calls ScrollRectToVisible(). But we don't want that call to do anything,
// since the true focused item is not this view but a node in the contained
// web contents. That will be scrolled into view by FocusedNodeChanged()
// below, so just no-op here.
if (focused_node_rect_.IsEmpty())
return;
// Make the focused node visible.
views::View::ScrollRectToVisible(focused_node_rect_);
}
void AssistantCardElementView::DidAutoResizeView(const gfx::Size& new_size) {
contents_->GetView()->view()->SetPreferredSize(new_size);
}
......@@ -164,8 +185,8 @@ void AssistantCardElementView::FocusedNodeChanged(
gfx::Point origin = node_bounds_in_screen.origin();
ConvertPointFromScreen(this, &origin);
gfx::Rect focused_rect_in_local(origin, node_bounds_in_screen.size());
ScrollRectToVisible(focused_rect_in_local);
focused_node_rect_ = gfx::Rect(origin, node_bounds_in_screen.size());
views::View::ScrollRectToVisible(focused_node_rect_);
}
void AssistantCardElementView::InitLayout(
......
......@@ -33,6 +33,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantCardElementView
void AboutToRequestFocusFromTabTraversal(bool reverse) override;
void OnFocus() override;
void OnGestureEvent(ui::GestureEvent* event) override;
void ScrollRectToVisible(const gfx::Rect& rect) override;
// content::NavigableContentsObserver:
void DidAutoResizeView(const gfx::Size& new_size) override;
......@@ -56,6 +57,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantCardElementView
// Owned by AssistantCardElement.
content::NavigableContents* const contents_;
// Rect of the focused node in the |contents_|.
gfx::Rect focused_node_rect_;
DISALLOW_COPY_AND_ASSIGN(AssistantCardElementView);
};
......
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