Commit cf1c693e authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

part 5 of the scrollableshelf view

Add focus traversal to ScrollableShelfView

Bug: 973481
Change-Id: I3beeea53aff1ed32ccb588f2033ab67851590574
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767484
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691759}
parent 97c11296
......@@ -96,8 +96,12 @@ void HotseatWidget::OnGestureEvent(ui::GestureEvent* event) {
bool HotseatWidget::OnNativeWidgetActivationChanged(bool active) {
if (!Widget::OnNativeWidgetActivationChanged(active))
return false;
if (active)
if (IsScrollableShelfEnabled())
scrollable_shelf_view_->OnFocusRingActivationChanged(active);
else if (active)
GetShelfView()->SetPaneFocusAndFocusDefault();
return true;
}
......
......@@ -43,6 +43,10 @@ class ASH_EXPORT HotseatWidget : public views::Widget {
ShelfView* GetShelfView();
const ShelfView* GetShelfView() const;
ScrollableShelfView* scrollable_shelf_view() {
return scrollable_shelf_view_;
}
private:
class DelegateView;
......
This diff is collapsed.
......@@ -15,9 +15,13 @@
#include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/controls/button/button.h"
namespace views {
class FocusSearch;
}
namespace ash {
class ASH_EXPORT ScrollableShelfView : public views::View,
class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
public ShellObserver,
public ShelfButtonDelegate {
public:
......@@ -41,6 +45,20 @@ class ASH_EXPORT ScrollableShelfView : public views::View,
void Init();
// Called when the focus ring for ScrollableShelfView is enabled/disabled.
// |activated| is true when enabling the focus ring.
void OnFocusRingActivationChanged(bool activated);
// Scrolls to a new page of shelf icons. |forward| indicates whether the next
// page or previous page is shown.
void ScrollToNewPage(bool forward);
// AccessiblePaneView:
views::FocusSearch* GetFocusSearch() override;
views::FocusTraversable* GetFocusTraversableParent() override;
views::View* GetFocusTraversableParentView() override;
views::View* GetDefaultFocusableChild() override;
views::View* GetShelfContainerViewForTest();
ShelfView* shelf_view() { return shelf_view_; }
......@@ -48,6 +66,13 @@ class ASH_EXPORT ScrollableShelfView : public views::View,
LayoutStrategy layout_strategy_for_test() const { return layout_strategy_; }
gfx::Vector2dF scroll_offset_for_test() const { return scroll_offset_; }
int first_tappable_app_index() { return first_tappable_app_index_; }
int last_tappable_app_index() { return last_tappable_app_index_; }
void set_default_last_focusable_child(bool default_last_focusable_child) {
default_last_focusable_child_ = default_last_focusable_child;
}
// Size of the arrow button.
static int GetArrowButtonSize();
......@@ -143,6 +168,18 @@ class ASH_EXPORT ScrollableShelfView : public views::View,
// Updates the gradient zone.
void UpdateGradientZone();
// Returns the actual scroll offset on the view's main axis. When the left
// arrow button shows, |shelf_view_| is translated due to the change in
// |shelf_container_view_|'s bounds. That translation offset is not included
// in |scroll_offset_|.
int GetActualScrollOffset() const;
// Updates |first_tappable_app_index_| and |last_tappable_app_index_|.
void UpdateTappableIconIndices();
views::View* FindFirstFocusableChild();
views::View* FindLastFocusableChild();
LayoutStrategy layout_strategy_ = kNotShowArrowButtons;
// Child views Owned by views hierarchy.
......@@ -169,6 +206,20 @@ class ASH_EXPORT ScrollableShelfView : public views::View,
std::unique_ptr<GradientLayerDelegate> gradient_layer_delegate_;
std::unique_ptr<views::FocusSearch> focus_search_;
// The index of the first/last tappable app index.
int first_tappable_app_index_ = -1;
int last_tappable_app_index_ = -1;
// Whether this view should focus its last focusable child (instead of its
// first) when focused.
bool default_last_focusable_child_ = false;
// Indicates whether the focus ring on shelf items contained by
// ScrollableShelfView is enabled.
bool focus_ring_activated_ = false;
DISALLOW_COPY_AND_ASSIGN(ScrollableShelfView);
};
......
......@@ -6,6 +6,7 @@
#include "ash/focus_cycler.h"
#include "ash/shelf/login_shelf_view.h"
#include "ash/shelf/scrollable_shelf_view.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_navigation_widget.h"
#include "ash/shelf/shelf_view.h"
......@@ -14,6 +15,7 @@
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "chromeos/constants/chromeos_switches.h"
namespace ash {
......@@ -83,8 +85,13 @@ void ShelfFocusCycler::FocusShelf(bool last_element) {
Shell::Get()->focus_cycler()->FocusWidget(shelf_widget);
} else {
HotseatWidget* hotseat_widget = shelf_->shelf_widget()->hotseat_widget();
if (chromeos::switches::ShouldShowScrollableShelf()) {
hotseat_widget->scrollable_shelf_view()->set_default_last_focusable_child(
last_element);
} else {
hotseat_widget->GetShelfView()->set_default_last_focusable_child(
last_element);
}
Shell::Get()->focus_cycler()->FocusWidget(hotseat_widget);
}
}
......
......@@ -576,6 +576,11 @@ void ShelfView::OnMouseEvent(ui::MouseEvent* event) {
}
views::FocusTraversable* ShelfView::GetPaneFocusTraversable() {
// ScrollableShelfView should handles the focus traversal if the flag
// is enabled.
if (chromeos::switches::ShouldShowScrollableShelf())
return nullptr;
return this;
}
......
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