| 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 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 // By setting us as DnD recipient, the app list knows that we can | 1491 // By setting us as DnD recipient, the app list knows that we can |
| 1492 // handle items. | 1492 // handle items. |
| 1493 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 1493 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 1494 ash::switches::kAshDisableDragAndDropAppListToLauncher)) | 1494 ash::switches::kAshDisableDragAndDropAppListToLauncher)) |
| 1495 Shell::GetInstance()->SetDragAndDropHostOfCurrentAppList(this); | 1495 Shell::GetInstance()->SetDragAndDropHostOfCurrentAppList(this); |
| 1496 break; | 1496 break; |
| 1497 } | 1497 } |
| 1498 } | 1498 } |
| 1499 | 1499 |
| 1500 if (model_->items()[view_index].type != TYPE_APP_LIST) | 1500 if (model_->items()[view_index].type != TYPE_APP_LIST) |
| 1501 ShowListMenuForView(model_->items()[view_index], sender, event.flags()); | 1501 ShowListMenuForView(model_->items()[view_index], sender, event); |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 bool LauncherView::ShowListMenuForView(const LauncherItem& item, | 1504 bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
| 1505 views::View* source, | 1505 views::View* source, |
| 1506 int event_flags) { | 1506 const ui::Event& event) { |
| 1507 scoped_ptr<ash::LauncherMenuModel> menu_model; | 1507 scoped_ptr<ash::LauncherMenuModel> menu_model; |
| 1508 menu_model.reset(delegate_->CreateApplicationMenu(item, event_flags)); | 1508 menu_model.reset(delegate_->CreateApplicationMenu(item, event.flags())); |
| 1509 | 1509 |
| 1510 // Make sure we have a menu and it has at least two items in addition to the | 1510 // Make sure we have a menu and it has at least two items in addition to the |
| 1511 // application title and the 3 spacing separators. | 1511 // application title and the 3 spacing separators. |
| 1512 if (!menu_model.get() || menu_model->GetItemCount() <= 5) | 1512 if (!menu_model.get() || menu_model->GetItemCount() <= 5) |
| 1513 return false; | 1513 return false; |
| 1514 | 1514 |
| 1515 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1515 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1516 new LauncherMenuModelAdapter(menu_model.get())), | 1516 new LauncherMenuModelAdapter(menu_model.get())), |
| 1517 source, | 1517 source, |
| 1518 gfx::Point(), | 1518 gfx::Point(), |
| 1519 false); | 1519 false, |
| 1520 ui::GetMenuSourceTypeForEvent(event)); |
| 1520 return true; | 1521 return true; |
| 1521 } | 1522 } |
| 1522 | 1523 |
| 1523 void LauncherView::ShowContextMenuForView(views::View* source, | 1524 void LauncherView::ShowContextMenuForView(views::View* source, |
| 1524 const gfx::Point& point) { | 1525 const gfx::Point& point, |
| 1526 ui:: MenuSourceType source_type) { |
| 1525 int view_index = view_model_->GetIndexOfView(source); | 1527 int view_index = view_model_->GetIndexOfView(source); |
| 1526 if (view_index != -1 && | 1528 if (view_index != -1 && |
| 1527 model_->items()[view_index].type == TYPE_APP_LIST) { | 1529 model_->items()[view_index].type == TYPE_APP_LIST) { |
| 1528 view_index = -1; | 1530 view_index = -1; |
| 1529 } | 1531 } |
| 1530 | 1532 |
| 1531 tooltip_->Close(); | 1533 tooltip_->Close(); |
| 1532 | 1534 |
| 1533 if (view_index == -1) { | 1535 if (view_index == -1) { |
| 1534 Shell::GetInstance()->ShowContextMenu(point); | 1536 Shell::GetInstance()->ShowContextMenu(point, source_type); |
| 1535 return; | 1537 return; |
| 1536 } | 1538 } |
| 1537 scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu( | 1539 scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu( |
| 1538 model_->items()[view_index], | 1540 model_->items()[view_index], |
| 1539 source->GetWidget()->GetNativeView()->GetRootWindow())); | 1541 source->GetWidget()->GetNativeView()->GetRootWindow())); |
| 1540 if (!menu_model) | 1542 if (!menu_model) |
| 1541 return; | 1543 return; |
| 1542 base::AutoReset<LauncherID> reseter( | 1544 base::AutoReset<LauncherID> reseter( |
| 1543 &context_menu_id_, | 1545 &context_menu_id_, |
| 1544 view_index == -1 ? 0 : model_->items()[view_index].id); | 1546 view_index == -1 ? 0 : model_->items()[view_index].id); |
| 1545 | 1547 |
| 1546 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1548 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1547 new views::MenuModelAdapter(menu_model.get())), | 1549 new views::MenuModelAdapter(menu_model.get())), |
| 1548 source, | 1550 source, |
| 1549 point, | 1551 point, |
| 1550 true); | 1552 true, |
| 1553 source_type); |
| 1551 } | 1554 } |
| 1552 | 1555 |
| 1553 void LauncherView::ShowMenu( | 1556 void LauncherView::ShowMenu( |
| 1554 scoped_ptr<views::MenuModelAdapter> menu_model_adapter, | 1557 scoped_ptr<views::MenuModelAdapter> menu_model_adapter, |
| 1555 views::View* source, | 1558 views::View* source, |
| 1556 const gfx::Point& click_point, | 1559 const gfx::Point& click_point, |
| 1557 bool context_menu) { | 1560 bool context_menu, |
| 1561 ui::MenuSourceType source_type) { |
| 1558 closing_event_time_ = base::TimeDelta(); | 1562 closing_event_time_ = base::TimeDelta(); |
| 1559 launcher_menu_runner_.reset( | 1563 launcher_menu_runner_.reset( |
| 1560 new views::MenuRunner(menu_model_adapter->CreateMenu())); | 1564 new views::MenuRunner(menu_model_adapter->CreateMenu())); |
| 1561 | 1565 |
| 1562 // Determine the menu alignment dependent on the shelf. | 1566 // Determine the menu alignment dependent on the shelf. |
| 1563 views::MenuItemView::AnchorPosition menu_alignment = | 1567 views::MenuItemView::AnchorPosition menu_alignment = |
| 1564 views::MenuItemView::TOPLEFT; | 1568 views::MenuItemView::TOPLEFT; |
| 1565 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); | 1569 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); |
| 1566 | 1570 |
| 1567 ShelfWidget* shelf = RootWindowController::ForLauncher( | 1571 ShelfWidget* shelf = RootWindowController::ForLauncher( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 got_deleted_ = &got_deleted; | 1609 got_deleted_ = &got_deleted; |
| 1606 | 1610 |
| 1607 shelf->ForceUndimming(true); | 1611 shelf->ForceUndimming(true); |
| 1608 // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building | 1612 // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building |
| 1609 // code. | 1613 // code. |
| 1610 if (launcher_menu_runner_->RunMenuAt( | 1614 if (launcher_menu_runner_->RunMenuAt( |
| 1611 source->GetWidget(), | 1615 source->GetWidget(), |
| 1612 NULL, | 1616 NULL, |
| 1613 anchor_point, | 1617 anchor_point, |
| 1614 menu_alignment, | 1618 menu_alignment, |
| 1615 views::MenuRunner::CONTEXT_MENU) == views::MenuRunner::MENU_DELETED) { | 1619 source_type, |
| 1620 context_menu ? views::MenuRunner::CONTEXT_MENU : 0) == |
| 1621 views::MenuRunner::MENU_DELETED) { |
| 1616 if (!got_deleted) { | 1622 if (!got_deleted) { |
| 1617 got_deleted_ = NULL; | 1623 got_deleted_ = NULL; |
| 1618 shelf->ForceUndimming(false); | 1624 shelf->ForceUndimming(false); |
| 1619 } | 1625 } |
| 1620 return; | 1626 return; |
| 1621 } | 1627 } |
| 1622 got_deleted_ = NULL; | 1628 got_deleted_ = NULL; |
| 1623 shelf->ForceUndimming(false); | 1629 shelf->ForceUndimming(false); |
| 1624 | 1630 |
| 1625 // Unpinning an item will reset the |launcher_menu_runner_| before coming | 1631 // Unpinning an item will reset the |launcher_menu_runner_| before coming |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { | 1667 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
| 1662 if (view == GetAppListButtonView() && | 1668 if (view == GetAppListButtonView() && |
| 1663 Shell::GetInstance()->GetAppListWindow()) | 1669 Shell::GetInstance()->GetAppListWindow()) |
| 1664 return false; | 1670 return false; |
| 1665 const LauncherItem* item = LauncherItemForView(view); | 1671 const LauncherItem* item = LauncherItemForView(view); |
| 1666 return (!item || delegate_->ShouldShowTooltip(*item)); | 1672 return (!item || delegate_->ShouldShowTooltip(*item)); |
| 1667 } | 1673 } |
| 1668 | 1674 |
| 1669 } // namespace internal | 1675 } // namespace internal |
| 1670 } // namespace ash | 1676 } // namespace ash |
| OLD | NEW |