Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 // So, it is safe to be checked after handling overflow button. | 443 // So, it is safe to be checked after handling overflow button. |
| 444 if (!ShouldEventActivateButton(sender, event)) | 444 if (!ShouldEventActivateButton(sender, event)) |
| 445 return; | 445 return; |
| 446 | 446 |
| 447 // Record the index for the last pressed shelf item. | 447 // Record the index for the last pressed shelf item. |
| 448 last_pressed_index_ = view_model_->GetIndexOfView(sender); | 448 last_pressed_index_ = view_model_->GetIndexOfView(sender); |
| 449 DCHECK_LT(-1, last_pressed_index_); | 449 DCHECK_LT(-1, last_pressed_index_); |
| 450 | 450 |
| 451 // Place new windows on the same display as the button. | 451 // Place new windows on the same display as the button. |
| 452 WmWindow* window = WmWindow::Get(sender->GetWidget()->GetNativeWindow()); | 452 WmWindow* window = WmWindow::Get(sender->GetWidget()->GetNativeWindow()); |
| 453 scoped_root_window_for_new_windows_.reset( | 453 scoped_root_window_for_new_windows_.reset( |
|
James Cook
2017/03/09 01:09:46
Do you think this should live in AfterItemSelected
msw
2017/03/10 06:17:56
I don't think so; item selection itself frequently
James Cook
2017/03/10 16:56:01
Yeah, makes sense.
| |
| 454 new ScopedRootWindowForNewWindows(window->GetRootWindow())); | 454 new ScopedRootWindowForNewWindows(window->GetRootWindow())); |
| 455 | 455 |
| 456 // Slow down activation animations if shift key is pressed. | 456 // Slow down activation animations if shift key is pressed. |
| 457 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; | 457 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations; |
| 458 if (event.IsShiftDown()) { | 458 if (event.IsShiftDown()) { |
| 459 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( | 459 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( |
| 460 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); | 460 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); |
| 461 } | 461 } |
| 462 | 462 |
| 463 // Collect usage statistics before we decide what to do with the click. | 463 // Collect usage statistics before we decide what to do with the click. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 476 case TYPE_APP_PANEL: | 476 case TYPE_APP_PANEL: |
| 477 case TYPE_DIALOG: | 477 case TYPE_DIALOG: |
| 478 break; | 478 break; |
| 479 | 479 |
| 480 case TYPE_UNDEFINED: | 480 case TYPE_UNDEFINED: |
| 481 NOTREACHED() << "ShelfItemType must be set."; | 481 NOTREACHED() << "ShelfItemType must be set."; |
| 482 break; | 482 break; |
| 483 } | 483 } |
| 484 | 484 |
| 485 const int64_t display_id = window->GetDisplayNearestWindow().id(); | 485 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 | 486 |
| 491 shelf_button_pressed_metric_tracker_.ButtonPressed(event, sender, | 487 // Notify the item of its selection; handle the result in AfterItemSelected. |
| 492 performed_action); | 488 const ShelfItem& item = model_->items()[last_pressed_index_]; |
| 493 | 489 model_->GetShelfItemDelegate(item.id)->ItemSelected( |
| 494 // For the app list menu no TRIGGERED ink drop effect is needed and it | 490 ui::Event::Clone(event), display_id, LAUNCH_FROM_UNKNOWN, |
| 495 // handles its own ACTIVATED/DEACTIVATED states. | 491 base::Bind(&ShelfView::AfterItemSelected, base::Unretained(this), item, |
|
James Cook
2017/03/09 01:09:46
Hrm. Is Unretained safe here? Could this cause a s
msw
2017/03/10 06:17:56
Added WeakPtr use to skip AfterItemSelected if the
James Cook
2017/03/10 16:56:01
nit: I would add a comment either here or in the h
| |
| 496 if (performed_action == SHELF_ACTION_NEW_WINDOW_CREATED || | 492 sender, base::Passed(ui::Event::Clone(event)), ink_drop)); |
| 497 (performed_action != SHELF_ACTION_APP_LIST_SHOWN && | |
| 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 } | 493 } |
| 507 | 494 |
| 508 //////////////////////////////////////////////////////////////////////////////// | 495 //////////////////////////////////////////////////////////////////////////////// |
| 509 // ShelfView, FocusTraversable implementation: | 496 // ShelfView, FocusTraversable implementation: |
| 510 | 497 |
| 511 views::FocusSearch* ShelfView::GetFocusSearch() { | 498 views::FocusSearch* ShelfView::GetFocusSearch() { |
| 512 return focus_search_.get(); | 499 return focus_search_.get(); |
| 513 } | 500 } |
| 514 | 501 |
| 515 views::FocusTraversable* ShelfView::GetFocusTraversableParent() { | 502 views::FocusTraversable* ShelfView::GetFocusTraversableParent() { |
| (...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1600 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1587 // 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 | 1588 // 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_|. | 1589 // at this time the |view_model_| is inconsistent with the |model_|. |
| 1603 if (!cancelling_drag_model_changed_) | 1590 if (!cancelling_drag_model_changed_) |
| 1604 AnimateToIdealBounds(); | 1591 AnimateToIdealBounds(); |
| 1605 } | 1592 } |
| 1606 | 1593 |
| 1607 void ShelfView::OnSetShelfItemDelegate(ShelfID id, | 1594 void ShelfView::OnSetShelfItemDelegate(ShelfID id, |
| 1608 ShelfItemDelegate* item_delegate) {} | 1595 ShelfItemDelegate* item_delegate) {} |
| 1609 | 1596 |
| 1610 bool ShelfView::ShowListMenuForView(const ShelfItem& item, | 1597 void ShelfView::AfterItemSelected(const ShelfItem& item, |
| 1611 views::View* source, | 1598 views::Button* sender, |
| 1612 const ui::Event& event, | 1599 std::unique_ptr<ui::Event> event, |
| 1613 views::InkDrop* ink_drop) { | 1600 views::InkDrop* ink_drop, |
| 1614 ShelfItemDelegate* item_delegate = model_->GetShelfItemDelegate(item.id); | 1601 ShelfAction action, |
| 1615 ShelfAppMenuItemList items = item_delegate->GetAppMenuItems(event.flags()); | 1602 ShelfItemDelegate::MenuItemList menu_items) { |
| 1603 const ui::Event& e = *event.get(); | |
|
James Cook
2017/03/09 01:09:46
how about evt or event (vs. event_in) vs. inline *
msw
2017/03/10 06:17:56
Done.
| |
| 1604 shelf_button_pressed_metric_tracker_.ButtonPressed(e, sender, action); | |
| 1616 | 1605 |
| 1617 // The application list menu should only show for two or more items; return | 1606 // Show the app menu if there are 2 or more items and no window was created. |
| 1618 // false here to ensure that other behavior is triggered (eg. activating or | 1607 if (action != SHELF_ACTION_NEW_WINDOW_CREATED && |
| 1619 // minimizing a single associated window, or launching a pinned shelf item). | 1608 action != SHELF_ACTION_APP_LIST_SHOWN && menu_items.size() > 1) { |
| 1620 if (items.size() < 2) | 1609 ink_drop->AnimateToState(views::InkDropState::ACTIVATED); |
| 1621 return false; | 1610 context_menu_id_ = item.id; |
| 1622 | 1611 ShowMenu(base::MakeUnique<ShelfApplicationMenuModel>( |
| 1623 ink_drop->AnimateToState(views::InkDropState::ACTIVATED); | 1612 item.title, std::move(menu_items), |
| 1624 context_menu_id_ = item.id; | 1613 model_->GetShelfItemDelegate(item.id)), |
| 1625 ShowMenu(base::MakeUnique<ShelfApplicationMenuModel>( | 1614 sender, gfx::Point(), false, ui::GetMenuSourceTypeForEvent(e), |
| 1626 item.title, std::move(items), item_delegate), | 1615 ink_drop); |
| 1627 source, gfx::Point(), false, ui::GetMenuSourceTypeForEvent(event), | 1616 } else if (action != SHELF_ACTION_APP_LIST_SHOWN) { |
| 1628 ink_drop); | 1617 // For the app list menu no TRIGGERED ink drop effect is needed and it |
| 1629 return true; | 1618 // handles its own ACTIVATED/DEACTIVATED states. |
| 1619 ink_drop->AnimateToState(views::InkDropState::ACTION_TRIGGERED); | |
| 1620 } | |
|
James Cook
2017/03/09 01:09:46
I'm having a hard time following the booleans here
msw
2017/03/10 06:17:56
Done. Using a nested if block.
| |
| 1621 // Allow the menu to clear |scoped_root_window_for_new_windows_| during | |
| 1622 // OnMenuClosed. | |
| 1623 if (!IsShowingMenu()) | |
| 1624 scoped_root_window_for_new_windows_.reset(); | |
| 1630 } | 1625 } |
| 1631 | 1626 |
| 1632 void ShelfView::ShowContextMenuForView(views::View* source, | 1627 void ShelfView::ShowContextMenuForView(views::View* source, |
| 1633 const gfx::Point& point, | 1628 const gfx::Point& point, |
| 1634 ui::MenuSourceType source_type) { | 1629 ui::MenuSourceType source_type) { |
| 1635 last_pressed_index_ = -1; | 1630 last_pressed_index_ = -1; |
| 1636 | 1631 |
| 1637 const ShelfItem* item = ShelfItemForView(source); | 1632 const ShelfItem* item = ShelfItemForView(source); |
| 1638 if (!item) { | 1633 if (!item) { |
| 1639 WmShell::Get()->ShowContextMenu(point, source_type); | 1634 WmShell::Get()->ShowContextMenu(point, source_type); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1770 | 1765 |
| 1771 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1766 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1772 const gfx::Rect bounds = GetBoundsInScreen(); | 1767 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1773 int distance = wm_shelf_->SelectValueForShelfAlignment( | 1768 int distance = wm_shelf_->SelectValueForShelfAlignment( |
| 1774 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1769 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1775 bounds.x() - coordinate.x()); | 1770 bounds.x() - coordinate.x()); |
| 1776 return distance > 0 ? distance : 0; | 1771 return distance > 0 ? distance : 0; |
| 1777 } | 1772 } |
| 1778 | 1773 |
| 1779 } // namespace ash | 1774 } // namespace ash |
| OLD | NEW |