Commit 65a43f36 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Use scrollable shelf as shelf button delegate

When the scrollable shelf is enabled, use ScrollableShelfView as the
shelf button delegate for the shelf app buttons. It helps to build
the connection between the app button and the topmost view in hotseat
widget. This CL should not bring any noticeable change.

Bug: 1010219
Change-Id: I0e4e3a810a72094a108af459561ebb306808c2f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869554
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709268}
parent aa2a6e2e
...@@ -173,7 +173,8 @@ void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) { ...@@ -173,7 +173,8 @@ void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) {
// The shelf view observes the shelf model and creates icons as items are // The shelf view observes the shelf model and creates icons as items are
// added to the model. // added to the model.
shelf_view_ = GetContentsView()->AddChildView(std::make_unique<ShelfView>( shelf_view_ = GetContentsView()->AddChildView(std::make_unique<ShelfView>(
ShelfModel::Get(), shelf, /*drag_and_drop_host=*/nullptr)); ShelfModel::Get(), shelf, /*drag_and_drop_host=*/nullptr,
/*shelf_button_delegate=*/nullptr));
shelf_view_->Init(); shelf_view_->Init();
} }
delegate_view_->Init(scrollable_shelf_view(), GetLayer()); delegate_view_->Init(scrollable_shelf_view(), GetLayer());
......
...@@ -330,7 +330,10 @@ class ScrollableShelfFocusSearch : public views::FocusSearch { ...@@ -330,7 +330,10 @@ class ScrollableShelfFocusSearch : public views::FocusSearch {
// ScrollableShelfView // ScrollableShelfView
ScrollableShelfView::ScrollableShelfView(ShelfModel* model, Shelf* shelf) ScrollableShelfView::ScrollableShelfView(ShelfModel* model, Shelf* shelf)
: shelf_view_(new ShelfView(model, shelf, /*drag_and_drop_host=*/this)), : shelf_view_(new ShelfView(model,
shelf,
/*drag_and_drop_host=*/this,
/*shelf_button_delegate=*/this)),
page_flip_time_threshold_(kShelfPageFlipDelay) { page_flip_time_threshold_(kShelfPageFlipDelay) {
Shell::Get()->AddShellObserver(this); Shell::Get()->AddShellObserver(this);
set_allow_deactivate_on_esc(true); set_allow_deactivate_on_esc(true);
...@@ -747,24 +750,31 @@ const char* ScrollableShelfView::GetClassName() const { ...@@ -747,24 +750,31 @@ const char* ScrollableShelfView::GetClassName() const {
void ScrollableShelfView::OnShelfButtonAboutToRequestFocusFromTabTraversal( void ScrollableShelfView::OnShelfButtonAboutToRequestFocusFromTabTraversal(
ShelfButton* button, ShelfButton* button,
bool reverse) {} bool reverse) {
if ((button == left_arrow_) || (button == right_arrow_))
return;
void ScrollableShelfView::ShowContextMenuForViewImpl( shelf_view_->OnShelfButtonAboutToRequestFocusFromTabTraversal(button,
views::View* source, reverse);
const gfx::Point& point,
ui::MenuSourceType source_type) {
// |point| is in screen coordinates. So it does not need to transform.
shelf_view_->ShowContextMenuForViewImpl(shelf_view_, point, source_type);
} }
void ScrollableShelfView::ButtonPressed(views::Button* sender, void ScrollableShelfView::ButtonPressed(views::Button* sender,
const ui::Event& event, const ui::Event& event,
views::InkDrop* ink_drop) { views::InkDrop* ink_drop) {
// Verfies that |sender| is either |left_arrow_| or |right_arrow_|. if ((sender == left_arrow_) || (sender == right_arrow_)) {
views::View* sender_view = sender; ScrollToNewPage(sender == right_arrow_);
DCHECK((sender_view == left_arrow_) || (sender_view == right_arrow_)); return;
}
ScrollToNewPage(sender_view == right_arrow_); shelf_view_->ButtonPressed(sender, event, ink_drop);
}
void ScrollableShelfView::ShowContextMenuForViewImpl(
views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
// |point| is in screen coordinates. So it does not need to transform.
shelf_view_->ShowContextMenuForViewImpl(shelf_view_, point, source_type);
} }
void ScrollableShelfView::OnShelfAlignmentChanged(aura::Window* root_window) { void ScrollableShelfView::OnShelfAlignmentChanged(aura::Window* root_window) {
......
...@@ -170,16 +170,15 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -170,16 +170,15 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// ShelfButtonDelegate: // ShelfButtonDelegate:
void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button, void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button,
bool reverse) override; bool reverse) override;
void ButtonPressed(views::Button* sender,
const ui::Event& event,
views::InkDrop* ink_drop) override;
// ContextMenuController: // ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source, void ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point, const gfx::Point& point,
ui::MenuSourceType source_type) override; ui::MenuSourceType source_type) override;
void ButtonPressed(views::Button* sender,
const ui::Event& event,
views::InkDrop* ink_drop) override;
// Overridden from ShellObserver: // Overridden from ShellObserver:
void OnShelfAlignmentChanged(aura::Window* root_window) override; void OnShelfAlignmentChanged(aura::Window* root_window) override;
......
...@@ -296,8 +296,9 @@ class ShelfAppButton::AppStatusIndicatorView ...@@ -296,8 +296,9 @@ class ShelfAppButton::AppStatusIndicatorView
// static // static
const char ShelfAppButton::kViewClassName[] = "ash/ShelfAppButton"; const char ShelfAppButton::kViewClassName[] = "ash/ShelfAppButton";
ShelfAppButton::ShelfAppButton(ShelfView* shelf_view) ShelfAppButton::ShelfAppButton(ShelfView* shelf_view,
: ShelfButton(shelf_view->shelf(), shelf_view), ShelfButtonDelegate* shelf_button_delegate)
: ShelfButton(shelf_view->shelf(), shelf_button_delegate),
icon_view_(new views::ImageView()), icon_view_(new views::ImageView()),
shelf_view_(shelf_view), shelf_view_(shelf_view),
indicator_(new AppStatusIndicatorView()), indicator_(new AppStatusIndicatorView()),
......
...@@ -45,7 +45,8 @@ class ASH_EXPORT ShelfAppButton : public ShelfButton { ...@@ -45,7 +45,8 @@ class ASH_EXPORT ShelfAppButton : public ShelfButton {
STATE_ACTIVE = 1 << 6, STATE_ACTIVE = 1 << 6,
}; };
explicit ShelfAppButton(ShelfView* shelf_view); ShelfAppButton(ShelfView* shelf_view,
ShelfButtonDelegate* shelf_button_delegate);
~ShelfAppButton() override; ~ShelfAppButton() override;
// Sets the image to display for this entry. // Sets the image to display for this entry.
......
...@@ -301,13 +301,15 @@ const int ShelfView::kMinimumDragDistance = 8; ...@@ -301,13 +301,15 @@ const int ShelfView::kMinimumDragDistance = 8;
ShelfView::ShelfView(ShelfModel* model, ShelfView::ShelfView(ShelfModel* model,
Shelf* shelf, Shelf* shelf,
ApplicationDragAndDropHost* drag_and_drop_host) ApplicationDragAndDropHost* drag_and_drop_host,
ShelfButtonDelegate* shelf_button_delegate)
: model_(model), : model_(model),
shelf_(shelf), shelf_(shelf),
view_model_(std::make_unique<views::ViewModel>()), view_model_(std::make_unique<views::ViewModel>()),
bounds_animator_(std::make_unique<views::BoundsAnimator>(this)), bounds_animator_(std::make_unique<views::BoundsAnimator>(this)),
focus_search_(std::make_unique<ShelfFocusSearch>(this)), focus_search_(std::make_unique<ShelfFocusSearch>(this)),
drag_and_drop_host_(drag_and_drop_host) { drag_and_drop_host_(drag_and_drop_host),
shelf_button_delegate_(shelf_button_delegate) {
DCHECK(model_); DCHECK(model_);
DCHECK(shelf_); DCHECK(shelf_);
Shell::Get()->tablet_mode_controller()->AddObserver(this); Shell::Get()->tablet_mode_controller()->AddObserver(this);
...@@ -525,7 +527,8 @@ void ShelfView::ToggleOverflowBubble() { ...@@ -525,7 +527,8 @@ void ShelfView::ToggleOverflowBubble() {
overflow_bubble_.reset(new OverflowBubble(shelf_)); overflow_bubble_.reset(new OverflowBubble(shelf_));
ShelfView* overflow_view = ShelfView* overflow_view =
new ShelfView(model_, shelf_, /*drag_and_drop_host=*/nullptr); new ShelfView(model_, shelf_, /*drag_and_drop_host=*/nullptr,
/*shelf_button_delegate=*/nullptr);
overflow_view->overflow_mode_ = true; overflow_view->overflow_mode_ = true;
overflow_view->Init(); overflow_view->Init();
overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); overflow_view->set_owner_overflow_bubble(overflow_bubble_.get());
...@@ -1154,7 +1157,8 @@ views::View* ShelfView::CreateViewForItem(const ShelfItem& item) { ...@@ -1154,7 +1157,8 @@ views::View* ShelfView::CreateViewForItem(const ShelfItem& item) {
case TYPE_BROWSER_SHORTCUT: case TYPE_BROWSER_SHORTCUT:
case TYPE_APP: case TYPE_APP:
case TYPE_DIALOG: { case TYPE_DIALOG: {
ShelfAppButton* button = new ShelfAppButton(this); ShelfAppButton* button = new ShelfAppButton(
this, shelf_button_delegate_ ? shelf_button_delegate_ : this);
button->SetImage(item.image); button->SetImage(item.image);
button->ReflectItemStatus(item); button->ReflectItemStatus(item);
view = button; view = button;
......
...@@ -120,7 +120,8 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -120,7 +120,8 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
public: public:
ShelfView(ShelfModel* model, ShelfView(ShelfModel* model,
Shelf* shelf, Shelf* shelf,
ApplicationDragAndDropHost* drag_and_drop_host); ApplicationDragAndDropHost* drag_and_drop_host,
ShelfButtonDelegate* delegate);
~ShelfView() override; ~ShelfView() override;
Shelf* shelf() const { return shelf_; } Shelf* shelf() const { return shelf_; }
...@@ -733,6 +734,10 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -733,6 +734,10 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
// ScrollableShelfView. // ScrollableShelfView.
ApplicationDragAndDropHost* drag_and_drop_host_ = nullptr; ApplicationDragAndDropHost* drag_and_drop_host_ = nullptr;
// When the scrollable shelf is enabled, |shelf_button_delegate_| should
// be ScrollableShelfView.
ShelfButtonDelegate* shelf_button_delegate_ = nullptr;
base::WeakPtrFactory<ShelfView> weak_factory_{this}; base::WeakPtrFactory<ShelfView> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ShelfView); DISALLOW_COPY_AND_ASSIGN(ShelfView);
......
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