Chromium Code Reviews| Index: ash/launcher/launcher_view.cc |
| diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc |
| index 2bc06d51b3f335fe7d9c947d8c376694acde4411..b0ff8404e4315af72c6c1f67c55e59e7f3baaa37 100644 |
| --- a/ash/launcher/launcher_view.cc |
| +++ b/ash/launcher/launcher_view.cc |
| @@ -14,6 +14,7 @@ |
| #include "ash/launcher/launcher_button.h" |
| #include "ash/launcher/launcher_delegate.h" |
| #include "ash/launcher/launcher_icon_observer.h" |
| +#include "ash/launcher/launcher_item_delegate.h" |
| #include "ash/launcher/launcher_model.h" |
| #include "ash/launcher/launcher_tooltip_manager.h" |
| #include "ash/launcher/overflow_bubble.h" |
| @@ -967,8 +968,11 @@ void LauncherView::PrepareForDrag(Pointer pointer, |
| start_drag_index_ = view_model_->GetIndexOfView(drag_view_); |
| // If the item is no longer draggable, bail out. |
| + LauncherItemDelegate* item_delegate = delegate_->GetLauncherItemDelegate( |
| + 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.
|
| if (start_drag_index_ == -1 || |
| - !delegate_->IsDraggable(model_->items()[start_drag_index_])) { |
| + !item_delegate || |
| + !item_delegate->IsDraggable(model_->items()[start_drag_index_])) { |
| CancelDrag(-1); |
| return; |
| } |
| @@ -988,8 +992,11 @@ void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { |
| DCHECK_NE(-1, current_index); |
| // If the item is no longer draggable, bail out. |
| + LauncherItemDelegate* item_delegate = delegate_->GetLauncherItemDelegate( |
| + 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
|
| if (current_index == -1 || |
| - !delegate_->IsDraggable(model_->items()[current_index])) { |
| + !item_delegate || |
| + !item_delegate->IsDraggable(model_->items()[current_index])) { |
| CancelDrag(-1); |
| return; |
| } |
| @@ -1381,9 +1388,12 @@ void LauncherView::PointerPressedOnButton(views::View* view, |
| tooltip_->Close(); |
| int index = view_model_->GetIndexOfView(view); |
| + LauncherItemDelegate* item_delegate = |
| + 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.
|
| if (index == -1 || |
| view_model_->view_size() <= 1 || |
| - !delegate_->IsDraggable(model_->items()[index])) |
| + !item_delegate || |
| + !item_delegate->IsDraggable(model_->items()[index])) |
| return; // View is being deleted or not draggable, ignore request. |
| ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); |
| @@ -1458,12 +1468,14 @@ base::string16 LauncherView::GetAccessibleName(const views::View* view) { |
| case TYPE_WINDOWED_APP: |
| case TYPE_PLATFORM_APP: |
| case TYPE_BROWSER_SHORTCUT: |
| - return delegate_->GetTitle(model_->items()[view_index]); |
| - |
| - case TYPE_APP_LIST: |
| - return model_->status() == LauncherModel::STATUS_LOADING ? |
| - l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_SYNCING_TITLE) : |
| - l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE); |
| + case TYPE_APP_LIST: { |
| + LauncherItemDelegate* item_delegate = |
| + delegate_->GetLauncherItemDelegate(model_->items()[view_index]); |
| + DCHECK(item_delegate); |
| + return item_delegate->GetTitle(model_->items()[view_index]); |
| + } |
| + 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.
|
| + break; |
| } |
| return base::string16(); |
| } |
| @@ -1510,28 +1522,32 @@ void LauncherView::ButtonPressed(views::Button* sender, |
| Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
| UMA_LAUNCHER_CLICK_ON_APP); |
| // 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.
|
| - case TYPE_TABBED: |
| - case TYPE_APP_PANEL: |
| - delegate_->ItemSelected(model_->items()[view_index], event); |
| - break; |
| - |
| case TYPE_APP_LIST: |
| Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
| UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); |
| - Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView()); |
| + // Fallthrough |
| + case TYPE_TABBED: |
| + case TYPE_APP_PANEL: { |
| + LauncherItemDelegate* item_delegate = |
| + delegate_->GetLauncherItemDelegate(model_->items()[view_index]); |
| + DCHECK(item_delegate); |
| + item_delegate->ItemSelected(model_->items()[view_index], event); |
| break; |
| + } |
| } |
| } |
| - if (model_->items()[view_index].type != TYPE_APP_LIST) |
| - ShowListMenuForView(model_->items()[view_index], sender, event); |
| + ShowListMenuForView(model_->items()[view_index], sender, event); |
| } |
| bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
| views::View* source, |
| const ui::Event& event) { |
| scoped_ptr<ash::LauncherMenuModel> menu_model; |
| - menu_model.reset(delegate_->CreateApplicationMenu(item, event.flags())); |
| + LauncherItemDelegate* item_delegate = |
| + delegate_->GetLauncherItemDelegate(item); |
| + if (item_delegate) |
| + 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.
|
| // Make sure we have a menu and it has at least two items in addition to the |
| // application title and the 3 spacing separators. |
| @@ -1551,6 +1567,7 @@ void LauncherView::ShowContextMenuForView(views::View* source, |
| const gfx::Point& point, |
| ui:: MenuSourceType source_type) { |
| int view_index = view_model_->GetIndexOfView(source); |
| + // TODO: Create LauncherContextMenu for applist in its LauncherItemDelegate. |
| if (view_index != -1 && |
| model_->items()[view_index].type == TYPE_APP_LIST) { |
| view_index = -1; |
| @@ -1562,9 +1579,14 @@ void LauncherView::ShowContextMenuForView(views::View* source, |
| Shell::GetInstance()->ShowContextMenu(point, source_type); |
| return; |
| } |
| - scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu( |
| - model_->items()[view_index], |
| - source->GetWidget()->GetNativeView()->GetRootWindow())); |
| + scoped_ptr<ui::MenuModel> menu_model; |
| + LauncherItemDelegate* item_delegate = |
| + delegate_->GetLauncherItemDelegate(model_->items()[view_index]); |
| + if (item_delegate) { |
| + menu_model.reset(item_delegate->CreateContextMenu( |
| + model_->items()[view_index], |
| + source->GetWidget()->GetNativeView()->GetRootWindow())); |
| + } |
| if (!menu_model) |
| return; |
| base::AutoReset<LauncherID> reseter( |
| @@ -1698,7 +1720,11 @@ bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { |
| Shell::GetInstance()->GetAppListWindow()) |
| return false; |
| 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.
|
| - return (!item || delegate_->ShouldShowTooltip(*item)); |
| + LauncherItemDelegate* item_delegate = |
| + delegate_->GetLauncherItemDelegate(*item); |
| + if (!item_delegate) |
| + return false; |
| + return item_delegate->ShouldShowTooltip(*item); |
| } |
| } // namespace internal |