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/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" |
| 11 #include "ash/drag_drop/drag_image_view.h" | 11 #include "ash/drag_drop/drag_image_view.h" |
| 12 #include "ash/launcher/alternate_app_list_button.h" | 12 #include "ash/launcher/alternate_app_list_button.h" |
| 13 #include "ash/launcher/app_list_button.h" | 13 #include "ash/launcher/app_list_button.h" |
| 14 #include "ash/launcher/launcher_button.h" | 14 #include "ash/launcher/launcher_button.h" |
| 15 #include "ash/launcher/launcher_delegate.h" | 15 #include "ash/launcher/launcher_delegate.h" |
| 16 #include "ash/launcher/launcher_icon_observer.h" | 16 #include "ash/launcher/launcher_icon_observer.h" |
| 17 #include "ash/launcher/launcher_item_delegate.h" | |
| 17 #include "ash/launcher/launcher_model.h" | 18 #include "ash/launcher/launcher_model.h" |
| 18 #include "ash/launcher/launcher_tooltip_manager.h" | 19 #include "ash/launcher/launcher_tooltip_manager.h" |
| 19 #include "ash/launcher/overflow_bubble.h" | 20 #include "ash/launcher/overflow_bubble.h" |
| 20 #include "ash/launcher/overflow_button.h" | 21 #include "ash/launcher/overflow_button.h" |
| 21 #include "ash/launcher/tabbed_launcher_button.h" | 22 #include "ash/launcher/tabbed_launcher_button.h" |
| 22 #include "ash/root_window_controller.h" | 23 #include "ash/root_window_controller.h" |
| 23 #include "ash/scoped_target_root_window.h" | 24 #include "ash/scoped_target_root_window.h" |
| 24 #include "ash/shelf/shelf_layout_manager.h" | 25 #include "ash/shelf/shelf_layout_manager.h" |
| 25 #include "ash/shelf/shelf_widget.h" | 26 #include "ash/shelf/shelf_widget.h" |
| 26 #include "ash/shell_delegate.h" | 27 #include "ash/shell_delegate.h" |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 } | 961 } |
| 961 | 962 |
| 962 void LauncherView::PrepareForDrag(Pointer pointer, | 963 void LauncherView::PrepareForDrag(Pointer pointer, |
| 963 const ui::LocatedEvent& event) { | 964 const ui::LocatedEvent& event) { |
| 964 DCHECK(!dragging()); | 965 DCHECK(!dragging()); |
| 965 DCHECK(drag_view_); | 966 DCHECK(drag_view_); |
| 966 drag_pointer_ = pointer; | 967 drag_pointer_ = pointer; |
| 967 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); | 968 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); |
| 968 | 969 |
| 969 // If the item is no longer draggable, bail out. | 970 // If the item is no longer draggable, bail out. |
| 971 LauncherItemDelegate* item_delegate = delegate_->GetLauncherItemDelegate( | |
| 972 model_->items()[start_drag_index_]); | |
|
Mr4D (OOO till 08-26)
2013/08/13 18:18:24
Should you do this assignment if start_drag_index_
simonhong_
2013/08/13 19:54:56
Done.
| |
| 970 if (start_drag_index_ == -1 || | 973 if (start_drag_index_ == -1 || |
| 971 !delegate_->IsDraggable(model_->items()[start_drag_index_])) { | 974 !item_delegate || |
| 975 !item_delegate->IsDraggable(model_->items()[start_drag_index_])) { | |
| 972 CancelDrag(-1); | 976 CancelDrag(-1); |
| 973 return; | 977 return; |
| 974 } | 978 } |
| 975 | 979 |
| 976 // Move the view to the front so that it appears on top of other views. | 980 // Move the view to the front so that it appears on top of other views. |
| 977 ReorderChildView(drag_view_, -1); | 981 ReorderChildView(drag_view_, -1); |
| 978 bounds_animator_->StopAnimatingView(drag_view_); | 982 bounds_animator_->StopAnimatingView(drag_view_); |
| 979 } | 983 } |
| 980 | 984 |
| 981 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { | 985 void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { |
| 982 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); | 986 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
| 983 | 987 |
| 984 // TODO: I don't think this works correctly with RTL. | 988 // TODO: I don't think this works correctly with RTL. |
| 985 gfx::Point drag_point(event.location()); | 989 gfx::Point drag_point(event.location()); |
| 986 views::View::ConvertPointToTarget(drag_view_, this, &drag_point); | 990 views::View::ConvertPointToTarget(drag_view_, this, &drag_point); |
| 987 int current_index = view_model_->GetIndexOfView(drag_view_); | 991 int current_index = view_model_->GetIndexOfView(drag_view_); |
| 988 DCHECK_NE(-1, current_index); | 992 DCHECK_NE(-1, current_index); |
| 989 | 993 |
| 990 // If the item is no longer draggable, bail out. | 994 // If the item is no longer draggable, bail out. |
| 995 LauncherItemDelegate* item_delegate = delegate_->GetLauncherItemDelegate( | |
| 996 model_->items()[current_index]); | |
|
Mr4D (OOO till 08-26)
2013/08/13 18:18:24
Should you do this assignment if start_drag_index_
simonhong_
2013/08/13 19:54:56
I think you mean current_index not start_drag_inde
| |
| 991 if (current_index == -1 || | 997 if (current_index == -1 || |
| 992 !delegate_->IsDraggable(model_->items()[current_index])) { | 998 !item_delegate || |
| 999 !item_delegate->IsDraggable(model_->items()[current_index])) { | |
| 993 CancelDrag(-1); | 1000 CancelDrag(-1); |
| 994 return; | 1001 return; |
| 995 } | 1002 } |
| 996 | 1003 |
| 997 // Constrain the location to the range of valid indices for the type. | 1004 // Constrain the location to the range of valid indices for the type. |
| 998 std::pair<int, int> indices(GetDragRange(current_index)); | 1005 std::pair<int, int> indices(GetDragRange(current_index)); |
| 999 int first_drag_index = indices.first; | 1006 int first_drag_index = indices.first; |
| 1000 int last_drag_index = indices.second; | 1007 int last_drag_index = indices.second; |
| 1001 // If the last index isn't valid, we're overflowing. Constrain to the app list | 1008 // If the last index isn't valid, we're overflowing. Constrain to the app list |
| 1002 // (which is the last visible item). | 1009 // (which is the last visible item). |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1374 } | 1381 } |
| 1375 | 1382 |
| 1376 void LauncherView::PointerPressedOnButton(views::View* view, | 1383 void LauncherView::PointerPressedOnButton(views::View* view, |
| 1377 Pointer pointer, | 1384 Pointer pointer, |
| 1378 const ui::LocatedEvent& event) { | 1385 const ui::LocatedEvent& event) { |
| 1379 if (drag_view_) | 1386 if (drag_view_) |
| 1380 return; | 1387 return; |
| 1381 | 1388 |
| 1382 tooltip_->Close(); | 1389 tooltip_->Close(); |
| 1383 int index = view_model_->GetIndexOfView(view); | 1390 int index = view_model_->GetIndexOfView(view); |
| 1391 LauncherItemDelegate* item_delegate = | |
| 1392 delegate_->GetLauncherItemDelegate(model_->items()[index]); | |
|
Mr4D (OOO till 08-26)
2013/08/13 18:18:24
Should you do this assignment if start_drag_index_
simonhong_
2013/08/13 19:54:56
Done.
| |
| 1384 if (index == -1 || | 1393 if (index == -1 || |
| 1385 view_model_->view_size() <= 1 || | 1394 view_model_->view_size() <= 1 || |
| 1386 !delegate_->IsDraggable(model_->items()[index])) | 1395 !item_delegate || |
| 1396 !item_delegate->IsDraggable(model_->items()[index])) | |
| 1387 return; // View is being deleted or not draggable, ignore request. | 1397 return; // View is being deleted or not draggable, ignore request. |
| 1388 | 1398 |
| 1389 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); | 1399 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
| 1390 | 1400 |
| 1391 drag_view_ = view; | 1401 drag_view_ = view; |
| 1392 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); | 1402 drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); |
| 1393 } | 1403 } |
| 1394 | 1404 |
| 1395 void LauncherView::PointerDraggedOnButton(views::View* view, | 1405 void LauncherView::PointerDraggedOnButton(views::View* view, |
| 1396 Pointer pointer, | 1406 Pointer pointer, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1451 if (view_index == -1) | 1461 if (view_index == -1) |
| 1452 return base::string16(); | 1462 return base::string16(); |
| 1453 | 1463 |
| 1454 switch (model_->items()[view_index].type) { | 1464 switch (model_->items()[view_index].type) { |
| 1455 case TYPE_TABBED: | 1465 case TYPE_TABBED: |
| 1456 case TYPE_APP_PANEL: | 1466 case TYPE_APP_PANEL: |
| 1457 case TYPE_APP_SHORTCUT: | 1467 case TYPE_APP_SHORTCUT: |
| 1458 case TYPE_WINDOWED_APP: | 1468 case TYPE_WINDOWED_APP: |
| 1459 case TYPE_PLATFORM_APP: | 1469 case TYPE_PLATFORM_APP: |
| 1460 case TYPE_BROWSER_SHORTCUT: | 1470 case TYPE_BROWSER_SHORTCUT: |
| 1461 return delegate_->GetTitle(model_->items()[view_index]); | 1471 case TYPE_APP_LIST: { |
| 1462 | 1472 LauncherItemDelegate* item_delegate = |
| 1463 case TYPE_APP_LIST: | 1473 delegate_->GetLauncherItemDelegate(model_->items()[view_index]); |
| 1464 return model_->status() == LauncherModel::STATUS_LOADING ? | 1474 DCHECK(item_delegate); |
| 1465 l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_SYNCING_TITLE) : | 1475 return item_delegate->GetTitle(model_->items()[view_index]); |
| 1466 l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE); | 1476 } |
| 1477 default: | |
|
Mr4D (OOO till 08-26)
2013/08/13 18:18:24
Please do not use default here. Reason: If we are
simonhong_
2013/08/13 19:54:56
Removed switch statement.
| |
| 1478 break; | |
| 1467 } | 1479 } |
| 1468 return base::string16(); | 1480 return base::string16(); |
| 1469 } | 1481 } |
| 1470 | 1482 |
| 1471 void LauncherView::ButtonPressed(views::Button* sender, | 1483 void LauncherView::ButtonPressed(views::Button* sender, |
| 1472 const ui::Event& event) { | 1484 const ui::Event& event) { |
| 1473 // Do not handle mouse release during drag. | 1485 // Do not handle mouse release during drag. |
| 1474 if (dragging()) | 1486 if (dragging()) |
| 1475 return; | 1487 return; |
| 1476 | 1488 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1502 } | 1514 } |
| 1503 | 1515 |
| 1504 // Collect usage statistics before we decide what to do with the click. | 1516 // Collect usage statistics before we decide what to do with the click. |
| 1505 switch (model_->items()[view_index].type) { | 1517 switch (model_->items()[view_index].type) { |
| 1506 case TYPE_APP_SHORTCUT: | 1518 case TYPE_APP_SHORTCUT: |
| 1507 case TYPE_WINDOWED_APP: | 1519 case TYPE_WINDOWED_APP: |
| 1508 case TYPE_PLATFORM_APP: | 1520 case TYPE_PLATFORM_APP: |
| 1509 case TYPE_BROWSER_SHORTCUT: | 1521 case TYPE_BROWSER_SHORTCUT: |
| 1510 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 1522 Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
| 1511 UMA_LAUNCHER_CLICK_ON_APP); | 1523 UMA_LAUNCHER_CLICK_ON_APP); |
| 1512 // Fallthrough | 1524 // Fallthrough |
|
Mr4D (OOO till 08-26)
2013/08/13 18:18:24
I don't think so! Using this fall through you reco
simonhong_
2013/08/13 19:54:56
Done.
| |
| 1513 case TYPE_TABBED: | |
| 1514 case TYPE_APP_PANEL: | |
| 1515 delegate_->ItemSelected(model_->items()[view_index], event); | |
| 1516 break; | |
| 1517 | |
| 1518 case TYPE_APP_LIST: | 1525 case TYPE_APP_LIST: |
| 1519 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 1526 Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
| 1520 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); | 1527 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); |
| 1521 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView()); | 1528 // Fallthrough |
| 1529 case TYPE_TABBED: | |
| 1530 case TYPE_APP_PANEL: { | |
| 1531 LauncherItemDelegate* item_delegate = | |
| 1532 delegate_->GetLauncherItemDelegate(model_->items()[view_index]); | |
| 1533 DCHECK(item_delegate); | |
| 1534 item_delegate->ItemSelected(model_->items()[view_index], event); | |
| 1522 break; | 1535 break; |
| 1536 } | |
| 1523 } | 1537 } |
| 1524 } | 1538 } |
| 1525 | 1539 |
| 1526 if (model_->items()[view_index].type != TYPE_APP_LIST) | 1540 ShowListMenuForView(model_->items()[view_index], sender, event); |
| 1527 ShowListMenuForView(model_->items()[view_index], sender, event); | |
| 1528 } | 1541 } |
| 1529 | 1542 |
| 1530 bool LauncherView::ShowListMenuForView(const LauncherItem& item, | 1543 bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
| 1531 views::View* source, | 1544 views::View* source, |
| 1532 const ui::Event& event) { | 1545 const ui::Event& event) { |
| 1533 scoped_ptr<ash::LauncherMenuModel> menu_model; | 1546 scoped_ptr<ash::LauncherMenuModel> menu_model; |
| 1534 menu_model.reset(delegate_->CreateApplicationMenu(item, event.flags())); | 1547 LauncherItemDelegate* item_delegate = |
| 1548 delegate_->GetLauncherItemDelegate(item); | |
| 1549 if (item_delegate) | |
| 1550 menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags())); | |
|
Mr4D (OOO till 08-26)
2013/08/13 18:18:24
And what else? It can be that another menu is stil
simonhong_
2013/08/13 19:54:56
Done.
| |
| 1535 | 1551 |
| 1536 // Make sure we have a menu and it has at least two items in addition to the | 1552 // Make sure we have a menu and it has at least two items in addition to the |
| 1537 // application title and the 3 spacing separators. | 1553 // application title and the 3 spacing separators. |
| 1538 if (!menu_model.get() || menu_model->GetItemCount() <= 5) | 1554 if (!menu_model.get() || menu_model->GetItemCount() <= 5) |
| 1539 return false; | 1555 return false; |
| 1540 | 1556 |
| 1541 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1557 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1542 new LauncherMenuModelAdapter(menu_model.get())), | 1558 new LauncherMenuModelAdapter(menu_model.get())), |
| 1543 source, | 1559 source, |
| 1544 gfx::Point(), | 1560 gfx::Point(), |
| 1545 false, | 1561 false, |
| 1546 ui::GetMenuSourceTypeForEvent(event)); | 1562 ui::GetMenuSourceTypeForEvent(event)); |
| 1547 return true; | 1563 return true; |
| 1548 } | 1564 } |
| 1549 | 1565 |
| 1550 void LauncherView::ShowContextMenuForView(views::View* source, | 1566 void LauncherView::ShowContextMenuForView(views::View* source, |
| 1551 const gfx::Point& point, | 1567 const gfx::Point& point, |
| 1552 ui:: MenuSourceType source_type) { | 1568 ui:: MenuSourceType source_type) { |
| 1553 int view_index = view_model_->GetIndexOfView(source); | 1569 int view_index = view_model_->GetIndexOfView(source); |
| 1570 // TODO: Create LauncherContextMenu for applist in its LauncherItemDelegate. | |
| 1554 if (view_index != -1 && | 1571 if (view_index != -1 && |
| 1555 model_->items()[view_index].type == TYPE_APP_LIST) { | 1572 model_->items()[view_index].type == TYPE_APP_LIST) { |
| 1556 view_index = -1; | 1573 view_index = -1; |
| 1557 } | 1574 } |
| 1558 | 1575 |
| 1559 tooltip_->Close(); | 1576 tooltip_->Close(); |
| 1560 | 1577 |
| 1561 if (view_index == -1) { | 1578 if (view_index == -1) { |
| 1562 Shell::GetInstance()->ShowContextMenu(point, source_type); | 1579 Shell::GetInstance()->ShowContextMenu(point, source_type); |
| 1563 return; | 1580 return; |
| 1564 } | 1581 } |
| 1565 scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu( | 1582 scoped_ptr<ui::MenuModel> menu_model; |
| 1566 model_->items()[view_index], | 1583 LauncherItemDelegate* item_delegate = |
| 1567 source->GetWidget()->GetNativeView()->GetRootWindow())); | 1584 delegate_->GetLauncherItemDelegate(model_->items()[view_index]); |
| 1585 if (item_delegate) { | |
| 1586 menu_model.reset(item_delegate->CreateContextMenu( | |
| 1587 model_->items()[view_index], | |
| 1588 source->GetWidget()->GetNativeView()->GetRootWindow())); | |
| 1589 } | |
| 1568 if (!menu_model) | 1590 if (!menu_model) |
| 1569 return; | 1591 return; |
| 1570 base::AutoReset<LauncherID> reseter( | 1592 base::AutoReset<LauncherID> reseter( |
| 1571 &context_menu_id_, | 1593 &context_menu_id_, |
| 1572 view_index == -1 ? 0 : model_->items()[view_index].id); | 1594 view_index == -1 ? 0 : model_->items()[view_index].id); |
| 1573 | 1595 |
| 1574 ShowMenu(scoped_ptr<views::MenuModelAdapter>( | 1596 ShowMenu(scoped_ptr<views::MenuModelAdapter>( |
| 1575 new views::MenuModelAdapter(menu_model.get())), | 1597 new views::MenuModelAdapter(menu_model.get())), |
| 1576 source, | 1598 source, |
| 1577 point, | 1599 point, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1690 int view_index = view_model_->GetIndexOfView(view); | 1712 int view_index = view_model_->GetIndexOfView(view); |
| 1691 if (view_index == -1) | 1713 if (view_index == -1) |
| 1692 return NULL; | 1714 return NULL; |
| 1693 return &(model_->items()[view_index]); | 1715 return &(model_->items()[view_index]); |
| 1694 } | 1716 } |
| 1695 | 1717 |
| 1696 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { | 1718 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
| 1697 if (view == GetAppListButtonView() && | 1719 if (view == GetAppListButtonView() && |
| 1698 Shell::GetInstance()->GetAppListWindow()) | 1720 Shell::GetInstance()->GetAppListWindow()) |
| 1699 return false; | 1721 return false; |
| 1700 const LauncherItem* item = LauncherItemForView(view); | 1722 const LauncherItem* item = LauncherItemForView(view); |
|
Mr4D (OOO till 08-26)
2013/08/13 18:18:24
Shouldn't you check here if (!item) return true?
simonhong_
2013/08/13 19:54:56
Done.
Q) Is "true" default value for showing toolt
Mr4D (OOO till 08-26)
2013/08/14 15:52:19
Look at the old code:
return (!item || ...);
simonhong_
2013/08/14 23:47:51
Done.
| |
| 1701 return (!item || delegate_->ShouldShowTooltip(*item)); | 1723 LauncherItemDelegate* item_delegate = |
| 1724 delegate_->GetLauncherItemDelegate(*item); | |
| 1725 if (!item_delegate) | |
| 1726 return false; | |
| 1727 return item_delegate->ShouldShowTooltip(*item); | |
| 1702 } | 1728 } |
| 1703 | 1729 |
| 1704 } // namespace internal | 1730 } // namespace internal |
| 1705 } // namespace ash | 1731 } // namespace ash |
| OLD | NEW |