summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimon.hong81@gmail.com <simon.hong81@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 05:22:34 +0000
committersimon.hong81@gmail.com <simon.hong81@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 05:22:34 +0000
commitcc29ba10009f91780c6d1bae5a828fb78cdeea74 (patch)
tree3bc62135545b45be96ad8076f0014df3c1976fd6
parent5113d1dd6dee32ef919d5520fc0b01587b97b1e4 (diff)
downloadchromium_src-cc29ba10009f91780c6d1bae5a828fb78cdeea74.zip
chromium_src-cc29ba10009f91780c6d1bae5a828fb78cdeea74.tar.gz
chromium_src-cc29ba10009f91780c6d1bae5a828fb78cdeea74.tar.bz2
Refactor LauncherDelegate
(This CL is splitted from https://codereview.chromium.org/11513005/ prior to adding LauncherItem for dialog) Refactor LauncherItem bits in LauncherDelegate into LauncherItemDelegate. LauncherItemDelegateManager helps Launcher/LauncherView to choose right LauncherItemDelegate based on LauncherItemType. * AppListLauncherItemDelegate is added for TYPE_APP_LIST. * LauncherItemManager (subclass of LauncherItemDelegate) will be added for TYPE_DIALOG in the separate CL. R=sky@chromium.org, skuhne@chromium.org BUG=121242, 279105 TEST=browser_tests, unit_tests, ash_unittests Review URL: https://chromiumcodereview.appspot.com/22429004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219924 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/ash.gyp5
-rw-r--r--ash/launcher/app_list_launcher_item_delegate.cc65
-rw-r--r--ash/launcher/app_list_launcher_item_delegate.h42
-rw-r--r--ash/launcher/launcher.cc8
-rw-r--r--ash/launcher/launcher_delegate.h61
-rw-r--r--ash/launcher/launcher_item_delegate.h83
-rw-r--r--ash/launcher/launcher_item_delegate_manager.cc29
-rw-r--r--ash/launcher/launcher_item_delegate_manager.h50
-rw-r--r--ash/launcher/launcher_view.cc88
-rw-r--r--ash/launcher/launcher_view.h4
-rw-r--r--ash/shell.cc7
-rw-r--r--ash/shell.h9
-rw-r--r--ash/shell/launcher_delegate_impl.cc6
-rw-r--r--ash/shell/launcher_delegate_impl.h22
-rw-r--r--ash/test/test_launcher_delegate.cc11
-rw-r--r--ash/test/test_launcher_delegate.h20
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc19
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller.h27
-rw-r--r--chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h1
19 files changed, 431 insertions, 126 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index 246e48e..1507ca4 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -134,6 +134,8 @@
'keyboard_overlay/keyboard_overlay_delegate.h',
'keyboard_overlay/keyboard_overlay_view.cc',
'keyboard_overlay/keyboard_overlay_view.h',
+ 'launcher/app_list_launcher_item_delegate.cc',
+ 'launcher/app_list_launcher_item_delegate.h',
'launcher/launcher.cc',
'launcher/launcher.h',
'launcher/launcher_alignment_menu.cc',
@@ -141,7 +143,10 @@
'launcher/launcher_button.cc',
'launcher/launcher_button.h',
'launcher/launcher_delegate.h',
+ 'launcher/launcher_item_delegate_manager.cc',
+ 'launcher/launcher_item_delegate_manager.h',
'launcher/launcher_icon_observer.h',
+ 'launcher/launcher_item_delegate.h',
'launcher/launcher_model.cc',
'launcher/launcher_model.h',
'launcher/launcher_model_observer.h',
diff --git a/ash/launcher/app_list_launcher_item_delegate.cc b/ash/launcher/app_list_launcher_item_delegate.cc
new file mode 100644
index 0000000..ffa6ba9
--- /dev/null
+++ b/ash/launcher/app_list_launcher_item_delegate.cc
@@ -0,0 +1,65 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/launcher/app_list_launcher_item_delegate.h"
+
+#include "ash/launcher/launcher_item_delegate_manager.h"
+#include "ash/launcher/launcher_model.h"
+#include "ash/shell.h"
+#include "ash/shell_delegate.h"
+#include "grit/ash_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace ash {
+namespace internal {
+
+AppListLauncherItemDelegate::AppListLauncherItemDelegate() {
+ // TODO(simon.hong81): This works for the moment, but the AppList LauncherItem
+ // creation should move here.
+ ash::Shell::GetInstance()->launcher_item_delegate_manager()->
+ RegisterLauncherItemDelegate(ash::TYPE_APP_LIST, this);
+}
+
+AppListLauncherItemDelegate::~AppListLauncherItemDelegate() {
+ // Don't unregister this from LauncherItemDelegateManager.
+ // LauncherItemDelegateManager is already destroyed.
+}
+
+void AppListLauncherItemDelegate::ItemSelected(const LauncherItem& item,
+ const ui::Event& event) {
+ // Pass NULL here to show the app list in the currently active RootWindow.
+ Shell::GetInstance()->ToggleAppList(NULL);
+}
+
+base::string16 AppListLauncherItemDelegate::GetTitle(const LauncherItem& item) {
+ LauncherModel* model = Shell::GetInstance()->launcher_model();
+ DCHECK(model);
+ return model->status() == LauncherModel::STATUS_LOADING ?
+ l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_SYNCING_TITLE) :
+ l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE);
+}
+
+ui::MenuModel* AppListLauncherItemDelegate::CreateContextMenu(
+ const LauncherItem& item,
+ aura::RootWindow* root_window) {
+ return NULL;
+}
+
+LauncherMenuModel* AppListLauncherItemDelegate::CreateApplicationMenu(
+ const LauncherItem& item,
+ int event_flags) {
+ // AppList does not show an application menu.
+ return NULL;
+}
+
+bool AppListLauncherItemDelegate::IsDraggable(const LauncherItem& item) {
+ return false;
+}
+
+bool AppListLauncherItemDelegate::ShouldShowTooltip(const LauncherItem& item) {
+ return true;
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/launcher/app_list_launcher_item_delegate.h b/ash/launcher/app_list_launcher_item_delegate.h
new file mode 100644
index 0000000..6452c6e
--- /dev/null
+++ b/ash/launcher/app_list_launcher_item_delegate.h
@@ -0,0 +1,42 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_LAUNCHER_APP_LIST_LAUNCHER_ITEM_DELEGATE_H_
+#define ASH_LAUNCHER_APP_LIST_LAUNCHER_ITEM_DELEGATE_H_
+
+#include "ash/launcher/launcher_item_delegate.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+namespace ash {
+namespace internal {
+
+// LauncherItemDelegate for TYPE_APP_LIST.
+class AppListLauncherItemDelegate : public LauncherItemDelegate {
+ public:
+ AppListLauncherItemDelegate();
+
+ virtual ~AppListLauncherItemDelegate();
+
+ // ash::LauncherItemDelegate overrides:
+ virtual void ItemSelected(const LauncherItem& item,
+ const ui::Event& event) OVERRIDE;
+ virtual base::string16 GetTitle(const LauncherItem& item) OVERRIDE;
+ virtual ui::MenuModel* CreateContextMenu(
+ const LauncherItem& item,
+ aura::RootWindow* root_window) OVERRIDE;
+ virtual LauncherMenuModel* CreateApplicationMenu(
+ const LauncherItem& item,
+ int event_flags) OVERRIDE;
+ virtual bool IsDraggable(const LauncherItem& item) OVERRIDE;
+ virtual bool ShouldShowTooltip(const LauncherItem& item) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AppListLauncherItemDelegate);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_LAUNCHER_APP_LIST_LAUNCHER_ITEM_DELEGATE_H_
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc
index 008646de..49ac6e7 100644
--- a/ash/launcher/launcher.cc
+++ b/ash/launcher/launcher.cc
@@ -9,6 +9,8 @@
#include "ash/focus_cycler.h"
#include "ash/launcher/launcher_delegate.h"
+#include "ash/launcher/launcher_item_delegate.h"
+#include "ash/launcher/launcher_item_delegate_manager.h"
#include "ash/launcher/launcher_model.h"
#include "ash/launcher/launcher_navigator.h"
#include "ash/launcher/launcher_view.h"
@@ -106,9 +108,9 @@ void Launcher::ActivateLauncherItem(int index) {
ui::EF_NONE,
false);
- const ash::LauncherItems& items =
- launcher_view_->model()->items();
- delegate_->ItemSelected(items[index], event);
+ const ash::LauncherItem& item = launcher_view_->model()->items()[index];
+ Shell::GetInstance()->launcher_item_delegate_manager()->
+ GetLauncherItemDelegate(item.type)->ItemSelected(item, event);
}
void Launcher::CycleWindowLinear(CycleDirection direction) {
diff --git a/ash/launcher/launcher_delegate.h b/ash/launcher/launcher_delegate.h
index 6afbe76..db69bab 100644
--- a/ash/launcher/launcher_delegate.h
+++ b/ash/launcher/launcher_delegate.h
@@ -7,83 +7,22 @@
#include "ash/ash_export.h"
#include "ash/launcher/launcher_types.h"
-#include "base/strings/string16.h"
-#include "ui/base/models/simple_menu_model.h"
-
-namespace aura {
-class RootWindow;
-}
-
-namespace ui {
-class Event;
-}
namespace ash {
class Launcher;
-// A special menu model which keeps track of an "active" menu item.
-class ASH_EXPORT LauncherMenuModel : public ui::SimpleMenuModel {
- public:
- explicit LauncherMenuModel(ui::SimpleMenuModel::Delegate* delegate)
- : ui::SimpleMenuModel(delegate) {}
-
- // Returns |true| when the given |command_id| is active and needs to be drawn
- // in a special state.
- virtual bool IsCommandActive(int command_id) const = 0;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(LauncherMenuModel);
-};
-
// Delegate for the Launcher.
class ASH_EXPORT LauncherDelegate {
public:
// Launcher owns the delegate.
virtual ~LauncherDelegate() {}
- // Invoked when the user clicks on a window entry in the launcher.
- // |event| is the click event. The |event| is dispatched by a view
- // and has an instance of |views::View| as the event target
- // but not |aura::Window|. If the |event| is of type KeyEvent, it is assumed
- // that this was triggered by keyboard action (Alt+<number>) and special
- // handling might happen.
- virtual void ItemSelected(const LauncherItem& item,
- const ui::Event& event) = 0;
-
- // Returns the title to display for the specified launcher item.
- virtual base::string16 GetTitle(const LauncherItem& item) = 0;
-
- // Returns the context menumodel for the specified item on
- // |root_window|. Return NULL if there should be no context
- // menu. The caller takes ownership of the returned model.
- virtual ui::MenuModel* CreateContextMenu(const LauncherItem& item,
- aura::RootWindow* root_window) = 0;
-
- // Returns the application menu model for the specified item. There are three
- // possible return values:
- // - A return of NULL indicates that no menu is wanted for this item.
- // - A return of a menu with one item means that only the name of the
- // application/item was added and there are no active applications.
- // Note: This is useful for hover menus which also show context help.
- // - A list containing the title and the active list of items.
- // The caller takes ownership of the returned model.
- // |event_flags| specifies the flags of the event which triggered this menu.
- virtual LauncherMenuModel* CreateApplicationMenu(
- const LauncherItem& item,
- int event_flags) = 0;
-
// Returns the id of the item associated with the specified window, or 0 if
// there isn't one.
// Note: Windows of tabbed browsers will return the |LauncherID| of the
// currently active tab or selected tab.
virtual LauncherID GetIDByWindow(aura::Window* window) = 0;
- // Whether the given launcher item is draggable.
- virtual bool IsDraggable(const LauncherItem& item) = 0;
-
- // Returns true if a tooltip should be shown for the item.
- virtual bool ShouldShowTooltip(const LauncherItem& item) = 0;
-
// Callback used to allow delegate to perform initialization actions that
// depend on the Launcher being in a known state.
virtual void OnLauncherCreated(Launcher* launcher) = 0;
diff --git a/ash/launcher/launcher_item_delegate.h b/ash/launcher/launcher_item_delegate.h
new file mode 100644
index 0000000..e1d940d
--- /dev/null
+++ b/ash/launcher/launcher_item_delegate.h
@@ -0,0 +1,83 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_LAUNCHER_LAUNCHER_ITEM_DELEGATE_H_
+#define ASH_LAUNCHER_LAUNCHER_ITEM_DELEGATE_H_
+
+#include "ash/ash_export.h"
+#include "ash/launcher/launcher_types.h"
+#include "base/strings/string16.h"
+#include "ui/base/models/simple_menu_model.h"
+
+namespace aura {
+class RootWindow;
+}
+
+namespace ui {
+class Event;
+}
+
+namespace ash {
+
+// A special menu model which keeps track of an "active" menu item.
+class ASH_EXPORT LauncherMenuModel : public ui::SimpleMenuModel {
+ public:
+ explicit LauncherMenuModel(ui::SimpleMenuModel::Delegate* delegate)
+ : ui::SimpleMenuModel(delegate) {}
+
+ // Returns |true| when the given |command_id| is active and needs to be drawn
+ // in a special state.
+ virtual bool IsCommandActive(int command_id) const = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LauncherMenuModel);
+};
+
+// Delegate for the LauncherItem.
+// TODO(simon.hong81): Remove LauncherItem from abstract function parameters.
+class ASH_EXPORT LauncherItemDelegate {
+ public:
+ virtual ~LauncherItemDelegate() {}
+
+ // Invoked when the user clicks on a window entry in the launcher.
+ // |event| is the click event. The |event| is dispatched by a view
+ // and has an instance of |views::View| as the event target
+ // but not |aura::Window|. If the |event| is of type KeyEvent, it is assumed
+ // that this was triggered by keyboard action (Alt+<number>) and special
+ // handling might happen.
+ virtual void ItemSelected(const LauncherItem& item,
+ const ui::Event& event) = 0;
+
+ // Returns the title to display for the specified launcher item.
+ virtual base::string16 GetTitle(const LauncherItem& item) = 0;
+
+ // Returns the context menumodel for the specified item on
+ // |root_window|. Return NULL if there should be no context
+ // menu. The caller takes ownership of the returned model.
+ virtual ui::MenuModel* CreateContextMenu(const LauncherItem& item,
+ aura::RootWindow* root_window) = 0;
+
+ // Returns the application menu model for the specified item. There are three
+ // possible return values:
+ // - A return of NULL indicates that no menu is wanted for this item.
+ // - A return of a menu with one item means that only the name of the
+ // application/item was added and there are no active applications.
+ // Note: This is useful for hover menus which also show context help.
+ // - A list containing the title and the active list of items.
+ // The caller takes ownership of the returned model.
+ // |event_flags| specifies the flags of the event which triggered this menu.
+ virtual LauncherMenuModel* CreateApplicationMenu(
+ const LauncherItem& item,
+ int event_flags) = 0;
+
+ // Whether the given launcher item is draggable.
+ virtual bool IsDraggable(const LauncherItem& item) = 0;
+
+ // Returns true if a tooltip should be shown for the item.
+ virtual bool ShouldShowTooltip(const LauncherItem& item) = 0;
+};
+
+} // namespace ash
+
+#endif // ASH_LAUNCHER_LAUNCHER_ITEM_DELEGATE_H_
diff --git a/ash/launcher/launcher_item_delegate_manager.cc b/ash/launcher/launcher_item_delegate_manager.cc
new file mode 100644
index 0000000..65fb0f0
--- /dev/null
+++ b/ash/launcher/launcher_item_delegate_manager.cc
@@ -0,0 +1,29 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/launcher/launcher_item_delegate_manager.h"
+
+namespace ash {
+
+LauncherItemDelegateManager::LauncherItemDelegateManager() {
+}
+
+LauncherItemDelegateManager::~LauncherItemDelegateManager() {
+}
+
+void LauncherItemDelegateManager::RegisterLauncherItemDelegate(
+ ash::LauncherItemType type, LauncherItemDelegate* item_delegate) {
+ // When a new |item_delegate| is registered with an exsiting |type|, it will
+ // get overwritten.
+ item_type_to_item_delegate_map_[type] = item_delegate;
+}
+
+LauncherItemDelegate* LauncherItemDelegateManager::GetLauncherItemDelegate(
+ ash::LauncherItemType item_type) {
+ DCHECK(item_type_to_item_delegate_map_.find(item_type) !=
+ item_type_to_item_delegate_map_.end());
+ return item_type_to_item_delegate_map_[item_type];
+}
+
+} // namespace ash
diff --git a/ash/launcher/launcher_item_delegate_manager.h b/ash/launcher/launcher_item_delegate_manager.h
new file mode 100644
index 0000000..f7c52f5
--- /dev/null
+++ b/ash/launcher/launcher_item_delegate_manager.h
@@ -0,0 +1,50 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_LAUNCHER_LAUNCHER_ITEM_DELEGATE_MANAGER_H_
+#define ASH_LAUNCHER_LAUNCHER_ITEM_DELEGATE_MANAGER_H_
+
+#include <map>
+
+#include "ash/ash_export.h"
+#include "ash/launcher/launcher_types.h"
+#include "base/compiler_specific.h"
+
+namespace ash {
+class LauncherItemDelegate;
+
+// LauncherItemDelegateManager helps Launcher/LauncherView to choose right
+// LauncherItemDelegate based on LauncherItemType.
+// When new LauncherItemDelegate is created, it must be registered by
+// RegisterLauncherItemDelegate(). If not, Launcher/LauncherView can't get
+// LauncherItem's LauncherItemDelegate.
+// TODO(simon.hong81): This class should own all LauncherItemDelegate.
+class ASH_EXPORT LauncherItemDelegateManager {
+ public:
+ LauncherItemDelegateManager();
+ virtual ~LauncherItemDelegateManager();
+
+ // Returns LauncherItemDelegate for |item_type|.
+ // This class doesn't own each LauncherItemDelegate for now.
+ LauncherItemDelegate* GetLauncherItemDelegate(
+ ash::LauncherItemType item_type);
+
+ // Register |item_delegate| for |type|.
+ // For now, This class doesn't own |item_delegate|.
+ // TODO(simon.hong81): Register LauncherItemDelegate with LauncherID.
+ void RegisterLauncherItemDelegate(
+ ash::LauncherItemType type, LauncherItemDelegate* item_delegate);
+
+ private:
+ typedef std::map<ash::LauncherItemType, LauncherItemDelegate*>
+ LauncherItemTypeToItemDelegateMap;
+
+ LauncherItemTypeToItemDelegateMap item_type_to_item_delegate_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(LauncherItemDelegateManager);
+};
+
+} // namespace ash
+
+#endif // ASH_LAUNCHER_LAUNCHER_ITEM_DELEGATE_MANAGER_H_
diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc
index ae7acc5..dd0e468 100644
--- a/ash/launcher/launcher_view.cc
+++ b/ash/launcher/launcher_view.cc
@@ -12,6 +12,8 @@
#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_item_delegate_manager.h"
#include "ash/launcher/launcher_model.h"
#include "ash/launcher/launcher_tooltip_manager.h"
#include "ash/launcher/overflow_bubble.h"
@@ -408,7 +410,8 @@ LauncherView::LauncherView(LauncherModel* model,
got_deleted_(NULL),
drag_and_drop_item_pinned_(false),
drag_and_drop_launcher_id_(0),
- dragged_off_shelf_(false) {
+ dragged_off_shelf_(false),
+ item_manager_(Shell::GetInstance()->launcher_item_delegate_manager()) {
DCHECK(model_);
bounds_animator_.reset(new views::BoundsAnimator(this));
bounds_animator_->AddObserver(this);
@@ -981,9 +984,15 @@ void LauncherView::PrepareForDrag(Pointer pointer,
drag_pointer_ = pointer;
start_drag_index_ = view_model_->GetIndexOfView(drag_view_);
+ if (start_drag_index_== -1) {
+ CancelDrag(-1);
+ return;
+ }
+
// If the item is no longer draggable, bail out.
- if (start_drag_index_ == -1 ||
- !delegate_->IsDraggable(model_->items()[start_drag_index_])) {
+ LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
+ model_->items()[start_drag_index_].type);
+ if (!item_delegate->IsDraggable(model_->items()[start_drag_index_])) {
CancelDrag(-1);
return;
}
@@ -998,8 +1007,10 @@ void LauncherView::ContinueDrag(const ui::LocatedEvent& event) {
// Bail if it is gone.
int current_index = view_model_->GetIndexOfView(drag_view_);
DCHECK_NE(-1, current_index);
- if (current_index == -1 ||
- !delegate_->IsDraggable(model_->items()[current_index])) {
+
+ LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
+ model_->items()[current_index].type);
+ if (!item_delegate->IsDraggable(model_->items()[current_index])) {
CancelDrag(-1);
return;
}
@@ -1496,9 +1507,13 @@ void LauncherView::PointerPressedOnButton(views::View* view,
tooltip_->Close();
int index = view_model_->GetIndexOfView(view);
- if (index == -1 ||
- view_model_->view_size() <= 1 ||
- !delegate_->IsDraggable(model_->items()[index]))
+ if (index == -1)
+ return;
+
+ LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
+ model_->items()[index].type);
+ if (view_model_->view_size() <= 1 ||
+ !item_delegate->IsDraggable(model_->items()[index]))
return; // View is being deleted or not draggable, ignore request.
ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
@@ -1567,21 +1582,9 @@ base::string16 LauncherView::GetAccessibleName(const views::View* view) {
if (view_index == -1)
return base::string16();
- switch (model_->items()[view_index].type) {
- case TYPE_TABBED:
- case TYPE_APP_PANEL:
- case TYPE_APP_SHORTCUT:
- 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);
- }
- return base::string16();
+ LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
+ model_->items()[view_index].type);
+ return item_delegate->GetTitle(model_->items()[view_index]);
}
void LauncherView::ButtonPressed(views::Button* sender,
@@ -1625,23 +1628,24 @@ void LauncherView::ButtonPressed(views::Button* sender,
case TYPE_BROWSER_SHORTCUT:
Shell::GetInstance()->delegate()->RecordUserMetricsAction(
UMA_LAUNCHER_CLICK_ON_APP);
- // Fallthrough
- case TYPE_TABBED:
- case TYPE_APP_PANEL:
- delegate_->ItemSelected(model_->items()[view_index], event);
- // Don't show the menu when the user creates a new browser using ctrl
- // click.
- if (model_->items()[view_index].type != TYPE_BROWSER_SHORTCUT ||
- !(event.flags() & ui::EF_CONTROL_DOWN))
- ShowListMenuForView(model_->items()[view_index], sender, event);
break;
case TYPE_APP_LIST:
Shell::GetInstance()->delegate()->RecordUserMetricsAction(
UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
- Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
+ break;
+
+ case TYPE_TABBED:
+ case TYPE_APP_PANEL:
break;
}
+
+ LauncherItemDelegate* item_delegate =
+ item_manager_->GetLauncherItemDelegate(
+ model_->items()[view_index].type);
+ item_delegate->ItemSelected(model_->items()[view_index], event);
+
+ ShowListMenuForView(model_->items()[view_index], sender, event);
}
}
@@ -1649,7 +1653,9 @@ 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 =
+ item_manager_->GetLauncherItemDelegate(item.type);
+ menu_model.reset(item_delegate->CreateApplicationMenu(item, event.flags()));
// Make sure we have a menu and it has at least two items in addition to the
// application title and the 3 spacing separators.
@@ -1669,6 +1675,8 @@ void LauncherView::ShowContextMenuForView(views::View* source,
const gfx::Point& point,
ui:: MenuSourceType source_type) {
int view_index = view_model_->GetIndexOfView(source);
+ // TODO(simon.hong81): Create LauncherContextMenu for applist in its
+ // LauncherItemDelegate.
if (view_index != -1 &&
model_->items()[view_index].type == TYPE_APP_LIST) {
view_index = -1;
@@ -1680,11 +1688,15 @@ void LauncherView::ShowContextMenuForView(views::View* source,
Shell::GetInstance()->ShowContextMenu(point, source_type);
return;
}
- scoped_ptr<ui::MenuModel> menu_model(delegate_->CreateContextMenu(
+ scoped_ptr<ui::MenuModel> menu_model;
+ LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate(
+ model_->items()[view_index].type);
+ menu_model.reset(item_delegate->CreateContextMenu(
model_->items()[view_index],
source->GetWidget()->GetNativeView()->GetRootWindow()));
if (!menu_model)
return;
+
base::AutoReset<LauncherID> reseter(
&context_menu_id_,
view_index == -1 ? 0 : model_->items()[view_index].id);
@@ -1816,7 +1828,11 @@ bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
Shell::GetInstance()->GetAppListWindow())
return false;
const LauncherItem* item = LauncherItemForView(view);
- return (!item || delegate_->ShouldShowTooltip(*item));
+ if (!item)
+ return true;
+ LauncherItemDelegate* item_delegate =
+ item_manager_->GetLauncherItemDelegate(item->type);
+ return item_delegate->ShouldShowTooltip(*item);
}
int LauncherView::CalculateShelfDistance(const gfx::Point& coordinate) const {
diff --git a/ash/launcher/launcher_view.h b/ash/launcher/launcher_view.h
index 364be49..b1e4f75 100644
--- a/ash/launcher/launcher_view.h
+++ b/ash/launcher/launcher_view.h
@@ -35,6 +35,7 @@ class LauncherViewTestAPI;
class LauncherDelegate;
struct LauncherItem;
class LauncherIconObserver;
+class LauncherItemDelegateManager;
class LauncherModel;
namespace internal {
@@ -386,6 +387,9 @@ class ASH_EXPORT LauncherView : public views::View,
// True when the icon was dragged off the shelf.
bool dragged_off_shelf_;
+ // Holds LauncherItemDelegateManager.
+ LauncherItemDelegateManager* item_manager_;
+
DISALLOW_COPY_AND_ASSIGN(LauncherView);
};
diff --git a/ash/shell.cc b/ash/shell.cc
index c32371f..96a8921 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -23,7 +23,10 @@
#include "ash/focus_cycler.h"
#include "ash/high_contrast/high_contrast_controller.h"
#include "ash/host/root_window_host_factory.h"
+#include "ash/launcher/app_list_launcher_item_delegate.h"
#include "ash/launcher/launcher_delegate.h"
+#include "ash/launcher/launcher_item_delegate.h"
+#include "ash/launcher/launcher_item_delegate_manager.h"
#include "ash/launcher/launcher_model.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/magnifier/partial_magnification_controller.h"
@@ -865,9 +868,13 @@ SystemTray* Shell::GetPrimarySystemTray() {
LauncherDelegate* Shell::GetLauncherDelegate() {
if (!launcher_delegate_) {
+ // Creates LauncherItemDelegateManager before LauncherDelegate.
+ launcher_item_delegate_manager_.reset(new LauncherItemDelegateManager);
launcher_model_.reset(new LauncherModel);
launcher_delegate_.reset(
delegate_->CreateLauncherDelegate(launcher_model_.get()));
+ app_list_launcher_item_delegate_.reset(
+ new internal::AppListLauncherItemDelegate);
}
return launcher_delegate_.get();
}
diff --git a/ash/shell.h b/ash/shell.h
index 5068815..718d1f8 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -75,6 +75,7 @@ class DisplayController;
class HighContrastController;
class Launcher;
class LauncherDelegate;
+class LauncherItemDelegateManager;
class LauncherModel;
class MagnificationController;
class MruWindowTracker;
@@ -101,6 +102,7 @@ namespace internal {
class AcceleratorFilter;
class ActivationController;
class AppListController;
+class AppListLauncherItemDelegate;
class CaptureController;
class DisplayChangeObserver;
class DisplayErrorObserver;
@@ -366,6 +368,10 @@ class ASH_EXPORT Shell
return activation_client_;
}
+ LauncherItemDelegateManager* launcher_item_delegate_manager() {
+ return launcher_item_delegate_manager_.get();
+ }
+
ScreenAsh* screen() { return screen_; }
// Force the shelf to query for it's current visibility state.
@@ -541,6 +547,9 @@ class ASH_EXPORT Shell
scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
scoped_ptr<SessionStateDelegate> session_state_delegate_;
scoped_ptr<LauncherDelegate> launcher_delegate_;
+ scoped_ptr<LauncherItemDelegateManager> launcher_item_delegate_manager_;
+ scoped_ptr<internal::AppListLauncherItemDelegate>
+ app_list_launcher_item_delegate_;
scoped_ptr<LauncherModel> launcher_model_;
diff --git a/ash/shell/launcher_delegate_impl.cc b/ash/shell/launcher_delegate_impl.cc
index da788e0..5664b00 100644
--- a/ash/shell/launcher_delegate_impl.cc
+++ b/ash/shell/launcher_delegate_impl.cc
@@ -4,7 +4,9 @@
#include "ash/shell/launcher_delegate_impl.h"
+#include "ash/launcher/launcher_item_delegate_manager.h"
#include "ash/launcher/launcher_util.h"
+#include "ash/shell.h"
#include "ash/shell/toplevel_window.h"
#include "ash/shell/window_watcher.h"
#include "ash/wm/window_util.h"
@@ -17,6 +19,10 @@ namespace shell {
LauncherDelegateImpl::LauncherDelegateImpl(WindowWatcher* watcher)
: watcher_(watcher) {
+ ash::LauncherItemDelegateManager* manager =
+ ash::Shell::GetInstance()->launcher_item_delegate_manager();
+ manager->RegisterLauncherItemDelegate(ash::TYPE_TABBED, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this);
}
LauncherDelegateImpl::~LauncherDelegateImpl() {
diff --git a/ash/shell/launcher_delegate_impl.h b/ash/shell/launcher_delegate_impl.h
index 658c21d..d6945d7 100644
--- a/ash/shell/launcher_delegate_impl.h
+++ b/ash/shell/launcher_delegate_impl.h
@@ -6,6 +6,7 @@
#define ASH_SHELL_LAUNCHER_DELEGATE_IMPL_H_
#include "ash/launcher/launcher_delegate.h"
+#include "ash/launcher/launcher_item_delegate.h"
#include "base/compiler_specific.h"
namespace aura {
@@ -17,7 +18,8 @@ namespace shell {
class WindowWatcher;
-class LauncherDelegateImpl : public ash::LauncherDelegate {
+class LauncherDelegateImpl : public ash::LauncherDelegate,
+ public ash::LauncherItemDelegate {
public:
explicit LauncherDelegateImpl(WindowWatcher* watcher);
virtual ~LauncherDelegateImpl();
@@ -25,6 +27,16 @@ class LauncherDelegateImpl : public ash::LauncherDelegate {
void set_watcher(WindowWatcher* watcher) { watcher_ = watcher; }
// LauncherDelegate overrides:
+ virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE;
+ virtual void OnLauncherCreated(Launcher* launcher) OVERRIDE;
+ virtual void OnLauncherDestroyed(Launcher* launcher) OVERRIDE;
+ virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE;
+ virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE;
+ virtual void PinAppWithID(const std::string& app_id) OVERRIDE;
+ virtual bool IsAppPinned(const std::string& app_id) OVERRIDE;
+ virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE;
+
+ // LauncherItemDelegate overrides:
virtual void ItemSelected(const ash::LauncherItem& item,
const ui::Event& event) OVERRIDE;
virtual base::string16 GetTitle(const ash::LauncherItem& item) OVERRIDE;
@@ -34,16 +46,8 @@ class LauncherDelegateImpl : public ash::LauncherDelegate {
virtual ash::LauncherMenuModel* CreateApplicationMenu(
const ash::LauncherItem&,
int event_flags) OVERRIDE;
- virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE;
virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE;
virtual bool ShouldShowTooltip(const LauncherItem& item) OVERRIDE;
- virtual void OnLauncherCreated(Launcher* launcher) OVERRIDE;
- virtual void OnLauncherDestroyed(Launcher* launcher) OVERRIDE;
- virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE;
- virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE;
- virtual void PinAppWithID(const std::string& app_id) OVERRIDE;
- virtual bool IsAppPinned(const std::string& app_id) OVERRIDE;
- virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE;
private:
// Used to update Launcher. Owned by main.
diff --git a/ash/test/test_launcher_delegate.cc b/ash/test/test_launcher_delegate.cc
index 047c2a9..7ca1663 100644
--- a/ash/test/test_launcher_delegate.cc
+++ b/ash/test/test_launcher_delegate.cc
@@ -4,8 +4,10 @@
#include "ash/test/test_launcher_delegate.h"
+#include "ash/launcher/launcher_item_delegate_manager.h"
#include "ash/launcher/launcher_model.h"
#include "ash/launcher/launcher_util.h"
+#include "ash/shell.h"
#include "ash/wm/window_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -21,6 +23,15 @@ TestLauncherDelegate::TestLauncherDelegate(LauncherModel* model)
: model_(model) {
CHECK(!instance_);
instance_ = this;
+
+ ash::LauncherItemDelegateManager* manager =
+ ash::Shell::GetInstance()->launcher_item_delegate_manager();
+ manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_TABBED, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this);
}
TestLauncherDelegate::~TestLauncherDelegate() {
diff --git a/ash/test/test_launcher_delegate.h b/ash/test/test_launcher_delegate.h
index ae1ca7a..e084a1a 100644
--- a/ash/test/test_launcher_delegate.h
+++ b/ash/test/test_launcher_delegate.h
@@ -9,6 +9,7 @@
#include <set>
#include "ash/launcher/launcher_delegate.h"
+#include "ash/launcher/launcher_item_delegate.h"
#include "base/compiler_specific.h"
#include "ui/aura/window_observer.h"
@@ -21,6 +22,7 @@ namespace test {
// Test implementation of LauncherDelegate.
// Tests may create icons for windows by calling AddLauncherItem
class TestLauncherDelegate : public LauncherDelegate,
+ public LauncherItemDelegate,
public aura::WindowObserver {
public:
explicit TestLauncherDelegate(LauncherModel* model);
@@ -38,6 +40,16 @@ class TestLauncherDelegate : public LauncherDelegate,
const HierarchyChangeParams& params) OVERRIDE;
// LauncherDelegate implementation.
+ virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE;
+ virtual void OnLauncherCreated(Launcher* launcher) OVERRIDE;
+ virtual void OnLauncherDestroyed(Launcher* launcher) OVERRIDE;
+ virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE;
+ virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE;
+ virtual void PinAppWithID(const std::string& app_id) OVERRIDE;
+ virtual bool IsAppPinned(const std::string& app_id) OVERRIDE;
+ virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE;
+
+ // LauncherItemDelegate implementation.
virtual void ItemSelected(const LauncherItem& item,
const ui::Event& event) OVERRIDE;
virtual base::string16 GetTitle(const LauncherItem& item) OVERRIDE;
@@ -46,16 +58,8 @@ class TestLauncherDelegate : public LauncherDelegate,
virtual ash::LauncherMenuModel* CreateApplicationMenu(
const LauncherItem& item,
int event_flags) OVERRIDE;
- virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE;
virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE;
virtual bool ShouldShowTooltip(const LauncherItem& item) OVERRIDE;
- virtual void OnLauncherCreated(Launcher* launcher) OVERRIDE;
- virtual void OnLauncherDestroyed(Launcher* launcher) OVERRIDE;
- virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE;
- virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE;
- virtual void PinAppWithID(const std::string& app_id) OVERRIDE;
- virtual bool IsAppPinned(const std::string& app_id) OVERRIDE;
- virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE;
private:
typedef std::map<aura::Window*, ash::LauncherID> WindowToID;
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
index d734685..a072cac 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc
@@ -8,6 +8,7 @@
#include "ash/ash_switches.h"
#include "ash/launcher/launcher.h"
+#include "ash/launcher/launcher_item_delegate_manager.h"
#include "ash/launcher/launcher_model.h"
#include "ash/launcher/launcher_util.h"
#include "ash/root_window_controller.h"
@@ -243,6 +244,11 @@ ChromeLauncherController::ChromeLauncherController(
prefs::kShelfPreferences,
base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs,
base::Unretained(this)));
+
+ // This check is needed for win7_aura. Without this, all tests in
+ // ChromeLauncherControllerTest will fail by win7_aura.
+ if (ash::Shell::HasInstance())
+ RegisterLauncherItemDelegate();
}
ChromeLauncherController::~ChromeLauncherController() {
@@ -1651,3 +1657,16 @@ ChromeLauncherController::MoveItemWithoutPinnedStateChangeNotification(
base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
model_->Move(source_index, target_index);
}
+
+void ChromeLauncherController::RegisterLauncherItemDelegate() {
+ // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate
+ // is created.
+ ash::LauncherItemDelegateManager* manager =
+ ash::Shell::GetInstance()->launcher_item_delegate_manager();
+ manager->RegisterLauncherItemDelegate(ash::TYPE_TABBED, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this);
+ manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this);
+}
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
index fd0c6c1..5ae9218 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h
@@ -13,6 +13,7 @@
#include "ash/display/display_controller.h"
#include "ash/launcher/launcher_delegate.h"
+#include "ash/launcher/launcher_item_delegate.h"
#include "ash/launcher/launcher_model_observer.h"
#include "ash/launcher/launcher_types.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
@@ -71,7 +72,10 @@ typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems;
// * App shell windows have ShellWindowLauncherItemController, owned by
// ShellWindowLauncherController.
// * Shortcuts have no LauncherItemController.
+// TODO(simon.hong81): Move LauncherItemDelegate out from
+// ChromeLauncherController and makes separate subclass with it.
class ChromeLauncherController : public ash::LauncherDelegate,
+ public ash::LauncherItemDelegate,
public ash::LauncherModelObserver,
public ash::ShellObserver,
public ash::DisplayController::Observer,
@@ -265,6 +269,17 @@ class ChromeLauncherController : public ash::LauncherDelegate,
bool allow_minimize);
// ash::LauncherDelegate overrides:
+ virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE;
+ virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE;
+ virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE;
+ virtual ash::LauncherID GetLauncherIDForAppID(
+ const std::string& app_id) OVERRIDE;
+ virtual const std::string& GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE;
+ virtual void PinAppWithID(const std::string& app_id) OVERRIDE;
+ virtual bool IsAppPinned(const std::string& app_id) OVERRIDE;
+ virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE;
+
+ // ash::LauncherItemDelegate overrides:
virtual void ItemSelected(const ash::LauncherItem& item,
const ui::Event& event) OVERRIDE;
virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE;
@@ -273,17 +288,8 @@ class ChromeLauncherController : public ash::LauncherDelegate,
virtual ash::LauncherMenuModel* CreateApplicationMenu(
const ash::LauncherItem& item,
int event_flags) OVERRIDE;
- virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE;
virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE;
virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE;
- virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE;
- virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE;
- virtual ash::LauncherID GetLauncherIDForAppID(
- const std::string& app_id) OVERRIDE;
- virtual const std::string& GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE;
- virtual void PinAppWithID(const std::string& app_id) OVERRIDE;
- virtual bool IsAppPinned(const std::string& app_id) OVERRIDE;
- virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE;
// ash::LauncherModelObserver overrides:
virtual void LauncherItemAdded(int index) OVERRIDE;
@@ -465,6 +471,9 @@ class ChromeLauncherController : public ash::LauncherDelegate,
void MoveItemWithoutPinnedStateChangeNotification(int source_index,
int target_index);
+ // Register LauncherItemDelegate.
+ void RegisterLauncherItemDelegate();
+
static ChromeLauncherController* instance_;
ash::LauncherModel* model_;
diff --git a/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h b/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h
index 46a483f..1db85e5 100644
--- a/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h
+++ b/chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_APPLICATION_MENU_ITEM_MODEL_H_
#include "ash/launcher/launcher_delegate.h"
+#include "ash/launcher/launcher_item_delegate.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"