Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: ash/common/shelf/shelf_view.cc

Issue 2718563008: mash: Use mojo for ShelfItemDelegate and [app] MenuItem. (Closed)
Patch Set: Address comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/shelf/shelf_view.h ('k') | ash/common/shelf/shelf_window_watcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/shelf/shelf_view.h" 5 #include "ash/common/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/common/ash_constants.h" 10 #include "ash/common/ash_constants.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 closing_event_time_(base::TimeTicks()), 268 closing_event_time_(base::TimeTicks()),
269 drag_and_drop_item_pinned_(false), 269 drag_and_drop_item_pinned_(false),
270 drag_and_drop_shelf_id_(0), 270 drag_and_drop_shelf_id_(0),
271 drag_replaced_view_(nullptr), 271 drag_replaced_view_(nullptr),
272 dragged_off_shelf_(false), 272 dragged_off_shelf_(false),
273 snap_back_from_rip_off_view_(nullptr), 273 snap_back_from_rip_off_view_(nullptr),
274 overflow_mode_(false), 274 overflow_mode_(false),
275 main_shelf_(nullptr), 275 main_shelf_(nullptr),
276 dragged_off_from_overflow_to_shelf_(false), 276 dragged_off_from_overflow_to_shelf_(false),
277 is_repost_event_on_same_item_(false), 277 is_repost_event_on_same_item_(false),
278 last_pressed_index_(-1) { 278 last_pressed_index_(-1),
279 weak_factory_(this) {
279 DCHECK(model_); 280 DCHECK(model_);
280 DCHECK(delegate_); 281 DCHECK(delegate_);
281 DCHECK(wm_shelf_); 282 DCHECK(wm_shelf_);
282 DCHECK(shelf_widget_); 283 DCHECK(shelf_widget_);
283 bounds_animator_.reset(new views::BoundsAnimator(this)); 284 bounds_animator_.reset(new views::BoundsAnimator(this));
284 bounds_animator_->AddObserver(this); 285 bounds_animator_->AddObserver(this);
285 set_context_menu_controller(this); 286 set_context_menu_controller(this);
286 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); 287 focus_search_.reset(new ShelfFocusSearch(view_model_.get()));
287 } 288 }
288 289
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 case TYPE_APP_PANEL: 477 case TYPE_APP_PANEL:
477 case TYPE_DIALOG: 478 case TYPE_DIALOG:
478 break; 479 break;
479 480
480 case TYPE_UNDEFINED: 481 case TYPE_UNDEFINED:
481 NOTREACHED() << "ShelfItemType must be set."; 482 NOTREACHED() << "ShelfItemType must be set.";
482 break; 483 break;
483 } 484 }
484 485
485 const int64_t display_id = window->GetDisplayNearestWindow().id(); 486 const int64_t display_id = window->GetDisplayNearestWindow().id();
486 ShelfAction performed_action =
487 model_->GetShelfItemDelegate(model_->items()[last_pressed_index_].id)
488 ->ItemSelected(event.type(), event.flags(), display_id,
489 LAUNCH_FROM_UNKNOWN);
490 487
491 shelf_button_pressed_metric_tracker_.ButtonPressed(event, sender, 488 // Notify the item of its selection; handle the result in AfterItemSelected.
492 performed_action); 489 const ShelfItem& item = model_->items()[last_pressed_index_];
493 490 model_->GetShelfItemDelegate(item.id)->ItemSelected(
494 // For the app list menu no TRIGGERED ink drop effect is needed and it 491 ui::Event::Clone(event), display_id, LAUNCH_FROM_UNKNOWN,
495 // handles its own ACTIVATED/DEACTIVATED states. 492 base::Bind(&ShelfView::AfterItemSelected, weak_factory_.GetWeakPtr(),
496 if (performed_action == SHELF_ACTION_NEW_WINDOW_CREATED || 493 item, sender, base::Passed(ui::Event::Clone(event)),
497 (performed_action != SHELF_ACTION_APP_LIST_SHOWN && 494 ink_drop));
498 !ShowListMenuForView(model_->items()[last_pressed_index_], sender, event,
499 ink_drop))) {
500 ink_drop->AnimateToState(views::InkDropState::ACTION_TRIGGERED);
501 }
502 // Allow the menu to clear |scoped_root_window_for_new_windows_| during
503 // OnMenuClosed.
504 if (!IsShowingMenu())
505 scoped_root_window_for_new_windows_.reset();
506 } 495 }
507 496
508 //////////////////////////////////////////////////////////////////////////////// 497 ////////////////////////////////////////////////////////////////////////////////
509 // ShelfView, FocusTraversable implementation: 498 // ShelfView, FocusTraversable implementation:
510 499
511 views::FocusSearch* ShelfView::GetFocusSearch() { 500 views::FocusSearch* ShelfView::GetFocusSearch() {
512 return focus_search_.get(); 501 return focus_search_.get();
513 } 502 }
514 503
515 views::FocusTraversable* ShelfView::GetFocusTraversableParent() { 504 views::FocusTraversable* ShelfView::GetFocusTraversableParent() {
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 void ShelfView::ShelfItemMoved(int start_index, int target_index) { 1586 void ShelfView::ShelfItemMoved(int start_index, int target_index) {
1598 view_model_->Move(start_index, target_index); 1587 view_model_->Move(start_index, target_index);
1599 // When cancelling a drag due to a shelf item being added, the currently 1588 // When cancelling a drag due to a shelf item being added, the currently
1600 // dragged item is moved back to its initial position. AnimateToIdealBounds 1589 // dragged item is moved back to its initial position. AnimateToIdealBounds
1601 // will be called again when the new item is added to the |view_model_| but 1590 // will be called again when the new item is added to the |view_model_| but
1602 // at this time the |view_model_| is inconsistent with the |model_|. 1591 // at this time the |view_model_| is inconsistent with the |model_|.
1603 if (!cancelling_drag_model_changed_) 1592 if (!cancelling_drag_model_changed_)
1604 AnimateToIdealBounds(); 1593 AnimateToIdealBounds();
1605 } 1594 }
1606 1595
1607 void ShelfView::OnSetShelfItemDelegate(ShelfID id, 1596 void ShelfView::OnSetShelfItemDelegate(
1608 ShelfItemDelegate* item_delegate) {} 1597 ShelfID id,
1598 mojom::ShelfItemDelegate* item_delegate) {}
1609 1599
1610 bool ShelfView::ShowListMenuForView(const ShelfItem& item, 1600 void ShelfView::AfterItemSelected(
1611 views::View* source, 1601 const ShelfItem& item,
1612 const ui::Event& event, 1602 views::Button* sender,
1613 views::InkDrop* ink_drop) { 1603 std::unique_ptr<ui::Event> event,
1614 ShelfItemDelegate* item_delegate = model_->GetShelfItemDelegate(item.id); 1604 views::InkDrop* ink_drop,
1615 ShelfAppMenuItemList items = item_delegate->GetAppMenuItems(event.flags()); 1605 ShelfAction action,
1606 base::Optional<std::vector<mojom::MenuItemPtr>> menu_items) {
1607 shelf_button_pressed_metric_tracker_.ButtonPressed(*event, sender, action);
1616 1608
1617 // The application list menu should only show for two or more items; return 1609 // The app list handles its own ink drop effect state changes.
1618 // false here to ensure that other behavior is triggered (eg. activating or 1610 if (action != SHELF_ACTION_APP_LIST_SHOWN) {
1619 // minimizing a single associated window, or launching a pinned shelf item). 1611 if (action != SHELF_ACTION_NEW_WINDOW_CREATED && menu_items &&
1620 if (items.size() < 2) 1612 menu_items->size() > 1) {
1621 return false; 1613 // Show the app menu if there are 2 or more items and no window was shown.
1622 1614 ink_drop->AnimateToState(views::InkDropState::ACTIVATED);
1623 ink_drop->AnimateToState(views::InkDropState::ACTIVATED); 1615 context_menu_id_ = item.id;
1624 context_menu_id_ = item.id; 1616 ShowMenu(base::MakeUnique<ShelfApplicationMenuModel>(
1625 ShowMenu(base::MakeUnique<ShelfApplicationMenuModel>( 1617 item.title, std::move(*menu_items),
1626 item.title, std::move(items), item_delegate), 1618 model_->GetShelfItemDelegate(item.id)),
1627 source, gfx::Point(), false, ui::GetMenuSourceTypeForEvent(event), 1619 sender, gfx::Point(), false,
1628 ink_drop); 1620 ui::GetMenuSourceTypeForEvent(*event), ink_drop);
1629 return true; 1621 } else {
1622 ink_drop->AnimateToState(views::InkDropState::ACTION_TRIGGERED);
1623 }
1624 }
1625 // The menu clears |scoped_root_window_for_new_windows_| in OnMenuClosed.
1626 if (!IsShowingMenu())
1627 scoped_root_window_for_new_windows_.reset();
1630 } 1628 }
1631 1629
1632 void ShelfView::ShowContextMenuForView(views::View* source, 1630 void ShelfView::ShowContextMenuForView(views::View* source,
1633 const gfx::Point& point, 1631 const gfx::Point& point,
1634 ui::MenuSourceType source_type) { 1632 ui::MenuSourceType source_type) {
1635 last_pressed_index_ = -1; 1633 last_pressed_index_ = -1;
1636 1634
1637 const ShelfItem* item = ShelfItemForView(source); 1635 const ShelfItem* item = ShelfItemForView(source);
1638 if (!item) { 1636 if (!item) {
1639 WmShell::Get()->ShowContextMenu(point, source_type); 1637 WmShell::Get()->ShowContextMenu(point, source_type);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 1768
1771 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1769 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1772 const gfx::Rect bounds = GetBoundsInScreen(); 1770 const gfx::Rect bounds = GetBoundsInScreen();
1773 int distance = wm_shelf_->SelectValueForShelfAlignment( 1771 int distance = wm_shelf_->SelectValueForShelfAlignment(
1774 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1772 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1775 bounds.x() - coordinate.x()); 1773 bounds.x() - coordinate.x());
1776 return distance > 0 ? distance : 0; 1774 return distance > 0 ? distance : 0;
1777 } 1775 }
1778 1776
1779 } // namespace ash 1777 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_view.h ('k') | ash/common/shelf/shelf_window_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698