| 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/launcher/launcher_view.h" | 5 #include "ash/launcher/launcher_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1506 | 1506 |
| 1507 // Make sure we have a menu and it has at least two items in addition to the | 1507 // Make sure we have a menu and it has at least two items in addition to the |
| 1508 // application title and the 3 spacing separators. | 1508 // application title and the 3 spacing separators. |
| 1509 if (!menu_model.get() || menu_model->GetItemCount() <= 5) | 1509 if (!menu_model.get() || menu_model->GetItemCount() <= 5) |
| 1510 return false; | 1510 return false; |
| 1511 | 1511 |
| 1512 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1512 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1513 new LauncherMenuModelAdapter(menu_model.get())), | 1513 new LauncherMenuModelAdapter(menu_model.get())), |
| 1514 source, | 1514 source, |
| 1515 gfx::Point(), | 1515 gfx::Point(), |
| 1516 false); | 1516 false, |
| 1517 ui::CONTEXT_MENU_SOURCE_NONE); |
| 1517 return true; | 1518 return true; |
| 1518 } | 1519 } |
| 1519 | 1520 |
| 1520 void LauncherView::ShowContextMenuForView(views::View* source, | 1521 void LauncherView::ShowContextMenuForView( |
| 1521 const gfx::Point& point) { | 1522 views::View* source, |
| 1523 const gfx::Point& point, |
| 1524 ui::ContextMenuSourceType source_type) { |
| 1522 int view_index = view_model_->GetIndexOfView(source); | 1525 int view_index = view_model_->GetIndexOfView(source); |
| 1523 if (view_index != -1 && | 1526 if (view_index != -1 && |
| 1524 model_->items()[view_index].type == TYPE_APP_LIST) { | 1527 model_->items()[view_index].type == TYPE_APP_LIST) { |
| 1525 view_index = -1; | 1528 view_index = -1; |
| 1526 } | 1529 } |
| 1527 | 1530 |
| 1528 if (view_index == -1) { | 1531 if (view_index == -1) { |
| 1529 Shell::GetInstance()->ShowContextMenu(point); | 1532 Shell::GetInstance()->ShowContextMenu(point, source_type); |
| 1530 return; | 1533 return; |
| 1531 } | 1534 } |
| 1532 scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu( | 1535 scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu( |
| 1533 model_->items()[view_index], | 1536 model_->items()[view_index], |
| 1534 source->GetWidget()->GetNativeView()->GetRootWindow())); | 1537 source->GetWidget()->GetNativeView()->GetRootWindow())); |
| 1535 if (!menu_model) | 1538 if (!menu_model) |
| 1536 return; | 1539 return; |
| 1537 base::AutoReset<LauncherID> reseter( | 1540 base::AutoReset<LauncherID> reseter( |
| 1538 &context_menu_id_, | 1541 &context_menu_id_, |
| 1539 view_index == -1 ? 0 : model_->items()[view_index].id); | 1542 view_index == -1 ? 0 : model_->items()[view_index].id); |
| 1540 | 1543 |
| 1541 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1544 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1542 new views::MenuModelAdapter(menu_model.get())), | 1545 new views::MenuModelAdapter(menu_model.get())), |
| 1543 source, | 1546 source, |
| 1544 point, | 1547 point, |
| 1545 true); | 1548 true, |
| 1549 source_type); |
| 1546 } | 1550 } |
| 1547 | 1551 |
| 1548 void LauncherView::ShowMenu( | 1552 void LauncherView::ShowMenu( |
| 1549 scoped_ptr<views::MenuModelAdapter> menu_model_adapter, | 1553 scoped_ptr<views::MenuModelAdapter> menu_model_adapter, |
| 1550 views::View* source, | 1554 views::View* source, |
| 1551 const gfx::Point& click_point, | 1555 const gfx::Point& click_point, |
| 1552 bool context_menu) { | 1556 bool context_menu, |
| 1557 ui::ContextMenuSourceType source_type) { |
| 1553 closing_event_time_ = base::TimeDelta(); | 1558 closing_event_time_ = base::TimeDelta(); |
| 1554 launcher_menu_runner_.reset( | 1559 launcher_menu_runner_.reset( |
| 1555 new views::MenuRunner(menu_model_adapter->CreateMenu())); | 1560 new views::MenuRunner(menu_model_adapter->CreateMenu())); |
| 1556 | 1561 |
| 1557 // Determine the menu alignment dependent on the shelf. | 1562 // Determine the menu alignment dependent on the shelf. |
| 1558 views::MenuItemView::AnchorPosition menu_alignment = | 1563 views::MenuItemView::AnchorPosition menu_alignment = |
| 1559 views::MenuItemView::TOPLEFT; | 1564 views::MenuItemView::TOPLEFT; |
| 1560 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); | 1565 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); |
| 1561 | 1566 |
| 1562 ShelfWidget* shelf = RootWindowController::ForLauncher( | 1567 ShelfWidget* shelf = RootWindowController::ForLauncher( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1587 } | 1592 } |
| 1588 } | 1593 } |
| 1589 // If this gets deleted while we are in the menu, the launcher will be gone | 1594 // If this gets deleted while we are in the menu, the launcher will be gone |
| 1590 // as well. | 1595 // as well. |
| 1591 bool got_deleted = false; | 1596 bool got_deleted = false; |
| 1592 got_deleted_ = &got_deleted; | 1597 got_deleted_ = &got_deleted; |
| 1593 | 1598 |
| 1594 shelf->ForceUndimming(true); | 1599 shelf->ForceUndimming(true); |
| 1595 // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building | 1600 // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building |
| 1596 // code. | 1601 // code. |
| 1597 if (launcher_menu_runner_->RunMenuAt( | 1602 views::MenuRunner::RunResult result; |
| 1598 source->GetWidget(), | 1603 if (context_menu) { |
| 1599 NULL, | 1604 result = launcher_menu_runner_->RunContextMenuAt(source->GetWidget(), |
| 1600 anchor_point, | 1605 NULL, |
| 1601 menu_alignment, | 1606 anchor_point, |
| 1602 views::MenuRunner::CONTEXT_MENU) == views::MenuRunner::MENU_DELETED) { | 1607 source_type, |
| 1608 0); |
| 1609 } else { |
| 1610 result = launcher_menu_runner_->RunMenuAt(source->GetWidget(), |
| 1611 NULL, |
| 1612 anchor_point, |
| 1613 menu_alignment, |
| 1614 0); |
| 1615 } |
| 1616 if (result == views::MenuRunner::MENU_DELETED) { |
| 1603 if (!got_deleted) { | 1617 if (!got_deleted) { |
| 1604 got_deleted_ = NULL; | 1618 got_deleted_ = NULL; |
| 1605 shelf->ForceUndimming(false); | 1619 shelf->ForceUndimming(false); |
| 1606 } | 1620 } |
| 1607 return; | 1621 return; |
| 1608 } | 1622 } |
| 1609 got_deleted_ = NULL; | 1623 got_deleted_ = NULL; |
| 1610 shelf->ForceUndimming(false); | 1624 shelf->ForceUndimming(false); |
| 1611 | 1625 |
| 1612 // Unpinning an item will reset the |launcher_menu_runner_| before coming | 1626 // Unpinning an item will reset the |launcher_menu_runner_| before coming |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1648 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { | 1662 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
| 1649 if (view == GetAppListButtonView() && | 1663 if (view == GetAppListButtonView() && |
| 1650 Shell::GetInstance()->GetAppListWindow()) | 1664 Shell::GetInstance()->GetAppListWindow()) |
| 1651 return false; | 1665 return false; |
| 1652 const LauncherItem* item = LauncherItemForView(view); | 1666 const LauncherItem* item = LauncherItemForView(view); |
| 1653 return (!item || delegate_->ShouldShowTooltip(*item)); | 1667 return (!item || delegate_->ShouldShowTooltip(*item)); |
| 1654 } | 1668 } |
| 1655 | 1669 |
| 1656 } // namespace internal | 1670 } // namespace internal |
| 1657 } // namespace ash | 1671 } // namespace ash |
| OLD | NEW |