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) {
// The shelf view observes the shelf model and creates icons as items are
// added to the model.
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();
}
delegate_view_->Init(scrollable_shelf_view(), GetLayer());
......
......@@ -330,7 +330,10 @@ class ScrollableShelfFocusSearch : public views::FocusSearch {
// ScrollableShelfView
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) {
Shell::Get()->AddShellObserver(this);
set_allow_deactivate_on_esc(true);
......@@ -747,24 +750,31 @@ const char* ScrollableShelfView::GetClassName() const {
void ScrollableShelfView::OnShelfButtonAboutToRequestFocusFromTabTraversal(
ShelfButton* button,
bool reverse) {}
bool reverse) {
if ((button == left_arrow_) || (button == right_arrow_))
return;
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);
shelf_view_->OnShelfButtonAboutToRequestFocusFromTabTraversal(button,
reverse);
}
void ScrollableShelfView::ButtonPressed(views::Button* sender,
const ui::Event& event,
views::InkDrop* ink_drop) {
// Verfies that |sender| is either |left_arrow_| or |right_arrow_|.
views::View* sender_view = sender;
DCHECK((sender_view == left_arrow_) || (sender_view == right_arrow_));
if ((sender == left_arrow_) || (sender == right_arrow_)) {
ScrollToNewPage(sender == 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) {
......
......@@ -170,16 +170,15 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// ShelfButtonDelegate:
void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button,
bool reverse) override;
void ButtonPressed(views::Button* sender,
const ui::Event& event,
views::InkDrop* ink_drop) override;
// ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
void ButtonPressed(views::Button* sender,
const ui::Event& event,
views::InkDrop* ink_drop) override;
// Overridden from ShellObserver:
void OnShelfAlignmentChanged(aura::Window* root_window) override;
......
......@@ -296,8 +296,9 @@ class ShelfAppButton::AppStatusIndicatorView
// static
const char ShelfAppButton::kViewClassName[] = "ash/ShelfAppButton";
ShelfAppButton::ShelfAppButton(ShelfView* shelf_view)
: ShelfButton(shelf_view->shelf(), shelf_view),
ShelfAppButton::ShelfAppButton(ShelfView* shelf_view,
ShelfButtonDelegate* shelf_button_delegate)
: ShelfButton(shelf_view->shelf(), shelf_button_delegate),
icon_view_(new views::ImageView()),
shelf_view_(shelf_view),
indicator_(new AppStatusIndicatorView()),
......
......@@ -45,7 +45,8 @@ class ASH_EXPORT ShelfAppButton : public ShelfButton {
STATE_ACTIVE = 1 << 6,
};
explicit ShelfAppButton(ShelfView* shelf_view);
ShelfAppButton(ShelfView* shelf_view,
ShelfButtonDelegate* shelf_button_delegate);
~ShelfAppButton() override;
// Sets the image to display for this entry.
......
......@@ -301,13 +301,15 @@ const int ShelfView::kMinimumDragDistance = 8;
ShelfView::ShelfView(ShelfModel* model,
Shelf* shelf,
ApplicationDragAndDropHost* drag_and_drop_host)
ApplicationDragAndDropHost* drag_and_drop_host,
ShelfButtonDelegate* shelf_button_delegate)
: model_(model),
shelf_(shelf),
view_model_(std::make_unique<views::ViewModel>()),
bounds_animator_(std::make_unique<views::BoundsAnimator>(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(shelf_);
Shell::Get()->tablet_mode_controller()->AddObserver(this);
......@@ -525,7 +527,8 @@ void ShelfView::ToggleOverflowBubble() {
overflow_bubble_.reset(new OverflowBubble(shelf_));
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->Init();
overflow_view->set_owner_overflow_bubble(overflow_bubble_.get());
......@@ -1154,7 +1157,8 @@ views::View* ShelfView::CreateViewForItem(const ShelfItem& item) {
case TYPE_BROWSER_SHORTCUT:
case TYPE_APP:
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->ReflectItemStatus(item);
view = button;
......
......@@ -120,7 +120,8 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
public:
ShelfView(ShelfModel* model,
Shelf* shelf,
ApplicationDragAndDropHost* drag_and_drop_host);
ApplicationDragAndDropHost* drag_and_drop_host,
ShelfButtonDelegate* delegate);
~ShelfView() override;
Shelf* shelf() const { return shelf_; }
......@@ -733,6 +734,10 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
// ScrollableShelfView.
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};
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