[ash] Add TYPE_DIALOG and its item's LauncherContextMenu

This is third CL for adding an item for dialog.
This cl adds new LauncherItemType, TYPE_DIALOG, and 
implements a context menu of item created by ShelfWindowWatcher.

R=sky@chromium.org
BUG=121242
TEST=NONE

Review URL: https://codereview.chromium.org/107163005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243965 0039d316-1c4b-4281-b951-d872f2087c98
parent 531cf0b2
...@@ -35,6 +35,9 @@ enum LauncherItemType { ...@@ -35,6 +35,9 @@ enum LauncherItemType {
// Represents a windowed V1 browser app. // Represents a windowed V1 browser app.
TYPE_WINDOWED_APP, TYPE_WINDOWED_APP,
// Represents a dialog.
TYPE_DIALOG,
// Default value. // Default value.
TYPE_UNDEFINED, TYPE_UNDEFINED,
}; };
......
...@@ -541,7 +541,9 @@ void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, ...@@ -541,7 +541,9 @@ void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
ui::MenuSourceType source_type) { ui::MenuSourceType source_type) {
DCHECK(Shell::GetInstance()->delegate()); DCHECK(Shell::GetInstance()->delegate());
scoped_ptr<ui::MenuModel> menu_model( scoped_ptr<ui::MenuModel> menu_model(
Shell::GetInstance()->delegate()->CreateContextMenu(root_window())); Shell::GetInstance()->delegate()->CreateContextMenu(root_window(),
NULL,
NULL));
if (!menu_model) if (!menu_model)
return; return;
......
...@@ -39,7 +39,9 @@ base::string16 AppListShelfItemDelegate::GetTitle() { ...@@ -39,7 +39,9 @@ base::string16 AppListShelfItemDelegate::GetTitle() {
ui::MenuModel* AppListShelfItemDelegate::CreateContextMenu( ui::MenuModel* AppListShelfItemDelegate::CreateContextMenu(
aura::Window* root_window) { aura::Window* root_window) {
return Shell::GetInstance()->delegate()->CreateContextMenu(root_window); return Shell::GetInstance()->delegate()->CreateContextMenu(root_window,
NULL,
NULL);
} }
ShelfMenuModel* AppListShelfItemDelegate::CreateApplicationMenu( ShelfMenuModel* AppListShelfItemDelegate::CreateApplicationMenu(
...@@ -56,5 +58,8 @@ bool AppListShelfItemDelegate::ShouldShowTooltip() { ...@@ -56,5 +58,8 @@ bool AppListShelfItemDelegate::ShouldShowTooltip() {
return true; return true;
} }
void AppListShelfItemDelegate::Close() {
}
} // namespace internal } // namespace internal
} // namespace ash } // namespace ash
...@@ -26,6 +26,7 @@ class AppListShelfItemDelegate : public ShelfItemDelegate { ...@@ -26,6 +26,7 @@ class AppListShelfItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE; virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE; virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE; virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private: private:
DISALLOW_COPY_AND_ASSIGN(AppListShelfItemDelegate); DISALLOW_COPY_AND_ASSIGN(AppListShelfItemDelegate);
......
...@@ -59,6 +59,10 @@ class ASH_EXPORT ShelfItemDelegate { ...@@ -59,6 +59,10 @@ class ASH_EXPORT ShelfItemDelegate {
// Returns true if a tooltip should be shown. // Returns true if a tooltip should be shown.
virtual bool ShouldShowTooltip() = 0; virtual bool ShouldShowTooltip() = 0;
// Closes all windows associated with this item.
virtual void Close() = 0;
}; };
} // namespace ash } // namespace ash
......
...@@ -26,8 +26,10 @@ int LauncherItemTypeToWeight(LauncherItemType type) { ...@@ -26,8 +26,10 @@ int LauncherItemTypeToWeight(LauncherItemType type) {
return 1; return 1;
case TYPE_PLATFORM_APP: case TYPE_PLATFORM_APP:
return 2; return 2;
case TYPE_APP_PANEL: case TYPE_DIALOG:
return 3; return 3;
case TYPE_APP_PANEL:
return 4;
case TYPE_UNDEFINED: case TYPE_UNDEFINED:
NOTREACHED() << "LauncherItemType must be set"; NOTREACHED() << "LauncherItemType must be set";
return -1; return -1;
...@@ -42,8 +44,10 @@ int LauncherItemTypeToWeight(LauncherItemType type) { ...@@ -42,8 +44,10 @@ int LauncherItemTypeToWeight(LauncherItemType type) {
return 1; return 1;
case TYPE_APP_LIST: case TYPE_APP_LIST:
return 2; return 2;
case TYPE_APP_PANEL: case TYPE_DIALOG:
return 3; return 3;
case TYPE_APP_PANEL:
return 4;
case TYPE_UNDEFINED: case TYPE_UNDEFINED:
NOTREACHED() << "LauncherItemType must be set"; NOTREACHED() << "LauncherItemType must be set";
return -1; return -1;
......
...@@ -918,6 +918,7 @@ views::View* ShelfView::CreateViewForItem(const LauncherItem& item) { ...@@ -918,6 +918,7 @@ views::View* ShelfView::CreateViewForItem(const LauncherItem& item) {
case TYPE_APP_SHORTCUT: case TYPE_APP_SHORTCUT:
case TYPE_WINDOWED_APP: case TYPE_WINDOWED_APP:
case TYPE_PLATFORM_APP: case TYPE_PLATFORM_APP:
case TYPE_DIALOG:
case TYPE_APP_PANEL: { case TYPE_APP_PANEL: {
ShelfButton* button = ShelfButton::Create(this, this, layout_manager_); ShelfButton* button = ShelfButton::Create(this, this, layout_manager_);
button->SetImage(item.image); button->SetImage(item.image);
...@@ -1252,6 +1253,7 @@ bool ShelfView::SameDragType(LauncherItemType typea, ...@@ -1252,6 +1253,7 @@ bool ShelfView::SameDragType(LauncherItemType typea,
case TYPE_PLATFORM_APP: case TYPE_PLATFORM_APP:
case TYPE_WINDOWED_APP: case TYPE_WINDOWED_APP:
case TYPE_APP_PANEL: case TYPE_APP_PANEL:
case TYPE_DIALOG:
return typeb == typea; return typeb == typea;
case TYPE_UNDEFINED: case TYPE_UNDEFINED:
NOTREACHED() << "LauncherItemType must be set."; NOTREACHED() << "LauncherItemType must be set.";
...@@ -1614,6 +1616,7 @@ void ShelfView::ShelfItemChanged(int model_index, ...@@ -1614,6 +1616,7 @@ void ShelfView::ShelfItemChanged(int model_index,
case TYPE_APP_SHORTCUT: case TYPE_APP_SHORTCUT:
case TYPE_WINDOWED_APP: case TYPE_WINDOWED_APP:
case TYPE_PLATFORM_APP: case TYPE_PLATFORM_APP:
case TYPE_DIALOG:
case TYPE_APP_PANEL: { case TYPE_APP_PANEL: {
ShelfButton* button = static_cast<ShelfButton*>(view); ShelfButton* button = static_cast<ShelfButton*>(view);
ReflectItemStatus(item, button); ReflectItemStatus(item, button);
...@@ -1788,6 +1791,7 @@ void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) { ...@@ -1788,6 +1791,7 @@ void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) {
break; break;
case TYPE_APP_PANEL: case TYPE_APP_PANEL:
case TYPE_DIALOG:
break; break;
case TYPE_UNDEFINED: case TYPE_UNDEFINED:
......
...@@ -91,7 +91,7 @@ void ShelfWindowWatcher::AddLauncherItem(aura::Window* window) { ...@@ -91,7 +91,7 @@ void ShelfWindowWatcher::AddLauncherItem(aura::Window* window) {
SetShelfItemDetailsForLauncherItem(&item, *item_details); SetShelfItemDetailsForLauncherItem(&item, *item_details);
SetLauncherIDForWindow(id, window); SetLauncherIDForWindow(id, window);
scoped_ptr<ShelfItemDelegate> item_delegate( scoped_ptr<ShelfItemDelegate> item_delegate(
new ShelfWindowWatcherItemDelegate(window)); new ShelfWindowWatcherItemDelegate(window, model_));
// |item_delegate| is owned by |item_delegate_manager_|. // |item_delegate| is owned by |item_delegate_manager_|.
item_delegate_manager_->SetShelfItemDelegate(id, item_delegate.Pass()); item_delegate_manager_->SetShelfItemDelegate(id, item_delegate.Pass());
model_->Add(item); model_->Add(item);
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
#include "ash/shelf/shelf_window_watcher_item_delegate.h" #include "ash/shelf/shelf_window_watcher_item_delegate.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_util.h" #include "ash/shelf/shelf_util.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/views/corewm/window_animations.h" #include "ui/views/corewm/window_animations.h"
...@@ -14,8 +17,9 @@ namespace ash { ...@@ -14,8 +17,9 @@ namespace ash {
namespace internal { namespace internal {
ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate( ShelfWindowWatcherItemDelegate::ShelfWindowWatcherItemDelegate(
aura::Window* window) aura::Window* window, ShelfModel* model)
: window_(window) { : window_(window),
model_(model) {
} }
ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() { ShelfWindowWatcherItemDelegate::~ShelfWindowWatcherItemDelegate() {
...@@ -47,8 +51,11 @@ base::string16 ShelfWindowWatcherItemDelegate::GetTitle() { ...@@ -47,8 +51,11 @@ base::string16 ShelfWindowWatcherItemDelegate::GetTitle() {
ui::MenuModel* ShelfWindowWatcherItemDelegate::CreateContextMenu( ui::MenuModel* ShelfWindowWatcherItemDelegate::CreateContextMenu(
aura::Window* root_window) { aura::Window* root_window) {
// TODO(simonhong): Create ShelfItemContextMenu. ash::LauncherItem item =
return NULL; *(model_->ItemByID(GetLauncherIDForWindow(window_)));
return Shell::GetInstance()->delegate()->CreateContextMenu(root_window,
this,
&item);
} }
ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu( ShelfMenuModel* ShelfWindowWatcherItemDelegate::CreateApplicationMenu(
......
...@@ -14,18 +14,18 @@ class Window; ...@@ -14,18 +14,18 @@ class Window;
} }
namespace ash { namespace ash {
class ShelfModel;
namespace internal { namespace internal {
// ShelfItemDelegate for the items created by ShelfWindowWatcher. // ShelfItemDelegate for the items created by ShelfWindowWatcher.
class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate { class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate {
public: public:
explicit ShelfWindowWatcherItemDelegate(aura::Window* window); ShelfWindowWatcherItemDelegate(aura::Window* window, ShelfModel* model_);
virtual ~ShelfWindowWatcherItemDelegate(); virtual ~ShelfWindowWatcherItemDelegate();
// Closes the window associated with this item.
void Close();
private: private:
// ShelfItemDelegate overrides: // ShelfItemDelegate overrides:
virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual bool ItemSelected(const ui::Event& event) OVERRIDE;
...@@ -34,10 +34,14 @@ class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate { ...@@ -34,10 +34,14 @@ class ShelfWindowWatcherItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE; virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE; virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE; virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
// Stores a Window associated with this item. Not owned. // Stores a Window associated with this item. Not owned.
aura::Window* window_; aura::Window* window_;
// Not owned.
ShelfModel* model_;
DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherItemDelegate); DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherItemDelegate);
}; };
......
...@@ -158,7 +158,10 @@ aura::client::UserActionClient* ShellDelegateImpl::CreateUserActionClient() { ...@@ -158,7 +158,10 @@ aura::client::UserActionClient* ShellDelegateImpl::CreateUserActionClient() {
return NULL; return NULL;
} }
ui::MenuModel* ShellDelegateImpl::CreateContextMenu(aura::Window* root) { ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) {
return new ContextMenu(root); return new ContextMenu(root);
} }
......
...@@ -55,7 +55,9 @@ class ShellDelegateImpl : public ash::ShellDelegate { ...@@ -55,7 +55,9 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE; virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE; virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu( virtual ui::MenuModel* CreateContextMenu(
aura::Window* root_window) OVERRIDE; aura::Window* root_window,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) OVERRIDE;
virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE; virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE;
virtual base::string16 GetProductName() const OVERRIDE; virtual base::string16 GetProductName() const OVERRIDE;
......
...@@ -53,5 +53,8 @@ bool WindowWatcherShelfItemDelegate::ShouldShowTooltip() { ...@@ -53,5 +53,8 @@ bool WindowWatcherShelfItemDelegate::ShouldShowTooltip() {
return true; return true;
} }
void WindowWatcherShelfItemDelegate::Close() {
}
} // namespace shell } // namespace shell
} // namespace ash } // namespace ash
...@@ -28,6 +28,7 @@ class WindowWatcherShelfItemDelegate : public ShelfItemDelegate { ...@@ -28,6 +28,7 @@ class WindowWatcherShelfItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE; virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE; virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE; virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private: private:
LauncherID id_; LauncherID id_;
......
...@@ -49,6 +49,7 @@ class NewWindowDelegate; ...@@ -49,6 +49,7 @@ class NewWindowDelegate;
class WindowTreeHostFactory; class WindowTreeHostFactory;
class SessionStateDelegate; class SessionStateDelegate;
class ShelfDelegate; class ShelfDelegate;
class ShelfItemDelegate;
class ShelfModel; class ShelfModel;
class SystemTrayDelegate; class SystemTrayDelegate;
class UserWallpaperDelegate; class UserWallpaperDelegate;
...@@ -126,7 +127,12 @@ class ASH_EXPORT ShellDelegate { ...@@ -126,7 +127,12 @@ class ASH_EXPORT ShellDelegate {
virtual aura::client::UserActionClient* CreateUserActionClient() = 0; virtual aura::client::UserActionClient* CreateUserActionClient() = 0;
// Creates a menu model of the context for the |root_window|. // Creates a menu model of the context for the |root_window|.
virtual ui::MenuModel* CreateContextMenu(aura::Window* root_window) = 0; // When a ContextMenu is used for an item created by ShelfWindowWatcher,
// passes its ShelfItemDelegate and LauncherItem.
virtual ui::MenuModel* CreateContextMenu(
aura::Window* root_window,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) = 0;
// Creates a root window host factory. Shell takes ownership of the returned // Creates a root window host factory. Shell takes ownership of the returned
// value. // value.
......
...@@ -48,5 +48,8 @@ bool TestShelfItemDelegate::ShouldShowTooltip() { ...@@ -48,5 +48,8 @@ bool TestShelfItemDelegate::ShouldShowTooltip() {
return true; return true;
} }
void TestShelfItemDelegate::Close() {
}
} // namespace test } // namespace test
} // namespace ash } // namespace ash
...@@ -29,6 +29,7 @@ class TestShelfItemDelegate : public ShelfItemDelegate { ...@@ -29,6 +29,7 @@ class TestShelfItemDelegate : public ShelfItemDelegate {
virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE; virtual ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE; virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE; virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private: private:
aura::Window* window_; aura::Window* window_;
......
...@@ -139,7 +139,10 @@ aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() { ...@@ -139,7 +139,10 @@ aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() {
return NULL; return NULL;
} }
ui::MenuModel* TestShellDelegate::CreateContextMenu(aura::Window* root) { ui::MenuModel* TestShellDelegate::CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) {
return NULL; return NULL;
} }
......
...@@ -50,7 +50,10 @@ class TestShellDelegate : public ShellDelegate { ...@@ -50,7 +50,10 @@ class TestShellDelegate : public ShellDelegate {
virtual NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE; virtual NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE;
virtual MediaDelegate* CreateMediaDelegate() OVERRIDE; virtual MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE; virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(aura::Window* root) OVERRIDE; virtual ui::MenuModel* CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) OVERRIDE;
virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE; virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE;
virtual base::string16 GetProductName() const OVERRIDE; virtual base::string16 GetProductName() const OVERRIDE;
......
...@@ -127,12 +127,18 @@ aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() { ...@@ -127,12 +127,18 @@ aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
return new UserActionHandler; return new UserActionHandler;
} }
ui::MenuModel* ChromeShellDelegate::CreateContextMenu(aura::Window* root) { ui::MenuModel* ChromeShellDelegate::CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) {
DCHECK(shelf_delegate_); DCHECK(shelf_delegate_);
// Don't show context menu for exclusive app runtime mode. // Don't show context menu for exclusive app runtime mode.
if (chrome::IsRunningInAppMode()) if (chrome::IsRunningInAppMode())
return NULL; return NULL;
if (item_delegate && item)
return new LauncherContextMenu(shelf_delegate_, item_delegate, item, root);
return new LauncherContextMenu(shelf_delegate_, root); return new LauncherContextMenu(shelf_delegate_, root);
} }
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
class Browser; class Browser;
namespace ash {
class ShelfItemDelegate;
}
namespace content { namespace content {
class WebContents; class WebContents;
} }
...@@ -57,7 +61,10 @@ class ChromeShellDelegate : public ash::ShellDelegate, ...@@ -57,7 +61,10 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual ash::NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE; virtual ash::NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE;
virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE; virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE; virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual ui::MenuModel* CreateContextMenu(aura::Window* root) OVERRIDE; virtual ui::MenuModel* CreateContextMenu(
aura::Window* root,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item) OVERRIDE;
virtual ash::WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE; virtual ash::WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE;
virtual base::string16 GetProductName() const OVERRIDE; virtual base::string16 GetProductName() const OVERRIDE;
......
...@@ -40,7 +40,6 @@ class AppShortcutLauncherItemController : public LauncherItemController { ...@@ -40,7 +40,6 @@ class AppShortcutLauncherItemController : public LauncherItemController {
virtual bool IsVisible() const OVERRIDE; virtual bool IsVisible() const OVERRIDE;
virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE; virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE;
virtual bool Activate(ash::LaunchSource source) OVERRIDE; virtual bool Activate(ash::LaunchSource source) OVERRIDE;
virtual void Close() OVERRIDE;
virtual ChromeLauncherAppMenuItems GetApplicationList( virtual ChromeLauncherAppMenuItems GetApplicationList(
int event_flags) OVERRIDE; int event_flags) OVERRIDE;
virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual bool ItemSelected(const ui::Event& event) OVERRIDE;
...@@ -50,6 +49,7 @@ class AppShortcutLauncherItemController : public LauncherItemController { ...@@ -50,6 +49,7 @@ class AppShortcutLauncherItemController : public LauncherItemController {
virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE; virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE; virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE; virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
// Get the refocus url pattern, which can be used to identify this application // Get the refocus url pattern, which can be used to identify this application
// from a URL link. // from a URL link.
......
...@@ -34,7 +34,6 @@ class BrowserShortcutLauncherItemController : public LauncherItemController { ...@@ -34,7 +34,6 @@ class BrowserShortcutLauncherItemController : public LauncherItemController {
virtual bool IsVisible() const OVERRIDE; virtual bool IsVisible() const OVERRIDE;
virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE; virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE;
virtual bool Activate(ash::LaunchSource source) OVERRIDE; virtual bool Activate(ash::LaunchSource source) OVERRIDE;
virtual void Close() OVERRIDE;
virtual ChromeLauncherAppMenuItems GetApplicationList( virtual ChromeLauncherAppMenuItems GetApplicationList(
int event_flags) OVERRIDE; int event_flags) OVERRIDE;
virtual bool ItemSelected(const ui::Event& event) OVERRIDE; virtual bool ItemSelected(const ui::Event& event) OVERRIDE;
...@@ -44,6 +43,7 @@ class BrowserShortcutLauncherItemController : public LauncherItemController { ...@@ -44,6 +43,7 @@ class BrowserShortcutLauncherItemController : public LauncherItemController {
virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE; virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE; virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE; virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
private: private:
// Get the favicon for the browser list entry for |web_contents|. // Get the favicon for the browser list entry for |web_contents|.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/desktop_background/user_wallpaper_delegate.h" #include "ash/desktop_background/user_wallpaper_delegate.h"
#include "ash/metrics/user_metrics_recorder.h" #include "ash/metrics/user_metrics_recorder.h"
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/shelf/shelf_item_delegate.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/bind.h" #include "base/bind.h"
...@@ -42,7 +43,24 @@ LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, ...@@ -42,7 +43,24 @@ LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
controller_(controller), controller_(controller),
item_(*item), item_(*item),
shelf_alignment_menu_(root), shelf_alignment_menu_(root),
root_window_(root) { root_window_(root),
item_delegate_(NULL) {
DCHECK(item);
DCHECK(root_window_);
Init();
}
LauncherContextMenu::LauncherContextMenu(
ChromeLauncherController* controller,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item,
aura::Window* root)
: ui::SimpleMenuModel(NULL),
controller_(controller),
item_(*item),
shelf_alignment_menu_(root),
root_window_(root),
item_delegate_(item_delegate) {
DCHECK(item); DCHECK(item);
DCHECK(root_window_); DCHECK(root_window_);
Init(); Init();
...@@ -57,7 +75,8 @@ LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, ...@@ -57,7 +75,8 @@ LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller,
extension_items_(new extensions::ContextMenuMatcher( extension_items_(new extensions::ContextMenuMatcher(
controller->profile(), this, this, controller->profile(), this, this,
base::Bind(MenuItemHasLauncherContext))), base::Bind(MenuItemHasLauncherContext))),
root_window_(root) { root_window_(root),
item_delegate_(NULL) {
DCHECK(root_window_); DCHECK(root_window_);
Init(); Init();
} }
...@@ -120,6 +139,9 @@ void LauncherContextMenu::Init() { ...@@ -120,6 +139,9 @@ void LauncherContextMenu::Init() {
AddItem(MENU_NEW_INCOGNITO_WINDOW, AddItem(MENU_NEW_INCOGNITO_WINDOW,
l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW)); l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW));
} }
} else if (item_.type == ash::TYPE_DIALOG) {
AddItem(MENU_CLOSE,
l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE));
} else { } else {
if (item_.type == ash::TYPE_PLATFORM_APP) { if (item_.type == ash::TYPE_PLATFORM_APP) {
AddItem( AddItem(
...@@ -246,7 +268,13 @@ void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) { ...@@ -246,7 +268,13 @@ void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) {
controller_->Launch(item_.id, ui::EF_NONE); controller_->Launch(item_.id, ui::EF_NONE);
break; break;
case MENU_CLOSE: case MENU_CLOSE:
controller_->Close(item_.id); if (item_.type == ash::TYPE_DIALOG) {
DCHECK(item_delegate_);
item_delegate_->Close();
} else {
// TODO(simonhong): Use ShelfItemDelegate::Close().
controller_->Close(item_.id);
}
ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
ash::UMA_CLOSE_THROUGH_CONTEXT_MENU); ash::UMA_CLOSE_THROUGH_CONTEXT_MENU);
break; break;
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
class ChromeLauncherController; class ChromeLauncherController;
namespace ash {
class ShelfItemDelegate;
}
namespace aura { namespace aura {
class Window; class Window;
} }
...@@ -31,6 +35,13 @@ class LauncherContextMenu : public ui::SimpleMenuModel, ...@@ -31,6 +35,13 @@ class LauncherContextMenu : public ui::SimpleMenuModel,
LauncherContextMenu(ChromeLauncherController* controller, LauncherContextMenu(ChromeLauncherController* controller,
const ash::LauncherItem* item, const ash::LauncherItem* item,
aura::Window* root_window); aura::Window* root_window);
// Creates a menu used by item created by ShelfWindowWatcher.
LauncherContextMenu(ChromeLauncherController* controller,
ash::ShelfItemDelegate* item_delegate,
ash::LauncherItem* item,
aura::Window* root_window);
// Creates a menu used as a desktop context menu on |root_window|. // Creates a menu used as a desktop context menu on |root_window|.
LauncherContextMenu(ChromeLauncherController* controller, LauncherContextMenu(ChromeLauncherController* controller,
aura::Window* root_window); aura::Window* root_window);
...@@ -90,6 +101,9 @@ class LauncherContextMenu : public ui::SimpleMenuModel, ...@@ -90,6 +101,9 @@ class LauncherContextMenu : public ui::SimpleMenuModel,
aura::Window* root_window_; aura::Window* root_window_;
// Not owned.
ash::ShelfItemDelegate* item_delegate_;
DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu); DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu);
}; };
......
...@@ -78,9 +78,6 @@ class LauncherItemController : public ash::ShelfItemDelegate { ...@@ -78,9 +78,6 @@ class LauncherItemController : public ash::ShelfItemDelegate {
// Returns true when a new item got created. // Returns true when a new item got created.
virtual bool Activate(ash::LaunchSource source) = 0; virtual bool Activate(ash::LaunchSource source) = 0;
// Closes all windows associated with this item.
virtual void Close() = 0;
// Called to retrieve the list of running applications. // Called to retrieve the list of running applications.
virtual ChromeLauncherAppMenuItems GetApplicationList(int event_flags) = 0; virtual ChromeLauncherAppMenuItems GetApplicationList(int event_flags) = 0;
......
...@@ -59,7 +59,6 @@ class ShellWindowLauncherItemController : public LauncherItemController, ...@@ -59,7 +59,6 @@ class ShellWindowLauncherItemController : public LauncherItemController,
virtual bool IsVisible() const OVERRIDE; virtual bool IsVisible() const OVERRIDE;
virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE; virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE;
virtual bool Activate(ash::LaunchSource source) OVERRIDE; virtual bool Activate(ash::LaunchSource source) OVERRIDE;
virtual void Close() OVERRIDE;
virtual ChromeLauncherAppMenuItems GetApplicationList( virtual ChromeLauncherAppMenuItems GetApplicationList(
int event_flags) OVERRIDE; int event_flags) OVERRIDE;
virtual bool ItemSelected(const ui::Event& eent) OVERRIDE; virtual bool ItemSelected(const ui::Event& eent) OVERRIDE;
...@@ -68,6 +67,7 @@ class ShellWindowLauncherItemController : public LauncherItemController, ...@@ -68,6 +67,7 @@ class ShellWindowLauncherItemController : public LauncherItemController,
virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE; virtual ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) OVERRIDE;
virtual bool IsDraggable() OVERRIDE; virtual bool IsDraggable() OVERRIDE;
virtual bool ShouldShowTooltip() OVERRIDE; virtual bool ShouldShowTooltip() OVERRIDE;
virtual void Close() OVERRIDE;
// aura::WindowObserver overrides: // aura::WindowObserver overrides:
virtual void OnWindowPropertyChanged(aura::Window* window, virtual void OnWindowPropertyChanged(aura::Window* window,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment