Commit 83636e90 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Commit Bot

Fix feature pods focus traversal

Always ensure the focused view is visible by switching pages
when needed.

Bug: 1013722
Change-Id: I27e561dabc43daea32167ff68d84ba710821d902
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856852
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705768}
parent d614483f
......@@ -163,6 +163,23 @@ int FeaturePodsContainerView::GetVisibleCount() const {
});
}
void FeaturePodsContainerView::EnsurePageWithButton(FeaturePodButton* button) {
int index = visible_buttons_.GetIndexOfView(button->parent());
if (index < 0)
return;
int tiles_per_page = GetTilesPerPage();
int first_index = pagination_model_->selected_page() * tiles_per_page;
int last_index =
((pagination_model_->selected_page() + 1) * tiles_per_page) - 1;
if (index < first_index || index > last_index) {
int page = ((index + 1) / tiles_per_page) +
((index + 1) % tiles_per_page ? 1 : 0) - 1;
pagination_model_->SelectPage(page, true /*animate*/);
}
}
gfx::Point FeaturePodsContainerView::GetButtonPosition(
int visible_index) const {
int row = visible_index / kUnifiedFeaturePodItemsInRow;
......
......@@ -50,6 +50,9 @@ class ASH_EXPORT FeaturePodsContainerView : public views::View,
// Returns the number of children that prefer to be visible.
int GetVisibleCount() const;
// Make sure button is visible by switching page if needed.
void EnsurePageWithButton(FeaturePodButton* button);
// views::View:
gfx::Size CalculatePreferredSize() const override;
void ChildVisibilityChanged(View* child) override;
......
......@@ -565,20 +565,26 @@ void UnifiedSystemTrayView::OnWillChangeFocus(views::View* before,
void UnifiedSystemTrayView::OnDidChangeFocus(views::View* before,
views::View* now) {
if (features::IsUnifiedMessageCenterRefactorEnabled()) {
views::View* first_view = GetFirstFocusableChild();
views::View* last_view = GetLastFocusableChild();
bool focused_out = false;
if (before == last_view && now == first_view)
focused_out = controller_->FocusOut(false);
else if (before == first_view && now == last_view)
focused_out = controller_->FocusOut(true);
if (focused_out) {
GetFocusManager()->ClearFocus();
GetFocusManager()->SetStoredFocusView(nullptr);
}
if (!features::IsUnifiedMessageCenterRefactorEnabled())
return;
if (feature_pods_container_->Contains(now)) {
feature_pods_container_->EnsurePageWithButton(
static_cast<FeaturePodButton*>(now));
}
views::View* first_view = GetFirstFocusableChild();
views::View* last_view = GetLastFocusableChild();
bool focused_out = false;
if (before == last_view && now == first_view)
focused_out = controller_->FocusOut(false);
else if (before == first_view && now == last_view)
focused_out = controller_->FocusOut(true);
if (focused_out) {
GetFocusManager()->ClearFocus();
GetFocusManager()->SetStoredFocusView(nullptr);
}
}
......
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